Added library functionality, settings screen and functionality, dynamic theming and dark mode full implementation, refactored some methods and changed app layout to nested scaffolds
This commit is contained in:
1 parent
de65ea1201
commit
27fb19c701
87 files changed
+1947
-1232
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.anthonyla.paperize
|
||||
|
||||
import android.app.Application
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
|
||||
File renamed without changes.
-76
@@ -1,76 +0,0 @@
|
||||
package com.anthonyla.paperize.core.presentation.components
|
||||
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarDefaults
|
||||
import androidx.compose.material3.NavigationBarDefaults.containerColor
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.BottomNavScreens
|
||||
|
||||
|
||||
/**
|
||||
* Bottom navigation bar for the app
|
||||
*
|
||||
* @param navController Controller to navigate between the screens
|
||||
* @param screens List of valid screens for bottom navigation
|
||||
* @param modifier
|
||||
*/
|
||||
@Composable
|
||||
fun BottomNavigationBar(
|
||||
navController: NavController,
|
||||
screens: List<BottomNavScreens>,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
NavigationBar(
|
||||
containerColor = containerColor,
|
||||
contentColor = MaterialTheme.colorScheme.contentColorFor(containerColor),
|
||||
tonalElevation = NavigationBarDefaults.Elevation,
|
||||
windowInsets = NavigationBarDefaults.windowInsets,
|
||||
modifier = Modifier
|
||||
) {
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
screens.forEach { screen ->
|
||||
NavigationBarItem(
|
||||
colors = NavigationBarItemDefaults.colors(),
|
||||
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
||||
label = {
|
||||
Text(
|
||||
text = stringResource(id = screen.resourceId),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
) },
|
||||
icon = {
|
||||
if (currentDestination != null) {
|
||||
Icon(imageVector =
|
||||
if (currentDestination.route == screen.route) screen.filledIcon else screen.unfilledIcon,
|
||||
contentDescription = "${stringResource(id = screen.resourceId)} Icon",
|
||||
)
|
||||
}
|
||||
},
|
||||
alwaysShowLabel = false,
|
||||
onClick = {
|
||||
navController.navigate(screen.route) {
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.anthonyla.paperize.core.presentation.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.windowInsets
|
||||
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.res.stringResource
|
||||
import androidx.navigation.NavController
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.data.Contact
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.SettingsNavScreens
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TopBar (
|
||||
navController: NavController,
|
||||
title: String?,
|
||||
showBackButton: Boolean,
|
||||
showMenuButton: Boolean,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
|
||||
var menuExpanded by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
var toContactPressed by rememberSaveable { mutableStateOf(false) }
|
||||
if (toContactPressed) {
|
||||
Contact(LocalContext.current)
|
||||
toContactPressed = false
|
||||
menuExpanded = false
|
||||
}
|
||||
|
||||
TopAppBar(
|
||||
title = { if (title != null) { Text(title) } },
|
||||
navigationIcon = {
|
||||
if (showBackButton) {
|
||||
IconButton(onClick = { navController.navigateUp() }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.ArrowBack,
|
||||
contentDescription = stringResource(R.string.settings_back)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
windowInsets = windowInsets,
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(),
|
||||
scrollBehavior = null,
|
||||
actions = {
|
||||
if (showMenuButton) {
|
||||
IconButton(onClick = { menuExpanded = !menuExpanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
contentDescription = stringResource(R.string.MoreVertIcon)
|
||||
)
|
||||
DropdownMenu(
|
||||
expanded = menuExpanded,
|
||||
onDismissRequest = { menuExpanded = !menuExpanded },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.dropdownmenu_settings)) },
|
||||
onClick = {
|
||||
menuExpanded = !menuExpanded
|
||||
navController.navigate(SettingsNavScreens.Settings.route) {
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("Contact") },
|
||||
onClick = { toContactPressed = true }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.anthonyla.paperize.core.presentation.components
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
@Composable
|
||||
fun SetTransparentSystemBars(darkMode: Boolean) {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val view = LocalView.current
|
||||
SideEffect {
|
||||
with(view.context as Activity) {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
systemUiController.setSystemBarsColor(
|
||||
color = Color.Transparent,
|
||||
darkIcons = !darkMode
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,5 +20,4 @@ fun Contact(context: Context) {
|
||||
val emailIntent = Intent(Intent.ACTION_SENDTO)
|
||||
emailIntent.setData(Uri.parse(mailto))
|
||||
startActivity(context, emailIntent, null)
|
||||
|
||||
}
|
||||
@@ -5,15 +5,14 @@ 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.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.AddAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AddImage
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AlbumUseCases
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.DeleteAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.DeleteImage
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.GetAlbums
|
||||
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 dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
@@ -26,33 +25,31 @@ import javax.inject.Singleton
|
||||
object AppModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumDatabase(app: Application): AlbumDatabase {
|
||||
fun provideWallpaperDatabase(app: Application): WallpaperDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
WallpaperDatabase::class.java,
|
||||
WallpaperDatabase.DATABASE_NAME
|
||||
).build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumRepository(
|
||||
db: AlbumDatabase
|
||||
): AlbumRepository {
|
||||
return AlbumRepositoryImpl(db.albumDao)
|
||||
fun provideWallpaperRepository(
|
||||
db: WallpaperDatabase
|
||||
): WallpaperRepository {
|
||||
return WallpaperRepositoryImpl(db.wallpaperDao)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAlbumUseCases(
|
||||
repository: AlbumRepository
|
||||
): AlbumUseCases {
|
||||
return AlbumUseCases (
|
||||
getAlbums = GetAlbums(repository),
|
||||
deleteAlbum = DeleteAlbum(repository),
|
||||
deleteImage = DeleteImage(repository),
|
||||
addAlbum = AddAlbum(repository),
|
||||
addImage = AddImage(repository),
|
||||
fun provideWallpaperUseCases(
|
||||
repository: WallpaperRepository
|
||||
): WallpaperUseCases {
|
||||
return WallpaperUseCases (
|
||||
getWallpapers = GetWallpapers(repository),
|
||||
deleteWallpaper = DeleteWallpaper(repository),
|
||||
addWallpaper = AddWallpaper(repository),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
-30
@@ -1,30 +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.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithImages
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
@Transaction
|
||||
@Query("SELECT * FROM album")
|
||||
fun getAlbumsWithImages(): Flow<List<AlbumWithImages>>
|
||||
|
||||
@Upsert
|
||||
suspend fun upsertAlbum(album: Album) : Long
|
||||
|
||||
@Upsert
|
||||
suspend fun upsertImage(image: Image)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteImage(image: Image)
|
||||
}
|
||||
-17
@@ -1,17 +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.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
|
||||
@Database(
|
||||
entities = [Album::class, Image::class],
|
||||
version = 1
|
||||
)
|
||||
abstract class AlbumDatabase: RoomDatabase() {
|
||||
abstract val albumDao: AlbumDao
|
||||
companion object {
|
||||
const val DATABASE_NAME = "album_db"
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
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
@@ -0,0 +1,16 @@
|
||||
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
@@ -1,32 +0,0 @@
|
||||
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.AlbumWithImages
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class AlbumRepositoryImpl(
|
||||
private val dao: AlbumDao
|
||||
): AlbumRepository {
|
||||
override fun getAlbums(): Flow<List<AlbumWithImages>> {
|
||||
return dao.getAlbumsWithImages()
|
||||
}
|
||||
|
||||
override suspend fun insertAlbum(album: Album) : Long {
|
||||
return dao.upsertAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun insertImage(image: Image) {
|
||||
dao.upsertImage(image)
|
||||
}
|
||||
|
||||
override suspend fun deleteAlbum(album: Album) {
|
||||
dao.deleteAlbum(album)
|
||||
}
|
||||
|
||||
override suspend fun deleteImage(image: Image) {
|
||||
dao.deleteImage(image)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class AlbumWithImages(
|
||||
@Embedded val album: Album,
|
||||
@Relation(
|
||||
parentColumn = "albumId",
|
||||
entityColumn = "albumId"
|
||||
)
|
||||
val images: List<Image>
|
||||
)
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.domain.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Image(
|
||||
@PrimaryKey(autoGenerate = true) val imageId: Long = 0,
|
||||
val albumId: Long ?= 0,
|
||||
val imageName: String,
|
||||
val dateAdded: String
|
||||
)
|
||||
+3
-4
@@ -4,8 +4,7 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Album(
|
||||
@PrimaryKey(autoGenerate = true) val albumId: Long = 0,
|
||||
val albumName: String,
|
||||
val dateAdded: String
|
||||
data class Wallpaper(
|
||||
@PrimaryKey(autoGenerate = false) val imageUri: String,
|
||||
val date: String
|
||||
)
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
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.AlbumWithImages
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AlbumRepository {
|
||||
fun getAlbums(): Flow<List<AlbumWithImages>>
|
||||
|
||||
suspend fun insertAlbum(album: Album) : Long
|
||||
|
||||
suspend fun insertImage(image: Image)
|
||||
|
||||
suspend fun deleteAlbum(album: Album)
|
||||
|
||||
suspend fun deleteImage(image: Image)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
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)
|
||||
}
|
||||
+36
-7
@@ -3,21 +3,50 @@ package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.anthonyla.paperize.R
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
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.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val splashScreen = installSplashScreen()
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.shouldNotBypassSplashScreen }
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(R.style.Theme_Paperize)
|
||||
setContent {
|
||||
PaperizeTheme() {
|
||||
val navController = rememberNavController()
|
||||
PaperizeApp(navController)
|
||||
PaperizeTheme(
|
||||
isDarkMode = isDarkMode(settingsState = settingsViewModel.state.value),
|
||||
isDynamicTheming = isDynamicTheming(settingsState = settingsViewModel.state.value)
|
||||
) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun isDarkMode(settingsState: SettingsState): Boolean =
|
||||
when(settingsState.darkMode) {
|
||||
true -> true // User enabled dark mode
|
||||
false -> false // User enabled light mode
|
||||
else -> isSystemInDarkTheme() // System default
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun isDynamicTheming(settingsState: SettingsState): Boolean =
|
||||
when(settingsState.dynamicTheming) {
|
||||
true -> true
|
||||
false -> false
|
||||
}
|
||||
+72
-78
@@ -1,94 +1,88 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
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.navigation.NavHostController
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.anthonyla.paperize.core.presentation.components.BottomNavigationBar
|
||||
import com.anthonyla.paperize.core.presentation.components.TopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library.components.AnimatedFab
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library.components.FabMenuOptions
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.AddEditNavScreens
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.BottomNavScreens
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.SettingsNavScreens
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.navGraph
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.anthonyla.paperize.data.Contact
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
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
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun PaperizeApp(navController: NavHostController) {
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
fun PaperizeApp(
|
||||
wallpaperViewModel: WallpaperViewModel = hiltViewModel(),
|
||||
settingsViewModel: SettingsViewModel = hiltViewModel()
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
val showBackButton = navBackStackEntry?.destination?.route in listOf(
|
||||
SettingsNavScreens.Settings.route,
|
||||
AddEditNavScreens.ImageAdd.route
|
||||
)
|
||||
val showDropDownMenu = navBackStackEntry?.destination?.route in listOf(
|
||||
BottomNavScreens.Wallpaper.route,
|
||||
BottomNavScreens.Library.route,
|
||||
BottomNavScreens.Configure.route
|
||||
)
|
||||
val showTitle = when (navBackStackEntry?.destination?.route) {
|
||||
SettingsNavScreens.Settings.route -> "Settings"
|
||||
AddEditNavScreens.ImageAdd.route -> ""
|
||||
else -> ""
|
||||
}
|
||||
TopBar(
|
||||
navController = navController,
|
||||
title = showTitle,
|
||||
showBackButton = showBackButton,
|
||||
showMenuButton = showDropDownMenu
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
val showNavigationBar = navBackStackEntry?.destination?.route in listOf(
|
||||
BottomNavScreens.Wallpaper.route,
|
||||
BottomNavScreens.Library.route,
|
||||
BottomNavScreens.Configure.route
|
||||
)
|
||||
if (showNavigationBar) BottomNavigationBar(
|
||||
navController = navController,
|
||||
screens = listOf(
|
||||
BottomNavScreens.Wallpaper,
|
||||
BottomNavScreens.Library,
|
||||
BottomNavScreens.Configure
|
||||
)
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
// Show floating action button if current screen is in the list
|
||||
val showFabButton = navBackStackEntry?.destination?.route in listOf(
|
||||
BottomNavScreens.Library.route,
|
||||
)
|
||||
var optionClicked by rememberSaveable { mutableStateOf("") }
|
||||
if (showFabButton) {
|
||||
AnimatedFab(FabMenuOptions()) {
|
||||
optionClicked = it
|
||||
val options = FabMenuOptions()
|
||||
when (optionClicked) {
|
||||
options.imageOption.id ->
|
||||
navController.navigate(AddEditNavScreens.ImageAdd.route) {
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
options.folderOption.id -> null
|
||||
}
|
||||
}
|
||||
/** 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()))
|
||||
}
|
||||
}
|
||||
) { innerPadding -> NavHost (
|
||||
navController,
|
||||
startDestination = "bottomNavigation",
|
||||
Modifier.padding(innerPadding)
|
||||
) { navGraph(navController) }
|
||||
)
|
||||
|
||||
val wallpaperState = wallpaperViewModel.state.value
|
||||
val settingsState = settingsViewModel.state.value
|
||||
val navController = rememberNavController()
|
||||
var toContact by rememberSaveable { mutableStateOf(false) }
|
||||
if (toContact) { Contact(LocalContext.current) }
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = NavScreens.Home.route,
|
||||
modifier = Modifier.navigationBarsPadding()
|
||||
) {
|
||||
composable(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))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
composable(NavScreens.Settings.route) {
|
||||
SettingsScreen(
|
||||
settingsState = settingsState,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onDynamicThemingClick = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDynamicTheming(it))
|
||||
},
|
||||
onDarkModeClick = {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetDarkMode(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_edit_albums
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
sealed class AddEditAlbumEvent{
|
||||
data class AddTitle(val value: String): AddEditAlbumEvent()
|
||||
data class AddImages(val images: List<Uri>)
|
||||
object SaveAlbum: AddEditAlbumEvent()
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_edit_albums
|
||||
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AlbumUseCases
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AddEditAlbumViewModel @Inject constructor(
|
||||
private val albumUseCases: AlbumUseCases
|
||||
) : ViewModel() {
|
||||
|
||||
private val _albumName = mutableStateOf("")
|
||||
val albumName: State<String> = _albumName
|
||||
|
||||
private val _eventFlow = MutableSharedFlow<UiEvent>()
|
||||
|
||||
sealed class UiEvent {
|
||||
object SaveAlbum
|
||||
}
|
||||
|
||||
fun onEvent(event: AddEditAlbumEvent) {
|
||||
when(event) {
|
||||
is AddEditAlbumEvent.AddTitle -> {
|
||||
_albumName.value = event.value
|
||||
}
|
||||
is AddEditAlbumEvent.AddImages -> {
|
||||
|
||||
}
|
||||
is AddEditAlbumEvent.SaveAlbum -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.add_edit_albums
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.clickable
|
||||
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.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
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.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
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.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
@Composable
|
||||
fun ImageAddScreen(navController: NavController, modifier: Modifier = Modifier) {
|
||||
var launchPickerButton: Boolean by rememberSaveable { mutableStateOf(false) }
|
||||
var selectedImageUris by rememberSaveable { mutableStateOf<List<Uri>>(emptyList()) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Image Add Screen")
|
||||
Button(onClick = { launchPickerButton = true}) {
|
||||
val multiplePhotoPickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.PickMultipleVisualMedia(),
|
||||
onResult = { uri -> selectedImageUris = uri }
|
||||
)
|
||||
if (launchPickerButton) {
|
||||
multiplePhotoPickerLauncher.launch(
|
||||
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
|
||||
)
|
||||
launchPickerButton = false
|
||||
}
|
||||
}
|
||||
LazyVerticalStaggeredGrid(
|
||||
columns = StaggeredGridCells.Fixed(3),
|
||||
verticalItemSpacing = 4.dp,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
content = {
|
||||
items(selectedImageUris) { image ->
|
||||
AsyncImage(
|
||||
model = image,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.clickable { }
|
||||
)
|
||||
}
|
||||
},
|
||||
contentPadding = PaddingValues(4.dp),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
|
||||
sealed class AlbumsEvent {
|
||||
data class DeleteAlbum(val album: Album): AlbumsEvent()
|
||||
data class DeleteImage(val image: Image): AlbumsEvent()
|
||||
data class AddAlbum(val album: Album): AlbumsEvent()
|
||||
data class AddImage(val image: Image): AlbumsEvent()
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
|
||||
data class AlbumsState(
|
||||
val albums: List<Album> = emptyList(),
|
||||
)
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album
|
||||
|
||||
|
||||
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.AlbumUseCases
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AlbumsViewModel @Inject constructor(
|
||||
private val albumUseCases: AlbumUseCases
|
||||
) : ViewModel() {
|
||||
|
||||
private var lastAlbumId: Long = 0
|
||||
private val _state = mutableStateOf(AlbumsState())
|
||||
val state: State<AlbumsState> = _state
|
||||
|
||||
fun onEvent(event: AlbumsEvent) {
|
||||
when (event) {
|
||||
is AlbumsEvent.AddAlbum -> {
|
||||
viewModelScope.launch {
|
||||
lastAlbumId = albumUseCases.addAlbum(event.album)
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.AddImage -> {
|
||||
viewModelScope.launch {
|
||||
albumUseCases.addImage(event.image.copy(albumId = lastAlbumId))
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
|
||||
@Composable
|
||||
fun AlbumItem(
|
||||
album: Album,
|
||||
modifier: Modifier = Modifier,
|
||||
onDeleteClick: () -> Unit
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
) {
|
||||
Text(album.albumName)
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.configure
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavController
|
||||
|
||||
@Composable
|
||||
fun ConfigureScreen(navController: NavController, modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Configure")
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SecondaryTabRow
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
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.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 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,
|
||||
onSettingsClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onLaunchImagePhotoPicker: () -> Unit,
|
||||
onDeleteImagesClick: (List<String>) -> Unit
|
||||
) {
|
||||
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 }
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
onSettingsClick = onSettingsClick,
|
||||
onContactClick = onContactClick,
|
||||
showSelectionModeAppBar = showSelectionModeAppBar,
|
||||
selectionCount = selectionCount,
|
||||
allSelected = allSelected,
|
||||
onSelectAllClick = { selectAll = true },
|
||||
deleteImagesOnClick = {
|
||||
deleteImages = true
|
||||
showSelectionModeAppBar = false
|
||||
}
|
||||
)
|
||||
}
|
||||
) {padding ->
|
||||
LaunchedEffect(tabIndex) { pagerState.animateScrollToPage(tabIndex) }
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page -> tabIndex = page }
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.padding(padding)
|
||||
) {
|
||||
SecondaryTabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
topStart = 6.dp,
|
||||
topEnd = 6.dp,
|
||||
bottomEnd = 0.dp,
|
||||
bottomStart = 0.dp,
|
||||
),
|
||||
width = 60.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
tabItems.forEachIndexed { index, item ->
|
||||
Tab(
|
||||
selected = (index == tabIndex),
|
||||
onClick = { tabIndex = index },
|
||||
text = { Text(text = item.title) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
HorizontalPager(state = pagerState) { index ->
|
||||
when(index) {
|
||||
0 -> WallpaperScreen(
|
||||
settingsState = settingsState,
|
||||
wallpaperState = wallpaperState
|
||||
)
|
||||
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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun DeleteImagesAlertDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
) {
|
||||
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?")
|
||||
},
|
||||
onDismissRequest = { onDismissRequest() },
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onConfirmation() }) {
|
||||
Text("Confirm")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { onDismissRequest() }) {
|
||||
Text("Cancel")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.SecondaryTabRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.tabItems
|
||||
|
||||
@Composable
|
||||
fun HomeTabRow(
|
||||
scroll: ScrollState,
|
||||
smallTopAppBarHeight: Dp,
|
||||
tabIndex: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
onIndexUpdate: (Int) -> Unit
|
||||
) {
|
||||
Surface (
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
translationY = -scroll.value.toFloat() / 2f
|
||||
alpha = 0f
|
||||
}
|
||||
) {
|
||||
SecondaryTabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
if (tabIndex < tabPositions.size) {
|
||||
TabRowDefaults.PrimaryIndicator(
|
||||
modifier = Modifier.tabIndicatorOffset(tabPositions[tabIndex]),
|
||||
shape = RoundedCornerShape(
|
||||
topStart = 6.dp,
|
||||
topEnd = 6.dp,
|
||||
bottomEnd = 0.dp,
|
||||
bottomStart = 0.dp,
|
||||
),
|
||||
width = 60.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
tabItems.forEachIndexed { index, item ->
|
||||
Tab(
|
||||
selected = (index == tabIndex),
|
||||
onClick = { onIndexUpdate(index) },
|
||||
text = { Text(text = item.title) },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
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.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.RadioButtonUnchecked
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.RadioButtonUnchecked
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
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.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@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),
|
||||
title = { if (!showSelectionModeAppBar) Text(stringResource(R.string.appname)) },
|
||||
actions = {
|
||||
if (!showSelectionModeAppBar) {
|
||||
var menuExpanded by rememberSaveable { mutableStateOf(false) }
|
||||
IconButton(onClick = { menuExpanded = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
contentDescription = stringResource(R.string.MoreVertIcon)
|
||||
)
|
||||
MaterialTheme(
|
||||
shapes = MaterialTheme.shapes.copy(extraSmall = RoundedCornerShape(16.dp))
|
||||
) {
|
||||
DropdownMenu(
|
||||
expanded = menuExpanded,
|
||||
onDismissRequest = { menuExpanded = false },
|
||||
offset = DpOffset(0.dp, 5.dp)
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.dropdownmenu_settings)) },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
onSettingsClick()
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.contact_button)) },
|
||||
onClick = {
|
||||
menuExpanded = false
|
||||
onContactClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
var showAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (showAlertDialog) DeleteImagesAlertDialog (
|
||||
onDismissRequest = { showAlertDialog = false },
|
||||
onConfirmation = {
|
||||
showAlertDialog = false
|
||||
deleteImagesOnClick()
|
||||
}
|
||||
)
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
if (showSelectionModeAppBar) {
|
||||
Row (
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onSelectAllClick
|
||||
) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (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("$selectionCount selected")
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.AlbumItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.use_case.AddImage
|
||||
|
||||
@Composable
|
||||
fun LibraryScreen(
|
||||
navController: NavController,
|
||||
modifier: Modifier = Modifier,
|
||||
albumsViewModel: AlbumsViewModel = hiltViewModel()
|
||||
) {
|
||||
/*
|
||||
val testAlbum1 = Album(albumName = "hi1", dateAdded = "today1")
|
||||
viewModel.onEvent(AlbumsEvent.AddAlbum(testAlbum1))
|
||||
val image1 = Image(imageName = "image1", dateAdded = "todayImage1")
|
||||
viewModel.onEvent(AlbumsEvent.AddImage(image1))
|
||||
|
||||
val testAlbum2 = Album(albumName = "hi2", dateAdded = "today2")
|
||||
viewModel.onEvent(AlbumsEvent.AddAlbum(testAlbum2))
|
||||
|
||||
val image2 = Image(imageName = "image2", dateAdded = "todayImage2")
|
||||
viewModel.onEvent(AlbumsEvent.AddImage(image2))
|
||||
*/
|
||||
|
||||
val state = albumsViewModel.state.value
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text(text = "Library")
|
||||
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||
items(state.albums) { album ->
|
||||
AlbumItem(
|
||||
album = album,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clickable {
|
||||
},
|
||||
onDeleteClick = {
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbum(album))
|
||||
//prompt some sort of message saying _ has been deleted
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library.components
|
||||
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun AnimatedFab(menuOptions: FabMenuOptions, onClick: (String) -> Unit) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
||||
|
||||
val expandHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = { tween(200, 25, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 155.dp else 60.dp
|
||||
}
|
||||
)
|
||||
|
||||
val shrinkVertically by fabTransition.animateDp(
|
||||
transitionSpec = { tween(200, 25, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 50.dp else 60.dp
|
||||
}
|
||||
)
|
||||
|
||||
val menuHeight by fabTransition.animateDp(
|
||||
transitionSpec = { tween(150, 100, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 100.dp else 0.dp
|
||||
}
|
||||
)
|
||||
ElevatedCard(
|
||||
modifier = Modifier.padding(4.dp)
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = expanded,
|
||||
enter = fadeIn(tween(400, 0, FastOutSlowInEasing)),
|
||||
exit = fadeOut(tween(400, 0, FastOutSlowInEasing)),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.height(menuHeight)
|
||||
) {
|
||||
MenuRow(menuOptions.imageOption.text, menuOptions.imageOption.icon, expandHorizontally) {
|
||||
onClick(menuOptions.imageOption.id)
|
||||
}
|
||||
MenuRow(menuOptions.folderOption.text, menuOptions.folderOption.icon, expandHorizontally) {
|
||||
onClick(menuOptions.folderOption.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
FloatingActionButton(
|
||||
onClick = { expanded = !expanded },
|
||||
modifier = Modifier
|
||||
.width(expandHorizontally)
|
||||
.height(shrinkVertically)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
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.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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
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
|
||||
|
||||
@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
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
var selectedImageUris by rememberSaveable(Unit) {
|
||||
mutableStateOf(listOf<String>())
|
||||
}
|
||||
var inSelectionMode by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
if (selectAll) {
|
||||
selectedImageUris = selectedImageUris.toMutableList().apply {
|
||||
clear()
|
||||
wallpaperState.wallpapers.forEach {
|
||||
add(it.imageUri)
|
||||
}
|
||||
}.toImmutableList()
|
||||
selectAllDone()
|
||||
onUpdateItemCount(selectedImageUris.size)
|
||||
if (selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
onAllSelected(true)
|
||||
}
|
||||
|
||||
if (deleteImages) {
|
||||
onDeleteImagesClick(selectedImageUris)
|
||||
}
|
||||
|
||||
BackHandler(inSelectionMode) {
|
||||
inSelectionMode = false
|
||||
onSelectionMode(false)
|
||||
selectedImageUris = selectedImageUris.toMutableList().apply {
|
||||
clear()
|
||||
}.toImmutableList()
|
||||
onUpdateItemCount(0)
|
||||
}
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
AnimatedVisibility(
|
||||
visible =
|
||||
!lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
|
||||
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
|
||||
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
|
||||
) {
|
||||
AnimatedFab(
|
||||
menuOptions = FabMenuOptions(),
|
||||
onImageClick = onLaunchImagePhotoPicker,
|
||||
onFolderClick = {}
|
||||
)
|
||||
}
|
||||
},
|
||||
content = { it
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
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)
|
||||
if (selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
onAllSelected(true)
|
||||
},
|
||||
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)
|
||||
if (selectedImageUris.size >= wallpaperState.wallpapers.size)
|
||||
onAllSelected(true)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Remove
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun AnimatedFab(menuOptions: FabMenuOptions, onImageClick: () -> Unit, onFolderClick: () -> Unit) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
val fabTransition = updateTransition(targetState = expanded, label = "")
|
||||
|
||||
BackHandler(expanded) { expanded = false }
|
||||
|
||||
val expandHorizontally by fabTransition.animateDp(
|
||||
transitionSpec = { tween(200, 25, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 155.dp else 90.dp
|
||||
}
|
||||
)
|
||||
|
||||
val shrinkVertically by fabTransition.animateDp(
|
||||
transitionSpec = { tween(200, 50, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 50.dp else 90.dp
|
||||
}
|
||||
)
|
||||
|
||||
val menuHeight by fabTransition.animateDp(
|
||||
transitionSpec = { tween(150, 50, FastOutSlowInEasing) }, label = "",
|
||||
targetValueByState = { isExpanded ->
|
||||
if (isExpanded) 100.dp else 90.dp
|
||||
}
|
||||
)
|
||||
ElevatedCard(
|
||||
shape = RoundedCornerShape(28.dp),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(onTap = { expanded = false })
|
||||
}
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = expanded,
|
||||
enter = fadeIn(tween(300, 0, FastOutSlowInEasing)),
|
||||
exit = fadeOut(tween(300, 0, FastOutSlowInEasing)),
|
||||
modifier = Modifier.animateContentSize(tween(50, 0, FastOutSlowInEasing)),
|
||||
) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
Column(modifier = Modifier.height(menuHeight)) {
|
||||
MenuRow(
|
||||
text = menuOptions.imageOption.text,
|
||||
icon = menuOptions.imageOption.icon,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onImageClick()
|
||||
}
|
||||
)
|
||||
MenuRow(
|
||||
text = menuOptions.folderOption.text,
|
||||
icon = menuOptions.folderOption.icon,
|
||||
horizontalExpansion = expandHorizontally,
|
||||
onClick = {
|
||||
expanded = false
|
||||
onFolderClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface(
|
||||
tonalElevation = 3.dp
|
||||
) {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = { expanded = !expanded },
|
||||
modifier = Modifier
|
||||
.width(expandHorizontally)
|
||||
.height(shrinkVertically)
|
||||
.animateContentSize(),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
if (!expanded) Icons.Filled.Add else Icons.Filled.Remove,
|
||||
contentDescription = stringResource(R.string.add_wallpaper),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -1,12 +1,10 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_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.core.presentation.components.SelectionOptions
|
||||
|
||||
data class FabMenuOptions (
|
||||
val imageOption: SelectionOptions = SelectionOptions("add_images", "Add Image", null, Icons.Filled.PhotoLibrary),
|
||||
val folderOption: SelectionOptions = SelectionOptions("add_folder", "Add Folder", null, Icons.Filled.Folder)
|
||||
|
||||
)
|
||||
+11
-7
@@ -1,9 +1,13 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -17,25 +21,25 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun MenuRow(text: String, icon: ImageVector?, expansion: Dp, onClick: () -> Unit) {
|
||||
fun MenuRow(text: String, icon: ImageVector?, horizontalExpansion: Dp, onClick: () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.width(expansion)
|
||||
.width(horizontalExpansion)
|
||||
.clickable { onClick() },
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
icon,
|
||||
contentDescription = null,
|
||||
imageVector = icon,
|
||||
contentDescription = text,
|
||||
modifier = Modifier.padding(12.dp)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Text(
|
||||
text = text,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
overflow = TextOverflow.Visible,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(end = 12.dp)
|
||||
)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.anthonyla.paperize.core.presentation.components
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.components
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
sealed class SettingsEvent {
|
||||
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
|
||||
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavController
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen(navController: NavController, modifier: Modifier = Modifier, viewModel: SettingsViewModel = hiltViewModel()) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Settings")
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings
|
||||
|
||||
data class SettingsState (
|
||||
val darkMode: Boolean?,
|
||||
val dynamicTheming: Boolean,
|
||||
)
|
||||
+51
-43
@@ -1,60 +1,68 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.anthonyla.paperize.core.SettingsConstants.DARK_MODE_TYPE
|
||||
import com.anthonyla.paperize.core.SettingsConstants.DYNAMIC_THEME_TYPE
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStoreImpl
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SettingsViewModel @Inject constructor (
|
||||
private val settingsDataStoreImpl: SettingsDataStoreImpl
|
||||
private val settingsDataStoreImpl: SettingsDataStore
|
||||
): ViewModel() {
|
||||
fun setDarkMode(status: Boolean?) = runBlocking {
|
||||
when (status) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(DARK_MODE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(DARK_MODE_TYPE, false) }
|
||||
null -> { settingsDataStoreImpl.deleteBoolean(DARK_MODE_TYPE) }
|
||||
var shouldNotBypassSplashScreen by mutableStateOf(true)
|
||||
private val _state = mutableStateOf(SettingsState(null, false))
|
||||
val state: State<SettingsState> = _state
|
||||
private var currentGetJob: Job? = null
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
refreshSettings()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDarkMode() = runBlocking {
|
||||
return@runBlocking settingsDataStoreImpl.getBoolean(DARK_MODE_TYPE)
|
||||
}
|
||||
|
||||
fun setDynamic (status: Boolean?) = runBlocking {
|
||||
when (status) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(DYNAMIC_THEME_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(DYNAMIC_THEME_TYPE, false) }
|
||||
null -> { settingsDataStoreImpl.deleteBoolean(DYNAMIC_THEME_TYPE) }
|
||||
fun onEvent(event: SettingsEvent) {
|
||||
when (event) {
|
||||
is SettingsEvent.SetDarkMode -> {
|
||||
viewModelScope.launch {
|
||||
when (event.darkMode) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DARK_MODE_TYPE, false) }
|
||||
null -> { settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
}
|
||||
refreshSettings()
|
||||
}
|
||||
}
|
||||
is SettingsEvent.SetDynamicTheming -> {
|
||||
viewModelScope.launch {
|
||||
when (event.dynamicTheming) {
|
||||
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, true) }
|
||||
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.DYNAMIC_THEME_TYPE, false) }
|
||||
}
|
||||
refreshSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDynamicTheme() = runBlocking {
|
||||
return@runBlocking settingsDataStoreImpl.getBoolean(DYNAMIC_THEME_TYPE)
|
||||
}
|
||||
|
||||
fun resetSettings() = runBlocking {
|
||||
settingsDataStoreImpl.clearPreferences()
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun isDarkMode(): Boolean {
|
||||
return when (getDarkMode()) {
|
||||
true -> true
|
||||
false -> false
|
||||
null -> isSystemInDarkTheme()
|
||||
private fun refreshSettings() {
|
||||
currentGetJob?.cancel()
|
||||
currentGetJob = viewModelScope.launch {
|
||||
_state.value = state.value.copy(
|
||||
darkMode = settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE),
|
||||
dynamicTheming = when(settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)) {
|
||||
true -> true
|
||||
false, null -> false
|
||||
}
|
||||
)
|
||||
shouldNotBypassSplashScreen = false
|
||||
}
|
||||
}
|
||||
|
||||
fun isDynamicTheming(): Boolean {
|
||||
return when (getDynamicTheme()) {
|
||||
true, null -> true
|
||||
false -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
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.SettingsSmallTopAppBar
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
settingsState: SettingsState,
|
||||
onBackClick: () -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit
|
||||
) {
|
||||
val scroll: ScrollState = rememberScrollState(0)
|
||||
val largeTopAppBarHeight = 152.dp
|
||||
val smallTopAppBarHeight = 64.dp
|
||||
val paddingMedium = 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
SettingsLargeTopAppBar(
|
||||
scroll = scroll,
|
||||
modifier = Modifier.height(largeTopAppBarHeight)
|
||||
)
|
||||
ScrollableSettings(
|
||||
settingsState = settingsState,
|
||||
largeTopAppBarHeightPx = largeTopAppBarHeight,
|
||||
scroll = scroll,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onDarkModeClick = onDarkModeClick
|
||||
)
|
||||
SettingsSmallTopAppBar(onBackClick = onBackClick)
|
||||
Title(
|
||||
scroll = scroll,
|
||||
largeTopAppBarHeight = largeTopAppBarHeight,
|
||||
smallTopAppBarHeight = smallTopAppBarHeight,
|
||||
paddingMedium = paddingMedium
|
||||
)
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.requiredSize
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.BrightnessAuto
|
||||
import androidx.compose.material.icons.filled.DarkMode
|
||||
import androidx.compose.material.icons.filled.LightMode
|
||||
import androidx.compose.material.icons.outlined.Brightness6
|
||||
import androidx.compose.material.icons.outlined.BrightnessAuto
|
||||
import androidx.compose.material.icons.outlined.DarkMode
|
||||
import androidx.compose.material.icons.outlined.LightMode
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.SegmentedButton
|
||||
import androidx.compose.material3.SegmentedButtonDefaults
|
||||
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DarkModeListItem(settingsState: SettingsState, onDarkModeClick: (Boolean?) -> Unit) {
|
||||
val options = listOf(
|
||||
Triple("Dark Mode", Icons.Outlined.DarkMode, Icons.Filled.DarkMode),
|
||||
Triple("Automatic Device Mode", Icons.Outlined.BrightnessAuto, Icons.Filled.BrightnessAuto),
|
||||
Triple("Light Mode", Icons.Outlined.LightMode, Icons.Filled.LightMode)
|
||||
)
|
||||
var selectedIndex by remember {
|
||||
mutableIntStateOf(
|
||||
when (settingsState.darkMode) {
|
||||
true -> 0
|
||||
false -> 2
|
||||
else -> 1
|
||||
}
|
||||
) }
|
||||
Row(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable {
|
||||
selectedIndex = when (selectedIndex) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
else -> 0
|
||||
}
|
||||
onDarkModeClick(
|
||||
when (selectedIndex) {
|
||||
0 -> true
|
||||
2 -> false
|
||||
else -> null
|
||||
}
|
||||
) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dark Mode",
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Easier on the eyes",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
) },
|
||||
trailingContent = {
|
||||
SingleChoiceSegmentedButtonRow(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.width(100.dp)
|
||||
.height(36.dp)
|
||||
) {
|
||||
options.forEachIndexed { index, label ->
|
||||
SegmentedButton(
|
||||
shape = SegmentedButtonDefaults.itemShape(index = index, count = options.size),
|
||||
onClick = {
|
||||
selectedIndex = index
|
||||
onDarkModeClick(
|
||||
when (index) {
|
||||
0 -> true
|
||||
2 -> false
|
||||
else -> null
|
||||
}
|
||||
) },
|
||||
selected = index == selectedIndex,
|
||||
icon = { null },
|
||||
) {
|
||||
Icon(
|
||||
contentDescription = label.first,
|
||||
imageVector =
|
||||
if(selectedIndex != index)
|
||||
label.second
|
||||
else
|
||||
label.third,
|
||||
modifier = Modifier.requiredSize(18.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Brightness6,
|
||||
contentDescription = "Dark Mode",
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
},
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Palette
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
|
||||
@Composable
|
||||
fun DynamicThemingListItem(settingsState: SettingsState, onDynamicThemingClick: (Boolean) -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onDynamicThemingClick(!settingsState.dynamicTheming) },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = "Dynamic Theme",
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = "Material You",
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {
|
||||
Switch(
|
||||
modifier = Modifier.semantics { contentDescription = "Dynamic Theme" },
|
||||
checked = settingsState.dynamicTheming,
|
||||
onCheckedChange = onDynamicThemingClick,
|
||||
enabled = true
|
||||
) },
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Palette,
|
||||
contentDescription = "Dynamic Theming",
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
|
||||
@Composable
|
||||
fun ListSectionTitle(title: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
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.verticalScroll
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
|
||||
@Composable
|
||||
fun ScrollableSettings(
|
||||
settingsState: SettingsState,
|
||||
largeTopAppBarHeightPx: Dp,
|
||||
scroll: ScrollState,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(scroll)
|
||||
.padding(horizontal = 24.dp),
|
||||
) {
|
||||
Spacer(Modifier.height(largeTopAppBarHeightPx))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle("Appearance")
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
settingsState = settingsState,
|
||||
onDarkModeClick = onDarkModeClick
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DynamicThemingListItem(
|
||||
settingsState = settingsState,
|
||||
onDynamicThemingClick = onDynamicThemingClick
|
||||
)
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun SettingsLargeTopAppBar(
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
translationY = -scroll.value.toFloat() / 2f
|
||||
alpha = 0f
|
||||
}
|
||||
)
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SettingsSmallTopAppBar(onBackClick: () -> Unit) {
|
||||
Surface {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class TabItem(
|
||||
val title: String,
|
||||
val filledIcon: ImageVector,
|
||||
val unfilledIcon: ImageVector,
|
||||
)
|
||||
|
||||
val tabItems = listOf(
|
||||
TabItem(
|
||||
title = "Wallpaper",
|
||||
filledIcon = Icons.Filled.Image,
|
||||
unfilledIcon = Icons.Outlined.Image
|
||||
),
|
||||
TabItem(
|
||||
title = "Library",
|
||||
filledIcon = Icons.Filled.AddToPhotos,
|
||||
unfilledIcon = Icons.Outlined.AddToPhotos
|
||||
)
|
||||
)
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@Composable
|
||||
fun Title(
|
||||
largeTopAppBarHeight: Dp,
|
||||
smallTopAppBarHeight: Dp,
|
||||
paddingMedium: Dp,
|
||||
scroll: ScrollState,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val titlePaddingStart = 16.dp
|
||||
val titlePaddingEnd = 64.dp
|
||||
val titleFontScaleStart = 1f
|
||||
val titleFontScaleEnd = 0.7f
|
||||
var titleHeightPx by remember { mutableFloatStateOf(0f) }
|
||||
var titleWidthPx by remember { mutableFloatStateOf(0f) }
|
||||
|
||||
Text(
|
||||
text = stringResource(id = R.string.settings_screen),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
fontSize = 30.sp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = modifier
|
||||
.graphicsLayer {
|
||||
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
|
||||
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
|
||||
|
||||
val scaleXY = lerp(
|
||||
titleFontScaleStart.dp,
|
||||
titleFontScaleEnd.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
|
||||
|
||||
val titleYFirstInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
|
||||
largeTopAppBarHeight / 2,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXFirstInterpolatedPoint = lerp(
|
||||
titlePaddingStart,
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleYSecondInterpolatedPoint = lerp(
|
||||
largeTopAppBarHeight / 2,
|
||||
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleXSecondInterpolatedPoint = lerp(
|
||||
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
|
||||
titlePaddingEnd - titleExtraStartPadding,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleY = lerp(
|
||||
titleYFirstInterpolatedPoint,
|
||||
titleYSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
val titleX = lerp(
|
||||
titleXFirstInterpolatedPoint,
|
||||
titleXSecondInterpolatedPoint,
|
||||
collapseFraction
|
||||
)
|
||||
|
||||
translationY = titleY.toPx()
|
||||
translationX = titleX.toPx()
|
||||
scaleX = scaleXY.value
|
||||
scaleY = scaleXY.value
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
titleHeightPx = it.size.height.toFloat()
|
||||
titleWidthPx = it.size.width.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
+47
-47
@@ -1,67 +1,67 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.themes
|
||||
package com.example.compose
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val md_theme_light_primary = Color(0xFF136D34)
|
||||
val md_theme_light_primary = Color(0xFF984061)
|
||||
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_primaryContainer = Color(0xFFA0F6AD)
|
||||
val md_theme_light_onPrimaryContainer = Color(0xFF00210A)
|
||||
val md_theme_light_secondary = Color(0xFF506351)
|
||||
val md_theme_light_primaryContainer = Color(0xFFFFD9E2)
|
||||
val md_theme_light_onPrimaryContainer = Color(0xFF3E001D)
|
||||
val md_theme_light_secondary = Color(0xFF74565F)
|
||||
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_secondaryContainer = Color(0xFFD3E8D2)
|
||||
val md_theme_light_onSecondaryContainer = Color(0xFF0E1F11)
|
||||
val md_theme_light_tertiary = Color(0xFF39656D)
|
||||
val md_theme_light_secondaryContainer = Color(0xFFFFD9E2)
|
||||
val md_theme_light_onSecondaryContainer = Color(0xFF2B151C)
|
||||
val md_theme_light_tertiary = Color(0xFF7C5635)
|
||||
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_tertiaryContainer = Color(0xFFBDEAF4)
|
||||
val md_theme_light_onTertiaryContainer = Color(0xFF001F24)
|
||||
val md_theme_light_tertiaryContainer = Color(0xFFFFDCC2)
|
||||
val md_theme_light_onTertiaryContainer = Color(0xFF2E1500)
|
||||
val md_theme_light_error = Color(0xFFBA1A1A)
|
||||
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
|
||||
val md_theme_light_onError = Color(0xFFFFFFFF)
|
||||
val md_theme_light_onErrorContainer = Color(0xFF410002)
|
||||
val md_theme_light_background = Color(0xFFFCFDF7)
|
||||
val md_theme_light_onBackground = Color(0xFF1A1C19)
|
||||
val md_theme_light_surface = Color(0xFFFCFDF7)
|
||||
val md_theme_light_onSurface = Color(0xFF1A1C19)
|
||||
val md_theme_light_surfaceVariant = Color(0xFFDDE5DA)
|
||||
val md_theme_light_onSurfaceVariant = Color(0xFF414941)
|
||||
val md_theme_light_outline = Color(0xFF727970)
|
||||
val md_theme_light_inverseOnSurface = Color(0xFFF0F1EC)
|
||||
val md_theme_light_inverseSurface = Color(0xFF2E312E)
|
||||
val md_theme_light_inversePrimary = Color(0xFF85D993)
|
||||
val md_theme_light_background = Color(0xFFFFFBFF)
|
||||
val md_theme_light_onBackground = Color(0xFF201A1B)
|
||||
val md_theme_light_surface = Color(0xFFFFFBFF)
|
||||
val md_theme_light_onSurface = Color(0xFF201A1B)
|
||||
val md_theme_light_surfaceVariant = Color(0xFFF2DDE2)
|
||||
val md_theme_light_onSurfaceVariant = Color(0xFF514347)
|
||||
val md_theme_light_outline = Color(0xFF837377)
|
||||
val md_theme_light_inverseOnSurface = Color(0xFFFAEEEF)
|
||||
val md_theme_light_inverseSurface = Color(0xFF352F30)
|
||||
val md_theme_light_inversePrimary = Color(0xFFFFB0C8)
|
||||
val md_theme_light_shadow = Color(0xFF000000)
|
||||
val md_theme_light_surfaceTint = Color(0xFF136D34)
|
||||
val md_theme_light_outlineVariant = Color(0xFFC1C9BE)
|
||||
val md_theme_light_surfaceTint = Color(0xFF984061)
|
||||
val md_theme_light_outlineVariant = Color(0xFFD5C2C6)
|
||||
val md_theme_light_scrim = Color(0xFF000000)
|
||||
|
||||
val md_theme_dark_primary = Color(0xFF85D993)
|
||||
val md_theme_dark_onPrimary = Color(0xFF003916)
|
||||
val md_theme_dark_primaryContainer = Color(0xFF005323)
|
||||
val md_theme_dark_onPrimaryContainer = Color(0xFFA0F6AD)
|
||||
val md_theme_dark_secondary = Color(0xFFB7CCB6)
|
||||
val md_theme_dark_onSecondary = Color(0xFF233425)
|
||||
val md_theme_dark_secondaryContainer = Color(0xFF394B3B)
|
||||
val md_theme_dark_onSecondaryContainer = Color(0xFFD3E8D2)
|
||||
val md_theme_dark_tertiary = Color(0xFFA1CED7)
|
||||
val md_theme_dark_onTertiary = Color(0xFF00363E)
|
||||
val md_theme_dark_tertiaryContainer = Color(0xFF204D55)
|
||||
val md_theme_dark_onTertiaryContainer = Color(0xFFBDEAF4)
|
||||
val md_theme_dark_primary = Color(0xFFFFB0C8)
|
||||
val md_theme_dark_onPrimary = Color(0xFF5E1133)
|
||||
val md_theme_dark_primaryContainer = Color(0xFF7B2949)
|
||||
val md_theme_dark_onPrimaryContainer = Color(0xFFFFD9E2)
|
||||
val md_theme_dark_secondary = Color(0xFFE2BDC6)
|
||||
val md_theme_dark_onSecondary = Color(0xFF422931)
|
||||
val md_theme_dark_secondaryContainer = Color(0xFF5A3F47)
|
||||
val md_theme_dark_onSecondaryContainer = Color(0xFFFFD9E2)
|
||||
val md_theme_dark_tertiary = Color(0xFFEFBD94)
|
||||
val md_theme_dark_onTertiary = Color(0xFF48290C)
|
||||
val md_theme_dark_tertiaryContainer = Color(0xFF623F20)
|
||||
val md_theme_dark_onTertiaryContainer = Color(0xFFFFDCC2)
|
||||
val md_theme_dark_error = Color(0xFFFFB4AB)
|
||||
val md_theme_dark_errorContainer = Color(0xFF93000A)
|
||||
val md_theme_dark_onError = Color(0xFF690005)
|
||||
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
|
||||
val md_theme_dark_background = Color(0xFF1A1C19)
|
||||
val md_theme_dark_onBackground = Color(0xFFE2E3DE)
|
||||
val md_theme_dark_surface = Color(0xFF1A1C19)
|
||||
val md_theme_dark_onSurface = Color(0xFFE2E3DE)
|
||||
val md_theme_dark_surfaceVariant = Color(0xFF414941)
|
||||
val md_theme_dark_onSurfaceVariant = Color(0xFFC1C9BE)
|
||||
val md_theme_dark_outline = Color(0xFF8B9389)
|
||||
val md_theme_dark_inverseOnSurface = Color(0xFF1A1C19)
|
||||
val md_theme_dark_inverseSurface = Color(0xFFE2E3DE)
|
||||
val md_theme_dark_inversePrimary = Color(0xFF136D34)
|
||||
val md_theme_dark_background = Color(0xFF201A1B)
|
||||
val md_theme_dark_onBackground = Color(0xFFEBE0E1)
|
||||
val md_theme_dark_surface = Color(0xFF201A1B)
|
||||
val md_theme_dark_onSurface = Color(0xFFEBE0E1)
|
||||
val md_theme_dark_surfaceVariant = Color(0xFF514347)
|
||||
val md_theme_dark_onSurfaceVariant = Color(0xFFD5C2C6)
|
||||
val md_theme_dark_outline = Color(0xFF9E8C90)
|
||||
val md_theme_dark_inverseOnSurface = Color(0xFF201A1B)
|
||||
val md_theme_dark_inverseSurface = Color(0xFFEBE0E1)
|
||||
val md_theme_dark_inversePrimary = Color(0xFF984061)
|
||||
val md_theme_dark_shadow = Color(0xFF000000)
|
||||
val md_theme_dark_surfaceTint = Color(0xFF85D993)
|
||||
val md_theme_dark_outlineVariant = Color(0xFF414941)
|
||||
val md_theme_dark_surfaceTint = Color(0xFFFFB0C8)
|
||||
val md_theme_dark_outlineVariant = Color(0xFF514347)
|
||||
val md_theme_dark_scrim = Color(0xFF000000)
|
||||
|
||||
|
||||
val seed = Color(0xFFA5D0A8)
|
||||
val seed = Color(0xFF984061)
|
||||
+89
-48
@@ -1,20 +1,84 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.themes
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Color.TRANSPARENT
|
||||
import android.os.Build
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.anthonyla.paperize.core.presentation.components.SetTransparentSystemBars
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsViewModel
|
||||
import com.example.compose.md_theme_dark_background
|
||||
import com.example.compose.md_theme_dark_error
|
||||
import com.example.compose.md_theme_dark_errorContainer
|
||||
import com.example.compose.md_theme_dark_inverseOnSurface
|
||||
import com.example.compose.md_theme_dark_inversePrimary
|
||||
import com.example.compose.md_theme_dark_inverseSurface
|
||||
import com.example.compose.md_theme_dark_onBackground
|
||||
import com.example.compose.md_theme_dark_onError
|
||||
import com.example.compose.md_theme_dark_onErrorContainer
|
||||
import com.example.compose.md_theme_dark_onPrimary
|
||||
import com.example.compose.md_theme_dark_onPrimaryContainer
|
||||
import com.example.compose.md_theme_dark_onSecondary
|
||||
import com.example.compose.md_theme_dark_onSecondaryContainer
|
||||
import com.example.compose.md_theme_dark_onSurface
|
||||
import com.example.compose.md_theme_dark_onSurfaceVariant
|
||||
import com.example.compose.md_theme_dark_onTertiary
|
||||
import com.example.compose.md_theme_dark_onTertiaryContainer
|
||||
import com.example.compose.md_theme_dark_outline
|
||||
import com.example.compose.md_theme_dark_outlineVariant
|
||||
import com.example.compose.md_theme_dark_primary
|
||||
import com.example.compose.md_theme_dark_primaryContainer
|
||||
import com.example.compose.md_theme_dark_scrim
|
||||
import com.example.compose.md_theme_dark_secondary
|
||||
import com.example.compose.md_theme_dark_secondaryContainer
|
||||
import com.example.compose.md_theme_dark_surface
|
||||
import com.example.compose.md_theme_dark_surfaceTint
|
||||
import com.example.compose.md_theme_dark_surfaceVariant
|
||||
import com.example.compose.md_theme_dark_tertiary
|
||||
import com.example.compose.md_theme_dark_tertiaryContainer
|
||||
import com.example.compose.md_theme_light_background
|
||||
import com.example.compose.md_theme_light_error
|
||||
import com.example.compose.md_theme_light_errorContainer
|
||||
import com.example.compose.md_theme_light_inverseOnSurface
|
||||
import com.example.compose.md_theme_light_inversePrimary
|
||||
import com.example.compose.md_theme_light_inverseSurface
|
||||
import com.example.compose.md_theme_light_onBackground
|
||||
import com.example.compose.md_theme_light_onError
|
||||
import com.example.compose.md_theme_light_onErrorContainer
|
||||
import com.example.compose.md_theme_light_onPrimary
|
||||
import com.example.compose.md_theme_light_onPrimaryContainer
|
||||
import com.example.compose.md_theme_light_onSecondary
|
||||
import com.example.compose.md_theme_light_onSecondaryContainer
|
||||
import com.example.compose.md_theme_light_onSurface
|
||||
import com.example.compose.md_theme_light_onSurfaceVariant
|
||||
import com.example.compose.md_theme_light_onTertiary
|
||||
import com.example.compose.md_theme_light_onTertiaryContainer
|
||||
import com.example.compose.md_theme_light_outline
|
||||
import com.example.compose.md_theme_light_outlineVariant
|
||||
import com.example.compose.md_theme_light_primary
|
||||
import com.example.compose.md_theme_light_primaryContainer
|
||||
import com.example.compose.md_theme_light_scrim
|
||||
import com.example.compose.md_theme_light_secondary
|
||||
import com.example.compose.md_theme_light_secondaryContainer
|
||||
import com.example.compose.md_theme_light_surface
|
||||
import com.example.compose.md_theme_light_surfaceTint
|
||||
import com.example.compose.md_theme_light_surfaceVariant
|
||||
import com.example.compose.md_theme_light_tertiary
|
||||
import com.example.compose.md_theme_light_tertiaryContainer
|
||||
|
||||
|
||||
private val LightColors = lightColorScheme(
|
||||
@@ -82,60 +146,37 @@ private val DarkColors = darkColorScheme(
|
||||
scrim = md_theme_dark_scrim,
|
||||
)
|
||||
|
||||
val typography = Typography(
|
||||
headlineSmall = TextStyle(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 24.sp,
|
||||
lineHeight = 32.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
titleLarge = TextStyle(
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 18.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
bodyLarge = TextStyle(
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.15.sp
|
||||
),
|
||||
bodyMedium = TextStyle(
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 20.sp,
|
||||
letterSpacing = 0.25.sp
|
||||
),
|
||||
labelMedium = TextStyle(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 12.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@Composable
|
||||
fun PaperizeTheme(
|
||||
viewModel: SettingsViewModel = hiltViewModel(),
|
||||
isDarkMode: Boolean,
|
||||
isDynamicTheming: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
// Check if dynamic theming is enabled in settings
|
||||
val context = LocalContext.current
|
||||
val supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
val colors = when {supported && viewModel.isDynamicTheming() -> {
|
||||
if (viewModel.isDarkMode()) dynamicDarkColorScheme(context)
|
||||
else dynamicLightColorScheme(context)
|
||||
}
|
||||
viewModel.isDynamicTheming() -> DarkColors
|
||||
|
||||
val colors = when {
|
||||
isDynamicTheming && dynamicThemingSupported && isDarkMode -> dynamicDarkColorScheme(context)
|
||||
isDynamicTheming && dynamicThemingSupported && !isDarkMode -> dynamicLightColorScheme(context)
|
||||
isDarkMode -> DarkColors
|
||||
else -> LightColors
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colors,
|
||||
typography = MaterialTheme.typography,
|
||||
content = content,
|
||||
shapes = MaterialTheme.shapes
|
||||
)
|
||||
SetTransparentSystemBars(viewModel.isDarkMode())
|
||||
}
|
||||
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = TRANSPARENT
|
||||
SystemBarStyle.light(TRANSPARENT, TRANSPARENT)
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !isDarkMode
|
||||
}
|
||||
}
|
||||
}
|
||||
val dynamicThemingSupported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
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()
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavController
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(navController: NavController, modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(text = "Wallpaper")
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
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
@@ -0,0 +1,50 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.components
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.compose.animation.core.animateDp
|
||||
import androidx.compose.animation.core.updateTransition
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
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.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
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.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.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.LocalHapticFeedback
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun WallpaperItem(
|
||||
selected: Boolean,
|
||||
selectionMode: Boolean,
|
||||
image: Uri,
|
||||
onSelectionListClick: () -> Unit,
|
||||
onSelection: () -> Unit
|
||||
) {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val transition = updateTransition(selected, 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
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(paddingTransition)
|
||||
.clip(RoundedCornerShape(roundedCornerShapeTransition))
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selectionMode) { onSelection() }
|
||||
else { /*zoom into photo*/ }
|
||||
},
|
||||
onLongClick = {
|
||||
if (!selectionMode) {
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onSelectionListClick()
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = image,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
)
|
||||
if (selectionMode) {
|
||||
val bgColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
|
||||
if (selected) {
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
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.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
|
||||
|
||||
@Composable
|
||||
fun WallpaperScreen(settingsState: SettingsState, wallpaperState: WallpaperState) {
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(it),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text("Wallpaper")
|
||||
Text(settingsState.darkMode.toString())
|
||||
var test by rememberSaveable { mutableStateOf(false) }
|
||||
Button(
|
||||
onClick = {
|
||||
//settingsViewModel.onEvent(SettingsEvent.SetDarkMode(test))
|
||||
test = !test
|
||||
}
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
|
||||
class AddAlbum(
|
||||
private val repository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(album: Album) : Long {
|
||||
return repository.insertAlbum(album)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
|
||||
class AddImage(
|
||||
private val repository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(image: Image) {
|
||||
repository.insertImage(image)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
data class AlbumUseCases(
|
||||
val getAlbums: GetAlbums,
|
||||
val addAlbum: AddAlbum,
|
||||
val addImage: AddImage,
|
||||
val deleteAlbum: DeleteAlbum,
|
||||
val deleteImage: DeleteImage
|
||||
)
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Album
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
|
||||
class DeleteAlbum(
|
||||
private val repository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(album: Album) {
|
||||
repository.deleteAlbum(album)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.Image
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
|
||||
class DeleteImage(
|
||||
private val repository: AlbumRepository
|
||||
) {
|
||||
suspend operator fun invoke(image: Image) {
|
||||
repository.deleteImage(image)
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithImages
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.repository.AlbumRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class GetAlbums(private val repository: AlbumRepository) {
|
||||
operator fun invoke(): Flow<List<AlbumWithImages>> {
|
||||
return repository.getAlbums()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* for getImages
|
||||
return repository.getAlbums().map { album ->
|
||||
when(albumsOrder.orderType) {
|
||||
is OrderType.Ascending -> {
|
||||
when (albumsOrder) {
|
||||
is AlbumsOrder.Date -> album.sortedBy { it.dateAdded.lowercase() }
|
||||
}
|
||||
}
|
||||
is OrderType.Descending -> {
|
||||
when (albumsOrder) {
|
||||
is AlbumsOrder.Date -> album.sortedBy { it.dateAdded.uppercase() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,11 @@
|
||||
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
@@ -0,0 +1,7 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.use_case
|
||||
|
||||
data class WallpaperUseCases(
|
||||
val getWallpapers: GetWallpapers,
|
||||
val addWallpaper: AddWallpaper,
|
||||
val deleteWallpaper: DeleteWallpaper
|
||||
)
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util
|
||||
|
||||
sealed class AlbumsOrder(
|
||||
val orderType: OrderType
|
||||
) {
|
||||
class Date(orderType: OrderType): AlbumsOrder(orderType)
|
||||
fun copyOrder(orderType: OrderType): AlbumsOrder {
|
||||
return when(this) {
|
||||
is Date -> Date(orderType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util
|
||||
|
||||
sealed class OrderType {
|
||||
object Ascending: OrderType()
|
||||
object Descending: OrderType()
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PhotoLibrary
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
sealed class AddEditNavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
|
||||
object ImageAdd : AddEditNavScreens("image_add_screen", R.string.add_image, Icons.Filled.PhotoLibrary, Icons.Filled.PhotoLibrary)
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddToPhotos
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.AddToPhotos
|
||||
import androidx.compose.material.icons.outlined.Home
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
sealed class BottomNavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
|
||||
object Wallpaper : BottomNavScreens("wallpaper_screen", R.string.wallpaper_screen, Icons.Outlined.Home, Icons.Filled.Home)
|
||||
object Library : BottomNavScreens("library_screen", R.string.library_screen, Icons.Outlined.AddToPhotos, Icons.Filled.AddToPhotos)
|
||||
object Configure : BottomNavScreens("configure_screen", R.string.configure_screen, Icons.Outlined.Settings, Icons.Filled.Settings)
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navigation
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_edit_albums.ImageAddScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.configure.ConfigureScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings.SettingsScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper.WallpaperScreen
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
fun NavGraphBuilder.navGraph(navController: NavController, modifier: Modifier = Modifier) {
|
||||
navigation(startDestination = BottomNavScreens.Wallpaper.route, route = "bottomNavigation") {
|
||||
composable(BottomNavScreens.Wallpaper.route) { WallpaperScreen(navController) }
|
||||
composable(BottomNavScreens.Library.route) { LibraryScreen(navController) }
|
||||
composable(BottomNavScreens.Configure.route) { ConfigureScreen(navController) }
|
||||
composable(SettingsNavScreens.Settings.route) { SettingsScreen(navController) }
|
||||
composable(AddEditNavScreens.ImageAdd.route) { ImageAddScreen(navController) }
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
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)
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
sealed class SettingsNavScreens(val route: String, @StringRes val resourceId: Int, val unfilledIcon: ImageVector, val filledIcon: ImageVector) {
|
||||
object Settings : SettingsNavScreens("settings_screen", R.string.settings_screen, Icons.Outlined.Settings, Icons.Filled.Settings)
|
||||
}
|
||||
Reference in new issue
Block a user