@@ -38,9 +38,7 @@ public class MainViewModel extends ViewModel {
3838 private final IsAppInstalledUseCase isAppInstalledUseCase ;
3939 private final BuildShortcutIntentUseCase buildShortcutIntentUseCase ;
4040 private final GetAppUpdateManagerUseCase getAppUpdateManagerUseCase ;
41- private final MutableLiveData <Integer > bottomNavLabelVisibility = new MutableLiveData <>();
42- private final MutableLiveData <Integer > defaultNavDestination = new MutableLiveData <>();
43- private final MutableLiveData <Boolean > themeChanged = new MutableLiveData <>();
41+ private final MutableLiveData <MainUiState > uiState = new MutableLiveData <>();
4442
4543 @ Inject
4644 public MainViewModel (ApplyThemeSettingsUseCase applyThemeSettingsUseCase ,
@@ -63,8 +61,8 @@ public MainViewModel(ApplyThemeSettingsUseCase applyThemeSettingsUseCase,
6361 this .getAppUpdateManagerUseCase = getAppUpdateManagerUseCase ;
6462 }
6563
66- private static int getVisibilityMode (String labelVisibilityStr , String [] bottomNavBarLabelsValues ) {
67- int visibilityMode = NavigationBarView .LABEL_VISIBILITY_AUTO ;
64+ private static @ NavigationBarView . LabelVisibility int getVisibilityMode (String labelVisibilityStr , String [] bottomNavBarLabelsValues ) {
65+ @ NavigationBarView . LabelVisibility int visibilityMode = NavigationBarView .LABEL_VISIBILITY_AUTO ;
6866 if (labelVisibilityStr .equals (bottomNavBarLabelsValues [0 ])) {
6967 visibilityMode = NavigationBarView .LABEL_VISIBILITY_LABELED ;
7068 } else if (labelVisibilityStr .equals (bottomNavBarLabelsValues [1 ])) {
@@ -83,11 +81,9 @@ public void applySettings(String[] themeValues,
8381 String [] bottomNavBarLabelsValues ,
8482 String [] defaultTabValues ) {
8583 boolean changedTheme = applyThemeSettingsUseCase .invoke (themeValues );
86- themeChanged .setValue (changedTheme );
8784
8885 String labelVisibilityStr = getBottomNavLabelVisibilityUseCase .invoke ();
89- int visibilityMode = getVisibilityMode (labelVisibilityStr , bottomNavBarLabelsValues );
90- bottomNavLabelVisibility .setValue (visibilityMode );
86+ @ NavigationBarView .LabelVisibility int visibilityMode = getVisibilityMode (labelVisibilityStr , bottomNavBarLabelsValues );
9187
9288 String startFragmentIdValue = getDefaultTabPreferenceUseCase .invoke ();
9389 int startFragmentId ;
@@ -100,7 +96,8 @@ public void applySettings(String[] themeValues,
10096 } else {
10197 startFragmentId = R .id .navigation_home ;
10298 }
103- defaultNavDestination .setValue (startFragmentId );
99+
100+ uiState .setValue (new MainUiState (visibilityMode , startFragmentId , changedTheme ));
104101 applyLanguageSettingsUseCase .invoke ();
105102 }
106103
@@ -133,24 +130,10 @@ public Intent getShortcutIntent(boolean isInstalled) {
133130 }
134131
135132 /**
136- * Expose the bottom nav visibility as LiveData, so MainActivity can observe it.
137- */
138- public LiveData <Integer > getBottomNavVisibility () {
139- return bottomNavLabelVisibility ;
140- }
141-
142- /**
143- * Expose the default nav destination as LiveData, so MainActivity can observe it.
144- */
145- public LiveData <Integer > getDefaultNavDestination () {
146- return defaultNavDestination ;
147- }
148-
149- /**
150- * This tells the UI whether the theme changed so it can decide to recreate if necessary.
133+ * Expose the consolidated UI state so MainActivity can observe it.
151134 */
152- public LiveData <Boolean > getThemeChanged () {
153- return themeChanged ;
135+ public LiveData <MainUiState > getUiState () {
136+ return uiState ;
154137 }
155138
156139 /**
0 commit comments