Fixed navigation bug due to passing large list of strings (reverted to JSON convert instead of type-safe for FolderView screen)
This commit is contained in:
1 parent
edfc942a6d
commit
69e9f91814
2 files changed
+82
-7
No files matched your search
+77
-5
@@ -17,9 +17,11 @@ 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
|
||||
@@ -43,10 +45,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
|
||||
@@ -56,11 +58,15 @@ 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.WallpaperAlarmSchedulerImpl
|
||||
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(
|
||||
@@ -558,7 +564,14 @@ fun PaperizeApp(
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
/*navController.navigate(
|
||||
com.anthonyla.paperize.feature.wallpaper.util.navigation.FolderView(
|
||||
folderName,
|
||||
wallpapers
|
||||
)
|
||||
)*/
|
||||
val encodedWallpapers = runBlocking { encodeUri(uri = Gson().toJson(wallpapers)) }
|
||||
navController.navigate("${NavScreens.FolderView.route}/$folderName/$encodedWallpapers")
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
@@ -593,7 +606,7 @@ fun PaperizeApp(
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
}
|
||||
composable<FolderView>(
|
||||
/*composable<FolderView>(
|
||||
enterTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
@@ -627,6 +640,52 @@ fun PaperizeApp(
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
} else { navController.navigateUp() }
|
||||
}*/
|
||||
composable(
|
||||
route = NavScreens.FolderView.route.plus("/{folderName}/{wallpapers}"),
|
||||
arguments = listOf(
|
||||
navArgument("folderName") { type = NavType.StringType },
|
||||
navArgument("wallpapers") { type = NavType.StringType }
|
||||
),
|
||||
enterTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
exitTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popEnterTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} else { null }
|
||||
},
|
||||
popExitTransition = {
|
||||
if (settingsState.value.animate) {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
} 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()) {
|
||||
FolderViewScreen(
|
||||
folderName = folderName,
|
||||
wallpapers = wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
} else {
|
||||
navController.navigateUp()
|
||||
}
|
||||
}
|
||||
// Navigate to the album view screen to view folders and wallpapers in an album
|
||||
composable<AlbumView> (
|
||||
@@ -662,7 +721,14 @@ fun PaperizeApp(
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
navController.navigate(FolderView(folderName, wallpapers))
|
||||
/*navController.navigate(
|
||||
com.anthonyla.paperize.feature.wallpaper.util.navigation.FolderView(
|
||||
folderName,
|
||||
wallpapers
|
||||
)
|
||||
)*/
|
||||
val encodedWallpapers = runBlocking { encodeUri(uri = Gson().toJson(wallpapers)) }
|
||||
navController.navigate("${NavScreens.FolderView.route}/$folderName/$encodedWallpapers")
|
||||
},
|
||||
onDeleteAlbum = {
|
||||
navController.navigateUp()
|
||||
@@ -793,4 +859,10 @@ 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())
|
||||
}
|
||||
+5
-2
@@ -57,8 +57,11 @@ 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")
|
||||
}
|
||||
Reference in new issue
Block a user