Added notifications page, privacy policy, privacy page, license page, animations toggle, last/next change display, and fixed UI sync

This commit is contained in:
Anthonyy232 committed 2024-04-28 23:39:10 -07:00
1 parent c8c8bd2fd3
commit 89a29d6742
41 files changed
+1561 -345

No files matched your search

@@ -14,7 +14,7 @@ import dagger.hilt.android.HiltAndroidApp
class App: Application() {
override fun onCreate() {
super.onCreate()
val channel = NotificationChannel("wallpaper_service_channel", "Paperize", NotificationManager.IMPORTANCE_NONE)
val channel = NotificationChannel("wallpaper_service_channel", "Paperize", NotificationManager.IMPORTANCE_LOW)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
@@ -7,8 +7,11 @@ object SettingsConstants {
const val SETTINGS_DATASTORE = "settings_datastore"
const val DARK_MODE_TYPE = "dark_mode_type"
const val DYNAMIC_THEME_TYPE = "dynamic_theme_type"
const val ANIMATE_TYPE = "animate_type"
const val WALLPAPER_CHANGE_INTERVAL = "wallpaper_change_interval"
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
const val SET_LOCK_WITH_HOME = "set_lock_with_home"
const val FIRST_LAUNCH = "first_launch"
const val LAST_SET_TIME = "last_set_time"
const val NEXT_SET_TIME = "next_set_time"
}
@@ -0,0 +1,62 @@
package com.anthonyla.paperize.data
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
/**
* Remember the current offset of a [LazyListState].
* Source:
* https://stackoverflow.com/a/75677163
* https://stackoverflow.com/a/70558512
*/
@Composable
fun rememberCurrentOffset(state: LazyListState): State<Int> {
val position = remember { derivedStateOf { state.firstVisibleItemIndex } }
val itemOffset = remember { derivedStateOf { state.firstVisibleItemScrollOffset } }
val lastPosition = rememberPrevious(position.value)
val lastItemOffset = rememberPrevious(itemOffset.value)
val currentOffset = remember { mutableIntStateOf(0) }
LaunchedEffect(position.value, itemOffset.value) {
currentOffset.intValue = when {
lastPosition == null || position.value == 0 -> itemOffset.value
lastPosition == position.value -> currentOffset.intValue + (itemOffset.value - (lastItemOffset ?: 0))
lastPosition > position.value -> currentOffset.intValue - (lastItemOffset ?: 0)
else -> currentOffset.intValue + itemOffset.value
}
}
return currentOffset
}
@Composable
fun <T> rememberPrevious(
current: T,
shouldUpdate: (prev: T?, curr: T) -> Boolean = { prev, curr -> prev != curr },
): T? {
val ref = rememberRef<T>()
SideEffect {
if (shouldUpdate(ref.value, current)) {
ref.value = current
}
}
return ref.value
}
@Composable
fun <T> rememberRef(): MutableState<T?> {
return remember {
object : MutableState<T?> {
override var value: T? = null
override fun component1(): T? = value
override fun component2(): (T?) -> Unit = { value = it }
}
}
}
@@ -2,45 +2,28 @@ package com.anthonyla.paperize.feature.wallpaper.presentation
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.anthonyla.paperize.core.SettingsConstants
import com.anthonyla.paperize.data.settings.SettingsDataStore
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import com.anthonyla.paperize.feature.wallpaper.wallpaperservice.WallpaperService
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val albumsViewModel: AlbumsViewModel by viewModels()
@@ -49,9 +32,6 @@ class MainActivity : ComponentActivity() {
private val context = this
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
override fun onCreate(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 0)
}
if (ContextCompat.checkSelfPermission(context, Manifest.permission.SET_WALLPAPER) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(context as Activity, arrayOf(Manifest.permission.SET_WALLPAPER), 0)
}
@@ -60,22 +40,6 @@ class MainActivity : ComponentActivity() {
val splashScreen = installSplashScreen()
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent {
// Refresh albums when the app is resumed
val lifecycleEvent = rememberLifecycleEvent()
LaunchedEffect(lifecycleEvent) {
if (lifecycleEvent == Lifecycle.Event.ON_RESUME) {
albumsViewModel.onEvent(AlbumsEvent.RefreshAlbums)
wallpaperScreenViewModel.onEvent(WallpaperEvent.Refresh)
if (!WallpaperService.isRunning && wallpaperScreenViewModel.state.value.selectedAlbum != null) {
val timeInMinutes = settingsDataStoreImpl.getInt("wallpaper_change_interval") ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
val intent = Intent(this@MainActivity, WallpaperService::class.java).apply {
action = WallpaperService.Actions.START.toString()
putExtra("timeInMinutes", timeInMinutes)
}
this@MainActivity.startForegroundService(intent)
}
}
}
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
PaperizeTheme(settingsViewModel.state) {
Surface(tonalElevation = 5.dp) {
@@ -85,19 +49,3 @@ class MainActivity : ComponentActivity() {
}
}
}
/**
* Return the latest lifecycle event of the [LifecycleOwner].
*/
@Composable
fun rememberLifecycleEvent(lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current): Lifecycle.Event {
var state by remember { mutableStateOf(Lifecycle.Event.ON_ANY) }
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event -> state = event }
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
return state
}
@@ -1,11 +1,15 @@
package com.anthonyla.paperize.feature.wallpaper.presentation
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavType
@@ -21,11 +25,14 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewMod
import com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.AlbumViewScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.FolderViewScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.HomeScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.LicensesScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen.WallpaperViewScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.startup.StartupScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.notifications_screen.NotificationScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.PrivacyScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.startup_screen.StartupScreen
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavConstants.INITIAL_OFFSET
@@ -34,8 +41,10 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitio
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
import com.anthonyla.paperize.feature.wallpaper.wallpaperservice.WallpaperService
import com.google.gson.Gson
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.net.URLEncoder
@@ -51,6 +60,7 @@ fun PaperizeApp(
val navController = rememberNavController()
val albumState = albumsViewModel.state.collectAsStateWithLifecycle()
val selectedState = wallpaperScreenViewModel.state.collectAsStateWithLifecycle()
val scope = rememberCoroutineScope()
val context = LocalContext.current
// React to albumState changes and change selectedAlbum's details to keep it from being stale
@@ -107,6 +117,7 @@ fun PaperizeApp(
startDestination = if (firstLaunch) NavScreens.Startup.route else NavScreens.Home.route,
modifier = Modifier.navigationBarsPadding()
) {
// Navigate to the startup screen to show the privacy policy and notification screen
composable(
route = NavScreens.Startup.route,
enterTransition = {
@@ -124,11 +135,46 @@ fun PaperizeApp(
) {
StartupScreen(
onAgree = {
settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch)
navController.navigate(NavScreens.Home.route)
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) {
settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch)
navController.navigate(NavScreens.Home.route) {
popUpTo(NavScreens.Startup.route) { inclusive = true }
popUpTo(NavScreens.Notification.route) { inclusive = true }
}
}
else {
navController.navigate(NavScreens.Notification.route)
}
}
)
}
// Navigate to the notification screen to ask for notification permission
composable(
route = NavScreens.Notification.route,
enterTransition = {
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
},
exitTransition = {
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
},
popEnterTransition = {
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
},
popExitTransition = {
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
},
) {
NotificationScreen(
onAgree = {
settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch)
navController.navigate(NavScreens.Home.route) {
popUpTo(NavScreens.Startup.route) { inclusive = true }
popUpTo(NavScreens.Notification.route) { inclusive = true }
}
}
)
}
// Navigate to the home screen to view all albums and wallpapers
composable(
route = NavScreens.Home.route,
enterTransition = {
@@ -157,7 +203,6 @@ fun PaperizeApp(
val intent = Intent(context, WallpaperService::class.java).apply {
action = WallpaperService.Actions.START.toString()
putExtra("timeInMinutes", timeInMinutes)
putExtra("setLockWithHome", settingsViewModel.state.value.setLockWithHome)
}
context.startForegroundService(intent)
},
@@ -344,7 +389,56 @@ fun PaperizeApp(
},
onDynamicThemingClick = {
settingsViewModel.onEvent(SettingsEvent.SetDynamicTheming(it))
}
},
onAnimateClick = {
settingsViewModel.onEvent(SettingsEvent.SetAnimate(it))
},
onPrivacyClick = {
navController.navigate(NavScreens.Privacy.route)
},
onLicenseClick = {
navController.navigate(NavScreens.Licenses.route)
},
)
}
// Navigate to the privacy screen to view the privacy policy
composable(
route = NavScreens.Privacy.route,
enterTransition = {
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
},
exitTransition = {
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
},
popEnterTransition = {
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
},
popExitTransition = {
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
},
) {
PrivacyScreen(
onBackClick = { navController.navigateUp() },
)
}
// Navigate to the licenses screen to view the licenses of the libraries used
composable(
route = NavScreens.Licenses.route,
enterTransition = {
sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() })
},
exitTransition = {
sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() })
},
popEnterTransition = {
sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() })
},
popExitTransition = {
sharedXTransitionOut(target = { (it * INITIAL_OFFSET).toInt() })
},
) {
LicensesScreen(
onBackClick = { navController.navigateUp() },
)
}
}
@@ -2,6 +2,7 @@ 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
@@ -43,14 +44,14 @@ fun AddAlbumScreen(
onConfirmation: () -> Unit,
onShowWallpaperView: (String) -> Unit,
onShowFolderView: (String, String?, List<String>) -> Unit
) {
) {
val context = LocalContext.current
val lazyListState = rememberLazyStaggeredGridState()
val lazyGridState = rememberLazyStaggeredGridState()
val state = viewModel.state.collectAsStateWithLifecycle()
var selectionMode by rememberSaveable { mutableStateOf(false) }
if (state.value.initialAlbumName.isEmpty())
if (state.value.initialAlbumName.isEmpty()) {
viewModel.onEvent(AddAlbumEvent.SetAlbumName(initialAlbumName))
}
BackHandler {
if (selectionMode) {
@@ -67,12 +68,14 @@ fun AddAlbumScreen(
contract = ActivityResultContracts.OpenMultipleDocuments(),
onResult = { uris: List<Uri> ->
for (uri in uris) {
val takeFlags: Int =
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
viewModel.onEvent(
AddAlbumEvent.AddWallpaper(wallpaperUri = uri.toString())
)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) {
viewModel.onEvent(AddAlbumEvent.AddWallpaper(wallpaperUri = uri.toString()))
} else {
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
}
}
}
)
@@ -81,13 +84,15 @@ fun AddAlbumScreen(
val folderPickerLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.OpenDocumentTree(),
onResult = { uri: Uri? ->
val takeFlags: Int =
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
if (uri != null) {
context.contentResolver.takePersistableUriPermission(uri, takeFlags)
viewModel.onEvent(
AddAlbumEvent.AddFolder(directoryUri = uri.toString())
)
val persistedUriPermissions = context.contentResolver.persistedUriPermissions
if (persistedUriPermissions.any { it.uri == uri }) {
viewModel.onEvent(AddAlbumEvent.AddFolder(directoryUri = uri.toString()))
} else {
Log.e("AddAlbumScreen", "Failed to persist permission for $uri")
}
}
}
)
@@ -106,6 +111,7 @@ fun AddAlbumScreen(
onConfirmationClick = {
viewModel.onEvent(AddAlbumEvent.ReflectAlbumName(it))
viewModel.onEvent(AddAlbumEvent.SaveAlbum)
viewModel.onEvent(AddAlbumEvent.ClearState)
onConfirmation()
},
onSelectAllClick = {
@@ -121,21 +127,20 @@ fun AddAlbumScreen(
},
floatingActionButton = {
AnimatedVisibility(
visible =
!lazyListState.isScrollInProgress || lazyListState.firstVisibleItemScrollOffset < 0,
visible = !lazyGridState.isScrollInProgress || lazyGridState.firstVisibleItemScrollOffset < 0,
enter = scaleIn(tween(400, 50, FastOutSlowInEasing)),
exit = scaleOut(tween(400, 50, FastOutSlowInEasing)),
) {
AddAlbumAnimatedFab(
menuOptions = AddAlbumFabMenuOptions(),
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
onFolderClick = { folderPickerLauncher.launch(null) }
)
}
AddAlbumAnimatedFab(
menuOptions = AddAlbumFabMenuOptions(),
onImageClick = { imagePickerLauncher.launch(arrayOf("image/*")) },
onFolderClick = { folderPickerLauncher.launch(null) }
)
},
content = {
LazyVerticalStaggeredGrid(
state = lazyListState,
state = lazyGridState,
modifier = Modifier
.fillMaxSize()
.padding(it),
@@ -4,6 +4,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerDefaults
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
@@ -96,15 +97,19 @@ fun HomeScreen(
)
}
}
HorizontalPager(state = pagerState, beyondBoundsPageCount = 1) { index ->
HorizontalPager(
state = pagerState,
outOfBoundsPageCount = 0,
userScrollEnabled = true,
) { index ->
when(index) {
0 -> WallpaperScreen(
onScheduleWallpaperChanger = { onScheduleWallpaperChanger(it) },
onStop = { onStop() }
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
onStop = onStop
)
1 -> LibraryScreen(
onAddNewAlbumClick = { addAlbumDialog = true },
onViewAlbum = { onAlbumViewClick(it) }
onViewAlbum = onAlbumViewClick
)
}
}
@@ -0,0 +1,38 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.data.rememberCurrentOffset
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseScrollableSettings
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseSmallTopAppBar
import com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components.LicenseTitle
@Composable
fun LicensesScreen(
onBackClick: () -> Unit,
) {
val lazyListState = rememberLazyListState()
val offset = rememberCurrentOffset(lazyListState)
val largeTopAppBarHeight = 152.dp
val smallTopAppBarHeight = 64.dp
val paddingMedium = 16.dp
Box(modifier = Modifier.fillMaxSize()) {
LicenseScrollableSettings(
largeTopAppBarHeightPx = largeTopAppBarHeight,
lazyListState = lazyListState,
offset = offset
)
LicenseSmallTopAppBar(onBackClick = onBackClick)
LicenseTitle(
largeTopAppBarHeight = largeTopAppBarHeight,
smallTopAppBarHeight = smallTopAppBarHeight,
paddingMedium = paddingMedium,
offset = offset
)
}
}
@@ -0,0 +1,55 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
/**
* Scrollable license screen to display open source licenses
*/
@Composable
fun LicenseScrollableSettings(
largeTopAppBarHeightPx: Dp,
lazyListState: LazyListState,
offset: State<Int>
) {
Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Top,
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 24.dp),
) {
val offsetInDp = offset.value.toFloat() / 2f.dp.value
val newHeight = largeTopAppBarHeightPx - offsetInDp.dp
Spacer(Modifier.height(newHeight))
Spacer(modifier = Modifier.height(16.dp))
LibrariesContainer(
modifier = Modifier.fillMaxSize(),
lazyListState = lazyListState,
showVersion = false,
colors = LibraryDefaults.libraryColors(
backgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
contentColor = MaterialTheme.colorScheme.onSurface,
badgeBackgroundColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp),
badgeContentColor = MaterialTheme.colorScheme.primary,
dialogConfirmButtonColor = MaterialTheme.colorScheme.onSurface
)
)
}
}
@@ -0,0 +1,45 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
/**
* Small top app bar for license screen to replace [LicenseLargeTopAppBar] when scrolling down
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LicenseSmallTopAppBar(onBackClick: () -> Unit) {
Surface {
TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
title = {},
navigationIcon = {
IconButton(
onClick = onBackClick,
modifier = Modifier
.padding(16.dp)
.size(24.dp)
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.home_screen)
)
}
}
)
}
}
@@ -0,0 +1,111 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen.components
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
import androidx.compose.ui.unit.sp
import com.anthonyla.paperize.R
/**
* Title for the license screen.
*/
@Composable
fun LicenseTitle(
largeTopAppBarHeight: Dp,
smallTopAppBarHeight: Dp,
paddingMedium: Dp,
modifier: Modifier = Modifier,
offset: State<Int>
) {
val titlePaddingStart = 16.dp
val titlePaddingEnd = 64.dp
val titleFontScaleStart = 1f
val titleFontScaleEnd = 0.7f
var titleHeightPx by remember { mutableFloatStateOf(0f) }
var titleWidthPx by remember { mutableFloatStateOf(0f) }
Text(
text = stringResource(R.string.licenses),
style = MaterialTheme.typography.headlineMedium,
fontSize = 30.sp,
color = MaterialTheme.colorScheme.onSurface,
modifier = modifier
.graphicsLayer {
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
val collapseFraction: Float = (offset.value.toFloat() / collapseRange).coerceIn(0f, 1f)
val scaleXY = lerp(
titleFontScaleStart.dp,
titleFontScaleEnd.dp,
collapseFraction
)
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
val titleYFirstInterpolatedPoint = lerp(
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
largeTopAppBarHeight / 2,
collapseFraction
)
val titleXFirstInterpolatedPoint = lerp(
titlePaddingStart,
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
collapseFraction
)
val titleYSecondInterpolatedPoint = lerp(
largeTopAppBarHeight / 2,
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
collapseFraction
)
val titleXSecondInterpolatedPoint = lerp(
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
titlePaddingEnd - titleExtraStartPadding,
collapseFraction
)
val titleY = lerp(
titleYFirstInterpolatedPoint,
titleYSecondInterpolatedPoint,
collapseFraction
)
val titleX = lerp(
titleXFirstInterpolatedPoint,
titleXSecondInterpolatedPoint,
collapseFraction
)
translationY = titleY.toPx()
translationX = titleX.toPx()
scaleX = scaleXY.value
scaleY = scaleXY.value
}
.onGloballyPositioned {
titleHeightPx = it.size.height.toFloat()
titleWidthPx = it.size.width.toFloat()
}
)
}
@@ -0,0 +1,154 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.notifications_screen
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowCircleRight
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
import com.anthonyla.paperize.R
import kotlinx.coroutines.launch
@Composable
fun NotificationScreen(
onAgree: () -> Unit
) {
val context = LocalContext.current
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.notification_animation))
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever,
)
val askPermission = rememberSaveable { mutableStateOf(false) }
val askCount = rememberSaveable { mutableIntStateOf(0) }
val requestPermissionLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
onAgree()
} else {
if (++askCount.intValue >= 2) {
snackbarHostState.currentSnackbarData?.dismiss()
onAgree()
}
scope.launch {
val result = snackbarHostState.showSnackbar(
message = context.getString(R.string.notification_permission_is_required_for_this_app_to_work_properly),
actionLabel = context.getString(R.string.allow),
duration = SnackbarDuration.Short,
)
when (result) {
SnackbarResult.Dismissed -> {}
SnackbarResult.ActionPerformed -> { askPermission.value = true }
}
}
}
}
fun handleFabClick() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
when {
(ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) -> {
onAgree()
}
else -> {
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
} else { onAgree() }
}
LaunchedEffect (askPermission.value) {
if (askPermission.value) {
handleFabClick()
askPermission.value = false
}
}
Scaffold(
snackbarHost = {
SnackbarHost(
hostState = snackbarHostState,
snackbar = { data ->
Snackbar(
snackbarData = data,
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp, vertical = 8.dp))
)
}
) },
content = { it
Column (modifier = Modifier.padding(32.dp)) {
Spacer(modifier = Modifier.height(120.dp))
Text(text = "Notifications", style = MaterialTheme.typography.headlineLarge)
Spacer(modifier = Modifier.height(16.dp))
LottieAnimation(
composition = composition,
progress = { progress },
modifier = Modifier.fillMaxHeight(0.5f)
)
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = stringResource(R.string.agree),
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
)
Text(
text = stringResource(R.string.notification_info_message),
style = MaterialTheme.typography.bodySmall
)
}
},
floatingActionButton = {
ExtendedFloatingActionButton(
modifier = Modifier.padding(8.dp),
onClick = { askPermission.value = true },
icon = {
Icon(
imageVector = Icons.Outlined.ArrowCircleRight,
contentDescription = stringResource(R.string.continue_button),
)
},
text = { Text(text = stringResource(R.string.continue_button)) },
)
}
)
}
@@ -0,0 +1,36 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyScrollableSettings
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacySmallTopAppBar
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components.PrivacyTitle
@Composable
fun PrivacyScreen(
onBackClick: () -> Unit,
) {
val scroll: ScrollState = rememberScrollState(0)
val largeTopAppBarHeight = 152.dp
val smallTopAppBarHeight = 64.dp
val paddingMedium = 16.dp
Box(modifier = Modifier.fillMaxSize()) {
PrivacyScrollableSettings(
largeTopAppBarHeightPx = largeTopAppBarHeight,
scroll = scroll,
)
PrivacySmallTopAppBar(onBackClick = onBackClick)
PrivacyTitle(
scroll = scroll,
largeTopAppBarHeight = largeTopAppBarHeight,
smallTopAppBarHeight = smallTopAppBarHeight,
paddingMedium = paddingMedium
)
}
}
@@ -0,0 +1,67 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
/**
* Scrollable privacy screen to display privacy policy
*/
@Composable
fun PrivacyScrollableSettings(
largeTopAppBarHeightPx: Dp,
scroll: ScrollState,
) {
Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Top,
modifier = Modifier
.fillMaxSize()
.verticalScroll(scroll)
.padding(horizontal = 24.dp),
) {
Spacer(Modifier.height(largeTopAppBarHeightPx))
Spacer(modifier = Modifier.height(16.dp))
PrivacyPolicyText()
}
}
@Composable
fun PrivacyPolicyText() {
SectionText("Introduction", "Welcome to Paperize! This privacy policy outlines how we collect, use, and protect your personal information when you use our mobile application. By using Paperize, you agree to the terms described in this policy.")
SectionText("Data Collection", "Notification Access: Paperize requests notification access to provide you with personalized wallpaper recommendations based on your notifications. We do not store any notification content or personally identifiable information (PII) outside of your device.\n\nLocal Files: Paperize accesses files stored on your device to allow you to set them as wallpapers. We do not upload or transfer these files to any external servers.")
SectionText("Information Usage", "Personal Data: We do not collect or store any personal data such as names, email addresses, or phone numbers.\n\nUsage Analytics: Paperize does not track your usage behavior or collect analytics data.")
SectionText("Data Security", "On-Device Storage: All data used by Paperize remains on your device. We do not transmit or store any data externally.\n\nEncryption: We use encryption protocols to secure communication between the app and your device.")
SectionText("Third-Party Services", "Advertisements: Paperize does not display third-party ads.\n\nExternal Links: Our app may contain links to external websites. Please note that we are not responsible for the privacy practices of these sites.")
SectionText("Children’s Privacy", "Paperize is not intended for children under the age of 13. We do not knowingly collect any information from children.")
SectionText("Changes to this Policy", "We may update this privacy policy from time to time. Any changes will be reflected in the app and on our website.")
SectionText("Contact Us", "If you have any questions or concerns about this privacy policy, please contact me at anthonyyla.dev@gmail.com.")
}
@Composable
fun SectionText(title: String, content: String) {
Text(
text = title,
style = MaterialTheme.typography.titleLarge,
modifier = Modifier.padding(vertical = 8.dp),
color = MaterialTheme.colorScheme.primary,
)
Text(
text = content,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(bottom = 16.dp)
)
}
@@ -0,0 +1,45 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
/**
* Small top app bar for privacy screen to replace [PrivacyLargeTopAppBar] when scrolling down
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PrivacySmallTopAppBar(onBackClick: () -> Unit) {
Surface {
TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
title = {},
navigationIcon = {
IconButton(
onClick = onBackClick,
modifier = Modifier
.padding(16.dp)
.size(24.dp)
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = stringResource(id = R.string.home_screen)
)
}
}
)
}
}
@@ -0,0 +1,103 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.components
import androidx.compose.foundation.ScrollState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
import androidx.compose.ui.unit.sp
import com.anthonyla.paperize.R
/**
* Title for the privacy screen.
*/
@Composable
fun PrivacyTitle(
largeTopAppBarHeight: Dp,
smallTopAppBarHeight: Dp,
paddingMedium: Dp,
scroll: ScrollState,
modifier: Modifier = Modifier
) {
val titlePaddingStart = 16.dp
val titlePaddingEnd = 64.dp
val titleFontScaleStart = 1f
val titleFontScaleEnd = 0.7f
var titleHeightPx by remember { mutableFloatStateOf(0f) }
var titleWidthPx by remember { mutableFloatStateOf(0f) }
Text(
text = stringResource(id = R.string.privacy_policy),
style = MaterialTheme.typography.headlineMedium,
fontSize = 30.sp,
color = MaterialTheme.colorScheme.onSurface,
modifier = modifier
.graphicsLayer {
val collapseRange: Float = (largeTopAppBarHeight.toPx() - smallTopAppBarHeight.toPx())
val collapseFraction: Float = (scroll.value / collapseRange).coerceIn(0f, 1f)
val scaleXY = lerp(
titleFontScaleStart.dp,
titleFontScaleEnd.dp,
collapseFraction
)
val titleExtraStartPadding = titleWidthPx.toDp() * (1 - scaleXY.value) / 2f
val titleYFirstInterpolatedPoint = lerp(
largeTopAppBarHeight - titleHeightPx.toDp() - paddingMedium,
largeTopAppBarHeight / 2,
collapseFraction
)
val titleXFirstInterpolatedPoint = lerp(
titlePaddingStart,
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
collapseFraction
)
val titleYSecondInterpolatedPoint = lerp(
largeTopAppBarHeight / 2,
(smallTopAppBarHeight - titleHeightPx.toDp() / 2) - 5.dp,
collapseFraction
)
val titleXSecondInterpolatedPoint = lerp(
(titlePaddingEnd - titleExtraStartPadding) * 5 / 4,
titlePaddingEnd - titleExtraStartPadding,
collapseFraction
)
val titleY = lerp(
titleYFirstInterpolatedPoint,
titleYSecondInterpolatedPoint,
collapseFraction
)
val titleX = lerp(
titleXFirstInterpolatedPoint,
titleXSecondInterpolatedPoint,
collapseFraction
)
translationY = titleY.toPx()
translationX = titleX.toPx()
scaleX = scaleXY.value
scaleY = scaleXY.value
}
.onGloballyPositioned {
titleHeightPx = it.size.height.toFloat()
titleWidthPx = it.size.width.toFloat()
}
)
}
@@ -2,11 +2,11 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
sealed class SettingsEvent {
data object RefreshUiState: SettingsEvent()
data object RefreshWallpaperState: SettingsEvent()
data object Refresh: SettingsEvent()
data object SetFirstLaunch: SettingsEvent()
data class SetDarkMode(val darkMode: Boolean?): SettingsEvent()
data class SetDynamicTheming(val dynamicTheming: Boolean): SettingsEvent()
data class SetAnimate(val animate: Boolean): SettingsEvent()
data class SetWallpaperInterval(val interval: Int): SettingsEvent()
data class SetLockWithHome(val lockWithHome: Boolean): SettingsEvent()
}
@@ -3,18 +3,13 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.rememberScrollState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ScrollableSettings
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsLargeTopAppBar
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsScrollableSettings
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsTitle
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.SettingsSmallTopAppBar
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@Composable
@@ -22,7 +17,10 @@ fun SettingsScreen(
settingsState: StateFlow<SettingsState>,
onBackClick: () -> Unit,
onDarkModeClick: (Boolean?) -> Unit,
onDynamicThemingClick: (Boolean) -> Unit
onDynamicThemingClick: (Boolean) -> Unit,
onAnimateClick: (Boolean) -> Unit,
onPrivacyClick: () -> Unit,
onLicenseClick: () -> Unit
) {
val scroll: ScrollState = rememberScrollState(0)
val largeTopAppBarHeight = 152.dp
@@ -30,16 +28,15 @@ fun SettingsScreen(
val paddingMedium = 16.dp
Box(modifier = Modifier.fillMaxSize()) {
SettingsLargeTopAppBar(
scroll = scroll,
modifier = Modifier.height(largeTopAppBarHeight)
)
ScrollableSettings(
SettingsScrollableSettings(
settingsState = settingsState,
largeTopAppBarHeightPx = largeTopAppBarHeight,
scroll = scroll,
onDarkModeClick = onDarkModeClick,
onDynamicThemingClick = onDynamicThemingClick
onDynamicThemingClick = onDynamicThemingClick,
onAnimateClick = onAnimateClick,
onPrivacyClick = onPrivacyClick,
onLicenseClick = onLicenseClick
)
SettingsSmallTopAppBar(onBackClick = onBackClick)
SettingsTitle(
@@ -5,6 +5,9 @@ data class SettingsState (
val firstLaunch: Boolean = true,
val darkMode: Boolean? = null,
val dynamicTheming: Boolean = false,
val animate: Boolean = true,
val interval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
val setLockWithHome: Boolean = false,
val lastSetTime: String? = null,
val nextSetTime: String? = null
)
@@ -1,21 +1,22 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.anthonyla.paperize.core.SettingsConstants
import com.anthonyla.paperize.data.settings.SettingsDataStore
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject
@HiltViewModel
@@ -38,13 +39,19 @@ class SettingsViewModel @Inject constructor (
val wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false }
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
_state.update { it.copy(
darkMode = darkMode.await(),
dynamicTheming = dynamicTheming.await(),
interval = wallpaperInterval.await(),
setLockWithHome = setLockWithHome.await(),
firstLaunch = firstLaunch.await()
firstLaunch = firstLaunch.await(),
lastSetTime = lastSetTime.await(),
nextSetTime = nextSetTime.await(),
animate = animate.await()
) }
setKeepOnScreenCondition = false
}
@@ -60,18 +67,27 @@ class SettingsViewModel @Inject constructor (
) }
}
}
is SettingsEvent.RefreshUiState -> {
viewModelScope.launch {
currentGetJob?.cancel()
currentGetJob = viewModelScope.launch {
_state.update { it.copy(
darkMode = settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE),
dynamicTheming = when(settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)) {
true -> true
false, null -> false
}
) }
}
is SettingsEvent.Refresh -> {
currentGetJob = viewModelScope.launch {
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
val wallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
val setLockWithHome = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false }
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
_state.update { it.copy(
darkMode = darkMode.await(),
dynamicTheming = dynamicTheming.await(),
interval = wallpaperInterval.await(),
setLockWithHome = setLockWithHome.await(),
firstLaunch = firstLaunch.await(),
lastSetTime = lastSetTime.await(),
nextSetTime = nextSetTime.await(),
animate = animate.await()
) }
}
}
is SettingsEvent.SetDarkMode -> {
@@ -97,11 +113,30 @@ class SettingsViewModel @Inject constructor (
) }
}
}
is SettingsEvent.SetAnimate -> {
viewModelScope.launch {
when (event.animate) {
true -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, true) }
false -> { settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, false) }
}
_state.update { it.copy(
animate = event.animate
) }
}
}
is SettingsEvent.SetWallpaperInterval -> {
viewModelScope.launch {
val formatter = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm\na")
val time = LocalDateTime.now()
val formattedLastSetTime = time.format(formatter)
val formattedNextSetTime = time.plusMinutes(event.interval.toLong()).format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, formattedLastSetTime)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, formattedNextSetTime)
settingsDataStoreImpl.putInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL, event.interval)
_state.update { it.copy(
interval = event.interval
interval = event.interval,
lastSetTime = formattedLastSetTime,
nextSetTime = formattedNextSetTime
) }
}
}
@@ -116,31 +151,6 @@ class SettingsViewModel @Inject constructor (
) }
}
}
is SettingsEvent.RefreshWallpaperState -> {
viewModelScope.launch {
currentGetJob?.cancel()
currentGetJob = viewModelScope.launch {
_state.update { it.copy(
interval = settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
) }
}
}
}
}
}
private fun refreshSettings() {
currentGetJob?.cancel()
currentGetJob = viewModelScope.launch {
_state.update { it.copy(
darkMode = settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE),
dynamicTheming = when(settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)) {
true -> true
false, null -> false
},
interval = settingsDataStoreImpl.getInt(SettingsConstants.WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
) }
}
}
}
@@ -0,0 +1,57 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Animation
import androidx.compose.material.icons.outlined.Palette
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
/**
* Enable animation switch
*/
@Composable
fun AnimationListItem(animate: Boolean, onAnimateClick: (Boolean) -> Unit) {
Row {
ListItem(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.clickable { onAnimateClick(!animate) },
headlineContent = {
Text(
text = "Animation",
style = MaterialTheme.typography.titleMedium
) },
supportingContent = {
Text(
text = "Increase visual appeal",
style = MaterialTheme.typography.bodySmall
) },
trailingContent = {
Switch(
modifier = Modifier.semantics { contentDescription = "Animation" },
checked = animate,
onCheckedChange = onAnimateClick,
enabled = true
) },
leadingContent = {
Icon(
Icons.Outlined.Animation,
contentDescription = "Animation",
tint = MaterialTheme.colorScheme.primary
) },
tonalElevation = 5.dp
)
}
}
@@ -0,0 +1,51 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.LibraryBooks
import androidx.compose.material.icons.outlined.LibraryBooks
import androidx.compose.material.icons.outlined.Newspaper
import androidx.compose.material.icons.outlined.PrivacyTip
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
/**
* A list item that displays the licenses
*/
@Composable
fun LicenseListItem(onLicenseClick: () -> Unit) {
Row {
ListItem(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.clickable { onLicenseClick() },
headlineContent = {
Text(
text = stringResource(R.string.licenses),
style = MaterialTheme.typography.titleMedium
) },
supportingContent = {
Text(
text = "Click here to view the licenses",
style = MaterialTheme.typography.bodySmall
) },
trailingContent = {},
leadingContent = {
Icon(
Icons.AutoMirrored.Outlined.LibraryBooks,
contentDescription = stringResource(R.string.licenses),
tint = MaterialTheme.colorScheme.primary
) },
tonalElevation = 5.dp
)
}
}
@@ -0,0 +1,49 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.PrivacyTip
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
/**
* Privacy policy card
*/
@Composable
fun PrivacyPolicyListItem(onPrivacyPolicyClick: () -> Unit) {
Row {
ListItem(
modifier = Modifier
.clip(RoundedCornerShape(16.dp))
.clickable { onPrivacyPolicyClick() },
headlineContent = {
Text(
text = stringResource(R.string.privacy_policy),
style = MaterialTheme.typography.titleMedium
) },
supportingContent = {
Text(
text = "Click here to view our privacy policy",
style = MaterialTheme.typography.bodySmall
) },
trailingContent = {},
leadingContent = {
Icon(
Icons.Outlined.PrivacyTip,
contentDescription = stringResource(R.string.privacy_policy),
tint = MaterialTheme.colorScheme.primary
) },
tonalElevation = 5.dp
)
}
}
@@ -1,24 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
/**
* Large top app bar for the settings screen. Replaced with [SettingsSmallTopAppBar] when scrolling down
*/
@Composable
fun SettingsLargeTopAppBar(
scroll: ScrollState,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier
.graphicsLayer {
translationY = -scroll.value.toFloat() / 2f
alpha = 0f
}
)
}
@@ -11,24 +11,30 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import kotlinx.coroutines.flow.StateFlow
/**
* Scrollable settings screen to wrap all settings components
*/
@Composable
fun ScrollableSettings(
fun SettingsScrollableSettings(
settingsState: StateFlow<SettingsState>,
largeTopAppBarHeightPx: Dp,
scroll: ScrollState,
onDynamicThemingClick: (Boolean) -> Unit,
onDarkModeClick: (Boolean?) -> Unit
onDarkModeClick: (Boolean?) -> Unit,
onAnimateClick: (Boolean) -> Unit,
onPrivacyClick: () -> Unit,
onLicenseClick: () -> Unit
) {
val state = settingsState.collectAsStateWithLifecycle()
val context = LocalContext.current
Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Top,
@@ -55,15 +61,18 @@ fun ScrollableSettings(
)
Spacer(modifier = Modifier.height(16.dp))
ListSectionTitle("Privacy")
//add crash reporting settings
Spacer(modifier = Modifier.height(16.dp))
DynamicThemingListItem(
dynamicTheming = state.value.dynamicTheming,
onDynamicThemingClick = { onDynamicThemingClick(it) }
AnimationListItem(
animate = state.value.animate,
onAnimateClick = { onAnimateClick(it) }
)
//GPL and License and link to github etc.
Spacer(modifier = Modifier.height(16.dp))
ListSectionTitle("About")
Spacer(modifier = Modifier.height(16.dp))
PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick)
Spacer(modifier = Modifier.height(16.dp))
LicenseListItem(onLicenseClick = onLicenseClick)
Spacer(modifier = Modifier.height(16.dp))
//GPL and License and link to github etc, contact, terms of service, privacy policy
}
}
@@ -1,118 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.startup
import android.view.textclassifier.TextLinks.TextLink
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.sharp.CheckCircleOutline
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
import com.anthonyla.paperize.R
@Composable
fun StartupScreen(
onAgree: () -> Unit
) {
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.onboarding_animation))
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever,
)
var showToS by remember { mutableStateOf(false) }
Scaffold(
content = { it
Column (modifier = Modifier.padding(32.dp)) {
Spacer(modifier = Modifier.height(120.dp))
Text(text = stringResource(R.string.welcome), style = MaterialTheme.typography.headlineLarge)
Spacer(modifier = Modifier.height(16.dp))
LottieAnimation(
composition = composition,
progress = { progress },
modifier = Modifier.fillMaxHeight(0.5f)
)
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = stringResource(R.string.agree),
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
)
Text(
text = "Please read and agree to the following terms of service and privacy policy to use the app.",
style = MaterialTheme.typography.bodySmall
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth()
) {
Button(
onClick = { showToS = true },
modifier = Modifier.padding(PaddingValues(vertical = 16.dp)),
) {
Text(text = "Terms of Service and Privacy Policy", textAlign = TextAlign.Start)
}
}
}
},
floatingActionButton = {
ExtendedFloatingActionButton(
modifier = Modifier.padding(8.dp),
onClick = onAgree,
icon = {
Icon(
imageVector = Icons.Sharp.CheckCircleOutline,
contentDescription = stringResource(R.string.agree),
)
},
text = { Text(text = stringResource(R.string.agree)) },
)
}
)
if (showToS) {
AlertDialog(
onDismissRequest = { showToS = false },
title = {
Box(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Terms of Service\nPrivacy Policy",
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center)
)
}
},
text = { Text(text = "ToS, Privacy TBD") },
confirmButton = {
Button(onClick = { showToS = false }) {
Text("Dismiss")
}
}
)
}
}
@@ -0,0 +1,210 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.startup_screen
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.sharp.CheckCircleOutline
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
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.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.animateLottieCompositionAsState
import com.airbnb.lottie.compose.rememberLottieComposition
import com.anthonyla.paperize.R
import kotlinx.coroutines.launch
@Composable
fun StartupScreen(
onAgree: () -> Unit
) {
val context = LocalContext.current
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.onboarding_animation))
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever,
)
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
var showToS by remember { mutableStateOf(false) }
var seenToS by remember { mutableStateOf(false) }
Scaffold(
snackbarHost = {
SnackbarHost(
hostState = snackbarHostState,
snackbar = { data ->
Snackbar(
snackbarData = data,
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp))
)
}
) },
content = { it
Column (modifier = Modifier.padding(32.dp)) {
Spacer(modifier = Modifier.height(120.dp))
Text(text = stringResource(R.string.welcome), style = MaterialTheme.typography.headlineLarge)
Spacer(modifier = Modifier.height(16.dp))
LottieAnimation(
composition = composition,
progress = { progress },
modifier = Modifier.fillMaxHeight(0.5f)
)
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = stringResource(R.string.agree),
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
)
Text(
text = "Please read and agree to the following privacy policy to use the app.",
style = MaterialTheme.typography.bodySmall
)
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth()
) {
Button(
onClick = {
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
showToS = true
} },
modifier = Modifier.padding(PaddingValues(vertical = 16.dp)),
) {
Text(text = "Privacy Policy", textAlign = TextAlign.Start)
}
}
}
},
floatingActionButton = {
ExtendedFloatingActionButton(
modifier = Modifier.padding(8.dp),
onClick = {
if (seenToS) {
onAgree()
} else {
scope.launch {
val result = snackbarHostState.showSnackbar(
message = "Please read and agree to the privacy policy.",
actionLabel = "View",
duration = SnackbarDuration.Short,
)
when (result) {
SnackbarResult.Dismissed -> {}
SnackbarResult.ActionPerformed -> {
showToS = true
}
}
}
}
},
icon = {
Icon(
imageVector = Icons.Sharp.CheckCircleOutline,
contentDescription = stringResource(R.string.agree),
)
},
text = { Text(text = stringResource(R.string.agree)) },
)
}
)
if (showToS) {
seenToS = true
AlertDialog(
modifier = Modifier.fillMaxHeight(0.8f),
onDismissRequest = { showToS = false },
title = {
Box(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Privacy Policy",
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center)
)
}
},
text = { PrivacyPolicyText() },
confirmButton = {
Button(
onClick = { showToS = false },
) {
Text("Dismiss")
}
}
)
}
}
@Composable
fun PrivacyPolicyText() {
LazyColumn {
item {
SectionText("Introduction", "Welcome to Paperize! This privacy policy outlines how we collect, use, and protect your personal information when you use our mobile application. By using Paperize, you agree to the terms described in this policy.")
}
item {
SectionText("Data Collection", "Notification Access: Paperize requests notification access to provide you with personalized wallpaper recommendations based on your notifications. We do not store any notification content or personally identifiable information (PII) outside of your device.\n\nLocal Files: Paperize accesses files stored on your device to allow you to set them as wallpapers. We do not upload or transfer these files to any external servers.")
}
item {
SectionText("Information Usage", "Personal Data: We do not collect or store any personal data such as names, email addresses, or phone numbers.\n\nUsage Analytics: Paperize does not track your usage behavior or collect analytics data.")
}
item {
SectionText("Data Security", "On-Device Storage: All data used by Paperize remains on your device. We do not transmit or store any data externally.\n\nEncryption: We use encryption protocols to secure communication between the app and your device.")
}
item {
SectionText("Third-Party Services", "Advertisements: Paperize does not display third-party ads.\n\nExternal Links: Our app may contain links to external websites. Please note that we are not responsible for the privacy practices of these sites.")
}
item {
SectionText("Children’s Privacy", "Paperize is not intended for children under the age of 13. We do not knowingly collect any information from children.")
}
item {
SectionText("Changes to this Policy", "We may update this privacy policy from time to time. Any changes will be reflected in the app and on our website.")
}
item {
SectionText("Contact Us", "If you have any questions or concerns about this privacy policy, please contact me at anthonyyla.dev@gmail.com.")
}
}
}
@Composable
fun SectionText(title: String, content: String) {
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
modifier = Modifier.padding(vertical = 8.dp)
)
Text(
text = content,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(bottom = 16.dp)
)
}
@@ -30,6 +30,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewMod
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SetLockScreenSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
@@ -91,27 +92,62 @@ fun WallpaperScreen(
}
)
}
item {
AnimatedVisibility(
visible = selectedState.value.selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
TimeSliders(
timeInMinutes = settingsState.value.interval,
onTimeChange = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
settingsViewModel.onEvent(SettingsEvent.SetWallpaperInterval(totalMinutes))
onScheduleWallpaperChanger(totalMinutes)
if (settingsState.value.animate) {
item {
AnimatedVisibility(
visible = selectedState.value.selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
if (selectedState.value.selectedAlbum != null) {
CurrentAndNextChange(
settingsState.value.lastSetTime,
settingsState.value.nextSetTime
)
}
)
}
AnimatedVisibility(
visible = selectedState.value.selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
if (selectedState.value.selectedAlbum != null) {
SetLockScreenSwitch(
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
checked = settingsState.value.setLockWithHome,
onCheckedChange = { isChecked ->
settingsViewModel.onEvent(SettingsEvent.SetLockWithHome(isChecked))
}
)
}
}
AnimatedVisibility(
visible = selectedState.value.selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
TimeSliders(
timeInMinutes = settingsState.value.interval,
onTimeChange = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
settingsViewModel.onEvent(
SettingsEvent.SetWallpaperInterval(totalMinutes)
)
onScheduleWallpaperChanger(totalMinutes)
}
)
}
}
AnimatedVisibility(
visible = selectedState.value.selectedAlbum != null,
enter = slideInVertically(initialOffsetY = { -it }),
exit = fadeOut()
) {
} else {
item {
if (selectedState.value.selectedAlbum != null) {
CurrentAndNextChange(
settingsState.value.lastSetTime,
settingsState.value.nextSetTime
)
}
}
item {
if (selectedState.value.selectedAlbum != null) {
SetLockScreenSwitch(
albumUri = selectedState.value.selectedAlbum!!.album.coverUri,
@@ -122,6 +158,20 @@ fun WallpaperScreen(
)
}
}
item {
TimeSliders(
timeInMinutes = settingsState.value.interval,
onTimeChange = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
settingsViewModel.onEvent(
SettingsEvent.SetWallpaperInterval(
totalMinutes
)
)
onScheduleWallpaperChanger(totalMinutes)
}
)
}
}
}
if (openBottomSheet) {
@@ -145,8 +195,6 @@ fun WallpaperScreen(
),
wallpapers = wallpapers
)
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
onScheduleWallpaperChanger(settingsState.value.interval)
openBottomSheet = false
scope.launch {
snackbarHostState.currentSnackbarData?.dismiss()
@@ -156,6 +204,8 @@ fun WallpaperScreen(
duration = SnackbarDuration.Short
)
}
wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum(newSelectedAlbum))
onScheduleWallpaperChanger(settingsState.value.interval)
}
)
}
@@ -0,0 +1,97 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
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.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.QueuePlayNext
import androidx.compose.material.icons.outlined.RemoveFromQueue
import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
@Composable
fun CurrentAndNextChange(
lastSetTime: String?,
nextSetTime: String?
) {
val textFirst = MaterialTheme.typography.bodyMedium.copy(textAlign = TextAlign.Center, fontWeight = FontWeight.W500)
val textSecond = MaterialTheme.typography.labelSmall.copy(textAlign = TextAlign.Center, fontWeight = FontWeight.W400)
Row(
horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth()
) {
Surface(
tonalElevation = 10.dp,
modifier = Modifier
.weight(1f)
.padding(PaddingValues(16.dp, 8.dp, 8.dp, 8.dp))
.clip(RoundedCornerShape(16.dp))
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier.padding(16.dp)
) {
Icon(
Icons.Outlined.RemoveFromQueue,
contentDescription = stringResource(R.string.last_change),
modifier = Modifier.padding(end = 16.dp),
tint = MaterialTheme.colorScheme.primary
)
Column {
lastSetTime?.split(" ", "\n")?.let { parts ->
if (parts.size == 3) {
Text(stringResource(R.string.last_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
Text(parts[0], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
Text("${parts[1]} ${parts[2]}", style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally)) }
}
}
}
}
Surface(
tonalElevation = 10.dp,
modifier = Modifier
.weight(1f)
.padding(PaddingValues(16.dp, 8.dp, 8.dp, 8.dp))
.clip(RoundedCornerShape(16.dp))
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier.padding(16.dp)
) {
Icon(
Icons.Outlined.QueuePlayNext,
contentDescription = stringResource(R.string.next_change),
modifier = Modifier.padding(end = 16.dp),
tint = MaterialTheme.colorScheme.primary
)
Column {
nextSetTime?.split(" ", "\n")?.let { parts ->
if (parts.size == 3) {
Text(stringResource(R.string.next_change), style = textFirst, modifier = Modifier.align(Alignment.CenterHorizontally))
Text(parts[0], style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally))
Text("${parts[1]} ${parts[2]}", style = textSecond, modifier = Modifier.align(Alignment.CenterHorizontally)) }
}
}
}
}
}
}
@@ -29,7 +29,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions
@@ -113,6 +112,6 @@ fun CurrentSelectedAlbum(
}
}
},
tonalElevation = 5.dp
tonalElevation = 10.dp
)
}
@@ -1,16 +1,14 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.shrinkVertically
import androidx.compose.animation.slideOutVertically
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.fillMaxWidth
import androidx.compose.foundation.layout.padding
@@ -22,7 +20,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.presentation.album.components.WallpaperItem
@Composable
@@ -32,17 +33,18 @@ fun SetLockScreenSwitch(
onCheckedChange: (Boolean) -> Unit
) {
Surface(
tonalElevation = 5.dp,
tonalElevation = 10.dp,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
.clip(RoundedCornerShape(16.dp))
) {
Column (horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Row {
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
Text(
text = "Set as lock screen",
modifier = Modifier.padding(16.dp)
text = stringResource(R.string.set_as_lock_screen),
modifier = Modifier.padding(16.dp),
fontWeight = FontWeight.W500
)
Switch(
checked = checked,
@@ -61,7 +63,7 @@ fun SetLockScreenSwitch(
.padding(4.dp),
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
) {
Text(text = "Lock screen")
Text(text = stringResource(R.string.lock_screen), fontWeight = FontWeight.W500)
if (albumUri != null) {
WallpaperItem(
wallpaperUri = albumUri,
@@ -80,7 +82,7 @@ fun SetLockScreenSwitch(
.padding(4.dp),
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
) {
Text(text = "Home screen")
Text(text = stringResource(R.string.home), fontWeight = FontWeight.W500)
if (albumUri != null) {
WallpaperItem(
wallpaperUri = albumUri,
@@ -19,6 +19,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@@ -38,7 +39,7 @@ fun TimeSliders(
var job by remember { mutableStateOf<Job?>(null) }
Surface(
tonalElevation = 5.dp,
tonalElevation = 10.dp,
modifier = Modifier
.padding(16.dp)
.clip(RoundedCornerShape(16.dp))
@@ -68,7 +69,8 @@ fun TimeSliders(
Text(
text = formattedTime,
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp, vertical = 12.dp))
modifier = Modifier.padding(PaddingValues(horizontal = 24.dp, vertical = 12.dp)),
fontWeight = FontWeight.W500
)
Slider(
@@ -5,11 +5,17 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.BrowseGallery
import androidx.compose.material.icons.filled.Image
import androidx.compose.material.icons.filled.Newspaper
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.PrivacyTip
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Start
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.BrowseGallery
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material.icons.outlined.Newspaper
import androidx.compose.material.icons.outlined.Notifications
import androidx.compose.material.icons.outlined.PrivacyTip
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Start
import androidx.compose.ui.graphics.vector.ImageVector
@@ -23,6 +29,15 @@ sealed class NavScreens(val route: String, @StringRes val resourceId: Int, val u
* Home screen that the user lands on initially
*/
object Startup : NavScreens("startup_screen", R.string.startup, Icons.Outlined.Start, Icons.Filled.Start)
/**
* Notification screen for the application to ask for permission
*/
object Notification : NavScreens("notification_screen", R.string.notifications, Icons.Outlined.Notifications, Icons.Filled.Notifications)
/**
* Home screen that the user lands on initially containing the wallpapers and albums
*/
object Home : NavScreens("home_screen", R.string.home_screen, Icons.Outlined.Image, Icons.Filled.Image)
/**
@@ -30,6 +45,16 @@ sealed class NavScreens(val route: String, @StringRes val resourceId: Int, val u
*/
object Settings : NavScreens("settings_screen", R.string.settings_screen, Icons.Outlined.Settings, Icons.Filled.Settings)
/**
* License screen for the application
*/
object Licenses : NavScreens("licenses_screen", R.string.licenses_screen, Icons.Outlined.Newspaper, Icons.Filled.Newspaper)
/**
* Settings screen for the application
*/
object Privacy : NavScreens("privacy_screen", R.string.privacy_screen, Icons.Outlined.PrivacyTip, Icons.Filled.PrivacyTip)
/**
* Add/Edit screen for album when adding or editing
*/
@@ -24,7 +24,7 @@ class WallpaperBootReceiver : BroadcastReceiver() {
serviceIntent.putExtra("timeInMinutes", timeInMinutes)
serviceIntent.putExtra("setLockWithHome", setLockWithHome)
}
context.startForegroundService(serviceIntent);
context.startForegroundService(serviceIntent)
}
}
}
@@ -6,6 +6,7 @@ import android.app.Service
import android.app.WallpaperManager
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.net.Uri
@@ -26,19 +27,18 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import java.io.IOException
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject
@AndroidEntryPoint
class WallpaperService: Service() {
@Inject lateinit var repository: SelectedAlbumRepository
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
private val handler = Handler(Looper.getMainLooper())
private lateinit var runnableCode: Runnable
private var timeInMinutes: Int = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
private var setLockWithHome: Boolean = false
companion object {
var isRunning = false
}
enum class Actions {
START,
STOP
@@ -54,7 +54,6 @@ class WallpaperService: Service() {
override fun onCreate() {
super.onCreate()
startForeground(1, createNotification(0, 0))
isRunning = true
runnableCode = object : Runnable {
override fun run() {
val self = this
@@ -78,10 +77,7 @@ class WallpaperService: Service() {
handler.removeCallbacks(runnableCode)
when(intent?.action) {
Actions.START.toString() -> {
isRunning = true
timeInMinutes = intent.getIntExtra("timeInMinutes", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
setLockWithHome = intent.getBooleanExtra("setLockWithHome", false)
Log.d("PaperizeWallpaperChanger", "Service started with interval $timeInMinutes minutes")
// Schedule the next wallpaper change
runnableCode = object : Runnable {
override fun run() {
@@ -100,7 +96,10 @@ class WallpaperService: Service() {
handler.post(runnableCode)
}
Actions.STOP.toString() -> {
isRunning = false
CoroutineScope(Dispatchers.IO).launch {
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
}
stopSelf()
}
}
@@ -113,15 +112,17 @@ class WallpaperService: Service() {
override fun onDestroy() {
Log.d("PaperizeWallpaperChanger", "Service destroyed")
super.onDestroy()
isRunning = false
handler.removeCallbacks(runnableCode)
CoroutineScope(Dispatchers.IO).launch {
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, "")
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, "")
}
}
/**
* Creates a notification for the wallpaper service
*/
private fun createNotification(current: Int = 0, total: Int = 0): Notification {
return NotificationCompat.Builder(this, "wallpaper_service_channel")
.setContentTitle("Paperize")
.setContentText("Rotation: $current/$total wallpapers\nInterval: ${formatTime(timeInMinutes)}")
@@ -134,6 +135,11 @@ class WallpaperService: Service() {
* If none left, reshuffle the wallpapers and pick the first one
*/
private suspend fun changeWallpaper(context: Context) {
val formatter = DateTimeFormatter.ofPattern("MM/dd/yy hh:mm\na")
val time = LocalDateTime.now()
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, time.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, time.plusMinutes(timeInMinutes.toLong()).format(formatter))
val setLockWithHome = settingsDataStoreImpl.getBoolean(SettingsConstants.SET_LOCK_WITH_HOME) ?: false
val album = repository.getSelectedAlbum().first().firstOrNull()
album?.let {
val notification = createNotification(it.album.wallpapersInQueue.size, it.wallpapers.size)