Refactored albums viewmodel injecting

This commit is contained in:
Anthonyy232 committed 2024-07-16 23:34:34 -07:00
1 parent b01b9a87d6
commit 829d982d23
4 files changed
+10 -13

No files matched your search

@@ -232,6 +232,7 @@ fun PaperizeApp(
}
) {
HomeScreen(
albums = albumState.value.albumsWithWallpapers,
onSettingsClick = { navController.navigate(Settings) },
navigateToAddWallpaperScreen = {
navController.navigate(AddEdit(it))
@@ -32,6 +32,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
@Composable
fun HomeScreen(
albums: List<AlbumWithWallpaperAndFolder>,
animate : Boolean,
darken: Boolean,
darkenPercentage: Int,
@@ -131,6 +132,7 @@ fun HomeScreen(
) { index ->
when(index.coerceIn(tabItems.indices)) {
0 -> WallpaperScreen(
albums = albums,
animate = animate,
darken = darken,
darkenPercentage = darkenPercentage,
@@ -163,6 +165,7 @@ fun HomeScreen(
blurPercentage = blurPercentage
)
else -> LibraryScreen(
albums = albums,
onAddNewAlbumClick = { addAlbumDialog = true },
onViewAlbum = onAlbumViewClick,
animate = animate
@@ -18,21 +18,18 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
@Composable
fun LibraryScreen(
albumsViewModel: AlbumsViewModel = hiltViewModel(),
albums: List<AlbumWithWallpaperAndFolder>,
onAddNewAlbumClick: () -> Unit,
onViewAlbum: (String) -> Unit,
animate: Boolean
) {
val lazyListState = rememberLazyGridState()
val state = albumsViewModel.state.collectAsStateWithLifecycle()
Scaffold(
modifier = Modifier.fillMaxSize(),
floatingActionButton = {
@@ -56,7 +53,7 @@ fun LibraryScreen(
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
content = {
items (state.value.albumsWithWallpapers, key = { album -> album.album.initialAlbumName}
items (albums, key = { album -> album.album.initialAlbumName}
) { album ->
AlbumItem(
album = album.album,
@@ -33,13 +33,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
@@ -53,7 +50,7 @@ import kotlinx.coroutines.launch
@Composable
fun WallpaperScreen(
albumsViewModel: AlbumsViewModel = hiltViewModel(),
albums: List<AlbumWithWallpaperAndFolder>,
animate: Boolean,
darken: Boolean,
darkenPercentage: Int,
@@ -86,7 +83,6 @@ fun WallpaperScreen(
blurPercentage: Int
) {
val context = LocalContext.current
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
var openBottomSheet by rememberSaveable { mutableStateOf(false) }
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
@@ -131,7 +127,7 @@ fun WallpaperScreen(
CurrentSelectedAlbum(
selectedAlbum = selectedAlbum,
onOpenBottomSheet = {
if (albumState.value.albumsWithWallpapers.firstOrNull() != null) {
if (albums.firstOrNull() != null) {
if (isLiveWallpaperSet(context)) {
openLiveDialog.value = true
} else {
@@ -342,7 +338,7 @@ fun WallpaperScreen(
}
if (((homeEnabled || lockEnabled)) && openBottomSheet) {
AlbumBottomSheet(
albums = albumState.value.albumsWithWallpapers,
albums = albums,
currentSelectedAlbum = selectedAlbum,
onDismiss = { openBottomSheet = false },
onSelect = { album ->