@@ -29,6 +29,8 @@ public class HomeViewModel extends ViewModel {
2929 private final GetAppPlayStoreUrlUseCase getAppPlayStoreUrlUseCase ;
3030
3131 private final MutableLiveData <HomeUiState > uiState = new MutableLiveData <>();
32+ private final MutableLiveData <String > searchQuery = new MutableLiveData <>("" );
33+ private List <PromotedApp > allPromotedApps = new ArrayList <>();
3234
3335 @ Inject
3436 public HomeViewModel (GetDailyTipUseCase getDailyTipUseCase ,
@@ -59,18 +61,8 @@ public HomeViewModel(GetDailyTipUseCase getDailyTipUseCase,
5961 result .add (apps .get ((startIndex + i ) % apps .size ()));
6062 }
6163 }
62- HomeUiState current = uiState .getValue ();
63- if (current == null ) {
64- current = new HomeUiState ("" , "" , "" , result );
65- } else {
66- current = new HomeUiState (
67- current .announcementTitle (),
68- current .announcementSubtitle (),
69- current .dailyTip (),
70- result
71- );
72- }
73- uiState .postValue (current );
64+ allPromotedApps = result ;
65+ filterPromotedApps ();
7466 });
7567 }
7668
@@ -84,6 +76,34 @@ public void setAnnouncements(String title, String subtitle) {
8476 uiState .setValue (current );
8577 }
8678
79+ public void setSearchQuery (String query ) {
80+ searchQuery .setValue (query );
81+ filterPromotedApps ();
82+ }
83+
84+ private void filterPromotedApps () {
85+ String query = searchQuery .getValue ();
86+ List <PromotedApp > filtered = new ArrayList <>();
87+ for (PromotedApp app : allPromotedApps ) {
88+ if (query == null || query .isEmpty () ||
89+ app .name ().toLowerCase ().contains (query .toLowerCase ())) {
90+ filtered .add (app );
91+ }
92+ }
93+ HomeUiState current = uiState .getValue ();
94+ if (current == null ) {
95+ current = new HomeUiState ("" , "" , getDailyTipUseCase .invoke (), filtered );
96+ } else {
97+ current = new HomeUiState (
98+ current .announcementTitle (),
99+ current .announcementSubtitle (),
100+ current .dailyTip (),
101+ filtered
102+ );
103+ }
104+ uiState .postValue (current );
105+ }
106+
87107 /**
88108 * Exposes the UI state for the Home screen.
89109 */
0 commit comments