diff --git a/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt b/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt index c8734e43845..1696cf74ca9 100644 --- a/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt +++ b/app/src/main/java/org/oppia/android/app/home/HomeViewModel.kt @@ -1,6 +1,7 @@ package org.oppia.android.app.home import androidx.appcompat.app.AppCompatActivity +import androidx.databinding.ObservableField import androidx.fragment.app.Fragment import androidx.lifecycle.LiveData import androidx.lifecycle.Transformations @@ -58,6 +59,15 @@ class HomeViewModel( R.integer.promoted_story_list_limit ) +/** + * A Boolean property indicating the visibility state of a progress bar. + * This property is used to control the visibility of a progress bar in a user interface. + * When set to true, the progress bar is made visible, indicating that an ongoing task + * or operation is in progress or pending or failed. When set to false, the progress bar is hidden, indicating + * that the operation has completed. + */ + val isProgressBarVisible = ObservableField(true) + private val profileDataProvider: DataProvider by lazy { profileManagementController.getProfile(profileId) } @@ -111,7 +121,10 @@ class HomeViewModel( listOf() } is AsyncResult.Pending -> listOf() - is AsyncResult.Success -> itemListResult.value + is AsyncResult.Success -> { + isProgressBarVisible.set(false) + itemListResult.value + } } } } diff --git a/app/src/main/res/layout/home_fragment.xml b/app/src/main/res/layout/home_fragment.xml index 80561b46581..d7dfe561d70 100644 --- a/app/src/main/res/layout/home_fragment.xml +++ b/app/src/main/res/layout/home_fragment.xml @@ -3,9 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> - - + @@ -17,6 +16,15 @@ android:background="@color/component_color_shared_screen_primary_background_color" android:gravity="center"> + + @color/color_palette_view_all_text_color @color/color_palette_layout_below_greeting_text_color + @color/color_palette_progress_bar_solid_color @color/color_palette_confetti_red_color @color/color_palette_confetti_yellow_color diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt index a0e79d44c34..8e7bf121487 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt @@ -246,6 +246,33 @@ class HomeActivityTest { assertThat(screenName).isEqualTo(ScreenName.HOME_ACTIVITY) } + @Test + fun testHomeActivity_loadingItemsPending_progressbarIsDisplayed() { + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME) + launch(createHomeActivityIntent(internalProfileId)).use { + onView(withId(R.id.home_fragment_progress_bar)).check( + matches( + isDisplayed() + ) + ) + } + } + + @Test + fun testHomeActivity_loadingItemsSuccess_checkProgressbarIsNotDisplayed() { + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_FIXED_FAKE_TIME) + launch(createHomeActivityIntent(internalProfileId)).use { + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.home_fragment_progress_bar)).check( + matches( + not( + isDisplayed() + ) + ) + ) + } + } + @Test fun testHomeActivity_hasCorrectActivityLabel() { launch(HomeActivity::class.java).use { scenario ->