Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e20f211f2 | ||
|
|
6f4a2bec97 | ||
|
|
85e5e3007b | ||
|
|
4760ab01d5 | ||
|
|
d8fc106a89 |
No files matched your search
Generated
+1
-1
@@ -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>
|
||||
Generated
+263
@@ -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>
|
||||
+22
-21
@@ -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,8 +19,8 @@ android {
|
||||
applicationId = "com.anthonyla.paperize"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 21
|
||||
versionName = "1.5.3"
|
||||
versionCode = 23
|
||||
versionName = "1.5.5"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
@@ -76,47 +77,47 @@ 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.2")
|
||||
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-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.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("androidx.compose.material:material-icons-extended:1.7.0-beta03")
|
||||
implementation("com.google.accompanist:accompanist-adaptive:0.34.0")
|
||||
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-beta03")
|
||||
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.2")
|
||||
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.4")
|
||||
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("androidx.compose.foundation:foundation:1.7.0-beta03")
|
||||
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.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")
|
||||
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.0")
|
||||
implementation("com.github.android:renderscript-intrinsics-replacement-toolkit:b6363490c3")
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -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)
|
||||
|
||||
+50
-7
@@ -258,6 +258,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -272,6 +273,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -287,6 +289,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,6 +306,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,10 +332,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 +358,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 +382,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
},
|
||||
onDarkenPercentage = {
|
||||
@@ -414,6 +438,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 +468,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 +483,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 +507,7 @@ fun PaperizeApp(
|
||||
scheduleSeparately = changeSeparately
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+99
-33
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -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 }
|
||||
@@ -147,23 +145,22 @@ 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(
|
||||
onAddNewAlbumClick = { addAlbumDialog = true },
|
||||
|
||||
-1
@@ -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()
|
||||
|
||||
-1
@@ -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,
|
||||
|
||||
+1
-17
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -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()
|
||||
}
|
||||
+2
-18
@@ -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 {
|
||||
|
||||
+3
-2
@@ -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
|
||||
)
|
||||
|
||||
-37
@@ -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))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+38
-29
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+63
-13
@@ -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
|
||||
*/
|
||||
|
||||
+26
-24
@@ -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))
|
||||
}
|
||||
|
||||
+12
-127
@@ -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
|
||||
@@ -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()
|
||||
@@ -247,7 +238,7 @@ class WallpaperService2: Service() {
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
blurPercent = blurPercentage,
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { it1 ->
|
||||
@@ -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 }
|
||||
)
|
||||
@@ -339,7 +326,7 @@ class WallpaperService2: Service() {
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
blurPercent = blurPercentage,
|
||||
)) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == wallpaper }
|
||||
?.let { 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,
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -385,7 +370,7 @@ class WallpaperService2: Service() {
|
||||
setLock = setLock,
|
||||
setLockOrHome = setHomeOrLock,
|
||||
blur = blur,
|
||||
blurPercent = blurPercentage
|
||||
blurPercent = blurPercentage,
|
||||
)
|
||||
) {
|
||||
selectedAlbum.wallpapers.firstOrNull { it.wallpaperUri == 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,15 @@ class WallpaperService2: Service() {
|
||||
setHome: Boolean, setLock: Boolean,
|
||||
setLockOrHome: Boolean? = null,
|
||||
blur: Boolean = false,
|
||||
blurPercent: Int
|
||||
blurPercent: Int,
|
||||
lastHomeWallpaper: Uri? = null,
|
||||
): 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) {
|
||||
@@ -627,101 +609,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -8,10 +8,11 @@ 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.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" 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 "1.9.22" apply false
|
||||
}
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Reference in new issue
Block a user