Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
902be61924 | ||
|
|
e9f6861d60 | ||
|
|
8f0c5aa309 | ||
|
|
a32ca75126 |
No files matched your search
Generated
+1
-1
@@ -15,7 +15,7 @@
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-24T06:32:43.708081Z" />
|
||||
<timeTargetWasSelectedWithDropDown value="2024-04-30T06:47:19.015867100Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
|
||||
@@ -33,7 +33,7 @@ Playstore and F-Droid will be added soon
|
||||
|
||||
## Technologies
|
||||
|
||||
- [Kotlin]([https://kotlinlang.org/) - A programming language that is used for Android app development
|
||||
- [Kotlin](https://kotlinlang.org/) - A programming language that is used for Android app development
|
||||
- [Jetpack Compose](https://developer.android.com/develop/ui/compose) - A declarative UI toolkit for building native Android UI
|
||||
- [Material 3](https://m3.material.io/) - A UI design system git for modern UI guidelines
|
||||
- [Dagger Hilt](https://dagger.dev/hilt/) - A dependency injection library
|
||||
|
||||
@@ -64,16 +64,16 @@ dependencies {
|
||||
implementation("androidx.compose.ui:ui:1.6.6")
|
||||
implementation("androidx.compose.ui:ui-graphics:1.6.6")
|
||||
implementation("androidx.compose.ui:ui-tooling-preview:1.6.6")
|
||||
implementation("androidx.compose.material3:material3:1.2.1")
|
||||
implementation("androidx.compose.material3:material3:1.3.0-alpha05")
|
||||
implementation("androidx.navigation:navigation-compose:2.8.0-alpha07")
|
||||
implementation("androidx.compose.material:material:1.6.6")
|
||||
implementation("androidx.compose.material:material:1.7.0-alpha07")
|
||||
implementation("androidx.datastore:datastore:1.1.0")
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.0")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.6.6")
|
||||
implementation("androidx.compose.material:material-icons-extended:1.7.0-alpha07")
|
||||
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-alpha07")
|
||||
implementation("androidx.core:core-splashscreen:1.1.0-rc01")
|
||||
implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
|
||||
|
||||
+20
-21
@@ -56,6 +56,7 @@ fun PaperizeApp(
|
||||
val navController = rememberNavController()
|
||||
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
|
||||
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
|
||||
// React to albumState changes and change selectedAlbum's details to keep it from being stale
|
||||
@@ -93,9 +94,13 @@ fun PaperizeApp(
|
||||
),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(
|
||||
WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum)
|
||||
)
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
|
||||
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(settingsState.value.interval))
|
||||
val intent = Intent(context, WallpaperService::class.java).apply {
|
||||
action = WallpaperService.Actions.START.toString()
|
||||
putExtra("timeInMinutes", settingsState.value.interval)
|
||||
}
|
||||
context.startForegroundService(intent)
|
||||
}
|
||||
?: run {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset)
|
||||
@@ -275,9 +280,8 @@ fun PaperizeApp(
|
||||
}
|
||||
// Navigate to folder view screen to view wallpapers in a particular folder
|
||||
composable(
|
||||
route = NavScreens.FolderView.route.plus("/{folderUri}/{folderName}/{wallpapers}"),
|
||||
route = NavScreens.FolderView.route.plus("/{folderName}/{wallpapers}"),
|
||||
arguments = listOf(
|
||||
navArgument("folderUri") { type = NavType.StringType },
|
||||
navArgument("folderName") { type = NavType.StringType },
|
||||
navArgument("wallpapers") { type = NavType.StringType }
|
||||
),
|
||||
@@ -294,24 +298,20 @@ fun PaperizeApp(
|
||||
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
|
||||
},
|
||||
) { backStackEntry ->
|
||||
val folderUri = backStackEntry.arguments?.getString("folderUri")
|
||||
val folderName = backStackEntry.arguments?.getString("folderName")
|
||||
val wallpapers = Gson().fromJson(
|
||||
backStackEntry.arguments?.getString("wallpapers"),
|
||||
Array<String>::class.java
|
||||
).toList()
|
||||
if (folderUri != null) {
|
||||
FolderViewScreen(
|
||||
folder = folderUri,
|
||||
folderName = folderName,
|
||||
wallpapers = wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = { wallpaper ->
|
||||
val encodedWallpaper = runBlocking { encodeUri(uri = wallpaper) }
|
||||
navController.navigate("${NavScreens.WallpaperView.route}/$encodedWallpaper")
|
||||
}
|
||||
)
|
||||
}
|
||||
FolderViewScreen(
|
||||
folderName = folderName,
|
||||
wallpapers = wallpapers,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = { wallpaper ->
|
||||
val encodedWallpaper = runBlocking { encodeUri(uri = wallpaper) }
|
||||
navController.navigate("${NavScreens.WallpaperView.route}/$encodedWallpaper")
|
||||
}
|
||||
)
|
||||
}
|
||||
// Navigate to the album view screen to view folders and wallpapers in an album
|
||||
composable(
|
||||
@@ -342,10 +342,9 @@ fun PaperizeApp(
|
||||
val encodedWallpaper = runBlocking { encodeUri(uri = wallpaper) }
|
||||
navController.navigate("${NavScreens.WallpaperView.route}/$encodedWallpaper")
|
||||
},
|
||||
onShowFolderView = { folder, folderName, wallpapers ->
|
||||
val encodedFolder = runBlocking { encodeUri(uri = folder) }
|
||||
onShowFolderView = { folderName, wallpapers ->
|
||||
val encodedWallpapers = runBlocking { encodeUri(uri = Gson().toJson(wallpapers)) }
|
||||
navController.navigate("${NavScreens.FolderView.route}/$encodedFolder/$folderName/$encodedWallpapers")
|
||||
navController.navigate("${NavScreens.FolderView.route}/$folderName/$encodedWallpapers")
|
||||
},
|
||||
onDeleteAlbum = {
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpaper))
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ sealed class AddAlbumEvent {
|
||||
data class ReflectAlbumName(
|
||||
val newAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class AddWallpaper(
|
||||
val wallpaperUri: String
|
||||
data class AddWallpapers(
|
||||
val wallpaperUris: List<String>
|
||||
): AddAlbumEvent()
|
||||
data class AddFolder(
|
||||
val directoryUri: String
|
||||
|
||||
+37
-17
@@ -2,7 +2,6 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -70,15 +69,14 @@ fun AddAlbumScreen(
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
for (uri in uris) {
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpaper(wallpaperUri = uri.toString()))
|
||||
} else {
|
||||
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
|
||||
}
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -92,9 +90,7 @@ fun AddAlbumScreen(
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(directoryUri = uri.toString()))
|
||||
} else {
|
||||
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +133,14 @@ fun AddAlbumScreen(
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) },
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
@@ -146,8 +148,14 @@ fun AddAlbumScreen(
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) },
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = false
|
||||
)
|
||||
}
|
||||
@@ -181,7 +189,13 @@ fun AddAlbumScreen(
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderUri, folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
items (items = addAlbumState.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
|
||||
@@ -203,7 +217,13 @@ fun AddAlbumScreen(
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+37
-25
@@ -113,40 +113,52 @@ class AddAlbumViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddWallpaper -> {
|
||||
is AddAlbumEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.wallpapers.any { it.wallpaperUri == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
wallpapers = it.wallpapers.plus(
|
||||
Wallpaper(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
wallpaperUri = event.wallpaperUri,
|
||||
key = event.wallpaperUri.hashCode() + it.initialAlbumName.hashCode(),
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
val newWallpaperUris = event.wallpaperUris.filterNot { it in _state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val newWallpapers = newWallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = _state.value.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + _state.value.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
wallpapers = it.wallpapers.plus(newWallpapers),
|
||||
isEmpty = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!_state.value.folders.any { it.folderUri == event.directoryUri }) {
|
||||
if (event.directoryUri !in _state.value.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
_state.update { state ->
|
||||
state.copy( folders = state.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = state.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + state.initialAlbumName.hashCode()
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
isEmpty = false,
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers,
|
||||
key = event.directoryUri.hashCode() + it.initialAlbumName.hashCode()
|
||||
)
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -11,6 +11,17 @@ sealed class AlbumViewEvent {
|
||||
data class DeleteSelected(
|
||||
val albumsWithWallpaper: AlbumWithWallpaperAndFolder
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class AddWallpapers(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val wallpaperUris: List<String>
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class AddFolder(
|
||||
val album: AlbumWithWallpaperAndFolder,
|
||||
val directoryUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
data class SelectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AlbumViewEvent()
|
||||
|
||||
+112
-17
@@ -1,6 +1,15 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -16,37 +25,75 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumFabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components.AlbumViewTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
|
||||
@Composable
|
||||
fun AlbumViewScreen(
|
||||
albumViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
albumViewScreenViewModel: AlbumViewScreenViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
album: AlbumWithWallpaperAndFolder,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String, String?, List<String>) -> Unit,
|
||||
onShowFolderView: (String?, List<String>) -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String, AlbumWithWallpaperAndFolder) -> Unit,
|
||||
onSelectionDeleted: () -> Unit
|
||||
) {
|
||||
albumViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size))
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.SetSize(album.wallpapers.size + album.folders.size)) // For selectedAll state
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val albumState = albumViewModel.state.collectAsStateWithLifecycle()
|
||||
val albumState = albumViewScreenViewModel.state.collectAsStateWithLifecycle()
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
|
||||
/** Image picker **/
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris: List<Uri> ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
val uriList = uris.mapNotNull { uri ->
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
|
||||
}
|
||||
if (uriList.isNotEmpty()) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(album, uriList))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** Folder picker **/
|
||||
val folderPickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.OpenDocumentTree(),
|
||||
onResult = { uri: Uri? ->
|
||||
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
|
||||
if (persistedUriPermissions.any { it.uri == uri }) {
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.AddFolder(album, uri.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
albumViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,25 +102,61 @@ fun AlbumViewScreen(
|
||||
AlbumViewTopBar(
|
||||
title = album.album.displayedAlbumName,
|
||||
selectionMode = selectionMode,
|
||||
albumState = albumViewModel.state,
|
||||
albumState = albumViewScreenViewModel.state,
|
||||
onBackClick = {
|
||||
albumViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.ClearState)
|
||||
onBackClick()
|
||||
},
|
||||
onDeleteAlbum = onDeleteAlbum,
|
||||
onTitleChange = { onTitleChange(it, album) },
|
||||
onSelectAllClick = {
|
||||
if (!albumState.value.allSelected) albumViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
if (!albumState.value.allSelected) albumViewScreenViewModel.onEvent(AlbumViewEvent.SelectAll(album))
|
||||
else albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
},
|
||||
onDeleteSelected = {
|
||||
selectionMode = false
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
|
||||
albumViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeleteSelected(album))
|
||||
albumViewScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
|
||||
onSelectionDeleted()
|
||||
}
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (settingsState.value.animate) {
|
||||
AnimatedVisibility(
|
||||
visible = !lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = {
|
||||
selectionMode = false
|
||||
imagePickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onFolderClick = {
|
||||
selectionMode = false
|
||||
folderPickerLauncher.launch(null)
|
||||
},
|
||||
animate = true
|
||||
)
|
||||
}
|
||||
},
|
||||
content = { it ->
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyListState,
|
||||
@@ -92,7 +175,7 @@ fun AlbumViewScreen(
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewModel.onEvent(
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedFolders.contains(folder.folderUri))
|
||||
AlbumViewEvent.SelectFolder(folder.folderUri)
|
||||
else {
|
||||
@@ -101,9 +184,15 @@ fun AlbumViewScreen(
|
||||
)
|
||||
},
|
||||
onFolderViewClick = {
|
||||
onShowFolderView(folder.folderUri, folder.folderName, folder.wallpapers)
|
||||
onShowFolderView(folder.folderName, folder.wallpapers)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
items (items = album.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri.hashCode()}
|
||||
@@ -114,7 +203,7 @@ fun AlbumViewScreen(
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
albumViewModel.onEvent(
|
||||
albumViewScreenViewModel.onEvent(
|
||||
if (!albumState.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else {
|
||||
@@ -125,7 +214,13 @@ fun AlbumViewScreen(
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+81
@@ -3,9 +3,14 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.lazygeniouz.dfc.file.DocumentFileCompat
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -153,6 +158,57 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddWallpapers -> {
|
||||
viewModelScope.launch {
|
||||
val newWallpaperUris = event.wallpaperUris.filterNot { it in event.album.wallpapers.map { wallpaper -> wallpaper.wallpaperUri } }
|
||||
val newWallpapers = newWallpaperUris.map { uri ->
|
||||
Wallpaper(
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
wallpaperUri = uri,
|
||||
key = uri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
)
|
||||
}
|
||||
repository.upsertWallpaperList(newWallpapers)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = _state.value.maxSize + newWallpapers.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is AlbumViewEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (event.directoryUri !in event.album.folders.map { it.folderUri }) {
|
||||
val wallpapers: List<String> = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
repository.upsertFolder(
|
||||
Folder(
|
||||
folderUri = event.directoryUri,
|
||||
folderName = folderName,
|
||||
initialAlbumName = event.album.album.initialAlbumName,
|
||||
key = event.directoryUri.hashCode() + event.album.album.initialAlbumName.hashCode(),
|
||||
coverUri = wallpapers.randomOrNull(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
)
|
||||
_state.update {
|
||||
it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
maxSize = _state.value.maxSize + 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,4 +221,29 @@ class AlbumViewScreenViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFileCompat.fromTreeUri(context, folderUri.toUri())
|
||||
return listFilesRecursive(folderDocumentFile, context)
|
||||
}
|
||||
|
||||
private fun listFilesRecursive(parent: DocumentFileCompat?, context: Context): List<String> {
|
||||
val files = mutableListOf<String>()
|
||||
parent?.listFiles()?.forEach { file ->
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(listFilesRecursive(file, context))
|
||||
} else {
|
||||
val extension = MimeTypeMap.getFileExtensionFromUrl(file.uri.toString())
|
||||
val allowedExtensions = listOf("jpg", "png", "heif", "webp")
|
||||
if (extension in allowedExtensions) {
|
||||
files.add(file.uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
private fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFileCompat.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -1,6 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -18,7 +20,6 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.
|
||||
|
||||
@Composable
|
||||
fun FolderViewScreen(
|
||||
folder: String,
|
||||
folderName: String?,
|
||||
wallpapers: List<String>,
|
||||
onBackClick: () -> Unit,
|
||||
@@ -56,7 +57,13 @@ fun FolderViewScreen(
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper)
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,5 +1,7 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
@@ -60,7 +62,13 @@ fun LibraryScreen(
|
||||
AlbumItem(
|
||||
album = album.album,
|
||||
onAlbumViewClick = { onViewAlbum(album.album.initialAlbumName) },
|
||||
modifier = Modifier.padding(4.dp)
|
||||
modifier = Modifier.padding(4.dp).animateItem(
|
||||
placementSpec = tween(
|
||||
durationMillis = 800,
|
||||
delayMillis = 0,
|
||||
easing = FastOutSlowInEasing
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user