Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe committed Dec 20, 2024
1 parent e95e2e5 commit 3868d0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -69,13 +70,15 @@ import org.grakovne.lissen.ui.screens.library.composables.placeholder.RecentBook
import org.grakovne.lissen.viewmodel.ContentCachingModelView
import org.grakovne.lissen.viewmodel.LibraryViewModel
import org.grakovne.lissen.viewmodel.PlayerViewModel
import org.grakovne.lissen.viewmodel.SettingsViewModel

@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@Composable
fun LibraryScreen(
navController: AppNavigationService,
libraryViewModel: LibraryViewModel = hiltViewModel(),
playerViewModel: PlayerViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
contentCachingModelView: ContentCachingModelView = hiltViewModel(),
imageLoader: ImageLoader,
networkQualityService: NetworkQualityService,
Expand All @@ -86,6 +89,7 @@ fun LibraryScreen(

val recentBooks: List<RecentBook> by libraryViewModel.recentBooks.observeAsState(emptyList())

var currentLibraryId by rememberSaveable { mutableStateOf("") }
var pullRefreshing by remember { mutableStateOf(false) }
val recentBookRefreshing by libraryViewModel.recentBookUpdating.observeAsState(false)
val searchRequested by libraryViewModel.searchRequested.observeAsState(false)
Expand Down Expand Up @@ -155,9 +159,10 @@ fun LibraryScreen(
}

LaunchedEffect(Unit) {
if (library.itemCount == 0) {
if (library.itemCount == 0 || currentLibraryId != settingsViewModel.fetchPreferredLibraryId()) {
libraryViewModel.refreshRecentListening()
libraryViewModel.refreshLibrary()
currentLibraryId = settingsViewModel.fetchPreferredLibraryId()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class SettingsViewModel @Inject constructor(
}
}

fun fetchPreferredLibraryId(): String {
return preferences.getPreferredLibrary()?.id ?: ""
}

fun preferLibrary(library: Library) {
_preferredLibrary.value = library
preferences.savePreferredLibrary(library)
Expand Down

0 comments on commit 3868d0b

Please sign in to comment.