Readded support for albums
This commit is contained in:
1 parent
85d8fe5855
commit
c9990c6dce
50 files changed
+1414
-453
No files matched your search
@@ -50,7 +50,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation("androidx.core:core-ktx:1.12.0")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0-alpha02")
|
||||
implementation("androidx.activity:activity-compose:1.8.0")
|
||||
implementation(platform("androidx.compose:compose-bom:2023.10.00"))
|
||||
implementation("androidx.compose.ui:ui:1.6.0-alpha07")
|
||||
@@ -68,6 +68,9 @@ dependencies {
|
||||
implementation("androidx.hilt:hilt-navigation-compose:1.1.0-beta01")
|
||||
implementation("androidx.compose.animation:animation:1.6.0-alpha07")
|
||||
implementation("androidx.core:core-splashscreen:1.1.0-alpha02")
|
||||
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0-alpha02")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("androidx.documentfile:documentfile:1.1.0-alpha01")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature
|
||||
android:name="android.software.live_wallpaper"
|
||||
android:name="android.software.paperize"
|
||||
android:required="true" />
|
||||
|
||||
<application
|
||||
@@ -40,7 +40,7 @@
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.service.wallpaper"
|
||||
android:resource="@xml/live_wallpaper" />
|
||||
android:resource="@xml/paperize" />
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -5,14 +5,12 @@ import android.content.Context
|
||||
import androidx.room.Room
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStoreImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.WallpaperDatabase
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.repository.WallpaperRepositoryImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.WallpaperRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.MainActivity
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AddWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.WallpaperUseCases
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.DeleteWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.GetWallpapers
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDatabase
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.repository.AlbumRepositoryImpl
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AddAlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AlbumsUseCases
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.GetAllAlbumsWithWallpaper
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -25,31 +23,30 @@ import javax.inject.Singleton
|
||||
object AppModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperDatabase(app: Application): WallpaperDatabase {
|
||||
fun provideAlbumDatabase(app: Application): AlbumDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
WallpaperDatabase::class.java,
|
||||
WallpaperDatabase.DATABASE_NAME
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperRepository(
|
||||
db: WallpaperDatabase
|
||||
): WallpaperRepository {
|
||||
return WallpaperRepositoryImpl(db.wallpaperDao)
|
||||
fun provideAlbumRepository(
|
||||
db: AlbumDatabase
|
||||
): AlbumRepository {
|
||||
return AlbumRepositoryImpl(db.albumDao)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWallpaperUseCases(
|
||||
repository: WallpaperRepository
|
||||
): WallpaperUseCases {
|
||||
return WallpaperUseCases (
|
||||
getWallpapers = GetWallpapers(repository),
|
||||
deleteWallpaper = DeleteWallpaper(repository),
|
||||
addWallpaper = AddWallpaper(repository),
|
||||
repository: AlbumRepository
|
||||
): AlbumsUseCases {
|
||||
return AlbumsUseCases (
|
||||
getAllAlbumsWithWallpaper = GetAllAlbumsWithWallpaper(repository),
|
||||
addAlbumWithWallpaper = AddAlbumWithWallpaper(repository)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -62,7 +59,5 @@ object AppModule {
|
||||
@Provides
|
||||
fun provideContext(
|
||||
@ApplicationContext context: Context,
|
||||
): Context {
|
||||
return context
|
||||
}
|
||||
): Context { return context }
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Upsert
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album")
|
||||
fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>>
|
||||
|
||||
@Upsert
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
|
||||
@Upsert
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
@Database(
|
||||
entities = [Album::class, Wallpaper::class],
|
||||
version = 1
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
abstract val albumDao: AlbumDao
|
||||
companion object {
|
||||
const val DATABASE_NAME = "paperize_album_db"
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class Converters {
|
||||
@TypeConverter
|
||||
fun listToJsonString(value: List<String>?): String = Gson().toJson(value)
|
||||
|
||||
@TypeConverter
|
||||
fun jsonStringToList(value: String) = Gson().fromJson(value, Array<String>::class.java).toList()
|
||||
|
||||
@TypeConverter
|
||||
fun fromFolderList(folders: List<Folder>): String {
|
||||
return Gson().toJson(folders)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toFolderList(foldersString: String): List<Folder> {
|
||||
val listType = object : TypeToken<List<Folder>>() {}.type
|
||||
return Gson().fromJson(foldersString, listType)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromFolder(folder: Folder): String {
|
||||
return Gson().toJson(folder)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toFolder(folderString: String): Folder {
|
||||
val type = object: TypeToken<Folder>() {}.type
|
||||
return Gson().fromJson(folderString, type)
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import androidx.room.Upsert
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface WallpaperDao {
|
||||
@Transaction
|
||||
@Query("SELECT * FROM wallpaper")
|
||||
fun getImages(): Flow<List<Wallpaper>>
|
||||
|
||||
@Upsert
|
||||
suspend fun upsertImage(wallpaper: Wallpaper)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteImage(wallpaper: Wallpaper)
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.data_source
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
@Database(
|
||||
entities = [Wallpaper::class],
|
||||
version = 1
|
||||
)
|
||||
abstract class WallpaperDatabase: RoomDatabase() {
|
||||
abstract val wallpaperDao: WallpaperDao
|
||||
companion object {
|
||||
const val DATABASE_NAME = "paperize_db"
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.AlbumDao
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class AlbumRepositoryImpl(
|
||||
private val dao: AlbumDao
|
||||
): AlbumRepository {
|
||||
override fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>> {
|
||||
return dao.getAlbumsWithWallpapers()
|
||||
}
|
||||
|
||||
override suspend fun upsertAlbum(album: Album) {
|
||||
dao.upsertAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun upsertWallpaper(wallpaper: Wallpaper) {
|
||||
dao.upsertWallpaper(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.data.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.data.data_source.WallpaperDao
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.WallpaperRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class WallpaperRepositoryImpl(
|
||||
private val dao: WallpaperDao
|
||||
): WallpaperRepository {
|
||||
override fun getWallpapers(): Flow<List<Wallpaper>> {
|
||||
return dao.getImages()
|
||||
}
|
||||
|
||||
override suspend fun insertWallpaper(wallpaper: Wallpaper) {
|
||||
dao.upsertImage(wallpaper)
|
||||
}
|
||||
|
||||
override suspend fun deleteWallpaper(wallpaper: Wallpaper) {
|
||||
dao.deleteImage(wallpaper)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Album(
|
||||
@PrimaryKey(autoGenerate = false) val initialAlbumName: String,
|
||||
val displayedAlbumName: String,
|
||||
val coverUri: String?,
|
||||
val folders: List<Folder> = emptyList()
|
||||
)
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class AlbumWithWallpaper(
|
||||
@Embedded val album: Album,
|
||||
@Relation(
|
||||
parentColumn = "initialAlbumName",
|
||||
entityColumn = "initialAlbumName",
|
||||
)
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
|
||||
data class Folder(
|
||||
val initialAlbumName: String,
|
||||
val folderUri: String,
|
||||
val folderName: String?,
|
||||
val coverUri: String?,
|
||||
val wallpapers: List<String> = emptyList()
|
||||
)
|
||||
+2
-2
@@ -5,6 +5,6 @@ import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Wallpaper(
|
||||
@PrimaryKey(autoGenerate = false) val imageUri: String,
|
||||
val date: String
|
||||
val initialAlbumName: String,
|
||||
@PrimaryKey(autoGenerate = false) val wallpaperUri: String,
|
||||
)
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AlbumRepository {
|
||||
fun getAlbumsWithWallpapers(): Flow<List<AlbumWithWallpaper>>
|
||||
suspend fun upsertAlbum(album: Album)
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
suspend fun upsertWallpaper(wallpaper: Wallpaper)
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.repository
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface WallpaperRepository {
|
||||
fun getWallpapers(): Flow<List<Wallpaper>>
|
||||
|
||||
suspend fun insertWallpaper(wallpaper: Wallpaper)
|
||||
|
||||
suspend fun deleteWallpaper(wallpaper: Wallpaper)
|
||||
}
|
||||
+2
@@ -10,6 +10,7 @@ import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
@@ -17,6 +18,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val addAlbumViewModel: AddAlbumViewModel by viewModels()
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val splashScreen = installSplashScreen()
|
||||
|
||||
+42
-34
@@ -1,9 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
@@ -15,38 +11,27 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import com.anthonyla.paperize.data.Contact
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.HomeScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavScreens
|
||||
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
wallpaperViewModel: WallpaperViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel()
|
||||
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel(),
|
||||
//albumsViewModel: AlbumsViewModel = hiltViewModel()
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
/** Image picker **/
|
||||
val multiplePhotoPickerLauncher = 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
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
wallpaperViewModel.onEvent(WallpaperEvent.AddWallpaper(uri.toString()))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
val wallpaperState = wallpaperViewModel.state.value
|
||||
val settingsState = settingsViewModel.state.value
|
||||
val navController = rememberNavController()
|
||||
var toContact by rememberSaveable { mutableStateOf(false) }
|
||||
@@ -57,23 +42,46 @@ fun PaperizeApp(
|
||||
startDestination = NavScreens.Home.route,
|
||||
modifier = Modifier.navigationBarsPadding()
|
||||
) {
|
||||
composable(
|
||||
route = NavScreens.Home.route
|
||||
) {
|
||||
composable(route = NavScreens.Home.route) {
|
||||
HomeScreen(
|
||||
wallpaperState = wallpaperState,
|
||||
settingsState = settingsState,
|
||||
onSettingsClick = { navController.navigate(NavScreens.Settings.route) },
|
||||
onContactClick = { toContact = true },
|
||||
onLaunchImagePhotoPicker = { multiplePhotoPickerLauncher.launch(arrayOf("image/*"))
|
||||
},
|
||||
onDeleteImagesClick = { image ->
|
||||
image.forEach {
|
||||
wallpaperViewModel.onEvent(WallpaperEvent.DeleteWallpaper(it))
|
||||
}
|
||||
navigateToAddWallpaperScreen = {
|
||||
navController.navigate("${NavScreens.AddEdit.route}/$it")
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = NavScreens.AddEdit.route.plus("/{initialAlbumName}"),
|
||||
arguments = listOf(navArgument("initialAlbumName") { type = NavType.StringType }),
|
||||
enterTransition = {
|
||||
slideIntoContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Down,
|
||||
animationSpec = tween(500)
|
||||
)
|
||||
},
|
||||
exitTransition = {
|
||||
slideOutOfContainer(
|
||||
AnimatedContentTransitionScope.SlideDirection.Up,
|
||||
animationSpec = tween(500)
|
||||
)
|
||||
}
|
||||
) {backStackEntry ->
|
||||
backStackEntry.arguments?.getString("initialAlbumName").let {
|
||||
if (it != null) {
|
||||
AddAlbumScreen(
|
||||
initialAlbumName = it,
|
||||
onBackClick = {
|
||||
navController.navigateUp()
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
},
|
||||
onConfirmation = {
|
||||
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = NavScreens.Settings.route,
|
||||
enterTransition = {
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
sealed class AddAlbumEvent {
|
||||
object SaveAlbum: AddAlbumEvent()
|
||||
object ClearState: AddAlbumEvent()
|
||||
|
||||
object SelectAll: AddAlbumEvent()
|
||||
object DeselectAll: AddAlbumEvent()
|
||||
data class SetAlbumName(
|
||||
val initialAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class ReflectAlbumName(
|
||||
val newAlbumName: String
|
||||
): AddAlbumEvent()
|
||||
data class AddWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AddAlbumEvent()
|
||||
data class AddFolder(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
|
||||
data class DeleteFolder(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
data class DeleteWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AddAlbumEvent()
|
||||
|
||||
data class SelectWallpaper(
|
||||
val wallpaperUri: String
|
||||
): AddAlbumEvent()
|
||||
data class SelectFolder(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
|
||||
data class RemoveFolderFromSelection(
|
||||
val directoryUri: String
|
||||
): AddAlbumEvent()
|
||||
data class RemoveWallpaperFromSelection(
|
||||
val wallpaperUri: String
|
||||
): AddAlbumEvent()
|
||||
}
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import android.content.Context
|
||||
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
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
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.core.net.toUri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
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.add_album_screen.components.AddAlbumSmallTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
|
||||
|
||||
@Composable
|
||||
fun AddAlbumScreen(
|
||||
initialAlbumName: String,
|
||||
viewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
onBackClick: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
) {
|
||||
viewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
|
||||
|
||||
val context = LocalContext.current
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val state = viewModel.state.collectAsStateWithLifecycle()
|
||||
var selectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
BackHandler {
|
||||
if (selectionMode) {
|
||||
selectionMode = false
|
||||
viewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
} else {
|
||||
onBackClick()
|
||||
viewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
}
|
||||
}
|
||||
|
||||
/** Image picker **/
|
||||
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
|
||||
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
viewModel.onEvent(
|
||||
AddAlbumEvent.AddWallpaper(wallpaperUri = uri.toString())
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/** 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)
|
||||
viewModel.onEvent(
|
||||
AddAlbumEvent.AddFolder(directoryUri = uri.toString())
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
AddAlbumSmallTopBar(
|
||||
title = initialAlbumName,
|
||||
isEmpty = state.value.isEmpty,
|
||||
selectionMode = selectionMode,
|
||||
albumState = viewModel.state,
|
||||
onBackClick = {
|
||||
viewModel.onEvent(AddAlbumEvent.ClearState)
|
||||
onBackClick()
|
||||
},
|
||||
onConfirmationClick = {
|
||||
viewModel.onEvent(AddAlbumEvent.ReflectAlbumName(it))
|
||||
onConfirmation()
|
||||
},
|
||||
onSelectAllClick = {
|
||||
if (!state.value.allSelected) viewModel.onEvent(AddAlbumEvent.SelectAll)
|
||||
else viewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
},
|
||||
onDeleteSelected = {
|
||||
selectionMode = false
|
||||
viewModel.onEvent(AddAlbumEvent.DeselectAll)
|
||||
state.value.selectedFolders.forEach { folder ->
|
||||
viewModel.onEvent(AddAlbumEvent.DeleteFolder(folder))
|
||||
}
|
||||
state.value.selectedWallpapers.forEach { wallpaper ->
|
||||
viewModel.onEvent(AddAlbumEvent.DeleteWallpaper(wallpaper))
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
AnimatedVisibility(
|
||||
visible =
|
||||
!lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AddAlbumAnimatedFab(
|
||||
menuOptions = AddAlbumFabMenuOptions(),
|
||||
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
|
||||
onFolderClick = { folderPickerLauncher.launch(null) }
|
||||
)
|
||||
}
|
||||
},
|
||||
content = {
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier
|
||||
.padding(it)
|
||||
.fillMaxSize(),
|
||||
columns = StaggeredGridCells.Fixed(2),
|
||||
contentPadding = PaddingValues(4.dp, 4.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
content = {
|
||||
if (state.value.folders.isNotEmpty()) {
|
||||
items (items = state.value.folders, key = { folder -> folder.folderUri}
|
||||
) { folder ->
|
||||
FolderItem(
|
||||
folder = folder,
|
||||
itemSelected = state.value.selectedFolders.contains(folder.folderUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
if (!state.value.selectedFolders.contains(folder.folderUri)) {
|
||||
viewModel.onEvent(AddAlbumEvent.SelectFolder(folder.folderUri))
|
||||
} else {
|
||||
viewModel.onEvent(AddAlbumEvent.RemoveFolderFromSelection(folder.folderUri))
|
||||
} },
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
if (state.value.wallpapers.isNotEmpty()) {
|
||||
items (items = state.value.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri}
|
||||
) { wallpaper ->
|
||||
WallpaperItem(
|
||||
wallpaperUri = wallpaper.wallpaperUri,
|
||||
itemSelected = state.value.selectedWallpapers.contains(wallpaper.wallpaperUri),
|
||||
selectionMode = selectionMode,
|
||||
onActivateSelectionMode = { selectionMode = it },
|
||||
onItemSelection = {
|
||||
viewModel.onEvent(
|
||||
if (!state.value.selectedWallpapers.contains(wallpaper.wallpaperUri))
|
||||
AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri)
|
||||
else
|
||||
AddAlbumEvent.RemoveWallpaperFromSelection(wallpaper.wallpaperUri)
|
||||
)
|
||||
},
|
||||
onImageViewClick = {
|
||||
|
||||
},
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun getWallpaperFromFolder(folderUri: String, context: Context): List<String> {
|
||||
val folderDocumentFile = DocumentFile.fromTreeUri(context, folderUri.toUri())
|
||||
return folderDocumentFile?.listFiles()?.map { it.uri.toString() } ?: emptyList()
|
||||
}
|
||||
fun getFolderNameFromUri(folderUri: String, context: Context): String? {
|
||||
return DocumentFile.fromTreeUri(context, folderUri.toUri())?.name
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
data class AddAlbumState (
|
||||
val albumWithWallpapers: List<AlbumWithWallpaper> = emptyList(),
|
||||
|
||||
val initialAlbumName: String = "",
|
||||
val displayedAlbumName: String = "",
|
||||
val coverUri: String = "",
|
||||
val wallpapers: List<Wallpaper> = emptyList(),
|
||||
val folders: List<Folder> = emptyList(),
|
||||
val isEmpty: Boolean = true,
|
||||
val selectedWallpapers: List<String> = emptyList(),
|
||||
val selectedFolders: List<String> = emptyList(),
|
||||
val allSelected: Boolean = false,
|
||||
val selectedCount: Int = 0
|
||||
)
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
|
||||
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.ViewModel
|
||||
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.use_case.AlbumsUseCases
|
||||
import dagger.hilt.android.internal.Contexts.getApplication
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.List.copyOf
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AddAlbumViewModel @Inject constructor(
|
||||
application: Application,
|
||||
private val albumsUseCases: AlbumsUseCases,
|
||||
) : AndroidViewModel(application) {
|
||||
private val context: Context
|
||||
get() = getApplication<Application>().applicationContext
|
||||
private val _state = MutableStateFlow(AddAlbumState())
|
||||
val state = _state.stateIn(
|
||||
viewModelScope,
|
||||
SharingStarted.WhileSubscribed(5000), AddAlbumState()
|
||||
)
|
||||
|
||||
|
||||
fun onEvent(event: AddAlbumEvent) {
|
||||
when (event) {
|
||||
is AddAlbumEvent.SaveAlbum -> {
|
||||
viewModelScope.launch {
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SetAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = event.initialAlbumName,
|
||||
displayedAlbumName = event.initialAlbumName,
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
is AddAlbumEvent.ReflectAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = event.newAlbumName,
|
||||
displayedAlbumName = event.newAlbumName,
|
||||
coverUri = it.coverUri,
|
||||
wallpapers = it.wallpapers.map { wallpaper ->
|
||||
wallpaper.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
folders = it.folders.map { folder ->
|
||||
folder.copy(initialAlbumName = event.newAlbumName)
|
||||
},
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.wallpapers.any { it.wallpaperUri == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
wallpapers = it.wallpapers.plus(
|
||||
Wallpaper(it.initialAlbumName, event.wallpaperUri)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeleteWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
val wallpaperToRemove = state.value.wallpapers.find { it.wallpaperUri == event.wallpaperUri }
|
||||
if (wallpaperToRemove != null) {
|
||||
_state.update { it.copy(
|
||||
wallpapers = it.wallpapers.minus(wallpaperToRemove),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.AddFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.folders.any { it.folderUri == event.directoryUri }) {
|
||||
val wallpapers = getWallpaperFromFolder(event.directoryUri, context)
|
||||
val folderName = getFolderNameFromUri(event.directoryUri, context)
|
||||
_state.update { it.copy(
|
||||
folders = it.folders.plus(
|
||||
Folder(
|
||||
initialAlbumName = it.initialAlbumName,
|
||||
folderName = folderName,
|
||||
folderUri = event.directoryUri,
|
||||
coverUri = wallpapers.random(),
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
),
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeleteFolder -> {
|
||||
viewModelScope.launch {
|
||||
val folderToRemove = state.value.folders.find { it.folderUri == event.directoryUri }
|
||||
if (folderToRemove != null) {
|
||||
_state.update { it.copy(
|
||||
folders = it.folders.minus(folderToRemove)
|
||||
) }
|
||||
updateIsEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectAll -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.allSelected) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = state.value.folders.map { folder -> folder.folderUri },
|
||||
selectedWallpapers = state.value.wallpapers.map { wallpaper -> wallpaper.wallpaperUri },
|
||||
selectedCount = it.folders.size + it.wallpapers.size
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.DeselectAll-> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
selectedCount = 0,
|
||||
allSelected = false
|
||||
) }
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectFolder -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.selectedFolders.any { it == event.directoryUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.plus(event.directoryUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.SelectWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
if (!state.value.selectedWallpapers.any { it == event.wallpaperUri }) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.plus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount + 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveFolderFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (state.value.selectedFolders.find { it == event.directoryUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedFolders = it.selectedFolders.minus(event.directoryUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.RemoveWallpaperFromSelection -> {
|
||||
viewModelScope.launch {
|
||||
if (state.value.selectedWallpapers.find { it == event.wallpaperUri } != null ) {
|
||||
_state.update { it.copy(
|
||||
selectedWallpapers = it.selectedWallpapers.minus(event.wallpaperUri),
|
||||
selectedCount = it.selectedCount - 1
|
||||
) }
|
||||
updateAllSelected()
|
||||
}
|
||||
}
|
||||
}
|
||||
is AddAlbumEvent.ClearState -> {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
initialAlbumName = "",
|
||||
displayedAlbumName = "",
|
||||
coverUri = "",
|
||||
wallpapers = emptyList(),
|
||||
folders = emptyList(),
|
||||
selectedFolders = emptyList(),
|
||||
selectedWallpapers = emptyList(),
|
||||
isEmpty = false,
|
||||
allSelected = false,
|
||||
selectedCount = 0,
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun updateIsEmpty() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
isEmpty = it.wallpapers.isEmpty() && it.folders.isEmpty()
|
||||
) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAllSelected() {
|
||||
viewModelScope.launch {
|
||||
_state.update { it.copy(
|
||||
allSelected = it.selectedFolders.size + it.selectedWallpapers.size >= it.wallpapers.size + it.folders.size
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
@@ -36,9 +36,10 @@ import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.MenuRow
|
||||
|
||||
@Composable
|
||||
fun AnimatedFab(menuOptions: FabMenuOptions, onImageClick: () -> Unit, onFolderClick: () -> Unit) {
|
||||
fun AddAlbumAnimatedFab(menuOptions: AddAlbumFabMenuOptions, onImageClick: () -> Unit, onFolderClick: () -> Unit) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
||||
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.android.awaitFrame
|
||||
|
||||
@Composable
|
||||
fun AddAlbumDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmation: (String) -> Unit
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var albumName by rememberSaveable { mutableStateOf("") }
|
||||
Dialog(onDismissRequest = onDismissRequest) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(
|
||||
text = "New Album",
|
||||
modifier = Modifier.padding(20.dp),
|
||||
fontSize = 25.sp
|
||||
)
|
||||
LaunchedEffect(focusRequester) {
|
||||
awaitFrame()
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = albumName,
|
||||
onValueChange = { albumName = it },
|
||||
label = { Text(stringResource(R.string.album_name)) },
|
||||
modifier = Modifier
|
||||
.padding(vertical = 12.dp, horizontal = 32.dp)
|
||||
.focusRequester(focusRequester),
|
||||
singleLine = true,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
if (albumName.isNotEmpty()) {
|
||||
onConfirmation(albumName)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
) {
|
||||
TextButton(
|
||||
onClick = { onDismissRequest() },
|
||||
modifier = Modifier.padding(8.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
TextButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
onClick = {
|
||||
if (albumName.isNotEmpty()) {
|
||||
onConfirmation(albumName)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.SelectionOptions
|
||||
|
||||
data class FabMenuOptions (
|
||||
data class AddAlbumFabMenuOptions (
|
||||
val imageOption: SelectionOptions = SelectionOptions("add_images", "Add Image", null, Icons.Filled.PhotoLibrary),
|
||||
val folderOption: SelectionOptions = SelectionOptions("add_folder", "Add Folder", null, Icons.Filled.Folder)
|
||||
)
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldColors
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
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
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.DeleteImagesAlertDialog
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AddAlbumSmallTopBar(
|
||||
albumState: StateFlow<AddAlbumState>,
|
||||
title: String,
|
||||
isEmpty: Boolean,
|
||||
selectionMode: Boolean,
|
||||
onSelectAllClick: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
onDeleteSelected: () -> Unit,
|
||||
onConfirmationClick: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val state = albumState.collectAsStateWithLifecycle()
|
||||
val focusManager = LocalFocusManager.current
|
||||
var editableTitle by rememberSaveable { mutableStateOf(title) }
|
||||
var showAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
title = {
|
||||
if (!selectionMode) {
|
||||
TextField(
|
||||
value = editableTitle,
|
||||
onValueChange = { editableTitle = it },
|
||||
placeholder = { Text(stringResource(R.string.enter_the_name_of_the_album)) },
|
||||
singleLine = true,
|
||||
textStyle = MaterialTheme.typography.titleLarge,
|
||||
colors = TextFieldDefaults.colors(
|
||||
focusedContainerColor = Color.Transparent,
|
||||
unfocusedContainerColor = Color.Transparent,
|
||||
focusedIndicatorColor = Color.Transparent,
|
||||
unfocusedIndicatorColor = Color.Transparent
|
||||
),
|
||||
isError = editableTitle.isEmpty(),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() })
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
if (!selectionMode) {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.requiredSize(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen),
|
||||
)
|
||||
}
|
||||
}
|
||||
else {
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (state.value.allSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.all_images_selected_for_deletion),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
Text("${state.value.selectedCount} selected")
|
||||
}
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
if(!selectionMode) {
|
||||
IconButton(onClick = { onConfirmationClick(editableTitle) }) {
|
||||
if (!isEmpty) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (showAlertDialog) DeleteImagesAlertDialog (
|
||||
onDismissRequest = { showAlertDialog = false },
|
||||
onConfirmation = {
|
||||
showAlertDialog = false
|
||||
onDeleteSelected()
|
||||
}
|
||||
)
|
||||
IconButton(
|
||||
onClick = { showAlertDialog = true }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Delete,
|
||||
contentDescription = stringResource(R.string.select_all_images_for_deletion),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
@Composable
|
||||
fun AlbumItem(
|
||||
//albumCover: Uri,
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(false, label = "")
|
||||
|
||||
val paddingTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 5.dp else 0.dp
|
||||
}
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 18.dp else 10.dp
|
||||
}
|
||||
|
||||
ElevatedCard(
|
||||
elevation = CardDefaults.cardElevation(),
|
||||
modifier = Modifier.size(width = 240.dp, height = 100.dp),
|
||||
colors = CardDefaults.elevatedCardColors()
|
||||
) {
|
||||
/*
|
||||
AsyncImage(
|
||||
model = albumCover,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
)
|
||||
*/
|
||||
Text(
|
||||
text = "Text",
|
||||
modifier = Modifier.padding(16.dp),
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedCard
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun FolderItem(
|
||||
folder: Folder,
|
||||
itemSelected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val configuration = LocalConfiguration.current
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
|
||||
val paddingTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 5.dp else 0.dp
|
||||
}
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
|
||||
OutlinedCard(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selectionMode) { onItemSelection() }
|
||||
else { /*go to photo screen*/ }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
),
|
||||
shape = RoundedCornerShape(roundedCornerShapeTransition),
|
||||
border = BorderStroke(1.dp, bgColor)
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
tonalElevation = 5.dp,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Box {
|
||||
AsyncImage(
|
||||
modifier = Modifier
|
||||
.height(configuration.screenHeightDp.dp / 4.0f)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition)),
|
||||
model = folder.coverUri,
|
||||
contentDescription = folder.folderName,
|
||||
alignment = Alignment.Center,
|
||||
contentScale = ContentScale.Crop,
|
||||
)
|
||||
if (selectionMode) {
|
||||
if (itemSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.border(2.dp, bgColor, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(bgColor)
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = Icons.Default.RadioButtonUnchecked,
|
||||
contentDescription = stringResource(R.string.image_is_not_selected),
|
||||
tint = Color.White.copy(alpha = 0.7f),
|
||||
modifier = Modifier.padding(6.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(6.dp))
|
||||
folder.folderName?.let { name ->
|
||||
Text(
|
||||
text = name,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 16.sp
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = folder.wallpapers.size.toString().plus(" wallpapers"),
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 24.dp)
|
||||
.align(Alignment.Start),
|
||||
fontSize = 12.sp,
|
||||
color = MaterialTheme.colorScheme.tertiary
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-14
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
@@ -29,46 +28,50 @@ import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import coil.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun WallpaperItem(
|
||||
selected: Boolean,
|
||||
wallpaperUri: String,
|
||||
itemSelected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
image: Uri,
|
||||
onSelectionListClick: () -> Unit,
|
||||
onSelection: () -> Unit
|
||||
onActivateSelectionMode: (Boolean) -> Unit,
|
||||
onItemSelection: () -> Unit,
|
||||
onImageViewClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(selected, label = "")
|
||||
val transition = updateTransition(itemSelected, label = "")
|
||||
|
||||
val paddingTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 5.dp else 0.dp
|
||||
}
|
||||
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
|
||||
if (selected) 18.dp else 10.dp
|
||||
if (selected) 24.dp else 16.dp
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selectionMode) { onSelection() }
|
||||
else { /*zoom into photo*/ }
|
||||
if (selectionMode) { onItemSelection() }
|
||||
else { onImageViewClick() }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onSelectionListClick()
|
||||
onActivateSelectionMode(true)
|
||||
onItemSelection()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = image,
|
||||
model = wallpaperUri.toUri(),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
@@ -77,7 +80,7 @@ fun WallpaperItem(
|
||||
)
|
||||
if (selectionMode) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (selected) {
|
||||
if (itemSelected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.image_is_selected),
|
||||
+18
-42
@@ -15,59 +15,49 @@ import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
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 androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumDialog
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.tabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
wallpaperState: WallpaperState,
|
||||
settingsState: SettingsState,
|
||||
addAlbumViewModel: AddAlbumViewModel = hiltViewModel(),
|
||||
onSettingsClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onLaunchImagePhotoPicker: () -> Unit,
|
||||
onDeleteImagesClick: (List<String>) -> Unit
|
||||
navigateToAddWallpaperScreen: (String) -> Unit
|
||||
) {
|
||||
val albumState = addAlbumViewModel.state.collectAsState()
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
var showSelectionModeAppBar by remember { mutableStateOf(false) }
|
||||
var selectionCount by rememberSaveable { mutableIntStateOf(0) }
|
||||
var allSelected by rememberSaveable { mutableStateOf(false) }
|
||||
var selectAll by rememberSaveable { mutableStateOf(false) }
|
||||
var deleteImages by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
|
||||
LaunchedEffect(tabIndex) { pagerState.animateScrollToPage(tabIndex) }
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
|
||||
}
|
||||
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumDialog) AddAlbumDialog(
|
||||
onDismissRequest = { addAlbumDialog = false },
|
||||
onConfirmation = { navigateToAddWallpaperScreen(it) }
|
||||
)
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
onSettingsClick = onSettingsClick,
|
||||
onContactClick = onContactClick,
|
||||
showSelectionModeAppBar = showSelectionModeAppBar,
|
||||
selectionCount = selectionCount,
|
||||
allSelected = allSelected,
|
||||
onSelectAllClick = { selectAll = true },
|
||||
deleteImagesOnClick = {
|
||||
deleteImages = true
|
||||
showSelectionModeAppBar = false
|
||||
}
|
||||
showSelectionModeAppBar = false,
|
||||
selectionCount = 0,
|
||||
)
|
||||
}
|
||||
) {padding ->
|
||||
@@ -75,9 +65,7 @@ fun HomeScreen(
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.padding(padding)
|
||||
) {
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
SecondaryTabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
@@ -116,23 +104,11 @@ fun HomeScreen(
|
||||
HorizontalPager(state = pagerState) { index ->
|
||||
when(index) {
|
||||
0 -> WallpaperScreen(
|
||||
settingsState = settingsState,
|
||||
wallpaperState = wallpaperState
|
||||
albumState = albumState
|
||||
)
|
||||
1 -> LibraryScreen(
|
||||
settingsState = settingsState,
|
||||
wallpaperState = wallpaperState,
|
||||
onLaunchImagePhotoPicker = onLaunchImagePhotoPicker,
|
||||
onSelectionMode = { showSelectionModeAppBar = it },
|
||||
onUpdateItemCount = { selectionCount = it },
|
||||
onAllSelected = {allSelected = it},
|
||||
selectAll = selectAll,
|
||||
selectAllDone = { selectAll = false },
|
||||
deleteImages = deleteImages,
|
||||
onDeleteImagesClick = {
|
||||
onDeleteImagesClick(it)
|
||||
deleteImages = false
|
||||
}
|
||||
albumState = albumState,
|
||||
onAddNewAlbumClick = { addAlbumDialog = true }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-9
@@ -17,16 +17,10 @@ fun DeleteImagesAlertDialog(
|
||||
) {
|
||||
AlertDialog(
|
||||
icon = {
|
||||
Icon(Icons.Outlined.Delete,
|
||||
contentDescription = stringResource(R.string.delete_confirmation)
|
||||
)
|
||||
},
|
||||
title = {
|
||||
Text(text = "Delete wallpapers?")
|
||||
},
|
||||
text = {
|
||||
Text(text = "Are you sure you want to delete these wallpapers?")
|
||||
Icon(Icons.Outlined.Delete, contentDescription = stringResource(R.string.delete_confirmation))
|
||||
},
|
||||
title = { Text(text = "Delete these?") },
|
||||
text = { Text(text = "Are you sure you want to delete these wallpapers?") },
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
|
||||
+3
-6
@@ -48,13 +48,10 @@ import com.anthonyla.paperize.R
|
||||
@Composable
|
||||
fun HomeTopBar (
|
||||
showSelectionModeAppBar: Boolean,
|
||||
allSelected: Boolean,
|
||||
selectionCount: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
onSettingsClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onSelectAllClick: () -> Unit,
|
||||
deleteImagesOnClick: () -> Unit,
|
||||
) {
|
||||
CenterAlignedTopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
@@ -99,7 +96,7 @@ fun HomeTopBar (
|
||||
onDismissRequest = { showAlertDialog = false },
|
||||
onConfirmation = {
|
||||
showAlertDialog = false
|
||||
deleteImagesOnClick()
|
||||
//deleteImagesOnClick()
|
||||
}
|
||||
)
|
||||
IconButton(
|
||||
@@ -121,10 +118,10 @@ fun HomeTopBar (
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
onClick = { }
|
||||
) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (allSelected) {
|
||||
if (true) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.CheckCircle,
|
||||
contentDescription = stringResource(R.string.all_images_selected_for_deletion),
|
||||
|
||||
+22
-119
@@ -1,108 +1,47 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
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.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.AnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components.FabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.components.WallpaperItem
|
||||
import okhttp3.internal.toImmutableList
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumState
|
||||
|
||||
@Composable
|
||||
fun LibraryScreen(
|
||||
wallpaperState: WallpaperState,
|
||||
settingsState: SettingsState,
|
||||
onLaunchImagePhotoPicker: () -> Unit,
|
||||
onSelectionMode: (Boolean) -> Unit,
|
||||
onUpdateItemCount: (Int) -> Unit,
|
||||
onAllSelected: (Boolean) -> Unit,
|
||||
selectAll: Boolean,
|
||||
selectAllDone: () -> Unit,
|
||||
deleteImages: Boolean,
|
||||
onDeleteImagesClick: (List<String>) -> Unit
|
||||
albumState: State<AddAlbumState>,
|
||||
onAddNewAlbumClick: () -> Unit
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
val albumLazyListState = rememberLazyStaggeredGridState()
|
||||
|
||||
var selectedImageUris by rememberSaveable(Unit) { mutableStateOf(listOf<String>()) }
|
||||
var inSelectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
/*
|
||||
If user selects all images available for deletion, add it to the list and clear the UI state
|
||||
*/
|
||||
if (selectAll) {
|
||||
selectedImageUris = selectedImageUris.toMutableList().apply {
|
||||
clear()
|
||||
wallpaperState.wallpapers.forEach { add(it.imageUri) }
|
||||
}.toImmutableList()
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
selectAllDone()
|
||||
onAllSelected(true)
|
||||
}
|
||||
|
||||
/*
|
||||
If user deletes the selected item,
|
||||
pass the list back for deletion and clear the UI state
|
||||
*/
|
||||
if (deleteImages) {
|
||||
onDeleteImagesClick(selectedImageUris)
|
||||
selectedImageUris = selectedImageUris.toMutableList().apply {
|
||||
clear()
|
||||
}.toImmutableList()
|
||||
onUpdateItemCount(0)
|
||||
inSelectionMode = false
|
||||
onSelectionMode(false)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
}
|
||||
|
||||
/*
|
||||
If user does a back press while in selection mode,
|
||||
turn off selection mode and clear the selected list
|
||||
*/
|
||||
BackHandler(inSelectionMode) {
|
||||
selectedImageUris = selectedImageUris.toMutableList().apply {
|
||||
clear()
|
||||
}.toImmutableList()
|
||||
onUpdateItemCount(0)
|
||||
inSelectionMode = false
|
||||
onSelectionMode(false)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
}
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
AnimatedVisibility(
|
||||
visible =
|
||||
!lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = onAddNewAlbumClick,
|
||||
) {
|
||||
AnimatedFab(
|
||||
menuOptions = FabMenuOptions(),
|
||||
onImageClick = onLaunchImagePhotoPicker,
|
||||
onFolderClick = {}
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
contentDescription = stringResource(R.string.add_album),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -112,49 +51,13 @@ fun LibraryScreen(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyListState,
|
||||
state = albumLazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = StaggeredGridCells.Fixed(3),
|
||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 16.dp),
|
||||
verticalItemSpacing = 8.dp,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
content = {
|
||||
items(wallpaperState.wallpapers, key = { it.imageUri })
|
||||
{ wallpaper ->
|
||||
WallpaperItem(
|
||||
selected = selectedImageUris.contains(wallpaper.imageUri),
|
||||
selectionMode = inSelectionMode,
|
||||
image = wallpaper.imageUri.toUri(),
|
||||
onSelectionListClick = {
|
||||
inSelectionMode = true
|
||||
selectedImageUris = if (selectedImageUris.contains(wallpaper.imageUri)) {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
remove(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
} else {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
add(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
}
|
||||
onSelectionMode(true)
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
},
|
||||
onSelection = {
|
||||
selectedImageUris = if (selectedImageUris.contains(wallpaper.imageUri)) {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
remove(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
} else {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
add(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
}
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun WallpaperLazyStaggeredList() {
|
||||
/*
|
||||
LazyVerticalStaggeredGrid(
|
||||
state = lazyListState,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
columns = StaggeredGridCells.Fixed(3),
|
||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 16.dp),
|
||||
verticalItemSpacing = 8.dp,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
content = {
|
||||
items(wallpaperState.wallpapers, key = { it.imageUri })
|
||||
{ wallpaper ->
|
||||
WallpaperItem(
|
||||
selected = selectedImageUris.contains(wallpaper.imageUri),
|
||||
selectionMode = inSelectionMode,
|
||||
image = wallpaper.imageUri.toUri(),
|
||||
onSelectionListClick = {
|
||||
inSelectionMode = true
|
||||
selectedImageUris = if (selectedImageUris.contains(wallpaper.imageUri)) {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
remove(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
} else {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
add(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
}
|
||||
onSelectionMode(true)
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
},
|
||||
onSelection = {
|
||||
selectedImageUris = if (selectedImageUris.contains(wallpaper.imageUri)) {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
remove(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
} else {
|
||||
selectedImageUris.toMutableList().apply {
|
||||
add(wallpaper.imageUri)
|
||||
}.toImmutableList()
|
||||
}
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
onAllSelected(selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
*/
|
||||
}
|
||||
+2
-5
@@ -5,16 +5,13 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ScrollableSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsLargeTopAppBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.Title
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsSmallTopAppBar
|
||||
|
||||
@Composable
|
||||
@@ -42,7 +39,7 @@ fun SettingsScreen(
|
||||
onDarkModeClick = onDarkModeClick
|
||||
)
|
||||
SettingsSmallTopAppBar(onBackClick = onBackClick)
|
||||
Title(
|
||||
SettingsTitle(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun Title(
|
||||
fun SettingsTitle(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper
|
||||
|
||||
sealed class WallpaperEvent {
|
||||
data class DeleteWallpaper(val uriString: String): WallpaperEvent()
|
||||
data class AddWallpaper(val uriString: String): WallpaperEvent()
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
data class WallpaperState (
|
||||
val wallpapers: List<Wallpaper> = emptyList()
|
||||
)
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper
|
||||
|
||||
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.WallpaperUseCases
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class WallpaperViewModel @Inject constructor(
|
||||
private val wallpaperUseCases: WallpaperUseCases
|
||||
) : ViewModel() {
|
||||
private val _state = mutableStateOf(WallpaperState())
|
||||
val state: State<WallpaperState> = _state
|
||||
private var currentGetJob: Job?= null
|
||||
|
||||
init { refreshWallpapers() }
|
||||
|
||||
fun onEvent(event: WallpaperEvent) {
|
||||
when (event) {
|
||||
is WallpaperEvent.AddWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
wallpaperUseCases.addWallpaper(event.uriString)
|
||||
}
|
||||
}
|
||||
is WallpaperEvent.DeleteWallpaper -> {
|
||||
viewModelScope.launch {
|
||||
wallpaperUseCases.deleteWallpaper(event.uriString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshWallpapers() {
|
||||
currentGetJob?.cancel()
|
||||
currentGetJob = wallpaperUseCases.getWallpapers().onEach { wallpapers ->
|
||||
_state.value = state.value.copy(
|
||||
wallpapers = wallpapers
|
||||
)
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-13
@@ -1,27 +1,17 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumState
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(settingsState: SettingsState, wallpaperState: WallpaperState) {
|
||||
fun WallpaperScreen(albumState: State<AddAlbumState>) {
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
|
||||
class AddAlbumWithWallpaper(private val repository: AlbumRepository) {
|
||||
suspend operator fun invoke(albumWithWallpaper: AlbumWithWallpaper) {
|
||||
repository.upsertAlbum(albumWithWallpaper.album)
|
||||
albumWithWallpaper.wallpapers.forEach { wallpaper ->
|
||||
repository.upsertWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import android.net.Uri
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.WallpaperRepository
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperEvent
|
||||
|
||||
class AddWallpaper(private val repository: WallpaperRepository) {
|
||||
suspend operator fun invoke(uriString: String) {
|
||||
val wallpaper = Wallpaper(imageUri = uriString, date = "today")
|
||||
repository.insertWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
data class AlbumsUseCases(
|
||||
val getAllAlbumsWithWallpaper: GetAllAlbumsWithWallpaper,
|
||||
val addAlbumWithWallpaper: AddAlbumWithWallpaper
|
||||
)
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.WallpaperRepository
|
||||
|
||||
class DeleteWallpaper(private val repository: WallpaperRepository) {
|
||||
suspend operator fun invoke(uriString: String) {
|
||||
val wallpaper = Wallpaper(imageUri = uriString, date = "today")
|
||||
repository.deleteWallpaper(wallpaper)
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class GetAllAlbumsWithWallpaper(private val repository: AlbumRepository) {
|
||||
operator fun invoke(): Flow<List<AlbumWithWallpaper>> {
|
||||
return repository.getAlbumsWithWallpapers()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.WallpaperRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class GetWallpapers(private val repository: WallpaperRepository) {
|
||||
operator fun invoke(): Flow<List<Wallpaper>> {
|
||||
return repository.getWallpapers()
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
data class WallpaperUseCases(
|
||||
val getWallpapers: GetWallpapers,
|
||||
val addWallpaper: AddWallpaper,
|
||||
val deleteWallpaper: DeleteWallpaper
|
||||
)
|
||||
+3
@@ -2,8 +2,10 @@ package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
@@ -13,4 +15,5 @@ import com.anthonyla.paperize.R
|
||||
sealed class NavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
|
||||
object Home : NavScreens("home_screen", R.string.home_screen, Icons.Outlined.Image, Icons.Filled.Image)
|
||||
object Settings : NavScreens("settings_screen", R.string.settings_screen, Icons.Outlined.Settings, Icons.Filled.Settings)
|
||||
object AddEdit : NavScreens("add_edit_screen", R.string.add_wallpaper_screen, Icons.Outlined.Add, Icons.Filled.Add)
|
||||
}
|
||||
@@ -20,4 +20,10 @@
|
||||
<string name="select_all_images_for_deletion">Select all images for deletion</string>
|
||||
<string name="delete_confirmation">Delete confirmation</string>
|
||||
<string name="all_images_selected_for_deletion">All images selected for deletion</string>
|
||||
<string name="add_album">Add album</string>
|
||||
<string name="add_wallpaper_screen">Add Wallpaper Screen</string>
|
||||
<string name="enter_the_name_of_the_album">Enter the name of the album</string>
|
||||
<string name="album_name">Album Name</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="save">Save</string>
|
||||
</resources>
|
||||
File renamed without changes.
Reference in new issue
Block a user