Changes to icon picker for reusability in "add mode" flow

* Don't finish the fragment from the controller (ugh!) instead just report the selected icon via a listener.
* Highlight the selected icon in the list.
* Cache the icon drawables (since we're using selectors for the colors, we don't need to swap them, one per icon resource id is enough).
* Improved the tests a bit too.

Bug: 333901673
Bug: 326442408
Test: ates
Flag: android.app.modes_ui
Change-Id: Ib2ec7a7e3ed99b13f9264aa6f7c209ee3f6967a0
This commit is contained in:
Matías Hernández
2024-06-25 20:29:14 +02:00
parent 67d977b72e
commit c2d2de085d
9 changed files with 190 additions and 67 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.notification.modes;
import static android.provider.Settings.EXTRA_AUTOMATIC_ZEN_RULE_ID;
import android.app.AutomaticZenRule;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
@@ -34,7 +33,10 @@ import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.notification.modes.ZenMode;
import com.google.common.base.Preconditions;
import java.util.List;
import java.util.function.Consumer;
/**
* Base class for Settings pages used to configure individual modes.
@@ -175,14 +177,15 @@ abstract class ZenModeFragmentBase extends ZenModesFragmentBase {
return mZenMode;
}
/**
* Get AutomaticZenRule associated with current mode data, or null if it doesn't exist.
*/
@Nullable
public AutomaticZenRule getAZR() {
if (mZenMode == null) {
return null;
protected final boolean saveMode(Consumer<ZenMode> updater) {
Preconditions.checkState(mBackend != null);
ZenMode mode = mZenMode;
if (mode == null) {
Log.wtf(TAG, "Cannot save mode, it hasn't been loaded (" + getClass() + ")");
return false;
}
return mZenMode.getRule();
updater.accept(mode);
mBackend.updateMode(mode);
return true;
}
}