feat(album): Add Album menu for rescan and rename #2
No files matched your search
+2
-1
@@ -17,4 +17,5 @@ local.properties
|
||||
/app/build
|
||||
/app/release
|
||||
.kotlin
|
||||
/.kotlin/sessions
|
||||
/.kotlin/sessions
|
||||
*.jks
|
||||
@@ -20,7 +20,7 @@ Paperize is an Android app that changes your home and lock screen wallpaper on a
|
||||
<img src=".github/readme/feature-albums-light.png" alt="01. Albums, on rotation. The library with two albums, and an album open showing its wallpapers.">
|
||||
</picture>
|
||||
|
||||
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and once a day while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Removing something from an album never touches the file on your device.
|
||||
An album holds single images, whole folders, or both. Paperize rescans folders each time you open the app, and once a day while a schedule is running, so new files join the rotation and deleted ones leave it by themselves; **Refresh folder** rescans one straight away. Open an album's options menu to rename or delete it, or rescan all its folders. Removing something from an album never touches the file on your device.
|
||||
|
||||
When creating an album, you can mark it encrypted; this choice is permanent and imports only `.jpg_enc` files made by wallpaper_changer. Set the same passphrase in **Settings → Encrypted albums**. It is protected by Android Keystore and remains available for scheduled changes. Encrypted previews are off by default; enabling them decrypts images in memory without caching them to disk. Turning previews off removes them from the app's display. Android may still retain the applied wallpaper, and wallpaper_changer's encryption format does not authenticate its contents.
|
||||
|
||||
@@ -90,6 +90,8 @@ cd Paperize
|
||||
|
||||
The APK lands in `app/build/outputs/apk/debug`. Or open the folder in Android Studio and press Run.
|
||||
|
||||
For the development setup with an emulator on `lucas@quiethost`, `./build_and_install.sh` builds locally, installs the debug app and test APK remotely, copies test images, and runs the tests. The Android tests can cancel wallpaper schedules in the installed app.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome. Report bugs in [issues](https://github.com/Anthonyy232/Paperize/issues), suggest features in [Discussions](https://github.com/Anthonyy232/Paperize/discussions), and read [AGENTS.md](AGENTS.md) before opening a pull request.
|
||||
|
||||
+13
@@ -34,6 +34,19 @@ class AlbumRepositoryInstrumentedTest {
|
||||
|
||||
@After fun close() = db.close()
|
||||
|
||||
@Test fun renamingPreservesAlbumContentsAndRejectsOtherNamesIgnoringCase() = runBlocking {
|
||||
val album = albums.createAlbum("Original", isEncrypted = true)
|
||||
albums.addWallpapersToAlbum(album.id, listOf(testWallpaper("image", album.id)))
|
||||
albums.createAlbum("Other")
|
||||
assertFalse(albums.renameAlbum(album.id, "other"))
|
||||
assertTrue(albums.renameAlbum(album.id, "ORIGINAL"))
|
||||
assertTrue(albums.renameAlbum(album.id, "Renamed"))
|
||||
val saved = albums.getAlbumById(album.id).first()!!
|
||||
assertEquals("Renamed", saved.name)
|
||||
assertTrue(saved.isEncrypted)
|
||||
assertEquals(listOf("image"), saved.wallpapers.map { it.id })
|
||||
}
|
||||
|
||||
@Test fun encryptedAlbumModeSurvivesPersistence() = runBlocking {
|
||||
val album = albums.createAlbum("Encrypted", isEncrypted = true)
|
||||
assertTrue(album.isEncrypted)
|
||||
|
||||
+28
@@ -28,6 +28,7 @@ import org.junit.Assert.*
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import com.anthonyla.paperize.presentation.screens.library.LibraryScreen
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.AlbumViewTopBar
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import androidx.compose.ui.semantics.SemanticsActions
|
||||
import com.anthonyla.paperize.core.WallpaperMode
|
||||
@@ -112,6 +113,33 @@ class AlbumUiInstrumentedTest {
|
||||
compose.runOnIdle { assertEquals(2, attempts) }
|
||||
}
|
||||
|
||||
@Test fun albumOptionsExposeActionsAndDisableRescanWithoutFolders() {
|
||||
val hasFolders = mutableStateOf(false)
|
||||
var action = ""
|
||||
compose.setContent {
|
||||
PaperizeTheme(false, false) {
|
||||
AlbumViewTopBar(
|
||||
title = "Album", isSelectionMode = false, selectedCount = 0, allSelected = false,
|
||||
onBackClick = {}, onSortClick = {}, onDeleteAlbum = { action = "delete" },
|
||||
onRenameAlbum = { action = "rename" }, onRefreshFolders = { action = "refresh" },
|
||||
albumActionsEnabled = true, hasFolders = hasFolders.value,
|
||||
onSelectAll = {}, onDeleteSelected = {}, onClearSelection = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
fun openMenu() = compose.onNodeWithContentDescription(context.getString(R.string.album_menu)).performClick()
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.refresh_album_folders)).assertIsNotEnabled()
|
||||
compose.onNodeWithText(context.getString(R.string.rename_album)).performClick()
|
||||
compose.runOnIdle { assertEquals("rename", action); hasFolders.value = true }
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.refresh_album_folders)).performClick()
|
||||
compose.runOnIdle { assertEquals("refresh", action) }
|
||||
openMenu()
|
||||
compose.onNodeWithText(context.getString(R.string.delete_album)).performClick()
|
||||
compose.runOnIdle { assertEquals("delete", action) }
|
||||
}
|
||||
|
||||
@Test fun sortSheetExposesCurrentSelectionAndAppliesNewChoice() {
|
||||
var chosen: SortOption? = null
|
||||
var dismissed = false
|
||||
|
||||
@@ -39,6 +39,9 @@ interface AlbumDao {
|
||||
@Query("DELETE FROM albums WHERE id = :albumId")
|
||||
suspend fun deleteAlbumById(albumId: String)
|
||||
|
||||
@Query("UPDATE albums SET name = :name, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun renameAlbum(albumId: String, name: String, modifiedAt: Long): Int
|
||||
|
||||
@Query("UPDATE albums SET coverUri = :coverUri, modifiedAt = :modifiedAt WHERE id = :albumId")
|
||||
suspend fun updateAlbumCover(albumId: String, coverUri: String?, modifiedAt: Long)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.anthonyla.paperize.domain.source.DocumentSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@Singleton
|
||||
@@ -52,6 +53,14 @@ class AlbumRepositoryImpl @Inject constructor(
|
||||
albumDao.deleteAlbumById(albumId)
|
||||
}
|
||||
|
||||
override suspend fun renameAlbum(albumId: String, name: String): Boolean = database.withTransaction {
|
||||
if (albumDao.getAlbumSummaries().first().any { it.id != albumId && it.name.equals(name, ignoreCase = true) }) {
|
||||
return@withTransaction false
|
||||
}
|
||||
check(albumDao.renameAlbum(albumId, name, System.currentTimeMillis()) == 1)
|
||||
true
|
||||
}
|
||||
|
||||
override suspend fun addWallpapersToAlbum(
|
||||
albumId: String,
|
||||
wallpapers: List<Wallpaper>,
|
||||
|
||||
@@ -17,6 +17,9 @@ interface AlbumRepository {
|
||||
|
||||
suspend fun createAlbum(name: String, coverUri: String? = null, isEncrypted: Boolean = false): Album
|
||||
|
||||
/** Returns false if another album has this name, ignoring case. */
|
||||
suspend fun renameAlbum(albumId: String, name: String): Boolean
|
||||
|
||||
suspend fun deleteAlbum(albumId: String)
|
||||
|
||||
/** Returns the number of new images. Progress counts rows written within the transaction. */
|
||||
|
||||
+81
-15
@@ -5,8 +5,14 @@ import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
@@ -17,6 +23,7 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -38,6 +45,7 @@ import com.anthonyla.paperize.presentation.screens.album_view.components.AlbumVi
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.FolderItem
|
||||
import com.anthonyla.paperize.presentation.screens.album_view.components.ImportProgressDialog
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
@@ -57,8 +65,14 @@ fun AlbumViewScreen(
|
||||
val importProgress by viewModel.importProgress.collectAsStateWithLifecycle()
|
||||
val message by viewModel.message.collectAsStateWithLifecycle()
|
||||
val isDeleting by viewModel.isDeleting.collectAsStateWithLifecycle()
|
||||
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle()
|
||||
val albumDeleted by viewModel.albumDeleted.collectAsStateWithLifecycle()
|
||||
var showDeleteAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showRenameDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var renameText by rememberSaveable { mutableStateOf("") }
|
||||
var renameError by rememberSaveable { mutableStateOf<Int?>(null) }
|
||||
var isRenaming by remember { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
SnackbarMessageEffect(message, snackbarHostState, viewModel::dismissMessage)
|
||||
LaunchedEffect(viewModel) {
|
||||
@@ -104,21 +118,32 @@ fun AlbumViewScreen(
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
topBar = {
|
||||
AlbumViewTopBar(
|
||||
title = album?.name ?: "",
|
||||
isSelectionMode = isSelectionMode,
|
||||
selectedCount = selectedCount,
|
||||
allSelected = allSelected,
|
||||
onBackClick = onBackClick,
|
||||
onSortClick = { showSortSheet = true },
|
||||
onDeleteAlbum = { showDeleteAlbumDialog = true },
|
||||
onSelectAll = { if (allSelected) viewModel.clearSelection() else viewModel.selectAll() },
|
||||
onDeleteSelected = { if (!isDeleting) showDeleteSelectedDialog = true },
|
||||
onClearSelection = { viewModel.clearSelection() }
|
||||
)
|
||||
Column {
|
||||
AlbumViewTopBar(
|
||||
title = album?.name ?: "",
|
||||
isSelectionMode = isSelectionMode,
|
||||
selectedCount = selectedCount,
|
||||
allSelected = allSelected,
|
||||
onBackClick = onBackClick,
|
||||
onSortClick = { showSortSheet = true },
|
||||
onDeleteAlbum = { showDeleteAlbumDialog = true },
|
||||
onRenameAlbum = {
|
||||
renameText = album?.name.orEmpty()
|
||||
renameError = null
|
||||
showRenameDialog = true
|
||||
},
|
||||
onRefreshFolders = viewModel::refreshFolders,
|
||||
albumActionsEnabled = album != null && !isDeleting && !isRefreshing && importProgress is ImportProgress.Idle,
|
||||
hasFolders = folders.isNotEmpty(),
|
||||
onSelectAll = { if (allSelected) viewModel.clearSelection() else viewModel.selectAll() },
|
||||
onDeleteSelected = { if (!isDeleting && !isRefreshing) showDeleteSelectedDialog = true },
|
||||
onClearSelection = { viewModel.clearSelection() }
|
||||
)
|
||||
if (isRefreshing) LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||
}
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (!isSelectionMode && totalItemsCount > 0) {
|
||||
if (!isSelectionMode && !isRefreshing && totalItemsCount > 0) {
|
||||
AddAlbumAnimatedFab(
|
||||
isLoading = importProgress !is ImportProgress.Idle,
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf(if (album?.isEncrypted == true) "*/*" else "image/*")) },
|
||||
@@ -133,10 +158,10 @@ fun AlbumViewScreen(
|
||||
hint = stringResource(R.string.album_empty_hint),
|
||||
modifier = modifier.padding(paddingValues)
|
||||
) {
|
||||
FilledTonalButton(onClick = { imagePickerLauncher.launch(arrayOf(if (album?.isEncrypted == true) "*/*" else "image/*")) }) {
|
||||
FilledTonalButton(enabled = !isRefreshing, onClick = { imagePickerLauncher.launch(arrayOf(if (album?.isEncrypted == true) "*/*" else "image/*")) }) {
|
||||
Text(stringResource(R.string.add_wallpapers))
|
||||
}
|
||||
TextButton(onClick = { folderPickerLauncher.launch(null) }) {
|
||||
TextButton(enabled = !isRefreshing, onClick = { folderPickerLauncher.launch(null) }) {
|
||||
Text(stringResource(R.string.add_folder))
|
||||
}
|
||||
}
|
||||
@@ -200,6 +225,47 @@ fun AlbumViewScreen(
|
||||
|
||||
ImportProgressDialog(progress = importProgress, onCancel = viewModel::cancelImport)
|
||||
|
||||
if (showRenameDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { if (!isRenaming) showRenameDialog = false },
|
||||
title = { Text(stringResource(R.string.rename_album)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = renameText,
|
||||
onValueChange = { renameText = it; renameError = null },
|
||||
label = { Text(stringResource(R.string.album_name)) },
|
||||
singleLine = true,
|
||||
enabled = !isRenaming,
|
||||
isError = renameError != null,
|
||||
supportingText = renameError?.let { error ->
|
||||
{ Text(stringResource(error), color = MaterialTheme.colorScheme.error) }
|
||||
}
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
enabled = !isRenaming && renameText.isNotBlank(),
|
||||
onClick = {
|
||||
isRenaming = true
|
||||
scope.launch {
|
||||
try {
|
||||
renameError = viewModel.renameAlbum(renameText.trim())
|
||||
if (renameError == null) showRenameDialog = false
|
||||
} finally {
|
||||
isRenaming = false
|
||||
}
|
||||
}
|
||||
}
|
||||
) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showRenameDialog = false }, enabled = !isRenaming) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showDeleteSelectedDialog) {
|
||||
ConfirmDialog(
|
||||
title = stringResource(R.string.remove_selected_title, selectedCount),
|
||||
|
||||
+45
-4
@@ -11,6 +11,7 @@ import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.usecase.DeleteAlbumUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.ImportWallpapersUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase
|
||||
import com.anthonyla.paperize.presentation.common.launchBusy
|
||||
import com.anthonyla.paperize.presentation.common.navigation.AlbumRoute
|
||||
import com.anthonyla.paperize.presentation.common.stateWhileSubscribed
|
||||
@@ -20,6 +21,7 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -28,7 +30,8 @@ class AlbumViewViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val albumRepository: AlbumRepository,
|
||||
private val importWallpapersUseCase: ImportWallpapersUseCase,
|
||||
private val deleteAlbumUseCase: DeleteAlbumUseCase
|
||||
private val deleteAlbumUseCase: DeleteAlbumUseCase,
|
||||
private val refreshFolderUseCase: RefreshFolderUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
@@ -55,6 +58,8 @@ class AlbumViewViewModel @Inject constructor(
|
||||
val isDeleting = _isDeleting.asStateFlow()
|
||||
private val _albumDeleted = MutableStateFlow(false)
|
||||
val albumDeleted = _albumDeleted.asStateFlow()
|
||||
private val _isRefreshing = MutableStateFlow(false)
|
||||
val isRefreshing = _isRefreshing.asStateFlow()
|
||||
private var importJob: Job? = null
|
||||
|
||||
fun dismissMessage() { _message.value = null }
|
||||
@@ -79,7 +84,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun import(initialProgress: ImportProgress, block: suspend () -> Boolean) {
|
||||
if (importJob?.isCompleted == false || _isDeleting.value) return
|
||||
if (importJob?.isCompleted == false || _isDeleting.value || _isRefreshing.value) return
|
||||
_message.value = null
|
||||
_importProgress.value = initialProgress
|
||||
importJob = viewModelScope.launch {
|
||||
@@ -101,7 +106,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
fun cancelImport() { importJob?.cancel() }
|
||||
|
||||
fun deleteAlbum() {
|
||||
if (_isDeleting.value || importJob?.isCompleted == false) return
|
||||
if (_isDeleting.value || _isRefreshing.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
launchBusy(_isDeleting) {
|
||||
runCatchingCancellable { deleteAlbumUseCase(albumId) }
|
||||
@@ -113,6 +118,42 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun renameAlbum(name: String): Int? =
|
||||
runCatchingCancellable { albumRepository.renameAlbum(albumId, name) }
|
||||
.fold(
|
||||
onSuccess = { renamed -> if (renamed) null else R.string.album_name_exists_error },
|
||||
onFailure = { e ->
|
||||
Log.e(TAG, "Error renaming album", e)
|
||||
R.string.rename_album_failed
|
||||
}
|
||||
)
|
||||
|
||||
fun refreshFolders() {
|
||||
if (_isRefreshing.value || _isDeleting.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
launchBusy(_isRefreshing) {
|
||||
val result = runCatchingCancellable {
|
||||
val folders = checkNotNull(albumRepository.getAlbumById(albumId).first()).folders
|
||||
var failed = false
|
||||
folders.forEach { folder ->
|
||||
runCatchingCancellable { refreshFolderUseCase(folder.id) }
|
||||
.onFailure { e ->
|
||||
Log.e(TAG, "Error refreshing folder '${folder.name}'", e)
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
failed
|
||||
}
|
||||
_message.value = result.fold(
|
||||
onSuccess = { failed -> if (failed) R.string.album_refresh_failed else R.string.album_refreshed },
|
||||
onFailure = { e ->
|
||||
Log.e(TAG, "Error loading album folders", e)
|
||||
R.string.album_refresh_failed
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleWallpaperSelection(wallpaperId: String) = toggle(_selectedWallpapers, wallpaperId)
|
||||
|
||||
fun toggleFolderSelection(folderId: String) = toggle(_selectedFolders, folderId)
|
||||
@@ -135,7 +176,7 @@ class AlbumViewViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun deleteSelected() {
|
||||
if (_isDeleting.value || importJob?.isCompleted == false) return
|
||||
if (_isDeleting.value || _isRefreshing.value || importJob?.isCompleted == false) return
|
||||
_message.value = null
|
||||
val wallpaperIds = _selectedWallpapers.value.toList()
|
||||
val folderIds = _selectedFolders.value.toList()
|
||||
|
||||
+35
-5
@@ -1,17 +1,25 @@
|
||||
package com.anthonyla.paperize.presentation.screens.album_view.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.Sort
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
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.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -27,6 +35,10 @@ fun AlbumViewTopBar(
|
||||
onBackClick: () -> Unit,
|
||||
onSortClick: () -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onRenameAlbum: () -> Unit,
|
||||
onRefreshFolders: () -> Unit,
|
||||
albumActionsEnabled: Boolean,
|
||||
hasFolders: Boolean,
|
||||
onSelectAll: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onClearSelection: () -> Unit
|
||||
@@ -64,6 +76,7 @@ fun AlbumViewTopBar(
|
||||
}
|
||||
)
|
||||
} else {
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
BackTopAppBar(title = title, onBack = onBackClick) {
|
||||
IconButton(onClick = onSortClick) {
|
||||
Icon(
|
||||
@@ -71,11 +84,28 @@ fun AlbumViewTopBar(
|
||||
contentDescription = stringResource(R.string.sort)
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onDeleteAlbum) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
contentDescription = stringResource(R.string.delete_album)
|
||||
)
|
||||
Box {
|
||||
IconButton(onClick = { menuExpanded = true }, enabled = albumActionsEnabled) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = stringResource(R.string.album_menu)
|
||||
)
|
||||
}
|
||||
DropdownMenu(expanded = menuExpanded, onDismissRequest = { menuExpanded = false }) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.rename_album)) },
|
||||
onClick = { menuExpanded = false; onRenameAlbum() }
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.refresh_album_folders)) },
|
||||
enabled = hasFolders,
|
||||
onClick = { menuExpanded = false; onRefreshFolders() }
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.delete_album)) },
|
||||
onClick = { menuExpanded = false; onDeleteAlbum() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
<string name="encrypted_album" tools:ignore="MissingTranslation">Encrypted album</string>
|
||||
<string name="encrypted_album_hint" tools:ignore="MissingTranslation">Only .jpg_enc files will be imported. This cannot be changed later.</string>
|
||||
<string name="album_create_failed">Could not create the album. Please try again.</string>
|
||||
<string name="album_menu" tools:ignore="MissingTranslation">Album options</string>
|
||||
<string name="rename_album" tools:ignore="MissingTranslation">Rename album</string>
|
||||
<string name="rename_album_failed" tools:ignore="MissingTranslation">Could not rename the album. Please try again.</string>
|
||||
<string name="refresh_album_folders" tools:ignore="MissingTranslation">Rescan all folders</string>
|
||||
<string name="album_refreshed" tools:ignore="MissingTranslation">Album folders checked for new wallpapers.</string>
|
||||
<string name="album_refresh_failed" tools:ignore="MissingTranslation">Some folders could not be rescanned. Check that they are accessible, then try again.</string>
|
||||
<string name="app_name" translatable="false">Paperize</string>
|
||||
<string name="continue_rotation_from_here">Continue rotation from here</string>
|
||||
<string name="continue_rotation_from_here_desc">Next changes follow album order after this wallpaper</string>
|
||||
|
||||
+42
-1
@@ -1,6 +1,7 @@
|
||||
package com.anthonyla.paperize.presentation.screens.album_view
|
||||
|
||||
import com.anthonyla.paperize.testAlbum
|
||||
import com.anthonyla.paperize.testFolder
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModelStore
|
||||
import androidx.navigation.toRoute
|
||||
@@ -10,6 +11,7 @@ import com.anthonyla.paperize.domain.model.Album
|
||||
import com.anthonyla.paperize.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.domain.usecase.DeleteAlbumUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.ImportWallpapersUseCase
|
||||
import com.anthonyla.paperize.domain.usecase.RefreshFolderUseCase
|
||||
import com.anthonyla.paperize.presentation.ViewModelTestRule
|
||||
import io.mockk.*
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
@@ -28,6 +30,7 @@ class AlbumViewViewModelTest {
|
||||
private val albums = mockk<AlbumRepository>()
|
||||
private val imports = mockk<ImportWallpapersUseCase>()
|
||||
private val delete = mockk<DeleteAlbumUseCase>()
|
||||
private val refresh = mockk<RefreshFolderUseCase>()
|
||||
private val store = ViewModelStore()
|
||||
private lateinit var viewModel: AlbumViewViewModel
|
||||
|
||||
@@ -38,7 +41,7 @@ class AlbumViewViewModelTest {
|
||||
val savedState = SavedStateHandle()
|
||||
mockkStatic("androidx.navigation.SavedStateHandleKt")
|
||||
every { savedState.toRoute<AlbumRoute>() } returns AlbumRoute("album")
|
||||
viewModel = AlbumViewViewModel(savedState, albums, imports, delete)
|
||||
viewModel = AlbumViewViewModel(savedState, albums, imports, delete, refresh)
|
||||
store.put("album", viewModel)
|
||||
}
|
||||
|
||||
@@ -111,4 +114,42 @@ class AlbumViewViewModelTest {
|
||||
assertEquals(R.string.delete_items_failed, viewModel.message.value)
|
||||
}
|
||||
|
||||
@Test fun `rescan checks every folder even when one fails and reports failure`() = runTest {
|
||||
every { albums.getAlbumById("album") } returns flowOf(testAlbum("album").copy(
|
||||
folders = listOf(testFolder("first", "album"), testFolder("second", "album"))
|
||||
))
|
||||
coEvery { refresh("first") } throws SecurityException()
|
||||
coEvery { refresh("second") } returns 1
|
||||
viewModel.refreshFolders()
|
||||
advanceUntilIdle()
|
||||
coVerify(exactly = 1) { refresh("first"); refresh("second") }
|
||||
assertEquals(R.string.album_refresh_failed, viewModel.message.value)
|
||||
assertFalse(viewModel.isRefreshing.value)
|
||||
}
|
||||
|
||||
@Test fun `rescan blocks duplicate scans and deletion while running`() = runTest {
|
||||
every { albums.getAlbumById("album") } returns flowOf(testAlbum("album").copy(
|
||||
folders = listOf(testFolder("first", "album"))
|
||||
))
|
||||
val completion = CompletableDeferred<Int>()
|
||||
coEvery { refresh("first") } coAnswers { completion.await() }
|
||||
viewModel.refreshFolders()
|
||||
runCurrent()
|
||||
viewModel.refreshFolders()
|
||||
viewModel.deleteAlbum()
|
||||
completion.complete(1)
|
||||
advanceUntilIdle()
|
||||
coVerify(exactly = 1) { refresh("first") }
|
||||
coVerify(exactly = 0) { delete(any()) }
|
||||
assertEquals(R.string.album_refreshed, viewModel.message.value)
|
||||
}
|
||||
|
||||
@Test fun `rename reports duplicates and storage errors`() = runTest {
|
||||
coEvery { albums.renameAlbum("album", "Duplicate") } returns false
|
||||
coEvery { albums.renameAlbum("album", "Broken") } throws IllegalStateException()
|
||||
coEvery { albums.renameAlbum("album", "New") } returns true
|
||||
assertEquals(R.string.album_name_exists_error, viewModel.renameAlbum("Duplicate"))
|
||||
assertEquals(R.string.rename_album_failed, viewModel.renameAlbum("Broken"))
|
||||
assertNull(viewModel.renameAlbum("New"))
|
||||
}
|
||||
}
|
||||
+44
-13
@@ -1,18 +1,49 @@
|
||||
cd /home/lucas/git/Paperize
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Build the app
|
||||
./gradlew assembleDebug
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# Run unit tests and lint
|
||||
./gradlew testDebugUnitTest lintDebug
|
||||
remote=lucas@quiethost
|
||||
assets=../Server-scripts/testassets/wallpaper_changer
|
||||
app_apk=app/build/outputs/apk/debug/app-debug.apk
|
||||
test_apk=app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
|
||||
|
||||
# Run device/emulator tests (requires a running emulator or connected device)
|
||||
./gradlew connectedDebugAndroidTest
|
||||
for directory in "$assets/corrupt" "$assets/Desktop1920x1080"; do
|
||||
if [[ ! -d "$directory" ]]; then
|
||||
echo "Missing test assets: $directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Install on a connected device
|
||||
./gradlew installDebug
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=10 "$remote" 'adb get-state'
|
||||
./gradlew assembleDebug assembleDebugAndroidTest testDebugUnitTest lintDebug
|
||||
|
||||
# Copy test assets to the device
|
||||
adb shell mkdir -p /sdcard/Pictures/Paperize-testfiles
|
||||
adb push ../Server-scripts/testassets/wallpaper_changer/corrupt /sdcard/Pictures/Paperize-testfiles/
|
||||
adb push ../Server-scripts/testassets/wallpaper_changer/Desktop1920x1080 /sdcard/Pictures/Paperize-testfiles/
|
||||
install_apk() {
|
||||
ssh -o BatchMode=yes "$remote" '
|
||||
set -eu
|
||||
apk=$(mktemp /tmp/paperize-apk.XXXXXX.apk)
|
||||
trap '\''rm -f -- "$apk"'\'' EXIT
|
||||
cat > "$apk"
|
||||
adb install -r "$apk"
|
||||
' < "$1"
|
||||
}
|
||||
|
||||
install_apk "$app_apk"
|
||||
install_apk "$test_apk"
|
||||
|
||||
ssh -o BatchMode=yes "$remote" 'adb shell mkdir -p /sdcard/Pictures/Paperize-testfiles'
|
||||
tar -C "$assets" -cf - corrupt Desktop1920x1080 |
|
||||
ssh -o BatchMode=yes "$remote" 'adb exec-in tar -xf - -C /sdcard/Pictures/Paperize-testfiles'
|
||||
|
||||
results=$(mktemp)
|
||||
trap 'rm -f -- "$results"' EXIT
|
||||
ssh -o BatchMode=yes "$remote" \
|
||||
'adb shell am instrument -w -r com.anthonyla.paperize.test/androidx.test.runner.AndroidJUnitRunner' |
|
||||
tee "$results"
|
||||
|
||||
if ! grep -Eq '^OK \([1-9][0-9]* tests?\)' "$results" ||
|
||||
! grep -q '^INSTRUMENTATION_CODE: -1' "$results" ||
|
||||
grep -q 'FAILURES!!!' "$results"; then
|
||||
echo "Android instrumentation tests failed or did not complete." >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user