Updated dependencies
Updated navigation for FolderView to type-safe navigation Updated error checking for tab navigation
This commit is contained in:
1 parent
bcff2f338f
commit
c1404ec522
6 files changed
+55
-80
No files matched your search
+10
-35
@@ -17,11 +17,9 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import androidx.navigation.toRoute
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
@@ -45,10 +43,10 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen.WallpaperViewScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.AddEdit
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.AlbumView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.FolderView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Home
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Licenses
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavConstants.INITIAL_OFFSET
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavScreens
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Notification
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Privacy
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Settings
|
||||
@@ -58,15 +56,11 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitio
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
@@ -100,9 +94,7 @@ fun PaperizeApp(
|
||||
navController.navigate(Home)
|
||||
}
|
||||
}
|
||||
albumsViewModel.onEvent(
|
||||
AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers)
|
||||
)
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers))
|
||||
}
|
||||
}
|
||||
selectedState.value.selectedAlbum?.let { selectedAlbum ->
|
||||
@@ -565,8 +557,7 @@ fun PaperizeApp(
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
val encodedWallpapers = runBlocking { encodeUri(uri = Gson().toJson(wallpapers)) }
|
||||
navController.navigate("${NavScreens.FolderView.route}/${folderName ?: " "}/$encodedWallpapers")
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -600,12 +591,7 @@ fun PaperizeApp(
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = NavScreens.FolderView.route.plus("/{folderName}/{wallpapers}"),
|
||||
arguments = listOf(
|
||||
navArgument("folderName") { type = NavType.StringType },
|
||||
navArgument("wallpapers") { type = NavType.StringType }
|
||||
),
|
||||
composable<FolderView>(
|
||||
enterTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
@@ -627,15 +613,11 @@ fun PaperizeApp(
|
||||
} else { null }
|
||||
}
|
||||
) { backStackEntry ->
|
||||
val folderName = backStackEntry.arguments?.getString("folderName")
|
||||
val wallpapers = Gson().fromJson(
|
||||
backStackEntry.arguments?.getString("wallpapers"),
|
||||
Array<String>::class.java
|
||||
).toList()
|
||||
if (wallpapers.isNotEmpty()) {
|
||||
val folderView: FolderView = backStackEntry.toRoute()
|
||||
if (folderView.wallpapers.isNotEmpty()) {
|
||||
FolderViewScreen(
|
||||
folderName = folderName,
|
||||
wallpapers = wallpapers,
|
||||
folderName = folderView.folderName,
|
||||
wallpapers = folderView.wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
@@ -677,8 +659,7 @@ fun PaperizeApp(
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
val encodedWallpapers = runBlocking { encodeUri(uri = Gson().toJson(wallpapers)) }
|
||||
navController.navigate("${NavScreens.FolderView.route}/${folderName ?: " "}/$encodedWallpapers")
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
},
|
||||
onDeleteAlbum = {
|
||||
navController.navigateUp()
|
||||
@@ -806,10 +787,4 @@ fun PaperizeApp(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Encode an URI so it can be passed with navigation
|
||||
suspend fun encodeUri(uri: String): String =
|
||||
withContext(Dispatchers.IO) {
|
||||
URLEncoder.encode(uri, StandardCharsets.UTF_8.toString())
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -102,7 +102,6 @@ fun AddAlbumSmallTopBar(
|
||||
), label = stringResource(R.string.circle_3_animation)
|
||||
)
|
||||
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
title = {
|
||||
@@ -174,7 +173,7 @@ fun AddAlbumSmallTopBar(
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
if (!isEmpty) {
|
||||
if (!isEmpty && editableTitle.isNotEmpty()) {
|
||||
Box {
|
||||
val primaryColor = MaterialTheme.colorScheme.inversePrimary
|
||||
val secondaryColor = MaterialTheme.colorScheme.secondary
|
||||
|
||||
+3
-3
@@ -95,7 +95,7 @@ fun HomeScreen(
|
||||
TabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
if (tabIndex in tabPositions.indices) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
@@ -129,7 +129,7 @@ fun HomeScreen(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
when(index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
@@ -162,7 +162,7 @@ fun HomeScreen(
|
||||
onBlurChange = onBlurChange,
|
||||
blurPercentage = blurPercentage
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
else -> LibraryScreen(
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
onViewAlbum = onAlbumViewClick,
|
||||
animate = animate
|
||||
|
||||
+2
-6
@@ -57,12 +57,8 @@ data class AddEdit(val wallpaper: String)
|
||||
@Serializable
|
||||
data class WallpaperView(val wallpaper: String)
|
||||
|
||||
/** Reverted back to passing JSON due to bug in navigation compose causing crash
|
||||
/**
|
||||
* Data class for FolderView screen
|
||||
*/
|
||||
@Serializable
|
||||
data class FolderView(val folderName: String?, val wallpapers: List<String>)
|
||||
*/
|
||||
|
||||
sealed class NavScreens(val route: String) {
|
||||
data object FolderView : NavScreens("folder_view_screen")
|
||||
}
|
||||
+5
-6
@@ -47,7 +47,7 @@ import javax.inject.Inject
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Used in conjunction with [WallpaperService1] to schedule home screen and lock screen separately
|
||||
* Used in conjunction with [WallpaperService1] to schedule home screen and lock screen separately -- sets lock screen wallpaper
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperService2: Service() {
|
||||
@@ -238,7 +238,7 @@ class WallpaperService2: Service() {
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
@@ -326,7 +326,7 @@ class WallpaperService2: Service() {
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage,
|
||||
blurPercent = blurPercentage
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
@@ -370,7 +370,7 @@ class WallpaperService2: Service() {
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage,
|
||||
blurPercent = blurPercentage
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
@@ -513,7 +513,6 @@ class WallpaperService2: Service() {
|
||||
setLockOrHome: Boolean? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercent: Int,
|
||||
lastHomeWallpaper: Uri? = null,
|
||||
): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
try {
|
||||
@@ -564,8 +563,8 @@ class WallpaperService2: Service() {
|
||||
image.recycle()
|
||||
}
|
||||
bitmap.recycle()
|
||||
return true
|
||||
}
|
||||
return true
|
||||
} catch (e: IOException) {
|
||||
Log.e("PaperizeWallpaperChanger", "Error setting wallpaper", e)
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user