Compare commits

..
9 Commits
Author SHA1 Message Date
Anthonyy232 c1404ec522 Updated dependencies
Updated navigation for FolderView to type-safe navigation
Updated error checking for tab navigation
2024-07-05 11:19:22 -07:00
Anthony La bcff2f338f Updated version code for F-Droid release 2024-06-18 16:48:03 -07:00
Anthony La 5582a5851f Update README.md 2024-06-15 18:20:49 -07:00
Anthony La 1d0794d135 Updated Serialization version to 2.0.0
Updated Dagger Hilt to 2.51.1
Updated Accompanist to 0.35.1-alpha-03
Updated Zoomable to 2.0.0-beta-03
2024-06-15 18:19:28 -07:00
Anthonyy232 0e20f211f2 Removed android.permission.USE_EXACT_ALARM 2024-06-14 09:07:34 -07:00
Anthonyy232 6f4a2bec97 Push gradle-wrapper.jar 2024-06-13 02:16:47 -07:00
Anthonyy232 85e5e3007b Removed delay notification on first set as it no longer applies due to shift from foreground service to alarm approach
Changed wallpaper scaling 4x->1x to reduce required RAM usage and optimize computation time. Verified that the difference is marginal
2024-06-13 02:15:54 -07:00
Anthonyy232 4760ab01d5 Added additional error catching
Updated Kotlin to 2.0.0
Updated KSP to 2.0.0
Updated AboutLibraries to 11.2.1
2024-06-11 12:18:22 -07:00
Anthonyy232 d8fc106a89 Refactored refreshing album method to separate service call 2024-06-11 02:00:32 -07:00
25 changed files with 651 additions and 414 deletions

No files matched your search

