Major refactor and localization update

This commit is contained in:
Anthony La committed 2025-06-07 14:02:49 -07:00
1 parent 8945002652
commit 493e6559df
65 files changed
+2229 -1123

No files matched your search

@@ -1,7 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
package com.anthonyla.paperize.core
import android.graphics.Bitmap
import com.anthonyla.paperize.core.vignetteBitmap
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import com.bumptech.glide.util.Util
@@ -8,7 +8,6 @@ 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.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -3,15 +3,12 @@ package com.anthonyla.paperize.feature.wallpaper.presentation
import android.Manifest
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.database.CursorWindow
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
@@ -21,7 +18,9 @@ import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.annotation.RequiresPermission
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.LaunchedEffect
@@ -32,7 +31,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.animation.doOnEnd
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -48,27 +46,47 @@ import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.runBlocking
import java.lang.reflect.Field
import javax.inject.Inject
import androidx.core.net.toUri
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
private val settingsViewModel: SettingsViewModel by viewModels()
private val context = this
// Launcher for SET_WALLPAPER permission
private val requestSetWallpaperPermission = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (!isGranted) {
// Handle the case where the user denies the permission.
// For wallpaper apps, this permission is critical, so denying it
// means the app won't function as intended.
// Consider showing a dialog explaining why it's needed and
// offering to open app settings.
}
}
// Launcher for SCHEDULE_EXACT_ALARM permission (Android 12+)
private val requestExactAlarmPermission = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
// No specific action needed on result here, as we just want the permission granted.
// The check `am.canScheduleExactAlarms()` will reflect the new state when needed.
}
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
)
super.onCreate(savedInstanceState)
if (ContextCompat.checkSelfPermission(context, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context as Activity, arrayOf(Manifest.permission.SET_WALLPAPER), 0)
// Request SET_WALLPAPER permission immediately if not granted
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
requestSetWallpaperPermission.launch(Manifest.permission.SET_WALLPAPER)
}
val splashScreen = installSplashScreen()
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
@@ -83,13 +101,19 @@ class MainActivity : ComponentActivity() {
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent {
ensureExactAlarmPermission(context)
// Request SCHEDULE_EXACT_ALARM permission when the Composable is active.
// This will prompt the user to grant the permission if not already granted.
LaunchedEffect(Unit) {
requestExactAlarmPermissionIfNeeded(this@MainActivity)
}
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
val scheduler = WallpaperAlarmSchedulerImpl(context)
val scheduler = WallpaperAlarmSchedulerImpl(this)
var hasScheduleRun by remember { mutableStateOf(false) }
LaunchedEffect(settingsState.value) {
// Only attempt to schedule once settings are initialized and the scheduling logic hasn't run yet.
if (!hasScheduleRun && settingsState.value.initialized) {
handleWallpaperScheduling(settingsState.value, scheduler)
hasScheduleRun = true
@@ -111,46 +135,80 @@ class MainActivity : ComponentActivity() {
}
}
private fun ensureExactAlarmPermission(context: Context) {
/**
* Requests the SCHEDULE_EXACT_ALARM permission if needed on Android 12 (S) and above.
* This function should be called from a LaunchedEffect or similar lifecycle-aware scope
* within Compose, or directly in onCreate if you prefer.
*/
private fun requestExactAlarmPermissionIfNeeded(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val am = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val am = context.getSystemService(ALARM_SERVICE) as AlarmManager
if (!am.canScheduleExactAlarms()) {
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM).apply {
data = "package:${context.packageName}".toUri()
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
context.startActivity(intent)
requestExactAlarmPermission.launch(intent)
}
}
}
@SuppressLint("MissingPermission")
private suspend fun handleWallpaperScheduling(
settings: SettingsState,
scheduler: WallpaperAlarmSchedulerImpl
) {
val wallpaperSettings = settings.wallpaperSettings
val scheduleSettings = settings.scheduleSettings
if (!wallpaperSettings.enableChanger) return
if (wallpaperSettings.homeAlbumName.isNullOrEmpty() || wallpaperSettings.lockAlbumName.isNullOrEmpty()) {
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
// If changer is not enabled, or essential album names are missing, disable changer and return.
if (!wallpaperSettings.enableChanger || wallpaperSettings.homeAlbumName.isNullOrEmpty() || wallpaperSettings.lockAlbumName.isNullOrEmpty()) {
if (wallpaperSettings.enableChanger) { // Only dispatch event if it was enabled
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
}
return
}
// Check if alarms are already set to avoid redundant scheduling
val shouldScheduleAlarm = if (scheduleSettings.scheduleSeparately) {
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
} else {
!isPendingIntentSet(Type.SINGLE.ordinal)
}
if (shouldScheduleAlarm) {
scheduleWallpaperAlarm(settings, scheduler)
val canScheduleExactAlarms = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
alarmManager.canScheduleExactAlarms()
} else {
true
}
if (canScheduleExactAlarms) {
scheduleWallpaperAlarm(settings, scheduler)
} else {
// Optionally prompt user to grant permission
requestExactAlarmPermissionIfNeeded(this)
}
}
}
@RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM)
private suspend fun scheduleWallpaperAlarm(
settings: SettingsState,
scheduler: WallpaperAlarmSchedulerImpl
) {
val scheduleSettings = settings.scheduleSettings
val wallpaperSettings = settings.wallpaperSettings
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val am = getSystemService(ALARM_SERVICE) as AlarmManager
if (!am.canScheduleExactAlarms()) {
return
}
}
scheduler.scheduleWallpaperAlarm(
WallpaperAlarmItem(
homeInterval = scheduleSettings.homeInterval,
@@ -171,27 +229,14 @@ class MainActivity : ComponentActivity() {
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
}
override fun onResume() {
super.onResume()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val alarmManager = ContextCompat.getSystemService(context, AlarmManager::class.java)
if (alarmManager?.canScheduleExactAlarms() == false) {
Intent().also { intent ->
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM
context.startActivity(intent)
}
}
}
}
private fun isPendingIntentSet(requestCode: Int): Boolean {
val intent = Intent(context.applicationContext, WallpaperReceiver::class.java)
val intent = Intent(applicationContext, WallpaperReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(
context.applicationContext,
applicationContext,
requestCode,
intent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_NO_CREATE
)
return pendingIntent != null
}
}
}
@@ -1,6 +1,7 @@
package com.anthonyla.paperize.feature.wallpaper.presentation
import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import androidx.compose.foundation.layout.fillMaxSize
@@ -288,7 +289,7 @@ fun PaperizeApp(
settingsViewModel.onEvent(SettingsEvent.SetHome(setHome))
if (albumState.value.selectedAlbum.isNotEmpty() && !setHome && !settingsState.value.wallpaperSettings.setLockWallpaper) {
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
albumState.value.selectedAlbum.let { albumsViewModel.onEvent(AlbumsEvent.Reset) }
albumState.value.selectedAlbum.let { albumsViewModel.onEvent(AlbumsEvent.DeselectSelected) }
scheduler.cancelWallpaperAlarm()
}
else if (albumState.value.selectedAlbum.isNotEmpty() && ((setHome && !settingsState.value.wallpaperSettings.setLockWallpaper) || (!setHome && settingsState.value.wallpaperSettings.setLockWallpaper))) {
@@ -325,7 +326,7 @@ fun PaperizeApp(
if (!setLock && !settingsState.value.wallpaperSettings.setHomeWallpaper) {
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
albumState.value.selectedAlbum.let {
albumsViewModel.onEvent(AlbumsEvent.Reset)
albumsViewModel.onEvent(AlbumsEvent.DeselectSelected)
}
scheduler.cancelWallpaperAlarm()
}
@@ -681,6 +682,7 @@ fun PaperizeApp(
}
}
@SuppressLint("MissingPermission")
private fun CoroutineScope.scheduleWallpaperUpdate(
job: Job?,
settingsState: SettingsState,
@@ -2,15 +2,18 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
@@ -22,6 +25,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
@@ -49,20 +53,40 @@ fun AddAlbumScreen(
onConfirmation: () -> Unit,
onShowWallpaperView: (String, String) -> Unit,
onShowFolderView: (Folder) -> Unit,
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
animate: Boolean
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
animate: Boolean // This likely controls item animation, similar to AlbumViewScreen
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val addAlbumState = addAlbumViewModel.state.collectAsStateWithLifecycle()
val addAlbumState by addAlbumViewModel.state.collectAsStateWithLifecycle() // Use by for direct access
val lazyListState = rememberLazyGridState()
var showSpotlight by rememberSaveable { mutableStateOf(false) }
// Remember scrollbar settings for consistency and performance
val colorScheme = MaterialTheme.colorScheme
val scrollbarSettings = remember {
ScrollbarSettings.Default.copy(
thumbUnselectedColor = colorScheme.primary,
thumbSelectedColor = colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
)
}
// Remember common modifier for grid items for consistency and responsiveness
val commonItemModifier = remember {
Modifier
.fillMaxWidth()
.aspectRatio(9f / 16f) // Common aspect ratio for wallpapers/photos
}
BackHandler(
enabled = addAlbumState.value.selectionState.selectedCount > 0,
onBack = {
if (!addAlbumState.value.isLoading) {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
enabled = addAlbumState.selectionState.selectedCount > 0,
onBack = remember(addAlbumState.isLoading, addAlbumViewModel) { // Remember the lambda
{
if (!addAlbumState.isLoading) {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
}
}
}
)
@@ -75,12 +99,17 @@ fun AddAlbumScreen(
addAlbumViewModel.onEvent(AddAlbumEvent.SetLoading(true))
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val uriList = uris.mapNotNull { uri ->
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
try {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
uri.toString()
} catch (_: Exception) {
null
}
}
if (uriList.isNotEmpty()) {
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
withContext(Dispatchers.Main) {
addAlbumViewModel.onEvent(AddAlbumEvent.AddWallpapers(uriList))
}
}
addAlbumViewModel.onEvent(AddAlbumEvent.SetLoading(false))
}
@@ -94,10 +123,13 @@ fun AddAlbumScreen(
scope.launch(Dispatchers.IO) {
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
if (uri != null) {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) {
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
try {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
withContext(Dispatchers.Main) {
addAlbumViewModel.onEvent(AddAlbumEvent.AddFolder(uri.toString()))
}
} catch (e: Exception) {
Log.e("AddAlbumScreen", "Failed to take persistable URI permission: ${e.message}")
}
}
}
@@ -106,140 +138,195 @@ fun AddAlbumScreen(
Scaffold(
topBar = {
AddAlbumSmallTopBar(
title = initialAlbumName,
allSelected = addAlbumState.value.selectionState.allSelected,
selectedCount = addAlbumState.value.selectionState.selectedCount,
isEmpty = addAlbumState.value.isEmpty,
selectionMode = addAlbumState.value.selectionState.selectedCount > 0,
showSpotlight = showSpotlight,
isLoad = addAlbumState.value.isLoading,
onBackClick = {
val onBackClickTopBar = remember(addAlbumViewModel, onBackClick) {
{
showSpotlight = false
addAlbumViewModel.onEvent(AddAlbumEvent.Reset)
onBackClick()
},
onConfirmationClick = {
if (!addAlbumState.value.isLoading) {
}
}
val onConfirmationClickTopBar = remember(addAlbumState.isLoading, addAlbumViewModel, initialAlbumName, onConfirmation) {
{ text: String ->
if (!addAlbumState.isLoading) {
showSpotlight = false
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum(initialAlbumName))
addAlbumViewModel.onEvent(AddAlbumEvent.SaveAlbum(text))
onConfirmation()
}
},
onSelectAllClick = {
if (!addAlbumState.value.isLoading) {
if (!addAlbumState.value.selectionState.allSelected) {
}
}
val onSelectAllClickTopBar = remember(addAlbumState.isLoading, addAlbumState.selectionState.allSelected, addAlbumViewModel) {
{
if (!addAlbumState.isLoading) {
if (!addAlbumState.selectionState.allSelected) {
addAlbumViewModel.onEvent(AddAlbumEvent.SelectAll)
} else {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
}
}
},
onDeleteSelected = {
if (!addAlbumState.value.isLoading) {
}
}
val onDeleteSelectedTopBar = remember(addAlbumState.isLoading, addAlbumViewModel) {
{
if (!addAlbumState.isLoading) {
addAlbumViewModel.onEvent(AddAlbumEvent.DeleteSelected)
}
},
onSortClick = {
if (!addAlbumState.value.isLoading) {
}
}
val onSortClickTopBar = remember(addAlbumState.isLoading, addAlbumViewModel, addAlbumState.folders, addAlbumState.wallpapers, onSortClick) {
{
if (!addAlbumState.isLoading) {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
onSortClick(addAlbumState.value.folders, addAlbumState.value.wallpapers)
onSortClick(addAlbumState.folders, addAlbumState.wallpapers)
}
}
}
AddAlbumSmallTopBar(
title = initialAlbumName,
allSelected = addAlbumState.selectionState.allSelected,
selectedCount = addAlbumState.selectionState.selectedCount,
isEmpty = addAlbumState.isEmpty,
selectionMode = addAlbumState.selectionState.selectedCount > 0,
showSpotlight = showSpotlight,
isLoad = addAlbumState.isLoading,
onBackClick = onBackClickTopBar,
onConfirmationClick = onConfirmationClickTopBar,
onSelectAllClick = onSelectAllClickTopBar,
onDeleteSelected = onDeleteSelectedTopBar,
onSortClick = onSortClickTopBar
)
},
floatingActionButton = {
AddAlbumAnimatedFab(
isLoading = addAlbumState.value.isLoading,
animate = animate,
onImageClick = {
// Remember FAB callbacks
val onImageClickFab = remember(addAlbumViewModel, imagePickerLauncher) {
{
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
imagePickerLauncher.launch(arrayOf("image/*"))
},
onFolderClick = {
}
}
val onFolderClickFab = remember(addAlbumViewModel, folderPickerLauncher) {
{
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectAll)
folderPickerLauncher.launch(null)
}
}
AddAlbumAnimatedFab(
isLoading = addAlbumState.isLoading,
animate = animate,
onImageClick = onImageClickFab,
onFolderClick = onFolderClickFab
)
},
bottomBar = {
if (addAlbumState.value.isLoading) {
if (addAlbumState.isLoading) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
},
content = {
content = { paddingValues -> // Use paddingValues from Scaffold
LazyVerticalGridScrollbar(
state = lazyListState,
settings = ScrollbarSettings.Default.copy(
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
thumbSelectedColor = MaterialTheme.colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
),
modifier = Modifier.fillMaxSize().padding(it),
settings = scrollbarSettings, // Use remembered settings
modifier = Modifier
.fillMaxSize()
.padding(paddingValues), // Apply Scaffold padding
) {
LazyVerticalGrid(
state = lazyListState,
modifier = Modifier.fillMaxSize(),
columns = GridCells.Adaptive(150.dp),
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
contentPadding = PaddingValues(4.dp), // Apply padding to grid content
horizontalArrangement = Arrangement.spacedBy(4.dp), // Use spacedBy for consistent spacing
verticalArrangement = Arrangement.spacedBy(4.dp), // Use spacedBy for consistent spacing
) {
items(
items = addAlbumState.value.folders,
items = addAlbumState.folders,
key = { folder -> folder.folderUri }
) {
FolderItem(
folder = it,
itemSelected = addAlbumState.value.selectionState.selectedFolders.contains(it.folderUri),
selectionMode = addAlbumState.value.selectionState.selectedCount > 0,
onItemSelection = {
if (!addAlbumState.value.isLoading) {
if (!addAlbumState.value.selectionState.selectedFolders.contains(it.folderUri)) {
addAlbumViewModel.onEvent(AddAlbumEvent.SelectFolder(it.folderUri)) }
else {
addAlbumViewModel.onEvent(
AddAlbumEvent.DeselectFolder(it.folderUri)
)
) { folder -> // Renamed 'it' to 'folder' for clarity
val isSelected = addAlbumState.selectionState.selectedFolders.contains(folder.folderUri)
val onFolderItemSelection = remember(folder.folderUri, addAlbumState.isLoading, addAlbumViewModel, isSelected) {
{
if (!addAlbumState.isLoading) {
if (!isSelected) {
addAlbumViewModel.onEvent(AddAlbumEvent.SelectFolder(folder.folderUri))
} else {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectFolder(folder.folderUri))
}
}
},
onFolderViewClick = {
if (!addAlbumState.value.isLoading) {
onShowFolderView(it)
}
}
val onFolderViewClickItem = remember(folder, addAlbumState.isLoading, onShowFolderView) {
{
if (!addAlbumState.isLoading) {
onShowFolderView(folder)
}
},
modifier = Modifier
.padding(4.dp)
.size(150.dp, 350.dp)
}
}
FolderItem(
folder = folder,
itemSelected = isSelected,
selectionMode = addAlbumState.selectionState.selectedCount > 0,
onItemSelection = onFolderItemSelection,
onFolderViewClick = onFolderViewClickItem,
modifier = commonItemModifier // Use common responsive modifier
.then(
if (animate) Modifier.animateItem( // Add item animation
placementSpec = tween(
durationMillis = 800,
delayMillis = 0,
easing = FastOutSlowInEasing
)
) else Modifier
)
)
}
items(
items = addAlbumState.value.wallpapers,
items = addAlbumState.wallpapers,
key = { wallpaper -> wallpaper.wallpaperUri }
) {
) { wallpaper -> // Renamed 'it' to 'wallpaper' for clarity
val isSelected = addAlbumState.selectionState.selectedWallpapers.contains(wallpaper.wallpaperUri)
val onWallpaperItemSelection = remember(wallpaper.wallpaperUri, addAlbumState.isLoading, addAlbumViewModel, isSelected) {
{
if (!addAlbumState.isLoading) {
if (!isSelected) {
addAlbumViewModel.onEvent(AddAlbumEvent.SelectWallpaper(wallpaper.wallpaperUri))
} else {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectWallpaper(wallpaper.wallpaperUri))
}
}
}
}
val onWallpaperViewClickItem = remember(wallpaper, addAlbumState.isLoading, onShowWallpaperView) {
{
if (!addAlbumState.isLoading) {
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
}
}
}
WallpaperItem(
wallpaperUri = it.wallpaperUri,
itemSelected = addAlbumState.value.selectionState.selectedWallpapers.contains(it.wallpaperUri),
selectionMode = addAlbumState.value.selectionState.selectedCount > 0,
onItemSelection = {
if (!addAlbumState.value.isLoading) {
if (!addAlbumState.value.selectionState.selectedWallpapers.contains(it.wallpaperUri)) {
addAlbumViewModel.onEvent(AddAlbumEvent.SelectWallpaper(it.wallpaperUri))
}
else {
addAlbumViewModel.onEvent(AddAlbumEvent.DeselectWallpaper(it.wallpaperUri))
}
}
},
onWallpaperViewClick = {
if (!addAlbumState.value.isLoading) {
onShowWallpaperView(it.wallpaperUri, it.fileName)
}
},
modifier = Modifier
.padding(4.dp)
.size(150.dp, 350.dp)
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = isSelected,
selectionMode = addAlbumState.selectionState.selectedCount > 0,
onItemSelection = onWallpaperItemSelection,
onWallpaperViewClick = onWallpaperViewClickItem,
modifier = commonItemModifier // Use common responsive modifier
.then(
if (animate) Modifier.animateItem( // Add item animation
placementSpec = tween(
durationMillis = 800,
delayMillis = 0,
easing = FastOutSlowInEasing
)
) else Modifier
)
)
}
}
@@ -7,11 +7,15 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Folder
import androidx.compose.material.icons.filled.PhotoLibrary
import androidx.compose.material.icons.filled.Remove
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
@@ -25,66 +29,65 @@ fun AddAlbumAnimatedFab(
onFolderClick: () -> Unit
) {
val expandedWidth = 165.dp
val itemSize = 2
val collapsedFabSize = 96.dp
val expandedFabHeight = 60.dp
val menuItemHeight = 56.dp
val menuItemCount = 2
val menuColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)
val fabColor = MaterialTheme.colorScheme.primaryContainer
var isFabExpanded by remember { mutableStateOf(false) }
BackHandler(isFabExpanded) { isFabExpanded = false }
val fabTransition = if (animate) {
updateTransition(targetState = isFabExpanded, label = "fabTransition")
} else null
val transition = updateTransition(targetState = isFabExpanded, label = "fabTransition")
val expandFabHorizontally = if (animate) {
fabTransition!!.animateDp(
transitionSpec = {
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
},
label = "expandHorizontally",
targetValueByState = { expanded ->
if (expanded) expandedWidth else 96.dp
val fabWidth by transition.animateDp(
label = "fabWidth",
transitionSpec = {
if (animate) {
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
} else {
snap()
}
).value
} else {
if (isFabExpanded) expandedWidth else 96.dp
}
) { expanded ->
if (expanded) expandedWidth else collapsedFabSize
}
val shrinkFabVertically = if (animate) {
fabTransition?.animateDp(
transitionSpec = {
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
},
label = "shrinkVertically",
targetValueByState = { expanded ->
if (expanded) 60.dp else 96.dp
val fabHeight by transition.animateDp(
label = "fabHeight",
transitionSpec = {
if (animate) {
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
} else {
snap()
}
)?.value ?: 0.dp
} else {
if (isFabExpanded) 60.dp else 96.dp
}
) { expanded ->
if (expanded) expandedFabHeight else collapsedFabSize
}
val menuHeight = if (animate) {
fabTransition?.animateDp(
transitionSpec = {
spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
},
label = "menuHeight",
targetValueByState = { expanded ->
if (expanded) (itemSize * 50).dp else 0.dp
val menuHeight by transition.animateDp(
label = "menuHeight",
transitionSpec = {
if (animate) {
spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)
} else {
snap()
}
)?.value ?: 0.dp
} else {
if (isFabExpanded) (itemSize * 50).dp else 0.dp
}
) { expanded ->
if (expanded) menuItemHeight * menuItemCount else 0.dp
}
val fabIconTransitionSpec: AnimatedContentTransitionScope<Boolean>.() -> ContentTransform = {
if (animate) {
(scaleIn(tween(100, 300, FastOutSlowInEasing)) + fadeIn(tween(250, 300, LinearEasing)))
.togetherWith(fadeOut(tween(10, 0, LinearEasing)))
} else {
EnterTransition.None.togetherWith(ExitTransition.None)
}
}
ElevatedCard(
@@ -96,7 +99,9 @@ fun AddAlbumAnimatedFab(
)
) {
Column(
modifier = Modifier.height(menuHeight),
modifier = Modifier
.height(menuHeight)
.width(fabWidth),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.SpaceEvenly
) {
@@ -106,32 +111,17 @@ fun AddAlbumAnimatedFab(
enter = if (animate) fadeIn(tween(300, 150, LinearEasing)) else EnterTransition.None,
exit = if (animate) fadeOut(tween(200, 50, LinearEasing)) + scaleOut() else ExitTransition.None
) {
Row(
MenuItemRow(
icon = Icons.Filled.PhotoLibrary,
text = stringResource(R.string.add_images_btn),
onClick = {
onImageClick()
isFabExpanded = false
},
modifier = Modifier
.width(expandFabHorizontally)
.clickable {
onImageClick()
isFabExpanded = false
},
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Filled.PhotoLibrary,
contentDescription = stringResource(R.string.add_images_btn),
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp)
)
Spacer(modifier = Modifier.weight(1f))
Text(
text = stringResource(R.string.add_images_btn),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp)
)
}
.fillMaxWidth()
.height(menuItemHeight)
)
}
AnimatedVisibility(
@@ -140,69 +130,72 @@ fun AddAlbumAnimatedFab(
enter = if (animate) fadeIn(tween(300, 150, LinearEasing)) else EnterTransition.None,
exit = if (animate) fadeOut(tween(200, 50, LinearEasing)) + scaleOut() else ExitTransition.None
) {
Row(
MenuItemRow(
icon = Icons.Filled.Folder,
text = stringResource(R.string.add_folder_btn),
onClick = {
onFolderClick()
isFabExpanded = false
},
modifier = Modifier
.width(expandFabHorizontally)
.clickable {
onFolderClick()
isFabExpanded = false
},
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Filled.Folder,
contentDescription = stringResource(R.string.add_folder_btn),
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(start = 16.dp, top = 12.dp, bottom = 12.dp)
)
Spacer(modifier = Modifier.weight(1f))
Text(
text = stringResource(R.string.add_folder_btn),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(end = 16.dp, top = 12.dp, bottom = 12.dp)
)
}
.fillMaxWidth()
.height(menuItemHeight)
)
}
}
LargeFloatingActionButton(
onClick = { if (!isLoading) isFabExpanded = !isFabExpanded },
modifier = Modifier
.width(expandFabHorizontally)
.height(shrinkFabVertically),
shape = RoundedCornerShape(28),
.width(fabWidth)
.height(fabHeight),
shape = RoundedCornerShape(28.dp),
containerColor = fabColor,
elevation = FloatingActionButtonDefaults.elevation(4.dp)
) {
if (animate) {
AnimatedContent(
targetState = isFabExpanded,
transitionSpec = {
if (targetState) {
(scaleIn(tween(100, 300, FastOutSlowInEasing)) + fadeIn(tween(250, 300, LinearEasing)))
.togetherWith(fadeOut(tween(10, 0, LinearEasing)))
} else {
fadeIn(tween(250, 200, FastOutSlowInEasing))
.togetherWith(fadeOut(tween(10, 0, LinearEasing)))
}
},
label = "FabContent"
) { expanded ->
Icon(
imageVector = if (expanded) Icons.Filled.Remove else Icons.Filled.Add,
contentDescription = stringResource(R.string.add_wallpaper)
)
}
} else {
AnimatedContent(
targetState = isFabExpanded,
transitionSpec = fabIconTransitionSpec,
label = "FabContent"
) { expanded ->
Icon(
imageVector = if (isFabExpanded) Icons.Filled.Remove else Icons.Filled.Add,
imageVector = if (expanded) Icons.Filled.Remove else Icons.Filled.Add,
contentDescription = stringResource(R.string.add_wallpaper)
)
}
}
}
}
/**
* Reusable Composable for a single menu item row.
*/
@Composable
private fun MenuItemRow(
modifier: Modifier = Modifier,
icon: ImageVector,
text: String,
onClick: () -> Unit
) {
Row(
modifier = modifier.clickable(onClick = onClick),
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = icon,
contentDescription = text,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(start = 16.dp)
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = text,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f)
)
}
}
@@ -1,11 +1,14 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
@@ -21,9 +24,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.net.toUri
import com.anthonyla.paperize.core.decompress
import com.anthonyla.paperize.core.isValidUri
@@ -41,7 +44,9 @@ fun AlbumItem(
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val showCoverUri by remember { mutableStateOf(!album.coverUri.isNullOrEmpty() && isValidUri(context, album.coverUri)) }
val showCoverUri by remember(album.coverUri) {
mutableStateOf(!album.coverUri.isNullOrEmpty() && isValidUri(context, album.coverUri))
}
Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
@@ -50,10 +55,22 @@ fun AlbumItem(
onClick = onAlbumViewClick
) {
Column(
modifier = Modifier.padding(12.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.Start
) {
Box {
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.border(
width = 1.dp,
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.1f),
shape = RoundedCornerShape(12.dp)
)
.clip(RoundedCornerShape(12.dp)),
contentAlignment = Alignment.Center
) {
if (showCoverUri) {
GlideImage(
imageModel = {
@@ -64,23 +81,19 @@ fun AlbumItem(
alignment = Alignment.Center,
requestSize = IntSize(300, 300),
),
modifier = Modifier
.aspectRatio(1f)
.clip(RoundedCornerShape(16.dp))
modifier = Modifier.fillMaxSize()
)
}
}
Spacer(modifier = Modifier.padding(6.dp))
Spacer(modifier = Modifier.height(12.dp))
Text(
text = album.displayedAlbumName,
modifier = Modifier
.padding(horizontal = 24.dp)
.align(Alignment.Start),
fontSize = 16.sp,
style = MaterialTheme.typography.titleSmall
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Spacer(modifier = Modifier.padding(8.dp))
}
}
}
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.CircleShape
@@ -19,7 +20,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.RadioButtonUnchecked
import androidx.compose.material.icons.rounded.Block
import androidx.compose.material.icons.sharp.Block
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
@@ -65,24 +65,24 @@ fun FolderItem(
) {
val context = LocalContext.current
val haptics = LocalHapticFeedback.current
val transition = updateTransition(itemSelected, label = "")
val transition = updateTransition(itemSelected, label = "FolderSelectionTransition")
val iconSelectionColor = MaterialTheme.colorScheme.surfaceColorAtElevation(10.dp)
val paddingTransition by transition.animateDp(label = "") { selected ->
if (selected) 5.dp else 0.dp
val paddingTransition by transition.animateDp(label = "FolderPaddingTransition") { selected ->
if (selected) 4.dp else 0.dp
}
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
val roundedCornerShapeTransition by transition.animateDp(label = "FolderRoundedCornerTransition") { selected ->
if (selected) 24.dp else 16.dp
}
val showCoverUri by remember { mutableStateOf(!folder.coverUri.isNullOrEmpty() && isValidUri(context, folder.coverUri)) }
val showCoverUri by remember(folder.coverUri) { mutableStateOf(!folder.coverUri.isNullOrEmpty() && isValidUri(context, folder.coverUri)) }
Card(
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant),
shape = RoundedCornerShape(roundedCornerShapeTransition),
modifier = modifier
.fillMaxSize()
.padding(paddingTransition)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
.combinedClickable(
onClick = {
if (!selectionMode) {
@@ -100,10 +100,21 @@ fun FolderItem(
),
) {
Column(
modifier = Modifier.padding(12.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Box (modifier = Modifier.fillMaxHeight(0.8f)) {
Box(
modifier = Modifier
.fillMaxHeight(0.8f)
.fillMaxWidth()
.border(
width = 1.dp,
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.1f),
shape = RoundedCornerShape(12.dp)
)
.clip(RoundedCornerShape(12.dp))
) {
if (showCoverUri) {
GlideImage(
imageModel = { folder.coverUri?.decompress("content://com.android.externalstorage.documents/")?.toUri() },
@@ -112,38 +123,43 @@ fun FolderItem(
alignment = Alignment.Center,
requestSize = IntSize(300, 300),
),
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(16.dp))
modifier = Modifier.fillMaxSize()
)
}
else {
Box (modifier = Modifier.fillMaxSize()) {
} else {
Box(modifier = Modifier.fillMaxSize()) {
Icon(
imageVector = Icons.Rounded.Block,
contentDescription = stringResource(R.string.image_is_not_selected),
modifier = Modifier.fillMaxSize().padding(16.dp),
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f)
)
}
}
if (selectionMode) {
if (itemSelected) {
Icon(
imageVector = Icons.Default.CheckCircle,
contentDescription = stringResource(R.string.image_is_selected),
modifier = Modifier
.padding(9.dp)
.border(2.dp, iconSelectionColor, CircleShape)
.clip(CircleShape)
.background(iconSelectionColor)
)
} 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)
)
Box(modifier = Modifier.fillMaxSize()) {
if (itemSelected) {
Icon(
imageVector = Icons.Default.CheckCircle,
contentDescription = stringResource(R.string.image_is_selected),
modifier = Modifier
.align(Alignment.TopStart)
.padding(9.dp)
.border(2.dp, iconSelectionColor, CircleShape)
.clip(CircleShape)
.background(iconSelectionColor)
)
} else {
Icon(
imageVector = Icons.Default.RadioButtonUnchecked,
contentDescription = stringResource(R.string.image_is_not_selected),
tint = Color.White.copy(alpha = 0.7f),
modifier = Modifier
.align(Alignment.TopStart)
.padding(6.dp)
)
}
}
}
}
@@ -151,7 +167,6 @@ fun FolderItem(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.padding(horizontal = 16.dp)
.align(Alignment.Start)
.fillMaxHeight()
.wrapContentHeight(Alignment.CenterVertically),
@@ -1,6 +1,5 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.album.components
import android.content.Context
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.ExperimentalFoundationApi
@@ -21,7 +20,7 @@ import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.remember // Added
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -55,44 +54,52 @@ fun WallpaperItem(
) {
val context = LocalContext.current
val haptics = LocalHapticFeedback.current
val transition = updateTransition(itemSelected, label = "")
val paddingTransition by transition.animateDp(label = "") { selected ->
val showUri by remember(wallpaperUri) { mutableStateOf(isValidUri(context, wallpaperUri)) }
val decompressedUri by remember(wallpaperUri) {
mutableStateOf(wallpaperUri.decompress("content://com.android.externalstorage.documents/").toUri())
}
val imageOptions = remember {
ImageOptions(
requestSize = IntSize(200, 200),
alignment = Alignment.Center,
)
}
val transition = updateTransition(itemSelected, label = "WallpaperItemSelection")
val paddingTransition by transition.animateDp(label = "padding") { selected ->
if (selected) 5.dp else 0.dp
}
val roundedCornerShapeTransition by transition.animateDp(label = "") { selected ->
val roundedCornerShapeTransition by transition.animateDp(label = "roundedCornerShape") { selected ->
if (selected) 24.dp else 16.dp
}
val showUri by remember { mutableStateOf(isValidUri(context, wallpaperUri)) }
Box(
modifier = modifier
.padding(paddingTransition)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
.combinedClickable(
onClick = {
if (!selectionMode) {
onWallpaperViewClick()
} else {
onItemSelection()
.padding(paddingTransition)
.clip(RoundedCornerShape(roundedCornerShapeTransition))
.combinedClickable(
onClick = {
if (!selectionMode) {
onWallpaperViewClick()
} else {
onItemSelection()
}
},
onLongClick = {
if (!selectionMode) {
if (allowHapticFeedback) haptics.performHapticFeedback(HapticFeedbackType.LongPress)
onItemSelection()
}
}
},
onLongClick = {
if (!selectionMode) {
if (allowHapticFeedback) haptics.performHapticFeedback(HapticFeedbackType.LongPress)
onItemSelection()
}
}
)
)
) {
if (showUri) {
GlideImage(
imageModel = { wallpaperUri.decompress("content://com.android.externalstorage.documents/").toUri() },
imageOptions = ImageOptions(
requestSize = IntSize(200, 200),
alignment = Alignment.Center,
),
imageModel = { decompressedUri },
imageOptions = imageOptions,
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(roundedCornerShapeTransition))
@@ -104,18 +111,22 @@ fun WallpaperItem(
Icon(
imageVector = Icons.Default.CheckCircle,
contentDescription = stringResource(R.string.image_is_selected),
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier
.padding(9.dp)
.clip(CircleShape)
.background(bgColor)
.border(2.dp, bgColor, CircleShape)
.align(Alignment.TopEnd)
)
} 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)
modifier = Modifier
.padding(6.dp)
.align(Alignment.TopEnd)
)
}
}
@@ -5,32 +5,32 @@ import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
import com.anthonyla.paperize.feature.wallpaper.domain.model.Wallpaper
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.AddAlbumEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.AddAlbumAnimatedFab
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.FolderItem
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
@@ -49,19 +49,41 @@ fun AlbumViewScreen(
onShowWallpaperView: (String, String) -> Unit,
onShowFolderView: (Folder) -> Unit,
onDeleteAlbum: () -> Unit,
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val lazyListState = rememberLazyGridState()
val albumViewState = albumScreenViewModel.state.collectAsStateWithLifecycle()
val album = albumViewState.value.albums.find { it.album.initialAlbumName == albumViewState.value.initialAlbumName }
val albumViewState by albumScreenViewModel.state.collectAsStateWithLifecycle()
val album = remember(albumViewState.albums, albumViewState.initialAlbumName) {
albumViewState.albums.find { it.album.initialAlbumName == albumViewState.initialAlbumName }
}
val colorScheme = MaterialTheme.colorScheme
val scrollbarSettings = remember {
ScrollbarSettings.Default.copy(
thumbUnselectedColor = colorScheme.primary,
thumbSelectedColor = colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
)
}
val commonItemModifier = remember {
Modifier
.fillMaxWidth()
.aspectRatio(9f / 16f)
}
BackHandler(
enabled = albumViewState.value.selectionState.selectedCount > 0,
onBack = {
if (!albumViewState.value.isLoading) {
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
enabled = albumViewState.selectionState.selectedCount > 0,
onBack = remember(albumViewState.isLoading, albumScreenViewModel) {
{
if (!albumViewState.isLoading) {
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
}
}
}
)
@@ -69,21 +91,23 @@ fun AlbumViewScreen(
/** Image picker **/
val imagePickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.OpenMultipleDocuments(),
onResult = { uris: List<Uri> ->
scope.launch(Dispatchers.IO) {
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(true))
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val uriList = uris.mapNotNull { uri ->
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
}
if (uriList.isNotEmpty()) {
withContext(Dispatchers.Main) {
albumScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(uriList))
onResult = remember(albumScreenViewModel, scope, context) {
{ uris: List<Uri> ->
scope.launch(Dispatchers.IO) {
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(true))
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val uriList = uris.mapNotNull { uri ->
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) uri.toString() else null
}
if (uriList.isNotEmpty()) {
withContext(Dispatchers.Main) {
albumScreenViewModel.onEvent(AlbumViewEvent.AddWallpapers(uriList))
}
}
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(false))
}
albumScreenViewModel.onEvent(AlbumViewEvent.SetLoading(false))
}
}
)
@@ -91,14 +115,16 @@ fun AlbumViewScreen(
/** Folder picker **/
val folderPickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.OpenDocumentTree(),
onResult = { uri: Uri? ->
scope.launch(Dispatchers.IO) {
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
if (uri != null) {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) {
albumScreenViewModel.onEvent(AlbumViewEvent.AddFolder(uri.toString()))
onResult = remember(albumScreenViewModel, scope, context) {
{ uri: Uri? ->
scope.launch(Dispatchers.IO) {
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
if (uri != null) {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) {
albumScreenViewModel.onEvent(AlbumViewEvent.AddFolder(uri.toString()))
}
}
}
}
@@ -107,145 +133,235 @@ fun AlbumViewScreen(
Scaffold(
topBar = {
AlbumViewTopBar(
title = album?.album?.displayedAlbumName ?: "" ,
allSelected = albumViewState.value.selectionState.allSelected,
selectedCount = albumViewState.value.selectionState.selectedCount,
selectionMode = albumViewState.value.selectionState.selectedCount > 0,
isLoad = albumViewState.value.isLoading,
onSelectAllClick = {
if (!albumViewState.value.isLoading) {
if (!albumViewState.value.selectionState.allSelected) albumScreenViewModel.onEvent(
val onSelectAllClick = remember(
albumViewState.isLoading,
albumViewState.selectionState.allSelected,
albumScreenViewModel
) {
{
if (!albumViewState.isLoading) {
if (!albumViewState.selectionState.allSelected) albumScreenViewModel.onEvent(
AlbumViewEvent.SelectAll
)
else albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
}
},
onBackClick = {
}
}
val onBackClickTopBar = remember(albumScreenViewModel, onBackClick) {
{
albumScreenViewModel.onEvent(AlbumViewEvent.Reset)
onBackClick()
},
onDeleteSelected = {
if (!albumViewState.value.isLoading) {
}
}
val onDeleteSelected = remember(
albumViewState.isLoading,
album,
albumViewState.selectionState.selectedCount,
albumScreenViewModel,
onBackClick
) {
{
if (!albumViewState.isLoading) {
if (album != null) {
if (album.folders.size + album.wallpapers.size == albumViewState.value.selectionState.selectedCount) {
if (album.folders.size + album.wallpapers.size == albumViewState.selectionState.selectedCount) {
onBackClick()
}
albumScreenViewModel.onEvent(AlbumViewEvent.DeleteSelected)
}
}
},
onDeleteAlbum = {
if (!albumViewState.value.isLoading && album != null) {
}
}
val onDeleteAlbumTopBar = remember(
albumViewState.isLoading,
album,
albumScreenViewModel,
onDeleteAlbum
) {
{
if (!albumViewState.isLoading && album != null) {
albumScreenViewModel.onEvent(AlbumViewEvent.DeleteAlbum)
onDeleteAlbum()
}
},
onTitleChange = {
if (!albumViewState.value.isLoading && album != null) {
albumScreenViewModel.onEvent(AlbumViewEvent.ChangeAlbumName(it))
}
}
val onTitleChangeTopBar: (String) -> Unit = remember(
albumViewState.isLoading,
album,
albumScreenViewModel
) {
{ newTitle ->
if (!albumViewState.isLoading && album != null) {
albumScreenViewModel.onEvent(AlbumViewEvent.ChangeAlbumName(newTitle))
}
},
onSortClick = {
if (!albumViewState.value.isLoading && album != null) {
}
}
val onSortClickTopBar = remember(
albumViewState.isLoading,
album,
onSortClick
) {
{
if (!albumViewState.isLoading && album != null) {
onSortClick(album.folders, album.wallpapers)
}
}
}
AlbumViewTopBar(
title = album?.album?.displayedAlbumName ?: "",
allSelected = albumViewState.selectionState.allSelected,
selectedCount = albumViewState.selectionState.selectedCount,
selectionMode = albumViewState.selectionState.selectedCount > 0,
isLoad = albumViewState.isLoading,
onSelectAllClick = onSelectAllClick,
onBackClick = onBackClickTopBar,
onDeleteSelected = onDeleteSelected,
onDeleteAlbum = onDeleteAlbumTopBar,
onTitleChange = onTitleChangeTopBar,
onSortClick = onSortClickTopBar
)
},
floatingActionButton = {
AddAlbumAnimatedFab(
isLoading = albumViewState.value.isLoading,
animate = animate,
onImageClick = {
val onImageClickFab = remember(albumScreenViewModel, imagePickerLauncher) {
{
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
imagePickerLauncher.launch(arrayOf("image/*"))
},
onFolderClick = {
}
}
val onFolderClickFab = remember(albumScreenViewModel, folderPickerLauncher) {
{
albumScreenViewModel.onEvent(AlbumViewEvent.DeselectAll)
folderPickerLauncher.launch(null)
}
}
AddAlbumAnimatedFab(
isLoading = albumViewState.isLoading,
animate = animate,
onImageClick = onImageClickFab,
onFolderClick = onFolderClickFab
)
},
bottomBar = {
if (albumViewState.value.isLoading) {
if (albumViewState.isLoading) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
},
content = { it ->
content = { paddingValues ->
if (album != null) {
LazyVerticalGridScrollbar(
state = lazyListState,
settings = ScrollbarSettings.Default.copy(
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
thumbSelectedColor = MaterialTheme.colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
),
settings = scrollbarSettings,
modifier = Modifier
.fillMaxSize()
.padding(it),
.padding(paddingValues),
) {
LazyVerticalGrid(
state = lazyListState,
modifier = Modifier.fillMaxSize(),
columns = GridCells.Adaptive(150.dp),
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
contentPadding = PaddingValues(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
items(count = album.folders.size, key = { index -> album.folders[index].folderUri }) { index ->
FolderItem(
folder = album.folders[index],
itemSelected = albumViewState.value.selectionState.selectedFolders.contains(album.folders[index].folderUri),
selectionMode = albumViewState.value.selectionState.selectedCount > 0,
onItemSelection = {
if (!albumViewState.value.isLoading) {
items(
items = album.folders,
key = { folder -> folder.folderUri }
) { folder ->
val isSelected = albumViewState.selectionState.selectedFolders.contains(folder.folderUri)
val onFolderItemSelection = remember(
folder.folderUri,
albumViewState.isLoading,
albumViewState.selectionState.selectedFolders
) {
{
if (!albumViewState.isLoading) {
albumScreenViewModel.onEvent(
if (!albumViewState.value.selectionState.selectedFolders.contains(album.folders[index].folderUri))
AlbumViewEvent.SelectFolder(album.folders[index].folderUri)
else {
AlbumViewEvent.DeselectFolder(album.folders[index].folderUri)
}
if (!isSelected) AlbumViewEvent.SelectFolder(folder.folderUri)
else AlbumViewEvent.DeselectFolder(folder.folderUri)
)
}
},
onFolderViewClick = {
if (!albumViewState.value.isLoading) {
onShowFolderView(album.folders[index])
}
}
val onFolderViewClickItem = remember(folder, albumViewState.isLoading, onShowFolderView) {
{
if (!albumViewState.isLoading) {
onShowFolderView(folder)
}
},
modifier = Modifier
.padding(4.dp)
.size(150.dp, 350.dp)
}
}
FolderItem(
folder = folder,
itemSelected = isSelected,
selectionMode = albumViewState.selectionState.selectedCount > 0,
onItemSelection = onFolderItemSelection,
onFolderViewClick = onFolderViewClickItem,
modifier = commonItemModifier
.then(
if (animate) Modifier.animateItem(
placementSpec = tween(
durationMillis = 800,
delayMillis = 0,
easing = FastOutSlowInEasing
)
) else Modifier
)
)
}
items(count = album.wallpapers.size, key = { index -> album.wallpapers[index].wallpaperUri }) { index ->
WallpaperItem(
wallpaperUri = album.wallpapers[index].wallpaperUri,
itemSelected = albumViewState.value.selectionState.selectedWallpapers.contains(album.wallpapers[index].wallpaperUri),
selectionMode = albumViewState.value.selectionState.selectedCount > 0,
onItemSelection = {
if (!albumViewState.value.isLoading) {
items(
items = album.wallpapers,
key = { wallpaper -> wallpaper.wallpaperUri }
) { wallpaper ->
val isSelected = albumViewState.selectionState.selectedWallpapers.contains(wallpaper.wallpaperUri)
val onWallpaperItemSelection = remember(
wallpaper.wallpaperUri,
albumViewState.isLoading,
albumViewState.selectionState.selectedWallpapers
) {
{
if (!albumViewState.isLoading) {
albumScreenViewModel.onEvent(
if (!albumViewState.value.selectionState.selectedWallpapers.contains(
album.wallpapers[index].wallpaperUri
)
) AlbumViewEvent.SelectWallpaper(album.wallpapers[index].wallpaperUri)
else AlbumViewEvent.DeselectWallpaper(album.wallpapers[index].wallpaperUri)
if (!isSelected) AlbumViewEvent.SelectWallpaper(wallpaper.wallpaperUri)
else AlbumViewEvent.DeselectWallpaper(wallpaper.wallpaperUri)
)
}
},
onWallpaperViewClick = {
if (!albumViewState.value.isLoading)
onShowWallpaperView(album.wallpapers[index].wallpaperUri, album.wallpapers[index].fileName)
},
modifier = Modifier
.padding(4.dp)
.size(150.dp, 350.dp)
}
}
val onWallpaperViewClickItem = remember(wallpaper, albumViewState.isLoading, onShowWallpaperView) {
{
if (!albumViewState.isLoading)
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
}
}
WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = isSelected,
selectionMode = albumViewState.selectionState.selectedCount > 0,
onItemSelection = onWallpaperItemSelection,
onWallpaperViewClick = onWallpaperViewClickItem,
modifier = commonItemModifier
.then(
if (animate) Modifier.animateItem(
placementSpec = tween(
durationMillis = 800,
delayMillis = 0,
easing = FastOutSlowInEasing
)
) else Modifier
)
)
}
}
}
}
}
@@ -5,9 +5,10 @@ import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
@@ -16,6 +17,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember // Added remember import
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.feature.wallpaper.domain.model.Folder
@@ -32,6 +34,19 @@ fun FolderViewScreen(
animate: Boolean
) {
val lazyListState = rememberLazyGridState()
val colorScheme = MaterialTheme.colorScheme
val scrollbarSettings = remember {
ScrollbarSettings.Default.copy(
thumbUnselectedColor = colorScheme.primary,
thumbSelectedColor = colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
)
}
val noOpItemSelection: () -> Unit = remember { { /* Do nothing */ } }
BackHandler { onBackClick() }
Scaffold(
@@ -41,39 +56,27 @@ fun FolderViewScreen(
onBackClick = onBackClick
)
},
content = {
content = { paddingValues ->
LazyVerticalGridScrollbar(
state = lazyListState,
settings = ScrollbarSettings.Default.copy(
thumbUnselectedColor = MaterialTheme.colorScheme.primary,
thumbSelectedColor = MaterialTheme.colorScheme.primary,
thumbShape = RoundedCornerShape(16.dp),
scrollbarPadding = 1.dp,
),
settings = scrollbarSettings,
modifier = Modifier
.fillMaxSize()
.padding(it)
.padding(paddingValues)
) {
LazyVerticalGrid(
state = lazyListState,
modifier = Modifier.fillMaxSize(),
columns = GridCells.Adaptive(150.dp),
contentPadding = PaddingValues(4.dp, 4.dp),
horizontalArrangement = Arrangement.Start,
contentPadding = PaddingValues(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
items(items = folder.wallpapers, key = { wallpaper -> wallpaper.wallpaperUri }) { wallpaper ->
WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = false,
selectionMode = false,
allowHapticFeedback = false,
onItemSelection = {},
onWallpaperViewClick = {
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
},
modifier = Modifier
.padding(4.dp)
.size(150.dp, 350.dp)
val itemModifier = remember(animate) {
Modifier
.fillMaxWidth()
.aspectRatio(9f / 16f)
.then(
if (animate) Modifier.animateItem(
placementSpec = tween(
@@ -83,6 +86,18 @@ fun FolderViewScreen(
)
) else Modifier
)
}
WallpaperItem(
wallpaperUri = wallpaper.wallpaperUri,
itemSelected = false,
selectionMode = false,
allowHapticFeedback = false,
onItemSelection = noOpItemSelection,
onWallpaperViewClick = {
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
},
modifier = itemModifier
)
}
}
@@ -51,6 +51,8 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.core.net.toUri
import com.anthonyla.paperize.core.decompress
import com.skydoves.landscapist.glide.GlideImage
import com.skydoves.landscapist.ImageOptions
import androidx.compose.ui.layout.ContentScale
@OptIn(ExperimentalSharedTransitionApi::class)
@@ -64,6 +66,25 @@ fun SortViewScreen(
val state = sortViewModel.state.collectAsStateWithLifecycle()
val lazyListState = rememberLazyListState()
val expandedFolderId = remember { mutableStateOf<String?>(null) }
val onTopBarBackClick: () -> Unit = {
if (expandedFolderId.value != null) {
expandedFolderId.value = null
} else {
onBackClick()
}
}
// Logic to determine the title for the top bar
val topBarTitle = remember(expandedFolderId.value, state.value.folders) {
val currentFolderId = expandedFolderId.value
if (!currentFolderId.isNullOrEmpty()) {
state.value.folders.find { it.folderUri == currentFolderId }?.folderName ?: ""
} else {
""
}
}
val reorderableLazyListStateFolder = rememberReorderableLazyListState(lazyListState) { from, to ->
sortViewModel.onEvent(SortEvent.ShiftFolder(from, to))
}
@@ -81,8 +102,8 @@ fun SortViewScreen(
modifier = Modifier.fillMaxSize(),
topBar = {
SortViewTopBar(
title = "",
onBackClick = onBackClick,
title = topBarTitle,
onBackClick = onTopBarBackClick,
onSaveClick = onSaveClick,
onSortAlphabetically = { sortViewModel.onEvent(SortEvent.SortAlphabetically) },
onSortAlphabeticallyReverse = { sortViewModel.onEvent(SortEvent.SortAlphabeticallyReverse) },
@@ -257,7 +278,10 @@ fun SortViewScreen(
modifier = Modifier
.size(48.dp)
.border(BorderStroke(1.dp, MaterialTheme.colorScheme.onSecondaryContainer), CircleShape)
.clip(CircleShape)
.clip(CircleShape),
imageOptions = ImageOptions(
contentScale = ContentScale.Crop
)
)
}
}
@@ -284,7 +308,10 @@ fun SortViewScreen(
imageModel = { currentFolder.coverUri?.decompress("content://com.android.externalstorage.documents/")?.toUri() },
modifier = Modifier
.size(48.dp)
.clip(RoundedCornerShape(8.dp))
.clip(RoundedCornerShape(8.dp)),
imageOptions = ImageOptions(
contentScale = ContentScale.Crop
)
)
},
headlineContent = {
@@ -364,7 +391,10 @@ fun SortViewScreen(
modifier = Modifier
.size(48.dp)
.clip(CircleShape)
.border(BorderStroke(1.dp, MaterialTheme.colorScheme.onSecondaryContainer), CircleShape)
.border(BorderStroke(1.dp, MaterialTheme.colorScheme.onSecondaryContainer), CircleShape),
imageOptions = ImageOptions(
contentScale = ContentScale.Crop
)
)
}
}
@@ -1,5 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
@@ -18,7 +19,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -71,17 +74,31 @@ fun BlurSwitchAndSlider(
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = columnModifier
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.change_blur),
modifier = Modifier.padding(16.dp),
fontWeight = FontWeight.W500
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_blur),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!blur) {
Text(
text = stringResource(R.string.add_blur_to_the_image),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = blur,
onCheckedChange = onBlurChange
@@ -98,128 +115,135 @@ fun BlurSwitchAndSlider(
)
)
) {
Column {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onBlurPercentageChange(it.roundToInt(), lockPercentage.roundToInt())
} else {
onBlurPercentageChange(it.roundToInt(), it.roundToInt())
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
homePercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onBlurPercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onBlurPercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
} else {
if (blur) {
Column {
Spacer(modifier = Modifier.height(8.dp))
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onBlurPercentageChange(it.roundToInt(), lockPercentage.roundToInt())
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
onBlurPercentageChange(it.roundToInt(), it.roundToInt())
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onBlurPercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onBlurPercentageChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onBlurPercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
}
@@ -59,7 +59,7 @@ fun CurrentSelectedAlbum(
val baseListItemModifier = { horizontal: Int ->
Modifier
.padding(PaddingValues(vertical = 8.dp, horizontal = horizontal.dp))
.padding(PaddingValues(vertical = 4.dp, horizontal = horizontal.dp))
.clip(RoundedCornerShape(16.dp))
}
@@ -1,5 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
@@ -18,7 +19,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -71,17 +74,31 @@ fun DarkenSwitchAndSlider(
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = columnModifier
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.change_brightness),
modifier = Modifier.padding(16.dp),
fontWeight = FontWeight.W500
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_brightness),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!darken) {
Text(
text = stringResource(R.string.change_the_image_brightness),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = darken,
onCheckedChange = onDarkCheck
@@ -98,130 +115,135 @@ fun DarkenSwitchAndSlider(
)
)
) {
Column {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onDarkenChange(it.roundToInt(), lockPercentage.roundToInt())
}
else {
onDarkenChange(it.roundToInt(), it.roundToInt())
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Spacer(modifier = Modifier.height(16.dp))
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
homePercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onDarkenChange(homeDarkenPercentage, it.roundToInt())
delay(100)
onDarkenChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
} else {
if (darken) {
Column {
Spacer(modifier = Modifier.height(8.dp))
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onDarkenChange(it.roundToInt(), lockPercentage.roundToInt())
}
else {
onDarkenChange(it.roundToInt(), it.roundToInt())
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Spacer(modifier = Modifier.height(16.dp))
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onDarkenChange(homeDarkenPercentage, it.roundToInt())
delay(100)
onDarkenChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onDarkenChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
}
@@ -1,5 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
@@ -18,7 +19,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -71,17 +74,31 @@ fun GrayscaleSwitchAndSlider(
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = columnModifier
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.gray_filter),
modifier = Modifier.padding(16.dp),
fontWeight = FontWeight.W500
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.gray_filter),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!grayscale) {
Text(
text = stringResource(R.string.make_the_colors_grayscale),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = grayscale,
onCheckedChange = onGrayscaleChange
@@ -98,128 +115,135 @@ fun GrayscaleSwitchAndSlider(
)
)
) {
Column {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
} else {
onGrayscalePercentageChange(it.roundToInt(), it.roundToInt())
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
homePercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onGrayscalePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
} else {
if (grayscale) {
Column {
Spacer(modifier = Modifier.height(8.dp))
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onGrayscalePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
onGrayscalePercentageChange(it.roundToInt(), it.roundToInt())
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onGrayscalePercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onGrayscalePercentageChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onGrayscalePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
}
@@ -1,6 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.util.Log
import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.size
@@ -19,11 +19,13 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times
import androidx.core.net.toUri
import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.core.VignetteBitmapTransformation
import com.anthonyla.paperize.core.decompress
import com.anthonyla.paperize.core.isValidUri
import com.bumptech.glide.request.RequestOptions
@@ -33,6 +35,7 @@ import com.skydoves.landscapist.glide.GlideImage
/**
* A composable that displays a wallpaper for preview
*/
@SuppressLint("ConfigurationScreenWidthHeight")
@Composable
fun PreviewItem(
wallpaperUri: String,
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -33,21 +34,31 @@ fun RefreshSwitch(
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.periodic_refresh),
modifier = Modifier.padding(16.dp),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Switch(
checked = refresh,
onCheckedChange = onRefreshChange
Text(
text = stringResource(R.string.check_folders_for_new_wallpapers),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = refresh,
onCheckedChange = onRefreshChange
)
}
}
}
@@ -1,8 +1,5 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
@@ -10,6 +7,7 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -33,24 +31,31 @@ fun ShuffleSwitch(
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Row(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.shuffle_wallpaper),
modifier = Modifier.padding(16.dp),
text = stringResource(R.string.shuffle),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Switch(
checked = shuffle,
onCheckedChange = onShuffleCheck,
Text(
text = stringResource(R.string.shuffle_the_wallpapers),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = shuffle,
onCheckedChange = onShuffleCheck
)
}
}
}
@@ -23,16 +23,21 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TimePicker
import androidx.compose.material3.TimePickerDefaults
import androidx.compose.material3.TimePickerState
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
@@ -108,10 +113,16 @@ fun TimeSliders(
) {
Surface(
shape = MaterialTheme.shapes.large,
tonalElevation = 5.dp,
tonalElevation = 8.dp,
modifier = Modifier
.width(IntrinsicSize.Min)
.height(IntrinsicSize.Min)
.animateContentSize(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
)
) {
Column(
modifier = Modifier.padding(24.dp),
@@ -122,23 +133,54 @@ fun TimeSliders(
.fillMaxWidth()
.padding(bottom = 24.dp),
text = stringResource(R.string.select_starting_time),
style = MaterialTheme.typography.labelMedium
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurface
)
TimePicker(
state = timePickerState,
colors = TimePickerDefaults.colors(
clockDialColor = MaterialTheme.colorScheme.primaryContainer,
clockDialSelectedContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
clockDialUnselectedContentColor = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.6f),
selectorColor = MaterialTheme.colorScheme.primary,
containerColor = MaterialTheme.colorScheme.surface,
periodSelectorBorderColor = MaterialTheme.colorScheme.outline,
periodSelectorSelectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
periodSelectorUnselectedContainerColor = MaterialTheme.colorScheme.surface,
periodSelectorSelectedContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
periodSelectorUnselectedContentColor = MaterialTheme.colorScheme.onSurface,
timeSelectorSelectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
timeSelectorUnselectedContainerColor = MaterialTheme.colorScheme.surface,
timeSelectorSelectedContentColor = MaterialTheme.colorScheme.onPrimaryContainer,
timeSelectorUnselectedContentColor = MaterialTheme.colorScheme.onSurface
)
)
TimePicker(state = timePickerState)
Spacer(modifier = Modifier.height(24.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(
onClick = { shouldShowDialog.value = false }
onClick = { shouldShowDialog.value = false },
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer,
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
)
) { Text(stringResource(R.string.dismiss)) }
Button(
onClick = { onStartTimeChange(timePickerState); shouldShowDialog.value = false }
onClick = { onStartTimeChange(timePickerState); shouldShowDialog.value = false },
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary
)
) { Text(stringResource(R.string.confirm)) }
}
Button(
onClick = { onChangeStartTimeToggle(false); shouldShowDialog.value = false }
Spacer(modifier = Modifier.height(16.dp))
TextButton(
onClick = { onChangeStartTimeToggle(false); shouldShowDialog.value = false },
colors = ButtonDefaults.textButtonColors(
contentColor = MaterialTheme.colorScheme.primary
)
) { Text(stringResource(R.string.reset_to_default)) }
}
}
@@ -277,7 +319,26 @@ fun TimeSliders(
)
)
) {
Column {
Column(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
) {
// Days Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.days_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = days1.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = days1,
onValueChange = { newDays ->
@@ -301,9 +362,31 @@ fun TimeSliders(
},
valueRange = 0f..30f,
steps = 30,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
Spacer(modifier = Modifier.height(16.dp))
// Hours Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.hours_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = hours1.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = hours1,
onValueChange = { newHours ->
@@ -327,9 +410,31 @@ fun TimeSliders(
},
valueRange = 0f..24f,
steps = 24,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
Spacer(modifier = Modifier.height(16.dp))
// Minutes Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.minutes_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = minutes1.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = minutes1,
onValueChange = { newMinutes ->
@@ -352,8 +457,13 @@ fun TimeSliders(
},
valueRange = 0f..60f,
steps = 60,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
if (homeEnabled && lockEnabled) {
AnimatedVisibility(
visible = scheduleSeparately,
@@ -385,6 +495,23 @@ fun TimeSliders(
text = formattedTime2,
fontWeight = FontWeight.W500,
)
// Days Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.days_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = days2.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = days2,
onValueChange = { newDays ->
@@ -408,9 +535,31 @@ fun TimeSliders(
},
valueRange = 0f..30f,
steps = 30,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
Spacer(modifier = Modifier.height(16.dp))
// Hours Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.hours_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = hours2.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = hours2,
onValueChange = { newHours ->
@@ -434,9 +583,31 @@ fun TimeSliders(
},
valueRange = 0f..24f,
steps = 24,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
Spacer(modifier = Modifier.height(16.dp))
// Minutes Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(R.string.minutes_txt),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Text(
text = minutes2.toInt().toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = minutes2,
onValueChange = { newMinutes ->
@@ -459,31 +630,64 @@ fun TimeSliders(
},
valueRange = 0f..60f,
steps = 60,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
)
)
}
}
}
Button(
onClick = {
shouldShowDialog.value = true
},
onClick = { shouldShowDialog.value = true },
modifier = Modifier
.padding(16.dp)
.padding(12.dp)
.align(Alignment.CenterHorizontally)
.then(
if (animate) {
Modifier.animateContentSize(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
)
} else {
Modifier
}
),
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
),
shape = RoundedCornerShape(16.dp)
) {
val (hour, minute, period) = if (changeStartTime) {
val hour = if (timePickerState.hour == 0) 12 else timePickerState.hour % 12
val period = if (timePickerState.hour < 12) "AM" else "PM"
Triple(hour, timePickerState.minute, period)
} else {
val currentTime = Calendar.getInstance()
val hour = if (currentTime.get(Calendar.HOUR) == 0) 12 else currentTime.get(Calendar.HOUR) % 12
val period = if (currentTime.get(Calendar.AM_PM) == 0) "AM" else "PM"
Triple(hour, currentTime.get(Calendar.MINUTE), period)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Icon(
imageVector = Icons.Default.Schedule,
contentDescription = null,
modifier = Modifier.padding(end = 8.dp)
)
val (hour, minute, period) = if (changeStartTime) {
val hour = if (timePickerState.hour == 0) 12 else timePickerState.hour % 12
val period = if (timePickerState.hour < 12) "AM" else "PM"
Triple(hour, timePickerState.minute, period)
} else {
val currentTime = Calendar.getInstance()
val hour = if (currentTime.get(Calendar.HOUR) == 0) 12 else currentTime.get(Calendar.HOUR) % 12
val period = if (currentTime.get(Calendar.AM_PM) == 0) "AM" else "PM"
Triple(hour, currentTime.get(Calendar.MINUTE), period)
}
val formattedMinutes = String.format(Locale.getDefault(), "%02d", minute)
Text(
text = "$hour:$formattedMinutes $period",
style = MaterialTheme.typography.titleMedium
)
}
val formattedMinutes = String.format(Locale.getDefault(), "%02d", minute)
Text(text = "$hour:$formattedMinutes $period")
}
}
}
@@ -1,5 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
@@ -18,7 +19,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
@@ -71,17 +74,31 @@ fun VignetteSwitchAndSlider(
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column (
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = columnModifier
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.change_vignette),
modifier = Modifier.padding(16.dp),
fontWeight = FontWeight.W500
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_vignette),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!vignette) {
Text(
text = stringResource(R.string.darken_the_edges_of_the_image),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = vignette,
onCheckedChange = onVignetteChange
@@ -98,128 +115,135 @@ fun VignetteSwitchAndSlider(
)
)
) {
Column {
Spacer(modifier = Modifier.height(8.dp))
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onVignettePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
} else {
onVignettePercentageChange(it.roundToInt(), it.roundToInt())
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
homePercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onVignettePercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onVignettePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
} else {
if (vignette) {
Column {
Spacer(modifier = Modifier.height(8.dp))
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen) + " | " + stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
else {
Text(
text = stringResource(R.string.percentage, homePercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
}
Slider(
value = homePercentage,
onValueChange = {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = it
job?.cancel()
job = scope.launch {
delay(500)
if (bothEnabled) {
onVignettePercentageChange(it.roundToInt(), lockPercentage.roundToInt())
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
onVignettePercentageChange(it.roundToInt(), it.roundToInt())
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
)
if (bothEnabled) {
Text(
text = stringResource(R.string.lock) + " | " + stringResource(R.string.percentage, lockPercentage.roundToInt()),
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp)),
fontWeight = FontWeight.W400
)
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = {
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = it
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(500)
onVignettePercentageChange(homePercentage.roundToInt(), it.roundToInt())
delay(100)
onVignettePercentageChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onVignettePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
Spacer(modifier = Modifier.height(16.dp))
}
}
}
@@ -4,14 +4,12 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
@@ -76,60 +74,111 @@ fun WallpaperPreviewAndScale(
)
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
tonalElevation = 8.dp,
shape = RoundedCornerShape(24.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
.padding(PaddingValues(horizontal = 16.dp, vertical = 12.dp))
) {
Column (
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.padding(vertical = 16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
val modifier = if (lockEnabled && homeEnabled) {
Modifier
.weight(1f)
.padding(8.dp)
} else {
Modifier
.fillMaxSize(0.5f)
.padding(8.dp)
}
if (lockEnabled) {
if (lockEnabled && homeEnabled) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (currentLockWallpaper != null) {
PreviewItem(
wallpaperUri = currentLockWallpaper,
darken = darken,
darkenPercentage = if (!homeEnabled) homeDarkenPercentage else lockDarkenPercentage,
darkenPercentage = lockDarkenPercentage,
scaling = scaling,
blur = blur,
blurPercentage = if (!homeEnabled) homeBlurPercentage else lockBlurPercentage,
blurPercentage = lockBlurPercentage,
vignette = vignette,
vignettePercentage = if (!homeEnabled) homeVignettePercentage else lockVignettePercentage,
vignettePercentage = lockVignettePercentage,
grayscale = grayscale,
grayscalePercentage = if (!homeEnabled) homeGrayscalePercentage else lockGrayscalePercentage
grayscalePercentage = lockGrayscalePercentage
)
Spacer(modifier = Modifier.height(8.dp))
}
}
}
if (homeEnabled) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
Text(
text = stringResource(R.string.home),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (currentHomeWallpaper != null) {
PreviewItem(
wallpaperUri = currentHomeWallpaper,
darken = darken,
darkenPercentage = homeDarkenPercentage,
scaling = scaling,
blur = blur,
blurPercentage = homeBlurPercentage,
vignette = vignette,
vignettePercentage = homeVignettePercentage,
grayscale = grayscale,
grayscalePercentage = homeGrayscalePercentage
)
}
}
}
} else {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
if (lockEnabled) {
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (currentLockWallpaper != null) {
PreviewItem(
wallpaperUri = currentLockWallpaper,
darken = darken,
darkenPercentage = lockDarkenPercentage,
scaling = scaling,
blur = blur,
blurPercentage = lockBlurPercentage,
vignette = vignette,
vignettePercentage = lockVignettePercentage,
grayscale = grayscale,
grayscalePercentage = lockGrayscalePercentage
)
}
}
if (homeEnabled) {
Text(
text = stringResource(R.string.home),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (currentHomeWallpaper != null) {
PreviewItem(
wallpaperUri = currentHomeWallpaper,
@@ -143,15 +192,15 @@ fun WallpaperPreviewAndScale(
grayscale = grayscale,
grayscalePercentage = homeGrayscalePercentage
)
Spacer(modifier = Modifier.height(8.dp))
}
}
}
}
SingleChoiceSegmentedButtonRow (
SingleChoiceSegmentedButtonRow(
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(start = 8.dp, end = 8.dp, bottom = 16.dp))
.padding(horizontal = 16.dp)
) {
options.forEachIndexed { index, label ->
SegmentedButton(
@@ -166,12 +215,14 @@ fun WallpaperPreviewAndScale(
3 -> ScalingConstants.NONE
else -> ScalingConstants.FILL
}
) },
selected = index == selectedIndex
)
},
selected = index == selectedIndex,
modifier = Modifier.weight(1f)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Icon(
painter = when (index) {
@@ -183,9 +234,14 @@ fun WallpaperPreviewAndScale(
},
contentDescription = null,
tint = Color.Unspecified,
modifier = Modifier.size(32.dp)
modifier = Modifier.size(24.dp)
)
Text(
text = label,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.labelMedium
)
Text(text = label, maxLines = 1, overflow = TextOverflow.Ellipsis )
}
}
}