fix some bugs
This commit is contained in:
1 parent
894b86cd14
commit
572252b187
14 files changed
+94
-622
No files matched your search
@@ -42,6 +42,12 @@ interface AlbumDao {
|
||||
@Query("SELECT * FROM albums WHERE id = :albumId")
|
||||
suspend fun getAlbumById(albumId: String): AlbumEntity?
|
||||
|
||||
/**
|
||||
* Get a specific album by name
|
||||
*/
|
||||
@Query("SELECT * FROM albums WHERE name = :name LIMIT 1")
|
||||
suspend fun getAlbumByName(name: String): AlbumEntity?
|
||||
|
||||
/**
|
||||
* Get album count
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,9 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
override fun getAlbumById(albumId: String): Flow<Album?> =
|
||||
albumDao.getAlbumWithDetails(albumId).map { it?.toDomainModel() }
|
||||
|
||||
override suspend fun getAlbumByName(name: String): Album? =
|
||||
albumDao.getAlbumByName(name)?.toDomainModel()
|
||||
|
||||
override fun getFolderById(folderId: String): Flow<Folder?> =
|
||||
folderDao.getFolderWithWallpapers(folderId).map { it?.toDomainModel() }
|
||||
|
||||
|
||||
@@ -217,6 +217,15 @@ class WallpaperRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clearQueuesForAlbum(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
wallpaperQueueDao.clearAllQueues(albumId)
|
||||
Result.Success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun normalizeAllQueuesForAlbum(albumId: String): Result<Unit> {
|
||||
return try {
|
||||
// Normalize both HOME and LOCK queues for this album
|
||||
|
||||
@@ -22,6 +22,11 @@ interface AlbumRepository {
|
||||
*/
|
||||
fun getAlbumById(albumId: String): Flow<Album?>
|
||||
|
||||
/**
|
||||
* Get a specific album by name
|
||||
*/
|
||||
suspend fun getAlbumByName(name: String): Album?
|
||||
|
||||
/**
|
||||
* Get a specific folder by ID
|
||||
*/
|
||||
|
||||
@@ -96,6 +96,12 @@ interface WallpaperRepository {
|
||||
*/
|
||||
suspend fun clearAllQueues(): Result<Unit>
|
||||
|
||||
/**
|
||||
* Clear all queues for a specific album
|
||||
* Used when sort order changes to force rebuild with new order
|
||||
*/
|
||||
suspend fun clearQueuesForAlbum(albumId: String): Result<Unit>
|
||||
|
||||
/**
|
||||
* Normalize queue positions for all queues (HOME and LOCK) of an album
|
||||
* Fixes gaps in queue positions caused by CASCADE deletes when wallpapers are removed
|
||||
|
||||
@@ -15,6 +15,12 @@ class CreateAlbumUseCase @Inject constructor(
|
||||
if (name.isBlank()) {
|
||||
return Result.Error(IllegalArgumentException("Album name cannot be empty"))
|
||||
}
|
||||
|
||||
val existingAlbum = albumRepository.getAlbumByName(name)
|
||||
if (existingAlbum != null) {
|
||||
return Result.Error(IllegalArgumentException("Album with this name already exists"))
|
||||
}
|
||||
|
||||
return albumRepository.createAlbum(name, coverUri)
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.anthonyla.paperize.presentation.theme.AppSpacing
|
||||
fun AddAlbumDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (String) -> Unit,
|
||||
errorMessage: String? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var albumName by remember { mutableStateOf("") }
|
||||
@@ -32,6 +33,10 @@ fun AddAlbumDialog(
|
||||
onValueChange = { albumName = it },
|
||||
label = { Text(stringResource(R.string.album_name)) },
|
||||
singleLine = true,
|
||||
isError = errorMessage != null,
|
||||
supportingText = if (errorMessage != null) {
|
||||
{ Text(errorMessage, color = MaterialTheme.colorScheme.error) }
|
||||
} else null,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
|
||||
+17
-20
@@ -235,19 +235,17 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
// Only change wallpaper and schedule if all required albums are selected
|
||||
if (hasRequiredAlbums) {
|
||||
val screenType = when {
|
||||
homeActive && lockActive && updated.homeAlbumId == updated.lockAlbumId && !updated.separateSchedules ->
|
||||
ScreenType.BOTH
|
||||
homeActive && lockActive ->
|
||||
ScreenType.BOTH // Change both even if different albums
|
||||
homeActive -> ScreenType.HOME
|
||||
lockActive -> ScreenType.LOCK
|
||||
else -> null
|
||||
}
|
||||
|
||||
// Only change wallpaper now if this is not a "check if scheduled" call
|
||||
if (!onlyIfNotScheduled) {
|
||||
screenType?.let { changeWallpaperNow(it) }
|
||||
val isSynced = homeActive && lockActive &&
|
||||
updated.homeAlbumId == updated.lockAlbumId &&
|
||||
!updated.separateSchedules
|
||||
if (isSynced) {
|
||||
changeWallpaperNow(ScreenType.BOTH)
|
||||
} else {
|
||||
if (homeActive) changeWallpaperNow(ScreenType.HOME)
|
||||
if (lockActive) changeWallpaperNow(ScreenType.LOCK)
|
||||
}
|
||||
}
|
||||
scheduleAlarms(updated, onlyIfNotScheduled)
|
||||
} else {
|
||||
@@ -315,16 +313,15 @@ class HomeViewModel @Inject constructor(
|
||||
// Handle display changes (scaling, effects, adaptive brightness)
|
||||
// Reapply current wallpaper immediately to show the effect
|
||||
if (validated.enableChanger && hasRequiredAlbums && displayChanged) {
|
||||
val screenType = when {
|
||||
homeActive && lockActive && validated.homeAlbumId == validated.lockAlbumId && !validated.separateSchedules ->
|
||||
ScreenType.BOTH
|
||||
homeActive && lockActive ->
|
||||
ScreenType.BOTH // Change both even if different albums
|
||||
homeActive -> ScreenType.HOME
|
||||
lockActive -> ScreenType.LOCK
|
||||
else -> null
|
||||
val isSynced = homeActive && lockActive &&
|
||||
validated.homeAlbumId == validated.lockAlbumId &&
|
||||
!validated.separateSchedules
|
||||
if (isSynced) {
|
||||
changeWallpaperNow(ScreenType.BOTH)
|
||||
} else {
|
||||
if (homeActive) changeWallpaperNow(ScreenType.HOME)
|
||||
if (lockActive) changeWallpaperNow(ScreenType.LOCK)
|
||||
}
|
||||
screenType?.let { changeWallpaperNow(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -19,7 +19,7 @@ fun HomeTopBar(
|
||||
onSettingsClick: () -> Unit
|
||||
) {
|
||||
if (!showSelectionModeAppBar) {
|
||||
TopAppBar(
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text(stringResource(R.string.app_name)) },
|
||||
actions = {
|
||||
IconButton(onClick = onSettingsClick) {
|
||||
|
||||
+4
-4
@@ -2,9 +2,9 @@ package com.anthonyla.paperize.presentation.screens.home.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Wallpaper
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.PhotoLibrary
|
||||
import androidx.compose.material.icons.outlined.Wallpaper
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class TabItem(
|
||||
@@ -19,8 +19,8 @@ fun getTabItems(
|
||||
): List<TabItem> = listOf(
|
||||
TabItem(
|
||||
title = wallpaperTitle,
|
||||
unfilledIcon = Icons.Outlined.Wallpaper,
|
||||
filledIcon = Icons.Filled.Wallpaper
|
||||
unfilledIcon = Icons.Outlined.Image,
|
||||
filledIcon = Icons.Filled.Image
|
||||
),
|
||||
TabItem(
|
||||
title = libraryTitle,
|
||||
|
||||
+17
-3
@@ -22,6 +22,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -45,6 +46,7 @@ fun LibraryScreen(
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
var showAddAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var albumNameError by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
Scaffold(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
@@ -117,10 +119,22 @@ fun LibraryScreen(
|
||||
|
||||
if (showAddAlbumDialog) {
|
||||
AddAlbumDialog(
|
||||
onDismiss = { },
|
||||
onDismiss = {
|
||||
showAddAlbumDialog = false
|
||||
albumNameError = null
|
||||
},
|
||||
onConfirm = { name ->
|
||||
onCreateAlbum(name)
|
||||
}
|
||||
// Check if album with this name already exists
|
||||
val isDuplicate = albums.any { it.name.equals(name, ignoreCase = true) }
|
||||
if (isDuplicate) {
|
||||
albumNameError = "Album with this name already exists"
|
||||
} else {
|
||||
onCreateAlbum(name)
|
||||
showAddAlbumDialog = false
|
||||
albumNameError = null
|
||||
}
|
||||
},
|
||||
errorMessage = albumNameError
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,12 @@ class SortViewModel @Inject constructor(
|
||||
is com.anthonyla.paperize.core.Result.Loading -> { /* Loading state not used */ }
|
||||
}
|
||||
}
|
||||
|
||||
// Clear queues for this album to force rebuild with new sort order
|
||||
// This ensures the wallpaper changer respects the new order immediately
|
||||
if (!hasError) {
|
||||
wallpaperRepository.clearQueuesForAlbum(albumId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,14 @@ class AlbumRefreshWorker @AssistedInject constructor(
|
||||
|
||||
// Add new wallpapers to album
|
||||
newWallpapers.forEach { wallpaper ->
|
||||
when (wallpaperRepository.addWallpaper(wallpaper)) {
|
||||
// Fix: Create copy with correct albumId and folderId
|
||||
// scanFolderForWallpapers returns wallpapers with empty albumId/null folderId
|
||||
val wallpaperToAdd = wallpaper.copy(
|
||||
albumId = album.id,
|
||||
folderId = folder.id
|
||||
)
|
||||
|
||||
when (wallpaperRepository.addWallpaper(wallpaperToAdd)) {
|
||||
is CoreResult.Success -> {
|
||||
totalAdded++
|
||||
albumHasNewWallpapers = true
|
||||
|
||||
Reference in new issue
Block a user