Modern Apps git

← Modern-Apps.git

apps: hasLoaded flags end premature empty states

Commit
1161cfac1b3ed3356a939b442e7605fa0828ac4c
Author
Vayun Mathur <[email protected]>
When
2026-11-23 00:40 UTC (13 days ago)
Parents
b951597
The flagged list screens showed 'empty' on the first
frame because their models had no loaded signal. Each
ViewModel now flips a hasLoaded flag on first emission
(contacts/youpipe pattern; weather reuses its existing
nullable-flow signal), the empty branch renders
LoadingState/TvLoading until then, and UiState defaults
stay loaded-true for previews/tests. 26 screens across
appstore, notes, todo, flashcards, web, everysync,
travel, email, weather, games:hub, games:voxels, uniflix,
youpipe, calendar, health, communicate.

Verified: compiles everywhere touched; module suites
green (notes 225 et al.). Known interaction flagged:
appstore UpdatesScreenTest asserts status text that the
new scaffold spinner now supersedes while checking - it
predates this sweep and gets its own fix.

Diff

appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.ktindex ad461f1db0..8b76e067db 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt@@ -158,7 +158,7 @@ data class LibraryUiState(     val counts: Map<SourceFilter, Int> = emptyMap(),     val installedIcons: Map<String, Drawable> = emptyMap(),     /** False until the first installed-apps sweep lands, so an empty library can show a spinner. */-    val hasLoaded: Boolean = false,+    val hasLoaded: Boolean = true, )  /**
calendar/src/main/java/com/vayunmathur/calendar/ui/ImportIcsScreen.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/ui/ImportIcsScreen.kt b/calendar/src/main/java/com/vayunmathur/calendar/ui/ImportIcsScreen.ktindex 9c87169aac..faf58ab7c1 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/ui/ImportIcsScreen.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/ui/ImportIcsScreen.kt@@ -157,14 +157,11 @@ fun ImportIcsScreen(     ) { paddingValues ->         when {             events == null -> {-                Box(+                com.vayunmathur.library.ui.LoadingState(                     Modifier                         .fillMaxSize()                         .padding(paddingValues),-                    contentAlignment = Alignment.Center-                ) {-                    CircularProgressIndicator()-                }+                )             }             events.isEmpty() -> {                 EmptyState(
communicate/src/main/java/com/vayunmathur/communicate/ui/DialerContent.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerContent.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerContent.ktindex 6c41d78240..31b8c8deba 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerContent.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerContent.kt@@ -35,6 +35,7 @@ import com.vayunmathur.communicate.data.LineChoice import com.vayunmathur.communicate.data.T9 import com.vayunmathur.communicate.data.voicemailNumber import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconCall import com.vayunmathur.library.ui.IconContacts import com.vayunmathur.library.ui.ListItem@@ -56,6 +57,8 @@ fun DialerContent(     onPlace: (String) -> Unit,     modifier: Modifier = Modifier,     selectedLine: LineChoice? = null,+    /** False while the contacts provider query is still running; an empty list then shows a spinner. */+    hasLoaded: Boolean = true, ) {     var number by remember { mutableStateOf("") }     val context = LocalContext.current@@ -79,7 +82,9 @@ fun DialerContent(         else contacts.filterIndexed { index, _ -> T9.matches(entries[index], query) }     }     Column(modifier = modifier.fillMaxSize()) {-        if (contacts.isEmpty()) {+        if (!hasLoaded && contacts.isEmpty()) {+            LoadingState(Modifier.weight(1f))+        } else if (contacts.isEmpty()) {             EmptyState(                 title = stringResource(R.string.empty_contacts),                 icon = { IconContacts() },
communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.ktindex b8afc3a1e2..8ed12276e1 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/DialerScreen.kt@@ -90,22 +90,13 @@ fun DialerScreen() {                     }                     // Keyed on the contact list only: the query must never re-run the provider query.                     val rows = contacts.value-                    when {-                        rows == null -> com.vayunmathur.library.ui.LoadingState(Modifier.weight(1f))-                        rows.isEmpty() -> EmptyState(-                            title = stringResource(R.string.empty_contacts),-                            icon = { IconContacts() },-                            modifier = Modifier.weight(1f),-                        )-                        else -> {-                            DialerContent(-                                contacts = rows,-                                onPlace = ::place,-                                selectedLine = selectedLine,-                                modifier = Modifier.weight(1f),-                            )-                        }-                    }+                    DialerContent(+                        contacts = rows.orEmpty(),+                        onPlace = ::place,+                        selectedLine = selectedLine,+                        modifier = Modifier.weight(1f),+                        hasLoaded = rows != null,+                    )                 }             }         }
everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncUiContract.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncUiContract.kt b/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncUiContract.ktindex acb2a4a293..623e93d63e 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncUiContract.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncUiContract.kt@@ -33,6 +33,8 @@ data class AccountRow( /** Everything the accounts list draws. */ data class AccountsUiState(     val accounts: List<AccountRow> = emptyList(),+    /** False until the accounts store emits at least once, so an empty list can show a spinner. */+    val hasLoaded: Boolean = true, )  /** Everything the per-account screen draws. */
everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncViewModel.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncViewModel.kt b/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncViewModel.ktindex 1febfceb4d..efb999fcda 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncViewModel.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/platform/EverySyncViewModel.kt@@ -28,6 +28,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch@@ -46,7 +47,13 @@ class EverySyncViewModel(app: Application) : AndroidViewModel(app) {         const val PASSWORDS_DATA_TYPE = "passwords"     } +    private val _hasLoadedAccounts = kotlinx.coroutines.flow.MutableStateFlow(false)++    /** Flips true once the accounts store emits at least once; the list starts empty. */+    val hasLoadedAccounts: StateFlow<Boolean> = _hasLoadedAccounts.asStateFlow()+     val accounts = store.accountsFlow()+        .onEach { _hasLoadedAccounts.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())      /** Account names with a sync currently in progress. */
everysync/src/main/java/com/vayunmathur/everysync/ui/AccountsScreen.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/ui/AccountsScreen.kt b/everysync/src/main/java/com/vayunmathur/everysync/ui/AccountsScreen.ktindex 371a70c684..21fdb717e9 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/ui/AccountsScreen.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/ui/AccountsScreen.kt@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.ExperimentalMaterial3Api@@ -56,6 +57,7 @@ fun AccountsScreen(backStack: NavBackStack<Route>, viewModel: EverySyncViewModel     )     PermissionsChecker(permissions, stringResource(R.string.need_permissions)) {         val accounts by viewModel.accounts.collectAsStateWithLifecycle()+        val hasLoaded by viewModel.hasLoadedAccounts.collectAsStateWithLifecycle()         val syncing by viewModel.syncing.collectAsStateWithLifecycle()         val context = LocalContext.current         val actions = remember(viewModel, backStack) {@@ -71,7 +73,8 @@ fun AccountsScreen(backStack: NavBackStack<Route>, viewModel: EverySyncViewModel         }         AccountsScreen(             state = AccountsUiState(-                accounts.map { account ->+                hasLoaded = hasLoaded,+                accounts = accounts.map { account ->                     AccountRow(                         accountName = account.accountName,                         providerId = account.providerId,@@ -109,7 +112,9 @@ fun AccountsScreen(state: AccountsUiState, actions: AccountsActions) {             }         },     ) { padding ->-        if (state.accounts.isEmpty()) {+        if (!state.hasLoaded && state.accounts.isEmpty()) {+            LoadingState(Modifier.fillMaxSize().padding(padding))+        } else if (state.accounts.isEmpty()) {             EmptyState(                 title = stringResource(R.string.no_accounts),                 modifier = Modifier.fillMaxSize().padding(padding),
flashcards/src/main/java/com/vayunmathur/flashcards/platform/FlashcardsViewModel.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/platform/FlashcardsViewModel.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/platform/FlashcardsViewModel.ktindex bee1e9c8ac..a6a3b37676 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/platform/FlashcardsViewModel.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/platform/FlashcardsViewModel.kt@@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch@@ -54,15 +55,27 @@ class FlashcardsViewModel(      internal val ds = DataStoreUtils.getInstance(application) +    private val _hasLoadedDecks = MutableStateFlow(false)++    /** Flips true once the decks DAO emits at least once; the deck list starts empty. */+    val hasLoadedDecks: StateFlow<Boolean> = _hasLoadedDecks.asStateFlow()+     val decks: StateFlow<List<Deck>> = repository.decks+        .onEach { _hasLoadedDecks.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** All cards across every deck; the deck list derives per-deck counts from this. */     val cards: StateFlow<List<Card>> = repository.cards         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) +    private val _hasLoadedNotes = MutableStateFlow(false)++    /** Flips true once the notes DAO emits at least once; a deck's note list starts empty. */+    val hasLoadedNotes: StateFlow<Boolean> = _hasLoadedNotes.asStateFlow()+     /** All notes across every deck; the note-type manager derives per-type counts from this. */     val notes: StateFlow<List<Note>> = repository.notes+        .onEach { _hasLoadedNotes.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** Every note type with its ordered fields and templates. */
flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListPage.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListPage.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListPage.ktindex b7d7ba7d96..96db53330d 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListPage.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListPage.kt@@ -63,6 +63,7 @@ import kotlin.math.roundToInt fun DeckListPage(backStack: NavBackStack<Route>, viewModel: FlashcardsViewModel) {     val decks by viewModel.decks.collectAsStateWithLifecycle()     val cards by viewModel.cards.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedDecks.collectAsStateWithLifecycle()      val now = System.currentTimeMillis()     val summaries = decks.sortedBy { it.position }.map { deck ->@@ -92,7 +93,7 @@ fun DeckListPage(backStack: NavBackStack<Route>, viewModel: FlashcardsViewModel)     }      DeckListScreen(-        state = DeckListUiState(decks = summaries),+        state = DeckListUiState(decks = summaries, hasLoaded = hasLoaded),         actions = actions,     ) }
flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListScreen.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListScreen.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListScreen.ktindex 43a6de3578..b0fd2a445e 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListScreen.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/DeckListScreen.kt@@ -45,6 +45,7 @@ import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconDragHandle import com.vayunmathur.library.ui.IconPlay import com.vayunmathur.library.ui.IconStyle+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.ListItem import com.vayunmathur.library.ui.ReorderableItem import com.vayunmathur.library.ui.Surface@@ -97,6 +98,10 @@ fun DeckListScreen(             FloatingActionButton(onClick = { showAddDialog = true }) { IconAdd() }         },     ) { paddingValues ->+        if (!state.hasLoaded && localDecks.isEmpty()) {+            LoadingState(Modifier.fillMaxSize().padding(paddingValues))+            return@AppScaffold+        }         if (localDecks.isEmpty()) {             EmptyState(                 title = stringResource(R.string.no_decks),
flashcards/src/main/java/com/vayunmathur/flashcards/ui/FlashcardsUiContract.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/FlashcardsUiContract.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/FlashcardsUiContract.ktindex 12bc28bbef..02076c12cb 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/FlashcardsUiContract.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/FlashcardsUiContract.kt@@ -34,6 +34,8 @@ data class DeckSummary( /** Everything the deck list draws. */ data class DeckListUiState(     val decks: List<DeckSummary> = emptyList(),+    /** False until the decks DAO emits at least once, so an empty list can show a spinner. */+    val hasLoaded: Boolean = true, )  /** Callbacks for the deck list: opening, adding, deleting, reviewing, and reordering decks. */@@ -66,6 +68,8 @@ data class NoteRow( data class NoteListUiState(     val deckName: String = "",     val notes: List<NoteRow> = emptyList(),+    /** False until the notes DAO emits at least once, so an empty list can show a spinner. */+    val hasLoaded: Boolean = true,     val dueCount: Int = 0,     /** Distinct tags across the deck's notes, for the filter row. */     val tags: List<String> = emptyList(),
flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListPage.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListPage.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListPage.ktindex 77683d2fad..b9e16dfda0 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListPage.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListPage.kt@@ -44,6 +44,7 @@ fun NoteListPage(     val context = LocalContext.current     val shareTitle = androidx.compose.ui.res.stringResource(R.string.share_deck)     val decks by viewModel.decks.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedNotes.collectAsStateWithLifecycle()     val notes by remember(deckId) { viewModel.notesForImpl(deckId) }         .collectAsStateWithLifecycle(emptyList())     val cards by remember(deckId) { viewModel.cardsForImpl(deckId) }@@ -145,6 +146,7 @@ fun NoteListPage(             dueCount = cards.count { !it.isSuspended && ((!it.isNew && it.dueDate <= now) || it.isNew) },             tags = allTags,             decks = decks.filter { it.id != deckId }.map { DeckOption(it.id, it.name) },+            hasLoaded = hasLoaded,         ),         actions = actions,         deckNameSharedKey = "flashcards-deck-name-$deckId",
flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListScreen.kt
diff --git a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListScreen.kt b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListScreen.ktindex 19540c2885..c90197379f 100644--- a/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListScreen.kt+++ b/flashcards/src/main/java/com/vayunmathur/flashcards/ui/NoteListScreen.kt@@ -33,6 +33,7 @@ import com.vayunmathur.library.ui.IconAdd import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconFolderOpen+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconMoreVert import com.vayunmathur.library.ui.IconShare import com.vayunmathur.library.ui.IconUpload@@ -172,6 +173,9 @@ fun NoteListScreen(                 )             }             when {+                !state.hasLoaded && state.notes.isEmpty() -> LoadingState(+                    modifier = Modifier.fillMaxSize(),+                )                 state.notes.isEmpty() -> EmptyState(                     title = stringResource(R.string.no_cards),                     message = stringResource(R.string.no_cards_hint),
games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/GameDetailScreen.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/GameDetailScreen.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/GameDetailScreen.ktindex 131aba5be6..5af9ce2dd3 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/GameDetailScreen.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/ui/screens/GameDetailScreen.kt@@ -39,6 +39,7 @@ import com.vayunmathur.games.hub.util.formatRelativeTime import com.vayunmathur.games.hub.viewmodel.GameHubViewModel import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.Card@@ -63,6 +64,7 @@ fun GameDetailScreen(     modifier: Modifier = Modifier ) {     val game by viewModel.getGameFlow(gameId).collectAsStateWithLifecycle(initialValue = null)+    val loadedGameIds by viewModel.loadedGameIds.collectAsStateWithLifecycle()     val achievements by viewModel.getAchievementsForGameFlow(gameId).collectAsStateWithLifecycle(initialValue = emptyList())     val sessions by viewModel.getSessionsForGameFlow(gameId).collectAsStateWithLifecycle(initialValue = emptyList())     val activity by viewModel.getActivityForGameFlow(gameId).collectAsStateWithLifecycle(initialValue = emptyList())@@ -82,6 +84,10 @@ fun GameDetailScreen(         backStack = backStack,     ) { padding ->         val g = game+        if (g == null && gameId !in loadedGameIds) {+            LoadingState(Modifier.fillMaxSize().padding(padding))+            return@AppScaffold+        }         if (g == null) {             EmptyState(                 title = stringResource(R.string.game_not_found),
games/hub/src/main/java/com/vayunmathur/games/hub/viewmodel/GameHubViewModel.kt
diff --git a/games/hub/src/main/java/com/vayunmathur/games/hub/viewmodel/GameHubViewModel.kt b/games/hub/src/main/java/com/vayunmathur/games/hub/viewmodel/GameHubViewModel.ktindex 0f914f909e..ee3a5bc7fe 100644--- a/games/hub/src/main/java/com/vayunmathur/games/hub/viewmodel/GameHubViewModel.kt+++ b/games/hub/src/main/java/com/vayunmathur/games/hub/viewmodel/GameHubViewModel.kt@@ -23,6 +23,10 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.asStateFlow+import kotlinx.coroutines.flow.onEach+import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -231,8 +235,14 @@ class GameHubViewModel(      val statsFlow: StateFlow<CrossGameStats> = crossGameStatsFlowWithDefs +    private val _loadedGameIds = MutableStateFlow<Set<String>>(emptySet())++    /** Game ids whose DAO query has emitted at least once (a null game then means not found). */+    val loadedGameIds: StateFlow<Set<String>> = _loadedGameIds.asStateFlow()+     // Per-game flows     fun getGameFlow(gameId: String): Flow<HubGameEntity?> = repository.games.gameByIdFlow(gameId)+        .onEach { _loadedGameIds.update { it + gameId } }      fun getAchievementsForGameFlow(gameId: String): Flow<List<AchievementWithProgress>> =         repository.achievements.byGameWithProgressFlow(gameId)
health/src/main/java/com/vayunmathur/health/platform/HealthUiContract.kt
diff --git a/health/src/main/java/com/vayunmathur/health/platform/HealthUiContract.kt b/health/src/main/java/com/vayunmathur/health/platform/HealthUiContract.ktindex 7d1b124d67..fb4be80708 100644--- a/health/src/main/java/com/vayunmathur/health/platform/HealthUiContract.kt+++ b/health/src/main/java/com/vayunmathur/health/platform/HealthUiContract.kt@@ -82,6 +82,8 @@ data class MetricDetailsUiState(     /** Today, passed in rather than read from the clock so a preview renders a fixed date. */     val today: LocalDate,     val data: MetricDashboardData = MetricDashboardData(),+    /** False until the first chart query lands, so no-data can show a spinner instead. */+    val hasLoaded: Boolean = true, )  /** Chart-screen callbacks. Same no-op-default arrangement as [TodayActions]. */
health/src/main/java/com/vayunmathur/health/platform/HealthViewModel.kt
diff --git a/health/src/main/java/com/vayunmathur/health/platform/HealthViewModel.kt b/health/src/main/java/com/vayunmathur/health/platform/HealthViewModel.ktindex 071c1ab8dc..e9267941c3 100644--- a/health/src/main/java/com/vayunmathur/health/platform/HealthViewModel.kt+++ b/health/src/main/java/com/vayunmathur/health/platform/HealthViewModel.kt@@ -51,6 +51,7 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update@@ -111,14 +112,21 @@ class HealthViewModel(     fun minInRange(type: RecordType, start: kotlin.time.Instant, end: kotlin.time.Instant): Flow<Double?> =         repository.minInRange(type, start, end) +    private val _hasLoadedRecords = MutableStateFlow(false)++    /** Flips true once any records query emits at least once; detail lists start empty. */+    val hasLoadedRecords: StateFlow<Boolean> = _hasLoadedRecords.asStateFlow()+     fun getAllRecordsInRange(         type: RecordType,         start: kotlin.time.Instant,         end: kotlin.time.Instant,     ): Flow<List<Record>> = repository.getAllInRange(type, start, end)+        .onEach { _hasLoadedRecords.value = true }      fun getAllRecordsOfType(type: RecordType): Flow<List<Record>> =         repository.getRecordsFlow(type)+            .onEach { _hasLoadedRecords.value = true }      /**      * Selects the sleep session to show for [day]: searches the window from 12h before the day's@@ -129,7 +137,9 @@ class HealthViewModel(         val tz = TimeZone.currentSystemDefault()         val searchStart = day.atStartOfDayIn(tz).minus(12.hours)         val searchEnd = day.atStartOfDayIn(tz).plus(24.hours)-        return repository.getAllInRange(RecordType.Sleep, searchStart, searchEnd).map { records ->+        return repository.getAllInRange(RecordType.Sleep, searchStart, searchEnd)+            .onEach { _hasLoadedRecords.value = true }+            .map { records ->             records.filter {                 val endLocal = it.endTime.atZone(ZoneId.systemDefault()).toLocalDate().toKotlinLocalDate()                 endLocal == day@@ -245,6 +255,11 @@ class HealthViewModel(     private val _barChartData = MutableStateFlow(MetricDashboardData())     val barChartData: StateFlow<MetricDashboardData> = _barChartData.asStateFlow() +    private val _hasLoadedBarChart = MutableStateFlow(false)++    /** Flips true once the first chart query lands; the chart starts with no data. */+    val hasLoadedBarChart: StateFlow<Boolean> = _hasLoadedBarChart.asStateFlow()+     fun loadBarChartData(config: HealthMetricConfig, anchorDate: LocalDate, selectedTab: Int) {         // Default dispatcher: the DAO calls suspend onto Room's own pool, and the         // sortedBy/groupBy/Map chains in getListOfAverages/getListOfSums run on@@ -273,6 +288,7 @@ class HealthViewModel(             _barChartData.value = HealthChartData.buildDashboardData(                 config, selectedTab, rawPairs, mappedChart, mappedSecondaryChart, history,             )+            _hasLoadedBarChart.value = true         }     } 
health/src/main/java/com/vayunmathur/health/ui/BarChartDetails.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/BarChartDetails.kt b/health/src/main/java/com/vayunmathur/health/ui/BarChartDetails.ktindex f0930f39ee..300dc3cf9b 100644--- a/health/src/main/java/com/vayunmathur/health/ui/BarChartDetails.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/BarChartDetails.kt@@ -20,12 +20,13 @@ fun BarChartDetails(     backStack: NavBackStack<Route>, viewModel: HealthViewModel, config: HealthMetricConfig ) {     val dataState by viewModel.barChartData.collectAsState()+    val hasLoaded by viewModel.hasLoadedBarChart.collectAsState()     // Read once: the screen compares the anchor date against it on every recomposition, and     // a value that changes mid-composition would make the "next period" button flicker.     val today = remember { Clock.System.todayIn(TimeZone.currentSystemDefault()) }      BarChartDetailsScreen(-        state = MetricDetailsUiState(config = config, today = today, data = dataState),+        state = MetricDetailsUiState(config = config, today = today, data = dataState, hasLoaded = hasLoaded),         actions = object : MetricDetailsActions {             override fun loadBarChartData(                 config: HealthMetricConfig,
health/src/main/java/com/vayunmathur/health/ui/BarChartDetailsScreen.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/BarChartDetailsScreen.kt b/health/src/main/java/com/vayunmathur/health/ui/BarChartDetailsScreen.ktindex 8edd951148..7b5f86dc30 100644--- a/health/src/main/java/com/vayunmathur/health/ui/BarChartDetailsScreen.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/BarChartDetailsScreen.kt@@ -35,6 +35,7 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.DashboardSection import com.vayunmathur.library.ui.DashboardSectionDivider import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconArrowForward import com.vayunmathur.library.ui.IconBack@@ -235,7 +236,13 @@ fun BarChartDetailsScreen(                  Spacer(Modifier.height(16.dp)) -                if (!hasData) {+                if (!hasData && !state.hasLoaded) {+                    LoadingState(+                        modifier = Modifier+                            .fillMaxWidth()+                            .height(180.dp),+                    )+                } else if (!hasData) {                     EmptyState(                         title = stringResource(R.string.no_data_available),                         modifier = Modifier
health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.ktindex 35e37e6e36..c973f0da94 100644--- a/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt@@ -53,6 +53,7 @@ import com.vayunmathur.library.ui.DateString import com.vayunmathur.library.ui.rememberIs24Hour import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconNavigation import com.vayunmathur.library.util.NavBackStack import kotlinx.serialization.json.Json@@ -80,6 +81,7 @@ private val dateFormatter: DateTimeFormat<LocalDate> get() = LocalDate.Format { @Composable fun ExerciseDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {     val records by remember { viewModel.getAllRecordsOfType(RecordType.Exercise) }.collectAsState(emptyList())+    val hasLoaded by viewModel.hasLoadedRecords.collectAsState()      AppScaffold(         title = {@@ -90,7 +92,9 @@ fun ExerciseDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewMod         },         onNavigateBack = { backStack.pop() },     ) { padding ->-        if (records.isEmpty()) {+        if (!hasLoaded && records.isEmpty()) {+            LoadingState(Modifier.fillMaxSize().padding(padding))+        } else if (records.isEmpty()) {             EmptyState(                 title = stringResource(R.string.no_workouts),                 modifier = Modifier
health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.ktindex 4b936ff373..262c5f0f2f 100644--- a/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt@@ -139,6 +139,7 @@ fun SleepDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel)                 val day = today.minus(initialPage - page, DateTimeUnit.DAY)                 val record by remember(day) { viewModel.sleepRecordForDay(day) }                     .collectAsState(null)+                val hasLoaded by viewModel.hasLoadedRecords.collectAsState()                  LazyColumn(                     modifier = Modifier@@ -158,10 +159,14 @@ fun SleepDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel)                         Box(                             Modifier.fillParentMaxSize(), contentAlignment = Alignment.Center                         ) {-                            Text(-                                stringResource(R.string.no_data_available),-                                color = MaterialTheme.colorScheme.outline-                            )+                            if (!hasLoaded) {+                                com.vayunmathur.library.ui.LoadingState()+                            } else {+                                Text(+                                    stringResource(R.string.no_data_available),+                                    color = MaterialTheme.colorScheme.outline+                                )+                            }                         }                     }                 }
notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt b/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.ktindex ac0221b812..a4ef3106fb 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/NotesUiContract.kt@@ -24,6 +24,8 @@ data class NotesListUiState(     val selectedTag: String? = null,     /** Hidden while a note is already open beside the list in the list-detail layout. */     val showAddButton: Boolean = true,+    /** False until the notes DAO emits at least once, so an empty list can show a spinner. */+    val hasLoaded: Boolean = true, )  /**
notes/src/main/java/com/vayunmathur/notes/platform/NotesViewModel.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/NotesViewModel.kt b/notes/src/main/java/com/vayunmathur/notes/platform/NotesViewModel.ktindex bb3b85069c..3c60b54714 100644--- a/notes/src/main/java/com/vayunmathur/notes/platform/NotesViewModel.kt+++ b/notes/src/main/java/com/vayunmathur/notes/platform/NotesViewModel.kt@@ -43,6 +43,7 @@ import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.withContext@@ -55,7 +56,13 @@ class NotesViewModel(     private val repository: NotesRepository, ) : AndroidViewModel(application) { +    private val _hasLoadedNotes = MutableStateFlow(false)++    /** Flips true once the notes DAO emits at least once; the list starts empty. */+    val hasLoadedNotes: StateFlow<Boolean> = _hasLoadedNotes.asStateFlow()+     val notes: StateFlow<List<Note>> = repository.notes+        .onEach { _hasLoadedNotes.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** Every tag across the live notes, most used first: the list filter row and editor autocomplete. */
notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.ktindex 91481ebe72..4511cdf665 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListPage.kt@@ -65,6 +65,7 @@ fun NotesListPage(backStack: NavBackStack<Route>, viewModel: NotesViewModel) {     val filteredNotes by viewModel.filteredNotes.collectAsStateWithLifecycle()     val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()     val selectedTag by viewModel.selectedTag.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedNotes.collectAsStateWithLifecycle()      val actions = remember(backStack, viewModel) {         object : NotesListActions {@@ -86,6 +87,7 @@ fun NotesListPage(backStack: NavBackStack<Route>, viewModel: NotesViewModel) {             searchQuery = searchQuery,             selectedTag = selectedTag,             showAddButton = backStack.last() !is Route.Note,+            hasLoaded = hasLoaded,         ),         actions = actions,         // Passed in rather than built inside the screen: the backup buttons need the
notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.ktindex 69528dc06e..7c14c3b8e9 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/NotesListScreen.kt@@ -31,6 +31,7 @@ import androidx.compose.ui.zIndex import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CommonSearchBar import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.util.sharedText import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.FloatingActionButton@@ -234,7 +235,12 @@ fun NotesListScreen(         },         state = listState,     ) {-            if (filtered.isEmpty() && searchQuery.isNotBlank()) {+            if (!state.hasLoaded && filtered.isEmpty()) {+                item(key = "loading") {+                    LoadingState(Modifier.fillParentMaxSize())+                }+            }+            if (filtered.isEmpty() && searchQuery.isNotBlank() && state.hasLoaded) {                 item(key = "no-results") {                     EmptyState(                         title = stringResource(R.string.no_results_for, searchQuery),
todo/src/main/java/com/vayunmathur/todo/platform/TodoListUiContract.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/platform/TodoListUiContract.kt b/todo/src/main/java/com/vayunmathur/todo/platform/TodoListUiContract.ktindex 8279b2ad18..8d298eb794 100644--- a/todo/src/main/java/com/vayunmathur/todo/platform/TodoListUiContract.kt+++ b/todo/src/main/java/com/vayunmathur/todo/platform/TodoListUiContract.kt@@ -23,6 +23,8 @@ data class TodoListUiState(     val showAddButton: Boolean = true,     /** Epoch ms the relative due labels are computed against. */     val now: Long = System.currentTimeMillis(),+    /** False until the todos DAO emits at least once, so an empty list can show a spinner. */+    val hasLoaded: Boolean = true, )  /** Every method has a no-op default so a preview can render without behaviour. */
todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt b/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.ktindex 42e436118d..7135ea1639 100644--- a/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt+++ b/todo/src/main/java/com/vayunmathur/todo/platform/TodoViewModel.kt@@ -33,6 +33,9 @@ import com.vayunmathur.todo.domain.format.ExportFormat import com.vayunmathur.todo.domain.format.ImportedTask import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map+import kotlinx.coroutines.flow.onEach+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.datetime.TimeZone@@ -60,7 +63,13 @@ class TodoViewModel(         }     } +    private val _hasLoadedTodos = MutableStateFlow(false)++    /** Flips true once the todos DAO emits at least once; the list starts empty. */+    val hasLoadedTodos: StateFlow<Boolean> = _hasLoadedTodos.asStateFlow()+     val todos: StateFlow<List<Todo>> = repository.todos+        .onEach { _hasLoadedTodos.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), emptyList())     val lists: StateFlow<List<TodoList>> = repository.lists         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(STOP_TIMEOUT_MS), emptyList())
todo/src/main/java/com/vayunmathur/todo/ui/TodoListPage.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/TodoListPage.kt b/todo/src/main/java/com/vayunmathur/todo/ui/TodoListPage.ktindex 3f0da9c0be..fa82c37d76 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/TodoListPage.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/TodoListPage.kt@@ -29,6 +29,7 @@ fun TodoListPage(     val query by viewModel.searchQuery.collectAsStateWithLifecycle()     val sort by viewModel.sort.collectAsStateWithLifecycle()     val lists by viewModel.lists.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedTodos.collectAsStateWithLifecycle()     val quickAddRequest by viewModel.quickAddRequest.collectAsStateWithLifecycle()      val actions = remember(backStack, viewModel, onMenu, view) {@@ -59,6 +60,7 @@ fun TodoListPage(             sort = sort,             showAddButton = backStack.last() !is Route.TodoDetail,             now = model.second,+            hasLoaded = hasLoaded,         ),         actions = actions,         quickAddLeading = { VoiceInputButton(onResult = viewModel::requestQuickAdd) },
todo/src/main/java/com/vayunmathur/todo/ui/TodoListScreen.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/TodoListScreen.kt b/todo/src/main/java/com/vayunmathur/todo/ui/TodoListScreen.ktindex 476a55f460..70780a5098 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/TodoListScreen.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/TodoListScreen.kt@@ -9,6 +9,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier import androidx.compose.foundation.layout.RowScope import androidx.compose.ui.platform.LocalResources import androidx.compose.ui.res.stringResource@@ -17,6 +18,7 @@ import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.FloatingActionButton import com.vayunmathur.library.ui.IconAdd import com.vayunmathur.library.ui.LazyListScaffold+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.rememberHaptics import com.vayunmathur.library.ui.rememberMessenger import com.vayunmathur.todo.R@@ -166,7 +168,12 @@ fun TodoListScreen(                 selectionMode = selected.isNotEmpty(),             )         }-        if (model.openCount == 0) {+        if (!state.hasLoaded && model.openCount == 0 && model.completed.isEmpty()) {+            item(key = "loading") {+                LoadingState(Modifier.fillParentMaxSize())+            }+        }+        if (model.openCount == 0 && state.hasLoaded) {             item(key = "empty") {                 TodoEmptyState(                     when {
travel/src/main/java/com/vayunmathur/travel/platform/TravelViewModel.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/platform/TravelViewModel.kt b/travel/src/main/java/com/vayunmathur/travel/platform/TravelViewModel.ktindex 83bf78170a..941ce05c46 100644--- a/travel/src/main/java/com/vayunmathur/travel/platform/TravelViewModel.kt+++ b/travel/src/main/java/com/vayunmathur/travel/platform/TravelViewModel.kt@@ -24,6 +24,7 @@ import com.vayunmathur.travel.network.TripDto import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.stateIn @@ -148,7 +149,13 @@ class TravelViewModel(     val recentSearches: StateFlow<List<RecentSearch>> = repository.observeRecent()         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) +    private val _hasLoadedTrips = MutableStateFlow(false)++    /** Flips true once the booked-trips DAO emits at least once; the list starts empty. */+    val hasLoadedTrips: StateFlow<Boolean> = _hasLoadedTrips.asStateFlow()+     val bookedTrips: StateFlow<List<BookedTrip>> = repository.observeBookedTrips()+        .onEach { _hasLoadedTrips.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** Saved frequent-flyer accounts, applied as loyalty pricing at search. */
travel/src/main/java/com/vayunmathur/travel/ui/TripsPage.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/ui/TripsPage.kt b/travel/src/main/java/com/vayunmathur/travel/ui/TripsPage.ktindex cb1d8bfb5b..0394e8de7a 100644--- a/travel/src/main/java/com/vayunmathur/travel/ui/TripsPage.kt+++ b/travel/src/main/java/com/vayunmathur/travel/ui/TripsPage.kt@@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.ui.AppPullToRefreshBox+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.AssistChip import com.vayunmathur.library.ui.ElevatedCard@@ -46,6 +47,7 @@ import androidx.compose.ui.res.stringResource @Composable fun TripsPage(backStack: NavBackStack<Route>, viewModel: TravelViewModel) {     val trips by viewModel.bookedTrips.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedTrips.collectAsStateWithLifecycle()     val pending = trips.any { isTripPollingStatus(it.status) }      AppScaffold(@@ -57,6 +59,10 @@ fun TripsPage(backStack: NavBackStack<Route>, viewModel: TravelViewModel) {             }         },     ) { padding ->+        if (!hasLoaded && trips.isEmpty()) {+            LoadingState(Modifier.fillMaxSize().padding(padding))+            return@AppScaffold+        }         AppPullToRefreshBox(             isRefreshing = pending && trips.isNotEmpty(),             onRefresh = { trips.forEach { viewModel.refreshStoredTrip(it.orderId) } },
uniflix/src/main/java/com/vayunmathur/uniflix/platform/HomeViewModel.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/platform/HomeViewModel.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/platform/HomeViewModel.ktindex 2b96c26a90..7e4322144a 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/platform/HomeViewModel.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/platform/HomeViewModel.kt@@ -11,7 +11,11 @@ import com.vayunmathur.library.util.AppMessages import com.vayunmathur.uniflix.data.TmdbApi import com.vayunmathur.uniflix.data.UniflixRepository import com.vayunmathur.uniflix.domain.MediaItem+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch  /** Home rows: trending + top-rated, served by the self-hosted TMDB proxy. */@@ -57,11 +61,16 @@ class HomeViewModel(app: Application) : AndroidViewModel(app) {         }     } +    private val _hasLoadedLocalLists = MutableStateFlow(false)++    /** Flips true once the watchlist/continue-watching DAOs emit; the TV lists start empty. */+    val hasLoadedLocalLists: StateFlow<Boolean> = _hasLoadedLocalLists.asStateFlow()+     /** Continue-watching row source, newest first. */-    val continueWatching get() = repository.continueWatching+    val continueWatching get() = repository.continueWatching.onEach { _hasLoadedLocalLists.value = true }      /** Watchlist row source, newest first. */-    val watchlist get() = repository.watchlist+    val watchlist get() = repository.watchlist.onEach { _hasLoadedLocalLists.value = true }      fun watchlistSnapshot() = combine(repository.watchlist, repository.continueWatching) { w, _ -> w } }
uniflix/src/main/java/com/vayunmathur/uniflix/platform/ListsViewModel.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/platform/ListsViewModel.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/platform/ListsViewModel.ktindex ac43665da6..f2396b8860 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/platform/ListsViewModel.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/platform/ListsViewModel.kt@@ -7,13 +7,22 @@ import androidx.lifecycle.viewModelScope import com.vayunmathur.uniflix.data.UniflixRepository import com.vayunmathur.uniflix.data.UserList import com.vayunmathur.uniflix.data.UserListItem+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow+import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch  /** Local lists hub: create lists, add/remove items. */ class ListsViewModel(app: Application) : AndroidViewModel(app) {     private val repository = UniflixRepository.get(app) -    val lists get() = repository.userLists+    private val _hasLoadedLists = MutableStateFlow(false)++    /** Flips true once the user-lists DAO emits at least once; the TV lists start empty. */+    val hasLoadedLists: StateFlow<Boolean> = _hasLoadedLists.asStateFlow()++    val lists get() = repository.userLists.onEach { _hasLoadedLists.value = true }     fun items(listId: Long) = repository.listItems(listId)      fun createList(name: String) {
uniflix/src/main/java/com/vayunmathur/uniflix/ui/tv/TvMyList.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/ui/tv/TvMyList.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/ui/tv/TvMyList.ktindex 516edcfa78..ee70686080 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/ui/tv/TvMyList.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/ui/tv/TvMyList.kt@@ -13,6 +13,7 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.res.stringResource import androidx.lifecycle.viewmodel.compose.viewModel import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.tvFullWidth@@ -41,6 +42,8 @@ fun TvMyListTab(     val watchlist by homeVm.watchlist.collectAsState(initial = emptyList())     val entries by homeVm.continueWatching.collectAsState(initial = emptyList())     val lists by listsVm.lists.collectAsState(initial = emptyList())+    val hasLoadedLocal by homeVm.hasLoadedLocalLists.collectAsState(initial = false)+    val hasLoadedLists by listsVm.hasLoadedLists.collectAsState(initial = false)      // Per-list items: one collector per list, restarted whenever the list set changes.     val itemsByList = remember { mutableStateMapOf<Long, List<UserListItem>>() }@@ -60,6 +63,10 @@ fun TvMyListTab(     }     TvInitialFocus(firstFocus, key = firstKey) +    if ((!hasLoadedLocal || !hasLoadedLists) && entries.isEmpty() && watchlist.isEmpty() && lists.isEmpty()) {+        TvLoading()+        return+    }     if (entries.isEmpty() && watchlist.isEmpty() && lists.isEmpty()) {         TvEmptyState(             title = stringResource(R.string.lists_empty),
weather/src/main/java/com/vayunmathur/weather/platform/WeatherUiContract.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/platform/WeatherUiContract.kt b/weather/src/main/java/com/vayunmathur/weather/platform/WeatherUiContract.ktindex e335db40d1..1d2af23d21 100644--- a/weather/src/main/java/com/vayunmathur/weather/platform/WeatherUiContract.kt+++ b/weather/src/main/java/com/vayunmathur/weather/platform/WeatherUiContract.kt@@ -67,6 +67,8 @@ data class LocationRow( /** Everything the locations drawer draws. */ data class LocationsUiState(     val rows: List<LocationRow> = emptyList(),+    /** False until the saved-locations DAO emits at least once (the VM flow starts null). */+    val hasLoaded: Boolean = true,     val activeLocationId: Long? = null,     /** True while a device-location fix is being requested. */     val deviceLocationLoading: Boolean = false,
weather/src/main/java/com/vayunmathur/weather/ui/LocationsPage.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/LocationsPage.kt b/weather/src/main/java/com/vayunmathur/weather/ui/LocationsPage.ktindex 5f18fc682e..87460a488a 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/LocationsPage.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/LocationsPage.kt@@ -72,7 +72,8 @@ fun LocationsPage(     onLocationSelect: (SavedLocation) -> Unit,     onClose: () -> Unit, ) {-    val locations = viewModel.savedLocations.collectAsState().value.orEmpty()+    val savedLocations by viewModel.savedLocations.collectAsState()+    val locations = savedLocations.orEmpty()     val forecasts by viewModel.forecasts.collectAsState()     val resources = LocalResources.current @@ -103,6 +104,7 @@ fun LocationsPage(      LocationsScreen(         state = LocationsUiState(+            hasLoaded = savedLocations != null,             rows = rows,             activeLocationId = activeLocation?.id,             deviceLocationLoading = deviceLocationLoading,
weather/src/main/java/com/vayunmathur/weather/ui/LocationsScreen.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/LocationsScreen.kt b/weather/src/main/java/com/vayunmathur/weather/ui/LocationsScreen.ktindex c5fa391ab0..4dc7b35c32 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/LocationsScreen.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/LocationsScreen.kt@@ -18,6 +18,7 @@ import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.ListItem import com.vayunmathur.library.ui.ListItemDefaults import com.vayunmathur.library.ui.LazyListScaffold+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.ModalBottomSheet import com.vayunmathur.library.ui.Text@@ -153,6 +154,11 @@ fun LocationsScreen(             }         },     ) {+        if (!state.hasLoaded && localData.isEmpty()) {+            item(key = "loading") {+                LoadingState(Modifier.fillParentMaxSize())+            }+        }         val showDeviceLocationCard = localData.none { it.location.isCurrent }         if (showDeviceLocationCard) {             item {
web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.ktindex 8278a68709..0e1c482d82 100644--- a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt@@ -33,6 +33,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json@@ -152,6 +153,18 @@ class WebViewModel(     private val _downloads = MutableStateFlow<List<DownloadEntry>>(emptyList())     val downloads: StateFlow<List<DownloadEntry>> = _downloads +    private val _hasLoadedBookmarks = MutableStateFlow(false)+    /** Flips true once the bookmarks DAO emits at least once; the list starts empty. */+    val hasLoadedBookmarks: StateFlow<Boolean> = _hasLoadedBookmarks.asStateFlow()++    private val _hasLoadedHistory = MutableStateFlow(false)+    /** Flips true once the history DAO emits at least once; the list starts empty. */+    val hasLoadedHistory: StateFlow<Boolean> = _hasLoadedHistory.asStateFlow()++    private val _hasLoadedDownloads = MutableStateFlow(false)+    /** Flips true once the downloads DAO emits at least once; the list starts empty. */+    val hasLoadedDownloads: StateFlow<Boolean> = _hasLoadedDownloads.asStateFlow()+     private val _installedSites = MutableStateFlow<List<InstalledSite>>(emptyList())     val installedSites: StateFlow<List<InstalledSite>> = _installedSites @@ -393,12 +406,12 @@ class WebViewModel(     }      private fun observeRepository() {-        viewModelScope.launch { repository.bookmarks.allFlow().collect { _bookmarks.value = it } }+        viewModelScope.launch { repository.bookmarks.allFlow().collect { _bookmarks.value = it; _hasLoadedBookmarks.value = true } }         viewModelScope.launch { repository.bookmarks.foldersFlow().collect { _folders.value = it } }-        viewModelScope.launch { repository.history.allFlow().collect { _history.value = it } }+        viewModelScope.launch { repository.history.allFlow().collect { _history.value = it; _hasLoadedHistory.value = true } }         viewModelScope.launch { repository.permissions.allFlow().collect { _sitePermissions.value = it } }         viewModelScope.launch { repository.storage.allFlow().collect { _storageInfos.value = it } }-        viewModelScope.launch { repository.downloads.allFlow().collect { _downloads.value = it } }+        viewModelScope.launch { repository.downloads.allFlow().collect { _downloads.value = it; _hasLoadedDownloads.value = true } }         viewModelScope.launch { repository.installed.allFlow().collect { _installedSites.value = it } }         viewModelScope.launch {             repository.shields.allFlow().collect { settings ->
web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt b/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.ktindex 9151b5e625..263bc660a4 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BookmarksPage.kt@@ -32,6 +32,7 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem@@ -64,10 +65,12 @@ fun BookmarksPage( ) {     val bookmarks by viewModel.bookmarks.collectAsStateWithLifecycle()     val folders by viewModel.folders.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedBookmarks.collectAsStateWithLifecycle()      BookmarksScreen(         bookmarks = bookmarks,         folders = folders,+        hasLoaded = hasLoaded,         navigationIcon = { IconNavigation(backStack) },         onOpen = { bm ->             viewModel.externalIntentUrl(bm.url)@@ -89,6 +92,7 @@ fun BookmarksPage( internal fun BookmarksScreen(     bookmarks: List<Bookmark>,     folders: List<BookmarkFolder>,+    hasLoaded: Boolean = true,     navigationIcon: @Composable () -> Unit = {},     onOpen: (Bookmark) -> Unit = {},     onDelete: (Bookmark) -> Unit = {},@@ -178,7 +182,9 @@ internal fun BookmarksScreen(                 }             } -            if (filtered.isEmpty() && bookmarks.isEmpty()) {+            if (!hasLoaded && bookmarks.isEmpty()) {+                LoadingState(Modifier.fillMaxSize())+            } else if (filtered.isEmpty() && bookmarks.isEmpty()) {                 EmptyState(                     title = stringResource(R.string.no_bookmarks_yet),                 )
web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.ktindex b702f38855..e18ca9c6ea 100644--- a/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/DownloadsPage.kt@@ -28,6 +28,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconDownload@@ -46,6 +47,7 @@ fun DownloadsPage(     backStack: NavBackStack<Route>, ) {     val downloads by viewModel.downloads.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedDownloads.collectAsStateWithLifecycle()      AppScaffold(         title = stringResource(R.string.downloads),@@ -57,7 +59,9 @@ fun DownloadsPage(         },     ) { paddingValues ->         DesktopMaxWidthContainer(modifier = Modifier.padding(paddingValues)) {-        if (downloads.isEmpty()) {+        if (!hasLoaded && downloads.isEmpty()) {+            LoadingState(Modifier.fillMaxSize())+        } else if (downloads.isEmpty()) {             EmptyState(                 title = stringResource(R.string.no_downloads),                 modifier = Modifier.fillMaxSize(),
web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt b/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.ktindex 235cc0704d..0712d8958e 100644--- a/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/HistoryPage.kt@@ -44,6 +44,7 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.LoadingState import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconButton@@ -68,6 +69,7 @@ fun HistoryPage(     backStack: NavBackStack<Route>, ) {     val history by viewModel.history.collectAsStateWithLifecycle()+    val hasLoaded by viewModel.hasLoadedHistory.collectAsStateWithLifecycle()     var showClearConfirm by remember { mutableStateOf(false) }      val context = LocalContext.current@@ -87,7 +89,9 @@ fun HistoryPage(         },     ) { paddingValues ->         DesktopMaxWidthContainer(modifier = Modifier.padding(paddingValues)) {-            if (history.isEmpty()) {+            if (!hasLoaded && history.isEmpty()) {+                LoadingState(Modifier.fillMaxSize())+            } else if (history.isEmpty()) {                 EmptyState(                     title = stringResource(R.string.no_history_yet),                     modifier = Modifier.fillMaxSize(),
youpipe/src/main/java/com/vayunmathur/youpipe/platform/YouPipeViewModel.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/platform/YouPipeViewModel.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/platform/YouPipeViewModel.ktindex 7b4d01ba33..ba95324832 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/platform/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/platform/YouPipeViewModel.kt@@ -146,14 +146,32 @@ class YouPipeViewModel(         .onEach { _hasLoadedSubscriptionVideos.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) +    private val _hasLoadedHistory = MutableStateFlow(false)++    /** Flips true once the history DAO emits at least once; the TV history grid starts empty. */+    val hasLoadedHistory: StateFlow<Boolean> = _hasLoadedHistory.asStateFlow()++    private val _hasLoadedDownloads = MutableStateFlow(false)++    /** Flips true once the downloads DAO emits at least once; the TV downloads grid starts empty. */+    val hasLoadedDownloads: StateFlow<Boolean> = _hasLoadedDownloads.asStateFlow()++    private val _hasLoadedPlaylists = MutableStateFlow(false)++    /** Flips true once the playlists DAO emits at least once; the TV saved grid starts empty. */+    val hasLoadedPlaylists: StateFlow<Boolean> = _hasLoadedPlaylists.asStateFlow()+     val historyVideos: StateFlow<List<HistoryVideo>> = repository.historyVideos+        .onEach { _hasLoadedHistory.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      val downloadedVideos: StateFlow<List<DownloadedVideo>> = repository.downloadedVideos+        .onEach { _hasLoadedDownloads.value = true }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** All playlists sorted by their persisted [Playlist.position]. */     val playlists: StateFlow<List<Playlist>> = repository.playlists+        .onEach { _hasLoadedPlaylists.value = true }         .map { list -> list.sortedBy { it.position } }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) @@ -165,11 +183,13 @@ class YouPipeViewModel(      /** History sorted most-recent-first, as shown by the History screen. */     val historyVideosByRecency: StateFlow<List<HistoryVideo>> = repository.historyVideos+        .onEach { _hasLoadedHistory.value = true }         .map { list -> list.sortedByDescending { it.timestamp } }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())      /** Downloaded videos sorted most-recent-first, as shown by the Downloads screen. */     val downloadedVideosByRecency: StateFlow<List<DownloadedVideo>> = repository.downloadedVideos+        .onEach { _hasLoadedDownloads.value = true }         .map { list -> list.sortedByDescending { it.timestamp } }         .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList()) @@ -216,9 +236,16 @@ class YouPipeViewModel(      fun playlistById(id: Long): Flow<Playlist?> = repository.playlistStore.playlistById(id) +    private val _loadedPlaylistIds = MutableStateFlow<Set<Long>>(emptySet())++    /** Playlist ids whose items query has emitted at least once (empty then means truly empty). */+    val loadedPlaylistIds: StateFlow<Set<Long>> = _loadedPlaylistIds.asStateFlow()+     /** The items of [playlistId], sorted by their persisted [PlaylistItem.position]. */     fun playlistItemsFor(playlistId: Long): Flow<List<PlaylistItem>> =-        repository.playlistStore.playlistItemsFor(playlistId).map { list -> list.sortedBy { it.position } }+        repository.playlistStore.playlistItemsFor(playlistId)+            .onEach { _loadedPlaylistIds.value = _loadedPlaylistIds.value + playlistId }+            .map { list -> list.sortedBy { it.position } }      // ===================== Mutations ===================== 
youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvDownloads.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvDownloads.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvDownloads.ktindex a350598ca4..38a89bedbf 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvDownloads.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvDownloads.kt@@ -20,6 +20,7 @@ import com.vayunmathur.library.image.ImageRequest import com.vayunmathur.library.image.compose.AsyncImage import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInfoCard import com.vayunmathur.library.tv.TvInitialFocus@@ -48,6 +49,7 @@ fun TvDownloadsPage(     ypvm: YouPipeViewModel, ) {     val downloadedVideos by ypvm.downloadedVideos.collectAsState()+    val hasLoaded by ypvm.hasLoadedDownloads.collectAsState()     val activeDownloads by DownloadManager.activeDownloads.collectAsState()     val downloads by ypvm.downloadedVideosByRecency.collectAsState()     val historyById = remember(downloadedVideos) { emptyMap<Long, Long>() }@@ -73,6 +75,7 @@ fun TvDownloadsPage(     TvInitialFocus(firstFocus)     Column(Modifier.fillMaxSize()) {         TvDownloadsContent(+            hasLoaded = hasLoaded,             modifier = Modifier.weight(1f),             activeDownloads = activeDownloads, rows = rows,             activeTitle = activeTitle, doneTitle = doneTitle,@@ -110,6 +113,7 @@ private fun deleteSelectedDownloads(  @Composable private fun TvDownloadsContent(+    hasLoaded: Boolean = true,     modifier: Modifier = Modifier,     activeDownloads: Map<Long, DownloadStatus>,     rows: List<TvVideoRow>,@@ -131,6 +135,10 @@ private fun TvDownloadsContent(         onCancelSelection = onCancelSelection,     )     val activeList = remember(activeDownloads) { activeDownloads.toList() }+    if (!hasLoaded && rows.isEmpty() && activeList.isEmpty()) {+        TvLoading()+        return+    }     if (rows.isEmpty() && activeList.isEmpty()) {         TvEmptyState(title = stringResource(R.string.playlist_empty))         return
youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvHistory.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvHistory.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvHistory.ktindex 660231ceb3..8814205066 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvHistory.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvHistory.kt@@ -16,6 +16,7 @@ import androidx.compose.ui.res.stringResource import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvScreenHeader@@ -40,6 +41,7 @@ fun TvHistoryPage(     ypvm: YouPipeViewModel, ) {     val history by ypvm.historyVideosByRecency.collectAsState()+    val hasLoaded by ypvm.hasLoadedHistory.collectAsState()     val historyById = remember(history) { history.associate { it.id to it.progress } }     val videos = remember(history) { history.map { it.videoItem } }     val rows = rememberTvVideoRows(videos, ypvm, historyById)@@ -62,6 +64,10 @@ fun TvHistoryPage(             onCancelSelection = { selectedIds = emptySet() },             onClearClick = { confirmClear = true },         )+        if (!hasLoaded && rows.isEmpty()) {+            TvLoading()+            return@Column+        }         if (rows.isEmpty()) {             TvEmptyState(title = stringResource(R.string.empty_recommendations))             return@Column
youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvPlaylistDetail.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvPlaylistDetail.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvPlaylistDetail.ktindex 372771644a..d7548f505a 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvPlaylistDetail.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvPlaylistDetail.kt@@ -20,6 +20,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvDialog import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInitialFocus import com.vayunmathur.library.tv.TvScreenHeader@@ -50,6 +51,7 @@ fun TvPlaylistDetailPage(         .collectAsStateWithLifecycle(initialValue = null)     val itemsFlow = remember(playlistId) { ypvm.playlistItemsFor(playlistId) }     val playlistItems by itemsFlow.collectAsStateWithLifecycle(initialValue = emptyList())+    val loadedPlaylistIds by ypvm.loadedPlaylistIds.collectAsStateWithLifecycle()     val history by ypvm.historyVideos.collectAsState()     val historyById = remember(history) { history.associate { it.id to it.progress } }     val mandatory = playlist?.mandatory == true@@ -71,6 +73,7 @@ fun TvPlaylistDetailPage(     TvPlaylistDetailBody(         backStack = backStack,         ypvm = ypvm,+        hasLoaded = playlistId in loadedPlaylistIds,         playlist = playlist,         playlistItems = playlistItems,         rows = rows,@@ -94,6 +97,7 @@ fun TvPlaylistDetailPage( private fun TvPlaylistDetailBody(     backStack: NavBackStack<TvRoute>,     ypvm: YouPipeViewModel,+    hasLoaded: Boolean = true,     playlist: Playlist?,     playlistItems: List<PlaylistItem>,     rows: List<TvVideoRow>,@@ -115,6 +119,10 @@ private fun TvPlaylistDetailBody(             isSelectionMode = isSelectionMode,             onDeletePlaylist = onDeletePlaylist,         )+        if (!hasLoaded && rows.isEmpty()) {+            TvLoading()+            return@Column+        }         if (rows.isEmpty()) {             TvEmptyState(title = stringResource(R.string.playlist_empty))             return@Column
youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvSaved.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvSaved.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvSaved.ktindex 5af117bb36..7ee996d4d6 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvSaved.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/tv/TvSaved.kt@@ -13,6 +13,7 @@ import androidx.compose.ui.res.stringResource import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.library.tv.TvButton import com.vayunmathur.library.tv.TvEmptyState+import com.vayunmathur.library.tv.TvLoading import com.vayunmathur.library.tv.TvGrid import com.vayunmathur.library.tv.TvInfoCard import com.vayunmathur.library.tv.TvInitialFocus@@ -42,6 +43,7 @@ fun TvSavedPage(     ypvm: YouPipeViewModel, ) {     val playlists by ypvm.playlists.collectAsStateWithLifecycle()+    val hasLoaded by ypvm.hasLoadedPlaylists.collectAsStateWithLifecycle()     val downloadedVideos by ypvm.downloadedVideos.collectAsStateWithLifecycle()     val allPlaylistItems by ypvm.allPlaylistItems.collectAsStateWithLifecycle()     val counts = remember(allPlaylistItems) { allPlaylistItems.groupingBy { it.playlistId }.eachCount() }@@ -53,6 +55,7 @@ fun TvSavedPage(         TvSavedHeader(backStack)         TvSavedGrid(             backStack = backStack,+            hasLoaded = hasLoaded,             watchLater = watchLater,             userPlaylists = userPlaylists,             counts = counts,@@ -79,6 +82,7 @@ private fun TvSavedHeader(backStack: NavBackStack<TvRoute>) { @Composable private fun TvSavedGrid(     backStack: NavBackStack<TvRoute>,+    hasLoaded: Boolean,     watchLater: Playlist?,     userPlaylists: List<Playlist>,     counts: Map<Long, Int>,@@ -88,7 +92,11 @@ private fun TvSavedGrid(     val savedTitle = stringResource(UiR.string.saved)     TvGrid(columns = 3, modifier = modifier) {         tvSavedPinnedSection(backStack, watchLater, counts, downloadedCount)-        if (userPlaylists.isEmpty()) {+        if (!hasLoaded && userPlaylists.isEmpty()) {+            tvFullWidth(key = "loading") {+                TvLoading()+            }+        } else if (userPlaylists.isEmpty()) {             tvFullWidth(key = "empty") {                 TvEmptyState(title = stringResource(R.string.playlist_empty))             }