• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification.modes;
18 
19 import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;
20 
21 import android.app.settings.SettingsEnums;
22 import android.os.Bundle;
23 import android.util.Log;
24 
25 import androidx.annotation.Nullable;
26 
27 import com.android.settings.R;
28 import com.android.settingslib.notification.modes.ZenMode;
29 
30 public class ZenModeEditNameIconFragment extends ZenModeEditNameIconFragmentBase {
31 
32     @Nullable
33     @Override
onCreateInstantiateZenMode()34     protected ZenMode onCreateInstantiateZenMode() {
35         String modeId = getModeIdFromArguments();
36         return modeId != null ? requireBackend().getMode(modeId) : null;
37     }
38 
39     @Override
onStart()40     public void onStart() {
41         super.onStart();
42         requireActivity().setTitle(R.string.zen_mode_rename_title);
43     }
44 
45     @Override
saveMode(ZenMode mode)46     void saveMode(ZenMode mode) {
47         String modeId = getModeIdFromArguments();
48         ZenMode modeToUpdate = modeId != null ? requireBackend().getMode(modeId) : null;
49         if (modeToUpdate == null) {
50             // Huh, maybe it was deleted while we were choosing the icon? Unusual...
51             Log.w(getLogTag(), "Couldn't fetch mode with id " + modeId
52                     + " from the backend for saving. Discarding changes!");
53             finish();
54             return;
55         }
56 
57         modeToUpdate.setName(mode.getName());
58         modeToUpdate.setIconResId(mode.getIconResId());
59         requireBackend().updateMode(modeToUpdate);
60         finish();
61     }
62 
63     @Nullable
getModeIdFromArguments()64     private String getModeIdFromArguments() {
65         Bundle bundle = getArguments();
66         if (bundle != null && bundle.containsKey(EXTRA_AUTOMATIC_ZEN_RULE_ID)) {
67             return bundle.getString(EXTRA_AUTOMATIC_ZEN_RULE_ID);
68         } else {
69             return null;
70         }
71     }
72 
73     @Override
getMetricsCategory()74     public int getMetricsCategory() {
75         return SettingsEnums.ZEN_MODE_EDIT_NAME_ICON;
76     }
77 
78     @Override
getLogTag()79     protected String getLogTag() {
80         return "ZenModeEditNameIconFragment";
81     }
82 }
83