From c1404ec522a3aa589605d819ba51c744200a4c2c Mon Sep 17 00:00:00 2001 From: Anthonyy232 Date: Fri, 5 Jul 2024 11:18:44 -0700 Subject: [PATCH] Updated dependencies Updated navigation for FolderView to type-safe navigation Updated error checking for tab navigation --- app/build.gradle.kts | 62 ++++++++++--------- .../wallpaper/presentation/PaperizeApp.kt | 45 +++----------- .../components/AddAlbumSmallTopBar.kt | 3 +- .../presentation/home_screen/HomeScreen.kt | 6 +- .../wallpaper/util/navigation/NavScreens.kt | 8 +-- .../wallpaper_service/WallpaperService2.kt | 11 ++-- 6 files changed, 55 insertions(+), 80 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8ee43c42..06828b24 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,17 +21,12 @@ android { targetSdk = 34 versionCode = 24 versionName = "1.5.6" - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary = true } - ndk { - debugSymbolLevel = "FULL" - } } - buildTypes { release { isMinifyEnabled = true @@ -39,21 +34,28 @@ android { getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + ndk { + debugSymbolLevel = "FULL" + } } } + compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } + kotlinOptions { jvmTarget = "1.8" freeCompilerArgs += strongSkippingConfiguration() } + buildFeatures { compose = true viewBinding = true buildConfig = true } + composeOptions { kotlinCompilerExtensionVersion = "1.5.10" } @@ -61,8 +63,13 @@ android { androidResources { generateLocaleConfig = true } + ndkVersion = "26.3.11579264" buildToolsVersion = "34.0.0" + dependenciesInfo { + includeInApk = true + includeInBundle = true + } aboutLibraries { excludeFields = arrayOf("generated") @@ -77,47 +84,46 @@ androidComponents { dependencies { implementation("androidx.core:core-ktx:1.13.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.2") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3") implementation("androidx.activity:activity-compose:1.9.0") implementation(platform("androidx.compose:compose-bom:2024.06.00")) - implementation("androidx.compose.ui:ui:1.7.0-beta03") - implementation("androidx.compose.ui:ui-graphics:1.7.0-beta03") - implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta03") - implementation("androidx.compose.material3:material3:1.3.0-beta03") - implementation("androidx.navigation:navigation-compose:2.8.0-beta03") - implementation("androidx.compose.material:material:1.7.0-beta03") + implementation("androidx.compose.ui:ui:1.7.0-beta04") + implementation("androidx.compose.ui:ui-graphics:1.7.0-beta04") + implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta04") + implementation("androidx.compose.material3:material3:1.3.0-beta04") + implementation("androidx.navigation:navigation-compose:2.8.0-beta04") + implementation("androidx.compose.material:material:1.7.0-beta04") implementation("androidx.datastore:datastore:1.1.1") implementation("androidx.datastore:datastore-preferences:1.1.1") - implementation("androidx.compose.material:material-icons-extended:1.7.0-beta03") - implementation("com.google.accompanist:accompanist-adaptive:0.35.1-alpha") + implementation("androidx.compose.material:material-icons-extended:1.7.0-beta04") implementation("androidx.hilt:hilt-navigation-compose:1.2.0") - implementation("androidx.compose.animation:animation:1.7.0-beta03") + implementation("androidx.compose.animation:animation:1.7.0-beta04") implementation("androidx.core:core-splashscreen:1.2.0-alpha01") - implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.2") + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.3") implementation("com.google.code.gson:gson:2.11.0") implementation("androidx.documentfile:documentfile:1.1.0-alpha01") - implementation("net.engawapg.lib:zoomable:2.0.0-beta01") - implementation("com.github.skydoves:landscapist-glide:2.3.4") + implementation("net.engawapg.lib:zoomable:1.7.0-beta02") + implementation("com.github.skydoves:landscapist-glide:2.3.6") implementation("androidx.work:work-runtime-ktx:2.10.0-alpha02") implementation("androidx.hilt:hilt-work:1.2.0") implementation("com.airbnb.android:lottie-compose:6.4.1") - implementation("com.google.accompanist:accompanist-permissions:0.35.1-alpha") - implementation("com.mikepenz:aboutlibraries-core:11.2.1") - implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.1") - implementation("androidx.compose.foundation:foundation:1.7.0-beta03") + implementation("com.google.accompanist:accompanist-permissions:0.35.0-alpha") + implementation("com.mikepenz:aboutlibraries-core:11.2.2") + implementation("com.mikepenz:aboutlibraries-compose-m3:11.2.2") + implementation("androidx.compose.foundation:foundation:1.7.0-beta04") testImplementation("junit:junit:4.13.2") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation("androidx.test.espresso:espresso-core:3.6.0-rc01") - androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta03") - debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta03") - debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta03") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") + androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.0-beta04") + debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta04") + debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta04") implementation("com.google.dagger:hilt-android:2.51.1") ksp("com.google.dagger:hilt-android-compiler:2.51.1") implementation("androidx.room:room-runtime:2.6.1") ksp("androidx.room:room-compiler:2.6.1") implementation("androidx.room:room-ktx:2.6.1") implementation("com.lazygeniouz:dfc:1.0.8") - implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") + implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1") implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3") } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt index 969b8c36..3f09628d 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt @@ -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( 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::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()) - } \ No newline at end of file +} \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/add_album_screen/components/AddAlbumSmallTopBar.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/add_album_screen/components/AddAlbumSmallTopBar.kt index 2e6a5013..2ba7340d 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/add_album_screen/components/AddAlbumSmallTopBar.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/add_album_screen/components/AddAlbumSmallTopBar.kt @@ -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 diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt index e0e57832..fa264480 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt @@ -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 diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt index 0f5c84df..f26cd9f6 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt @@ -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) - */ - -sealed class NavScreens(val route: String) { - data object FolderView : NavScreens("folder_view_screen") -} \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/WallpaperService2.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/WallpaperService2.kt index 218de0b9..dbd16959 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/WallpaperService2.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/wallpaper_service/WallpaperService2.kt @@ -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