+1 -1
View File
@@ -4,6 +4,6 @@
<option name="jvmTarget" value="1.8" />
</component>
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.22" />
<option name="version" value="2.0.0" />
</component>
</project>
+263
View File
@@ -0,0 +1,263 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="direct_access_persist.xml">
<option name="deviceSelectionList">
<list>
<PersistentDeviceSelectionData>
<option name="api" value="27" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="F01L" />
<option name="id" value="F01L" />
<option name="manufacturer" value="FUJITSU" />
<option name="name" value="F-01L" />
<option name="screenDensity" value="360" />
<option name="screenX" value="720" />
<option name="screenY" value="1280" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="28" />
<option name="brand" value="DOCOMO" />
<option name="codename" value="SH-01L" />
<option name="id" value="SH-01L" />
<option name="manufacturer" value="SHARP" />
<option name="name" value="AQUOS sense2 SH-01L" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1080" />
<option name="screenY" value="2160" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="samsung" />
<option name="codename" value="a51" />
<option name="id" value="a51" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy A51" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="akita" />
<option name="id" value="akita" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="b0q" />
<option name="id" value="b0q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S22 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="32" />
<option name="brand" value="google" />
<option name="codename" value="bluejay" />
<option name="id" value="bluejay" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="crownqlteue" />
<option name="id" value="crownqlteue" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Note9" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2220" />
<option name="screenY" value="1080" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="dm3q" />
<option name="id" value="dm3q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S23 Ultra" />
<option name="screenDensity" value="600" />
<option name="screenX" value="1440" />
<option name="screenY" value="3088" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix" />
<option name="id" value="felix" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="felix_camera" />
<option name="id" value="felix_camera" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Fold (Camera-enabled)" />
<option name="screenDensity" value="420" />
<option name="screenX" value="2208" />
<option name="screenY" value="1840" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="samsung" />
<option name="codename" value="gts8uwifi" />
<option name="id" value="gts8uwifi" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Tab S8 Ultra" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1848" />
<option name="screenY" value="2960" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="husky" />
<option name="id" value="husky" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8 Pro" />
<option name="screenDensity" value="390" />
<option name="screenX" value="1008" />
<option name="screenY" value="2244" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="motorola" />
<option name="codename" value="java" />
<option name="id" value="java" />
<option name="manufacturer" value="Motorola" />
<option name="name" value="G20" />
<option name="screenDensity" value="280" />
<option name="screenX" value="720" />
<option name="screenY" value="1600" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="lynx" />
<option name="id" value="lynx" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7a" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="google" />
<option name="codename" value="oriole" />
<option name="id" value="oriole" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 6" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="panther" />
<option name="id" value="panther" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 7" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="31" />
<option name="brand" value="samsung" />
<option name="codename" value="q2q" />
<option name="id" value="q2q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Z Fold3" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1768" />
<option name="screenY" value="2208" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="samsung" />
<option name="codename" value="q5q" />
<option name="id" value="q5q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy Z Fold5" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1812" />
<option name="screenY" value="2176" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="r11" />
<option name="id" value="r11" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Watch" />
<option name="screenDensity" value="320" />
<option name="screenX" value="384" />
<option name="screenY" value="384" />
<option name="type" value="WEAR_OS" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="30" />
<option name="brand" value="google" />
<option name="codename" value="redfin" />
<option name="id" value="redfin" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 5" />
<option name="screenDensity" value="440" />
<option name="screenX" value="1080" />
<option name="screenY" value="2340" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="34" />
<option name="brand" value="google" />
<option name="codename" value="shiba" />
<option name="id" value="shiba" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel 8" />
<option name="screenDensity" value="420" />
<option name="screenX" value="1080" />
<option name="screenY" value="2400" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="33" />
<option name="brand" value="google" />
<option name="codename" value="tangorpro" />
<option name="id" value="tangorpro" />
<option name="manufacturer" value="Google" />
<option name="name" value="Pixel Tablet" />
<option name="screenDensity" value="320" />
<option name="screenX" value="1600" />
<option name="screenY" value="2560" />
</PersistentDeviceSelectionData>
<PersistentDeviceSelectionData>
<option name="api" value="29" />
<option name="brand" value="samsung" />
<option name="codename" value="x1q" />
<option name="id" value="x1q" />
<option name="manufacturer" value="Samsung" />
<option name="name" value="Galaxy S20" />
<option name="screenDensity" value="480" />
<option name="screenX" value="1440" />
<option name="screenY" value="3200" />
</PersistentDeviceSelectionData>
</list>
</option>
</component>
</project>
+1 -1
View File
@@ -64,7 +64,7 @@ This project is built using Kotlin, Java, and Gradle. Here are the steps to buil
### Prerequisites
- Java 8 (1.8)
- Android Studio Jellyfish | 2023.3.1 or later
- Android Gradle Plugin 8.4.1 or later
- Android Gradle Plugin 8.5.0 or later
- Gradle 8.8
- Minimum SDK 26
+38 -31
View File
@@ -3,8 +3,9 @@ plugins {
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
id ("com.mikepenz.aboutlibraries.plugin")
id ("org.jetbrains.kotlin.plugin.serialization")
id("com.mikepenz.aboutlibraries.plugin")
id("org.jetbrains.kotlin.plugin.serialization")
id("org.jetbrains.kotlin.plugin.compose")
}
ksp {
arg("room.schemaLocation", "$projectDir/schemas")
@@ -18,19 +19,14 @@ android {
applicationId = "com.anthonyla.paperize"
minSdk = 26
targetSdk = 34
versionCode = 21
versionName = "1.5.3"
versionCode = 24
versionName = "1.5.6"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
ndk {
debugSymbolLevel = "FULL"
}
}
buildTypes {
release {
isMinifyEnabled = true
@@ -38,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"
}
@@ -60,8 +63,13 @@ android {
androidResources {
generateLocaleConfig = true
}
ndkVersion = "26.3.11579264"
buildToolsVersion = "34.0.0"
dependenciesInfo {
includeInApk = true
includeInBundle = true
}
aboutLibraries {
excludeFields = arrayOf("generated")
@@ -76,47 +84,46 @@ androidComponents {
dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.3")
implementation("androidx.activity:activity-compose:1.9.0")
implementation(platform("androidx.compose:compose-bom:2024.05.00"))
implementation("androidx.compose.ui:ui:1.7.0-beta02")
implementation("androidx.compose.ui:ui-graphics:1.7.0-beta02")
implementation("androidx.compose.ui:ui-tooling-preview:1.7.0-beta02")
implementation("androidx.compose.material3:material3:1.3.0-beta02")
implementation("androidx.navigation:navigation-compose:2.8.0-beta02")
implementation("androidx.compose.material:material:1.7.0-beta02")
implementation(platform("androidx.compose:compose-bom:2024.06.00"))
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-beta02")
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
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-beta02")
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.1")
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:1.7.0-beta02")
implementation("com.github.skydoves:landscapist-glide:2.3.3")
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.0-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-beta02")
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-beta02")
debugImplementation("androidx.compose.ui:ui-tooling:1.7.0-beta02")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.0-beta02")
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.6.3")
implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
}
-1
View File
@@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
@@ -19,7 +19,7 @@ import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.google.android.renderscript.Toolkit
import com.lazygeniouz.dfc.file.DocumentFileCompat
enum class Type { HOME, LOCK, BOTH }
enum class Type { HOME, LOCK, BOTH, REFRESH }
/**
* Get the dimensions of the image from the uri
@@ -157,7 +157,6 @@ fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
return listFilesRecursive(folderDocumentFile, context)
}
}
/**
@@ -199,16 +198,30 @@ fun listFilesRecursive(parent: DocumentFile?, context: Context): List<String> {
*/
fun findFirstValidUri(context: Context, wallpapers: List<Wallpaper>, folders: List<Folder>): String? {
wallpapers.forEach { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
if (file?.exists() == true) {
return wallpaper.wallpaperUri
try {
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
if (file?.exists() == true) {
return wallpaper.wallpaperUri
}
} catch (e: Exception) {
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
if (file?.exists() == true) {
return wallpaper.wallpaperUri
}
}
}
folders.forEach { folder ->
folder.wallpapers.forEach { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
if (file?.exists() == true) {
return wallpaper
try {
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.toUri())
if (file?.exists() == true) {
return wallpaper
}
} catch (e: Exception) {
val file = DocumentFile.fromSingleUri(context, wallpaper.toUri())
if (file?.exists() == true) {
return wallpaper
}
}
}
}
@@ -85,6 +85,7 @@ class MainActivity : ComponentActivity() {
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
if (isFirstLaunch) {
scheduler.cancelWallpaperAlarm()
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
settingsViewModel.onEvent(SettingsEvent.Reset)
albumsViewModel.onEvent(AlbumsEvent.Reset)
@@ -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 ->
@@ -258,6 +250,7 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
},
@@ -272,6 +265,7 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
},
@@ -287,6 +281,7 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
scheduler.scheduleRefresh()
}
}
@@ -303,6 +298,7 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
scheduler.scheduleRefresh()
}
}
@@ -328,10 +324,23 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately,
blur = settingsState.value.blur,
blurPercentage = settingsState.value.blurPercentage,
firstSet = settingsState.value.firstSet,
onToggleChanger = { enableWallpaperChanger ->
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(enableWallpaperChanger))
if (selectedState.value.selectedAlbum!= null && enableWallpaperChanger && (settingsState.value.setHomeWallpaper || settingsState.value.setLockWallpaper)) {
if (selectedState.value.selectedAlbum != null && enableWallpaperChanger && (settingsState.value.setHomeWallpaper || settingsState.value.setLockWallpaper)) {
wallpaperScreenViewModel.onEvent(
WallpaperEvent.UpdateSelectedAlbum(
selectedState.value.selectedAlbum!!.copy(
album = selectedState.value.selectedAlbum!!.album.copy(
currentHomeWallpaper = if (settingsState.value.setHomeWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null,
currentLockWallpaper = if (settingsState.value.scheduleSeparately && settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.lockWallpapersInQueue.firstOrNull() else if (settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null
)
),
null,
settingsState.value.scheduleSeparately,
settingsState.value.setHomeWallpaper,
settingsState.value.setLockWallpaper
)
)
job?.cancel()
job = scope.launch {
delay(2000)
@@ -341,16 +350,22 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
else { scheduler.cancelWallpaperAlarm() }
},
onSelectAlbum = {album ->
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(true))
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(null, album, settingsState.value.scheduleSeparately))
if (settingsState.value.firstSet) {
settingsViewModel.onEvent(SettingsEvent.SetFirstSet)
}
wallpaperScreenViewModel.onEvent(
WallpaperEvent.UpdateSelectedAlbum(
null,
album,
settingsState.value.scheduleSeparately,
settingsState.value.setHomeWallpaper,
settingsState.value.setLockWallpaper
)
)
job?.cancel()
job = scope.launch {
val alarmItem = WallpaperAlarmItem(
@@ -359,6 +374,7 @@ fun PaperizeApp(
scheduleSeparately = settingsState.value.scheduleSeparately
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
},
onDarkenPercentage = {
@@ -414,6 +430,7 @@ fun PaperizeApp(
scheduleSeparately = false
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
@@ -443,7 +460,9 @@ fun PaperizeApp(
timeInMinutes2 = settingsState.value.lockInterval,
scheduleSeparately = false
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}}
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
else if (selectedState.value.selectedAlbum != null && settingsState.value.enableChanger) {
job?.cancel()
@@ -456,6 +475,21 @@ fun PaperizeApp(
onScheduleSeparatelyChange = { changeSeparately ->
settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(changeSeparately))
if (selectedState.value.selectedAlbum!= null && settingsState.value.enableChanger) {
wallpaperScreenViewModel.onEvent(
WallpaperEvent.UpdateSelectedAlbum(
selectedState.value.selectedAlbum!!.copy(
album = selectedState.value.selectedAlbum!!.album.copy(
currentHomeWallpaper = if (settingsState.value.setHomeWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null,
currentLockWallpaper = if (changeSeparately && settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.lockWallpapersInQueue.firstOrNull() else if (settingsState.value.setLockWallpaper) selectedState.value.selectedAlbum!!.album.homeWallpapersInQueue.firstOrNull() else null
)
),
null,
settingsState.value.scheduleSeparately,
settingsState.value.setHomeWallpaper,
settingsState.value.setLockWallpaper
)
)
job?.cancel()
job = scope.launch {
delay(2000)
@@ -465,6 +499,7 @@ fun PaperizeApp(
scheduleSeparately = changeSeparately
)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
scheduler.scheduleRefresh()
}
}
},
@@ -522,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))
}
)
}
@@ -557,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() })
@@ -584,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))
@@ -634,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()
@@ -763,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())
}
}
@@ -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
@@ -86,8 +86,17 @@ class AlbumsViewModel @Inject constructor (
albumWithWallpapers.forEach { albumWithWallpaper ->
// Delete wallpaper if the URI is invalid
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
file?.exists() == true
try {
val file = DocumentFileCompat.fromSingleUri(
context,
wallpaper.wallpaperUri.toUri()
)
file?.exists() == true
} catch (e: Exception) {
val file =
DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
file?.exists() == true
}
}
if (invalidWallpapers.isNotEmpty()) {
repository.deleteWallpaperList(invalidWallpapers)
@@ -96,42 +105,99 @@ class AlbumsViewModel @Inject constructor (
// Update folder cover uri and wallpapers uri
albumWithWallpaper.folders.forEach { folder ->
try {
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
if (!folderDirectory.isDirectory()) {
repository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())
?.let { folderDirectory ->
if (!folderDirectory.isDirectory()) {
repository.deleteFolder(folder)
} else {
val wallpapers =
getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let {
DocumentFileCompat.fromSingleUri(
context,
it.toUri()
)
}
val folderCover =
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
?: wallpapers.randomOrNull()
repository.updateFolder(
folder.copy(
coverUri = folderCover,
wallpapers = wallpapers
)
)
}
}
}
} catch (e: Exception) {
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
if (!folderDirectory.isDirectory) {
repository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
repository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())
?.let { folderDirectory ->
if (!folderDirectory.isDirectory) {
repository.deleteFolder(folder)
} else {
val wallpapers =
getWallpaperFromFolder(folder.folderUri, context)
try {
val folderCoverFile = folder.coverUri?.let {
DocumentFileCompat.fromSingleUri(
context,
it.toUri()
)
}
val folderCover =
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
?: wallpapers.randomOrNull()
repository.updateFolder(
folder.copy(
coverUri = folderCover,
wallpapers = wallpapers
)
)
} catch (e: Exception) {
val folderCoverFile = folder.coverUri?.let {
DocumentFile.fromSingleUri(
context,
it.toUri()
)
}
val folderCover =
folderCoverFile?.takeIf { it.exists() }?.uri?.toString()
?: wallpapers.randomOrNull()
repository.updateFolder(
folder.copy(
coverUri = folderCover,
wallpapers = wallpapers
)
)
}
}
}
}
}
}
}
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
albumWithWallpapers.forEach { albumWithWallpaper ->
// Delete empty albums
if (albumWithWallpaper.wallpapers.isEmpty() && albumWithWallpaper.folders.all { it.wallpapers.isEmpty() }) {
repository.deleteAlbum(albumWithWallpaper.album)
}
else {
// Update album cover uri if null or invalid
val albumCoverFile = albumWithWallpaper.album.coverUri?.toUri()?.let { DocumentFile.fromSingleUri(context, it) }
if (albumCoverFile == null || !albumCoverFile.exists()) {
val newCoverUri = findFirstValidUri(context, albumWithWallpaper.wallpapers, albumWithWallpaper.folders)
repository.updateAlbum(albumWithWallpaper.album.copy(coverUri = newCoverUri))
albumWithWallpapers = repository.getAlbumsWithWallpaperAndFolder().first()
albumWithWallpapers.forEach { album ->
// Delete empty albums
if (album.wallpapers.isEmpty() && album.folders.all { it.wallpapers.isEmpty() }) {
repository.deleteAlbum(album.album)
} else {
// Update album cover uri if null or invalid
try {
val albumCoverFile = album.album.coverUri?.toUri()
?.let { DocumentFileCompat.fromSingleUri(context, it) }
if (albumCoverFile == null || !albumCoverFile.exists()) {
val newCoverUri =
findFirstValidUri(context, album.wallpapers, album.folders)
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
}
} catch (e: Exception) {
val albumCoverFile = album.album.coverUri?.toUri()
?.let { DocumentFile.fromSingleUri(context, it) }
if (albumCoverFile == null || !albumCoverFile.exists()) {
val newCoverUri =
findFirstValidUri(context, album.wallpapers, album.folders)
repository.updateAlbum(album.album.copy(coverUri = newCoverUri))
}
}
}
}
}
@@ -19,7 +19,6 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.core.ScalingConstants
@@ -66,7 +65,6 @@ fun HomeScreen(
onBlurPercentageChange: (Int) -> Unit,
onBlurChange: (Boolean) -> Unit,
blurPercentage: Int,
firstSet: Boolean
) {
val tabItems = getTabItems()
val pagerState = rememberPagerState(0) { tabItems.size }
@@ -97,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(
@@ -131,7 +129,7 @@ fun HomeScreen(
state = pagerState,
beyondViewportPageCount = 1
) { index ->
when(index) {
when(index.coerceIn(tabItems.indices)) {
0 -> WallpaperScreen(
animate = animate,
darken = darken,
@@ -147,25 +145,24 @@ fun HomeScreen(
onDarkenPercentage = onDarkenPercentage,
onHomeCheckedChange = onHomeCheckedChange,
onLockCheckedChange = onLockCheckedChange,
scheduleSeparately = scheduleSeparately,
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
onScheduleWallpaperChanger1 = onScheduleWallpaperChanger1,
onScheduleWallpaperChanger2 = onScheduleWallpaperChanger2,
onScalingChange = onScalingChange,
onSelectAlbum = onSelectAlbum,
onTimeChange1 = onTimeChange1,
onTimeChange2 = onTimeChange2,
onStop = onStop,
onToggleChanger = onToggleChanger,
scaling = scaling,
selectedAlbum = selectedAlbum,
scheduleSeparately = scheduleSeparately,
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
onTimeChange1 = onTimeChange1,
onTimeChange2 = onTimeChange2,
blur = blur,
onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange,
blurPercentage = blurPercentage,
firstSet = firstSet
blurPercentage = blurPercentage
)
1 -> LibraryScreen(
else -> LibraryScreen(
onAddNewAlbumClick = { addAlbumDialog = true },
onViewAlbum = onAlbumViewClick,
animate = animate
@@ -7,7 +7,6 @@ sealed class SettingsEvent {
data object Refresh: SettingsEvent()
data object Reset: SettingsEvent()
data object SetFirstLaunch: SettingsEvent()
data object SetFirstSet: SettingsEvent()
data object RefreshNextSetTime: SettingsEvent()
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
@@ -4,7 +4,6 @@ import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_D
data class SettingsState(
val firstLaunch: Boolean = true,
val firstSet: Boolean = true,
// App settings
val darkMode: Boolean? = null,
val dynamicTheming: Boolean = false,
@@ -35,7 +35,6 @@ class SettingsViewModel @Inject constructor (
init {
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: false }
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: true }
@@ -60,7 +59,6 @@ class SettingsViewModel @Inject constructor (
homeInterval = homeWallpaperInterval.await(),
lockInterval = lockWallpaperInterval.await(),
firstLaunch = firstLaunch.await(),
firstSet = firstSet.await(),
lastSetTime = lastSetTime.await(),
nextSetTime = nextSetTime.await(),
animate = animate.await(),
@@ -121,7 +119,6 @@ class SettingsViewModel @Inject constructor (
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
val blurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.BLUR_PERCENTAGE) ?: 0 }
val firstSet = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_SET) ?: true }
_state.update {
it.copy(
darkMode = darkMode.await(),
@@ -140,7 +137,6 @@ class SettingsViewModel @Inject constructor (
scheduleSeparately = scheduleSeparately.await(),
blur = blur.await(),
blurPercentage = blurPercentage.await(),
firstSet = firstSet.await()
)
}
}
@@ -183,17 +179,6 @@ class SettingsViewModel @Inject constructor (
}
}
is SettingsEvent.SetFirstSet -> {
viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_SET, false)
_state.update {
it.copy(
firstSet = false
)
}
}
}
is SettingsEvent.SetHomeWallpaperInterval -> {
viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
@@ -407,8 +392,7 @@ class SettingsViewModel @Inject constructor (
homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
scheduleSeparately = false,
blur = false,
blurPercentage = 0,
firstSet = true
blurPercentage = 0
)
}
}
@@ -7,8 +7,10 @@ sealed class WallpaperEvent {
data class UpdateSelectedAlbum(
val selectedAlbum: SelectedAlbum?,
val album: AlbumWithWallpaperAndFolder?,
val scheduleSeparately: Boolean = false
val scheduleSeparately: Boolean = false,
val setHome: Boolean = false,
val setLock: Boolean = false
): WallpaperEvent()
object Reset : WallpaperEvent()
object Refresh : WallpaperEvent()
data object Reset : WallpaperEvent()
data object Refresh : WallpaperEvent()
}
@@ -46,7 +46,6 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.co
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowDelayNoticeDialog
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShowLiveWallpaperEnabledDialog
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
@@ -84,8 +83,7 @@ fun WallpaperScreen(
blur: Boolean,
onBlurPercentageChange: (Int) -> Unit,
onBlurChange: (Boolean) -> Unit,
blurPercentage: Int,
firstSet: Boolean
blurPercentage: Int
) {
val context = LocalContext.current
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
@@ -93,7 +91,6 @@ fun WallpaperScreen(
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val openLiveDialog = rememberSaveable { mutableStateOf(false) }
val openNoticeDialog = rememberSaveable { mutableStateOf(false) }
val showInterval = rememberSaveable { mutableStateOf(false) }
val scrollState = rememberScrollState()
@@ -102,14 +99,6 @@ fun WallpaperScreen(
onDismissRequest = { openLiveDialog.value = false }
)
}
if (openNoticeDialog.value) {
ShowDelayNoticeDialog(
onDismissRequest = {
openNoticeDialog.value = false
openBottomSheet = true
}
)
}
Scaffold(
snackbarHost = {
@@ -146,12 +135,7 @@ fun WallpaperScreen(
if (isLiveWallpaperSet(context)) {
openLiveDialog.value = true
} else {
if (firstSet) {
openNoticeDialog.value = true
}
else {
openBottomSheet = true
}
openBottomSheet = true
}
} else {
scope.launch {
@@ -43,6 +43,7 @@ class WallpaperScreenViewModel @Inject constructor (
when (event) {
is WallpaperEvent.UpdateSelectedAlbum -> {
viewModelScope.launch(Dispatchers.IO) {
if (!event.setHome && !event.setLock) return@launch
if (event.selectedAlbum != null) {
_state.update {
it.copy(
@@ -67,8 +68,8 @@ class WallpaperScreenViewModel @Inject constructor (
album = event.album.album.copy(
homeWallpapersInQueue = shuffledWallpapers1,
lockWallpapersInQueue = shuffledWallpapers2,
currentHomeWallpaper = shuffledWallpapers1.firstOrNull(),
currentLockWallpaper = if (event.scheduleSeparately) shuffledWallpapers2.firstOrNull() else shuffledWallpapers1.firstOrNull(),
currentHomeWallpaper = if (event.setHome) shuffledWallpapers1.firstOrNull() else null,
currentLockWallpaper = if (event.scheduleSeparately && event.setLock) shuffledWallpapers2.firstOrNull() else if (event.setLock) shuffledWallpapers1.firstOrNull() else null,
),
wallpapers = wallpapers
)
@@ -1,37 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.anthonyla.paperize.R
/**
* Dialog to let the user know of the app's potential delays when it comes to scheduling wallpapers.
*/
@Composable
fun ShowDelayNoticeDialog(
onDismissRequest: () -> Unit
) {
AlertDialog(
onDismissRequest = { onDismissRequest() },
icon = { Icon(Icons.Filled.Notifications, stringResource(R.string.delay_notice)) },
title = {
Text(stringResource(R.string.delay_notice_dialog))
},
text = {
Text(stringResource(R.string.to_minimize_battery_usage_changing_wallpapers_may_have_some_delays_once_scheduled_when_the_device_is_asleep_the_wallpaper_may_take_longer_to_apply))
},
confirmButton = {
Button(
onClick = { onDismissRequest() }
) {
Text(stringResource(R.string.ok))
}
}
)
}
@@ -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")
}
@@ -3,7 +3,6 @@ package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
import com.anthonyla.paperize.core.Type
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService1
@@ -17,37 +16,47 @@ import dagger.hilt.android.AndroidEntryPoint
class WallpaperReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (context != null) {
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
val timeInMinutes2 = intent?.getIntExtra("timeInMinutes2", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
val type = intent?.getIntExtra("type", Type.BOTH.ordinal) ?: Type.BOTH.ordinal
val serviceIntent = Intent().apply {
putExtra("timeInMinutes1", timeInMinutes1)
putExtra("timeInMinutes2", timeInMinutes2)
putExtra("scheduleSeparately", scheduleSeparately)
putExtra("type", type)
}
if (type == Type.BOTH.ordinal || type == Type.HOME.ordinal) {
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
action = WallpaperService1.Actions.START.toString()
}
} else {
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
action = WallpaperService2.Actions.START.toString()
val refresh = intent?.getBooleanExtra("refresh", false) ?: false
if (refresh) {
val serviceIntent = Intent(context, WallpaperService1::class.java).apply {
action = WallpaperService1.Actions.REFRESH.toString()
}
context.startService(serviceIntent)
WallpaperScheduler(context).scheduleRefresh()
}
context.startService(serviceIntent)
else {
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
val timeInMinutes2 = intent?.getIntExtra("timeInMinutes2", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
val type = intent?.getIntExtra("type", Type.BOTH.ordinal) ?: Type.BOTH.ordinal
val serviceIntent = Intent().apply {
putExtra("timeInMinutes1", timeInMinutes1)
putExtra("timeInMinutes2", timeInMinutes2)
putExtra("scheduleSeparately", scheduleSeparately)
putExtra("type", type)
}
if (type == Type.BOTH.ordinal || type == Type.HOME.ordinal) {
serviceIntent.setClass(context, WallpaperService1::class.java).apply {
action = WallpaperService1.Actions.START.toString()
}
} else {
serviceIntent.setClass(context, WallpaperService2::class.java).apply {
action = WallpaperService2.Actions.START.toString()
}
}
context.startService(serviceIntent)
// Schedule next alarm for next wallpaper change
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
WallpaperScheduler(context).scheduleWallpaperAlarm(
WallpaperAlarmItem(
timeInMinutes1 = timeInMinutes1,
timeInMinutes2 = timeInMinutes2,
scheduleSeparately = scheduleSeparately
),
origin
)
// Schedule next alarm for next wallpaper change
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
WallpaperScheduler(context).scheduleWallpaperAlarm(
WallpaperAlarmItem(
timeInMinutes1 = timeInMinutes1,
timeInMinutes2 = timeInMinutes2,
scheduleSeparately = scheduleSeparately
),
origin
)
}
}
}
}
@@ -5,7 +5,6 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import com.anthonyla.paperize.core.Type
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService1
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.WallpaperService2
@@ -22,6 +21,9 @@ class WallpaperScheduler (
): WallpaperAlarmScheduler {
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
/**
* Schedules the wallpaper alarm based on the origin and changeImmediate
*/
override fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int?, changeImmediate: Boolean, cancelImmediate: Boolean) {
if (cancelImmediate) cancelWallpaperAlarm()
else {
@@ -37,21 +39,21 @@ class WallpaperScheduler (
}
if (wallpaperAlarmItem.scheduleSeparately) {
when (origin) {
Type.HOME.ordinal -> {
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin)
}
Type.LOCK.ordinal -> {
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin)
}
Type.HOME.ordinal -> {
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin)
}
null -> {
if (changeImmediate) {
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
}
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal)
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal)
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal)
}
}
}
@@ -61,31 +63,41 @@ class WallpaperScheduler (
}
}
/**
* Update the alarms
*/
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem) {
cancelWallpaperAlarm()
if (wallpaperAlarmItem.scheduleSeparately) {
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, true)
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, true)
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, true)
}
else {
scheduleWallpaper(wallpaperAlarmItem, Type.BOTH, null, true)
}
}
/**
* Update the wallpaper without scheduling alarms
*/
override fun updateWallpaper(scheduleSeparately: Boolean) {
if (scheduleSeparately) {
updateWallpaper(Type.HOME)
updateWallpaper(Type.LOCK)
updateWallpaper(Type.HOME)
}
else {
updateWallpaper(Type.BOTH)
}
}
/**
* Cancels all active alarms
*/
override fun cancelWallpaperAlarm() {
cancelAlarm(Type.HOME)
cancelAlarm(Type.LOCK)
cancelAlarm(Type.BOTH)
cancelAlarm(Type.REFRESH)
}
/**
@@ -95,6 +107,7 @@ class WallpaperScheduler (
val nextTime = when (type) {
Type.HOME, Type.BOTH -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.timeInMinutes1.toLong())
Type.LOCK -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.timeInMinutes2.toLong())
else -> LocalDateTime.now()
}
val intent = Intent(context, WallpaperReceiver::class.java).apply {
putExtra("timeInMinutes1", wallpaperAlarmItem.timeInMinutes1)
@@ -106,10 +119,7 @@ class WallpaperScheduler (
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!alarmManager.canScheduleExactAlarms()) {
Intent().also {
it.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
context.startActivity(it)
}
cancelWallpaperAlarm()
}
else {
alarmManager.setExactAndAllowWhileIdle(
@@ -156,6 +166,46 @@ class WallpaperScheduler (
}
}
/**
* Schedules a refresh alarm every 24hrs
*/
fun scheduleRefresh() {
cancelAlarm(Type.REFRESH)
val intent = Intent(context, WallpaperReceiver::class.java).apply {
putExtra("refresh", true)
}
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!alarmManager.canScheduleExactAlarms()) {
cancelWallpaperAlarm()
}
else {
alarmManager.setExact(
AlarmManager.RTC_WAKEUP,
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
PendingIntent.getBroadcast(
context,
Type.REFRESH.ordinal,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
)
}
}
else {
alarmManager.setExact(
AlarmManager.RTC_WAKEUP,
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
PendingIntent.getBroadcast(
context,
Type.REFRESH.ordinal,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
)
}
}
/**
* Use the service to change the wallpaper
*/
@@ -72,7 +72,8 @@ class WallpaperService1: Service() {
enum class Actions {
START,
REQUEUE,
UPDATE
UPDATE,
REFRESH
}
override fun onBind(p0: Intent?): IBinder? {
@@ -110,6 +111,9 @@ class WallpaperService1: Service() {
Actions.UPDATE.toString() -> {
workerTaskUpdate()
}
Actions.REFRESH.toString() -> {
workerTaskRefresh()
}
}
}
return START_NOT_STICKY
@@ -124,8 +128,7 @@ class WallpaperService1: Service() {
private fun workerTaskStart(setHomeOrLock: Boolean? = null) {
workerHandler.post {
CoroutineScope(Dispatchers.IO).launch {
refreshAlbum(this@WallpaperService1)
delay(2000)
if (scheduleSeparately) delay(5000)
changeWallpaper(this@WallpaperService1, setHomeOrLock)
}
stopSelf()
@@ -155,6 +158,15 @@ class WallpaperService1: Service() {
}
}
private fun workerTaskRefresh() {
workerHandler.post {
CoroutineScope(Dispatchers.IO).launch {
refreshAlbum(this@WallpaperService1)
}
stopSelf()
}
}
/**
* Creates a notification for the wallpaper service
*/
@@ -252,9 +264,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -299,9 +309,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue
),
wallpapers = it.wallpapers.filter { it == it1 }
)
@@ -344,9 +352,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
currentHomeWallpaper = null,
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -391,9 +397,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
currentHomeWallpaper = null,
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
),
wallpapers = it.wallpapers.filter { it == it1 }
)
@@ -468,8 +472,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
currentHomeWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -498,8 +501,7 @@ class WallpaperService1: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -527,14 +529,14 @@ class WallpaperService1: Service() {
setHome: Boolean, setLock: Boolean,
setLockOrHome: Boolean? = null,
blur: Boolean = false,
blurPercent: Int
blurPercent: Int,
): Boolean {
val wallpaperManager = WallpaperManager.getInstance(context)
try {
val imageSize = wallpaper.getImageDimensions(context) ?: return false
val aspectRatio = imageSize.height.toFloat() / imageSize.width.toFloat()
val device = context.resources.displayMetrics
val targetWidth = min(4 * device.widthPixels, imageSize.width)
val targetWidth = min(device.widthPixels, imageSize.width)
val targetHeight = (targetWidth * aspectRatio).toInt()
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -631,7 +633,7 @@ class WallpaperService1: Service() {
albumWithWallpapers.forEach { albumWithWallpaper ->
// Delete wallpaper if the URI is invalid
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
val file = DocumentFileCompat.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
file?.exists() == true
}
if (invalidWallpapers.isNotEmpty()) {
@@ -646,7 +648,7 @@ class WallpaperService1: Service() {
albumRepository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCoverFile = folder.coverUri?.let { DocumentFileCompat.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
@@ -657,7 +659,7 @@ class WallpaperService1: Service() {
albumRepository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCoverFile = folder.coverUri?.let { DocumentFileCompat.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
@@ -19,7 +19,6 @@ import android.util.DisplayMetrics
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.core.SettingsConstants
@@ -30,19 +29,14 @@ import com.anthonyla.paperize.core.darkenBitmap
import com.anthonyla.paperize.core.fillBitmap
import com.anthonyla.paperize.core.fitBitmap
import com.anthonyla.paperize.core.getImageDimensions
import com.anthonyla.paperize.core.getWallpaperFromFolder
import com.anthonyla.paperize.core.stretchBitmap
import com.anthonyla.paperize.data.settings.SettingsDataStore
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
import com.anthonyla.paperize.feature.wallpaper.domain.repository.SelectedAlbumRepository
import com.anthonyla.paperize.feature.wallpaper.presentation.MainActivity
import com.lazygeniouz.dfc.file.DocumentFileCompat
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import java.io.IOException
@@ -53,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() {
@@ -124,9 +118,6 @@ class WallpaperService2: Service() {
private fun workerTaskStart(setHomeOrLock: Boolean? = null) {
workerHandler.post {
CoroutineScope(Dispatchers.IO).launch {
delay(3000)
refreshAlbum(this@WallpaperService2)
delay(2000)
changeWallpaper(this@WallpaperService2, setHomeOrLock)
}
stopSelf()
@@ -257,8 +248,6 @@ class WallpaperService2: Service() {
album = it.album.copy(
homeWallpapersInQueue = if (setHomeOrLock) it.album.homeWallpapersInQueue.drop(1) else it.album.homeWallpapersInQueue,
lockWallpapersInQueue = if (!setHomeOrLock) it.album.lockWallpapersInQueue.drop(1) else it.album.lockWallpapersInQueue,
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -303,9 +292,7 @@ class WallpaperService2: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = if (setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.homeWallpapersInQueue,
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue,
currentHomeWallpaper = if (setHomeOrLock) wallpaper else it.album.currentHomeWallpaper,
currentLockWallpaper = if (!setHomeOrLock) wallpaper else it.album.currentLockWallpaper
lockWallpapersInQueue = if (!setHomeOrLock) newWallpaperInQueue.drop(1) else it.album.lockWallpapersInQueue
),
wallpapers = it.wallpapers.filter { it == it1 }
)
@@ -348,9 +335,7 @@ class WallpaperService2: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
currentHomeWallpaper = null,
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -364,7 +349,7 @@ class WallpaperService2: Service() {
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
currentHomeWallpaper = wallpaper,
currentLockWallpaper = wallpaper
currentLockWallpaper = wallpaper,
)
)
)
@@ -395,9 +380,7 @@ class WallpaperService2: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.drop(1),
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper },
currentHomeWallpaper = null,
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper }
),
wallpapers = it.wallpapers.filter { it == it1 }
)
@@ -472,8 +455,7 @@ class WallpaperService2: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
currentHomeWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -502,8 +484,7 @@ class WallpaperService2: Service() {
it.copy(
album = it.album.copy(
homeWallpapersInQueue = it.album.homeWallpapersInQueue.filter { it != wallpaper1 },
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 },
currentLockWallpaper = null
lockWallpapersInQueue = it.album.lockWallpapersInQueue.filter { it != wallpaper1 }
),
wallpapers = it.wallpapers.filter { it == it1 },
)
@@ -531,14 +512,14 @@ class WallpaperService2: Service() {
setHome: Boolean, setLock: Boolean,
setLockOrHome: Boolean? = null,
blur: Boolean = false,
blurPercent: Int
blurPercent: Int,
): Boolean {
val wallpaperManager = WallpaperManager.getInstance(context)
try {
val imageSize = wallpaper.getImageDimensions(context) ?: return false
val aspectRatio = imageSize.height.toFloat() / imageSize.width.toFloat()
val device = context.resources.displayMetrics
val targetWidth = min(4 * device.widthPixels, imageSize.width)
val targetWidth = min(device.widthPixels, imageSize.width)
val targetHeight = (targetWidth * aspectRatio).toInt()
val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -582,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
@@ -627,101 +608,4 @@ class WallpaperService2: Service() {
return null
}
}
private fun refreshAlbum(context: Context) {
CoroutineScope(Dispatchers.IO).launch {
try {
var albumWithWallpapers = albumRepository.getAlbumsWithWallpaperAndFolder().first()
albumWithWallpapers.forEach { albumWithWallpaper ->
// Delete wallpaper if the URI is invalid
val invalidWallpapers = albumWithWallpaper.wallpapers.filterNot { wallpaper ->
val file = DocumentFile.fromSingleUri(context, wallpaper.wallpaperUri.toUri())
file?.exists() == true
}
if (invalidWallpapers.isNotEmpty()) {
albumRepository.deleteWallpaperList(invalidWallpapers)
}
// Update folder cover uri and wallpapers uri
albumWithWallpaper.folders.forEach { folder ->
try {
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
if (!folderDirectory.isDirectory()) {
albumRepository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
}
} catch (e: Exception) {
DocumentFile.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
if (!folderDirectory.isDirectory) {
albumRepository.deleteFolder(folder)
} else {
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
val folderCoverFile = folder.coverUri?.let { DocumentFile.fromSingleUri(context, it.toUri()) }
val folderCover = folderCoverFile?.takeIf { it.exists() }?.uri?.toString() ?: wallpapers.randomOrNull()
albumRepository.updateFolder(folder.copy(coverUri = folderCover, wallpapers = wallpapers))
}
}
}
}
// Delete empty albums
if (albumWithWallpaper.wallpapers.isEmpty() && albumWithWallpaper.folders.all { it.wallpapers.isEmpty() }) {
albumRepository.deleteAlbum(albumWithWallpaper.album)
}
}
// Update selected album
albumWithWallpapers = albumRepository.getAlbumsWithWallpaperAndFolder().first()
val selectedAlbum = selectedRepository.getSelectedAlbum().first().firstOrNull()
if (selectedAlbum != null) {
albumWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName }
?.let { foundAlbum ->
val albumNameHashCode = foundAlbum.album.initialAlbumName.hashCode()
val wallpapers: List<Wallpaper> =
foundAlbum.wallpapers + foundAlbum.folders.flatMap { folder ->
folder.wallpapers.map { wallpaper ->
Wallpaper(
initialAlbumName = foundAlbum.album.initialAlbumName,
wallpaperUri = wallpaper,
key = wallpaper.hashCode() + albumNameHashCode,
)
}
}
val wallpapersUri = wallpapers.map { it.wallpaperUri }.toSet()
if (wallpapersUri.isEmpty()) {
selectedRepository.deleteAll()
onDestroy()
}
else {
val newSelectedAlbum = SelectedAlbum(
album = foundAlbum.album.copy(
homeWallpapersInQueue = if (selectedAlbum.album.homeWallpapersInQueue.firstOrNull() in wallpapersUri) {
val firstElement = selectedAlbum.album.homeWallpapersInQueue.first()
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
listOf(firstElement) + modifiedWallpapersUri.shuffled()
} else { wallpapersUri.shuffled() },
lockWallpapersInQueue = if (selectedAlbum.album.lockWallpapersInQueue.firstOrNull() in wallpapersUri) {
val firstElement = selectedAlbum.album.lockWallpapersInQueue.first()
val modifiedWallpapersUri = wallpapersUri.filter { it != firstElement }
listOf(firstElement) + modifiedWallpapersUri.shuffled()
} else { wallpapersUri.shuffled() },
currentHomeWallpaper = if (selectedAlbum.album.currentHomeWallpaper in wallpapersUri) selectedAlbum.album.currentHomeWallpaper else selectedAlbum.album.homeWallpapersInQueue.firstOrNull { it in wallpapersUri },
currentLockWallpaper = if (selectedAlbum.album.currentLockWallpaper in wallpapersUri) selectedAlbum.album.currentLockWallpaper else selectedAlbum.album.lockWallpapersInQueue.firstOrNull { it in wallpapersUri }
),
wallpapers = wallpapers
)
selectedRepository.upsertSelectedAlbum(newSelectedAlbum)
}
} ?: run { onDestroy() }
}
} catch (e: Exception) {
Log.e("PaperizeWallpaperChanger", "Error refreshing album", e)
}
}
}
}
+8 -7
View File
@@ -6,13 +6,14 @@ buildscript {
}
plugins {
id("com.android.application") version "8.4.1" apply false
id("com.android.library") version "8.4.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.google.dagger.hilt.android") version "2.50" apply false
id("com.google.devtools.ksp") version "1.9.0-1.0.13" apply false
id ("com.mikepenz.aboutlibraries.plugin") version "11.1.3" apply false
id ("org.jetbrains.kotlin.plugin.serialization") version "1.9.22" apply false
id("com.android.application") version "8.5.0" apply false
id("com.android.library") version "8.5.0" apply false
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
id ("org.jetbrains.kotlin.plugin.compose") version "2.0.0" apply false
id("com.google.dagger.hilt.android") version "2.51.1" apply false
id("com.google.devtools.ksp") version "2.0.0-1.0.21" apply false
id ("com.mikepenz.aboutlibraries.plugin") version "11.2.1" apply false
id ("org.jetbrains.kotlin.plugin.serialization") version "2.0.0" apply false
}
Binary file not shown.