Follow-up improvements to zen mode icon picker

* Propose icons from com.android.internal.R instead of android.R (as a proof of concept) since this is what we'll be doing with the final icons.
* Provide the icon options as a parameter to the controller (can also be used for testing).
* Fix some Lint warnings.

Test: atest ZenModeIconPickerListPreferenceControllerTest
Bug: 333901673
Flag: android.app.modes_ui
Change-Id: I023eed0fd5719c5c4540f8d145335f60d088e7fb
This commit is contained in:
Matías Hernández
2024-06-12 19:33:12 +02:00
parent 98a5dbfb42
commit 37bdf39ad6
6 changed files with 104 additions and 38 deletions

View File

@@ -34,6 +34,8 @@ import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.widget.LayoutPreference;
import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,7 +63,8 @@ public class ZenModeIconPickerListPreferenceControllerTest {
DashboardFragment fragment = mock(DashboardFragment.class);
mController = new ZenModeIconPickerListPreferenceController(
RuntimeEnvironment.getApplication(), "icon_list", fragment, mBackend);
RuntimeEnvironment.getApplication(), "icon_list", fragment,
new TestIconOptionsProvider(), mBackend);
mRecyclerView = new RecyclerView(context);
mRecyclerView.setId(R.id.icon_list);
@@ -75,7 +78,7 @@ public class ZenModeIconPickerListPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen);
assertThat(mRecyclerView.getAdapter()).isNotNull();
assertThat(mRecyclerView.getAdapter().getItemCount()).isEqualTo(20);
assertThat(mRecyclerView.getAdapter().getItemCount()).isEqualTo(3);
}
@Test
@@ -88,4 +91,15 @@ public class ZenModeIconPickerListPreferenceControllerTest {
verify(mBackend).updateMode(captor.capture());
assertThat(captor.getValue().getRule().getIconResId()).isEqualTo(R.drawable.ic_android);
}
private static class TestIconOptionsProvider implements IconOptionsProvider {
@Override
public ImmutableList<IconInfo> getIcons() {
return ImmutableList.of(
new IconInfo(R.drawable.ic_android, "android"),
new IconInfo(R.drawable.ic_info, "info"),
new IconInfo(R.drawable.ic_hearing, "hearing"));
}
}
}