Fixed album wallpapers not being refreshed before changing wallpapers
Fixed album cover art not being refreshed
This commit is contained in:
1 parent
87ef7ebaf0
commit
068f78f86c
4 files changed
+51
-20
No files matched your search
+13
-7
@@ -101,9 +101,7 @@ fun PaperizeApp(
|
||||
}
|
||||
}
|
||||
albumsViewModel.onEvent(
|
||||
AlbumsEvent.DeleteAlbumWithWallpapers(
|
||||
albumWithWallpapers
|
||||
)
|
||||
AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -124,10 +122,18 @@ fun PaperizeApp(
|
||||
val wallpapersUri = wallpapers.map { it.wallpaperUri }.toSet()
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = selectedAlbum.album.homeWallpapersInQueue.filter { it in wallpapersUri },
|
||||
lockWallpapersInQueue = selectedAlbum.album.lockWallpapersInQueue.filter { it in wallpapersUri },
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
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
|
||||
)
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ class AlbumsViewModel @Inject constructor (
|
||||
repository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder cover uri and children uri
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
|
||||
+19
-6
@@ -41,6 +41,7 @@ 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
|
||||
@@ -123,6 +124,8 @@ class WallpaperService1: Service() {
|
||||
private fun workerTaskStart(setHomeOrLock: Boolean? = null) {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
refreshAlbum(this@WallpaperService1)
|
||||
delay(1000)
|
||||
changeWallpaper(this@WallpaperService1, setHomeOrLock)
|
||||
}
|
||||
stopSelf()
|
||||
@@ -625,14 +628,16 @@ class WallpaperService1: Service() {
|
||||
albumRepository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder wallpapers
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
albumRepository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
albumRepository.updateFolder(folder.copy(wallpapers = wallpapers))
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,10 +673,18 @@ class WallpaperService1: Service() {
|
||||
else {
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = wallpapersUri.shuffled(),
|
||||
lockWallpapersInQueue = wallpapersUri.shuffled(),
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
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
|
||||
)
|
||||
|
||||
+18
-6
@@ -125,6 +125,8 @@ class WallpaperService2: Service() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
delay(5 * 1000)
|
||||
refreshAlbum(this@WallpaperService2)
|
||||
delay(1000)
|
||||
changeWallpaper(this@WallpaperService2, setHomeOrLock)
|
||||
}
|
||||
stopSelf()
|
||||
@@ -630,14 +632,16 @@ class WallpaperService2: Service() {
|
||||
albumRepository.deleteWallpaperList(invalidWallpapers)
|
||||
}
|
||||
|
||||
// Update folder wallpapers
|
||||
// Update folder cover uri and wallpapers uri
|
||||
albumWithWallpaper.folders.forEach { folder ->
|
||||
DocumentFileCompat.fromTreeUri(context, folder.folderUri.toUri())?.let { folderDirectory ->
|
||||
if (!folderDirectory.isDirectory()) {
|
||||
albumRepository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
albumRepository.updateFolder(folder.copy(wallpapers = wallpapers))
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -673,10 +677,18 @@ class WallpaperService2: Service() {
|
||||
else {
|
||||
val newSelectedAlbum = SelectedAlbum(
|
||||
album = foundAlbum.album.copy(
|
||||
homeWallpapersInQueue = wallpapersUri.shuffled(),
|
||||
lockWallpapersInQueue = wallpapersUri.shuffled(),
|
||||
currentHomeWallpaper = selectedAlbum.album.currentHomeWallpaper,
|
||||
currentLockWallpaper = selectedAlbum.album.currentLockWallpaper,
|
||||
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
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user