Fixed crash due to importing folder caused by type-safe navigation compose bug
Updated version number and version code for 1.0.1
This commit is contained in:
1 parent
4429355a1e
commit
c97f9f7e3d
5 files changed
+92
-25
No files matched your search
+82
-16
@@ -11,9 +11,11 @@ import androidx.compose.ui.platform.LocalContext
|
||||
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
|
||||
@@ -37,10 +39,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
|
||||
@@ -49,6 +51,12 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.WallpaperView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionIn
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaperservice.WallpaperService
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
@@ -242,11 +250,18 @@ fun PaperizeApp(
|
||||
initialAlbumName = addEdit.wallpaper,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onConfirmation = { navController.navigateUp() },
|
||||
onShowWallpaperView = { wallpaper ->
|
||||
navController.navigate(WallpaperView(wallpaper))
|
||||
onShowWallpaperView = {
|
||||
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")
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -273,7 +288,7 @@ fun PaperizeApp(
|
||||
)
|
||||
}
|
||||
// Navigate to folder view screen to view wallpapers in a particular folder
|
||||
composable<FolderView> (
|
||||
/*composable<FolderView> (
|
||||
enterTransition = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
@@ -288,15 +303,53 @@ fun PaperizeApp(
|
||||
},
|
||||
) { backStackEntry ->
|
||||
val folderView: FolderView = backStackEntry.toRoute()
|
||||
FolderViewScreen(
|
||||
folderName = folderView.folderName,
|
||||
wallpapers = folderView.wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
animate = settingsState.value.animate
|
||||
)
|
||||
if (folderView.wallpapers.isNotEmpty()) {
|
||||
FolderViewScreen(
|
||||
folderName = folderView.folderName,
|
||||
wallpapers = folderView.wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
},
|
||||
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 = {
|
||||
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
exitTransition = {
|
||||
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
popEnterTransition = {
|
||||
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
popExitTransition = {
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
) { 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> (
|
||||
@@ -323,7 +376,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 = {
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpaper))
|
||||
@@ -430,4 +490,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())
|
||||
}
|
||||
+1
-3
@@ -3,7 +3,6 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@@ -274,9 +273,8 @@ class AddAlbumViewModel @Inject constructor(
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
if (file.extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ fun PaperizeListItem(onGitHubClick: () -> Unit, onPlaystoreClick: () -> Unit, on
|
||||
fontSize = MaterialTheme.typography.titleLarge.fontSize
|
||||
)
|
||||
Text(
|
||||
text = "Version: 1.0.0",
|
||||
text = "Version: 1.0.1",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize
|
||||
)
|
||||
|
||||
+6
-3
@@ -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>)
|
||||
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