Fixed service not starting
This commit is contained in:
1 parent
0a6ce5bf07
commit
3e9e8ca299
33 files changed
+348
-386
No files matched your search
@@ -1,9 +1,13 @@
|
||||
package com.anthonyla.paperize
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.database.CursorWindow
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import java.lang.reflect.Field
|
||||
|
||||
|
||||
/**
|
||||
* Application class for Hilt
|
||||
|
||||
@@ -8,6 +8,7 @@ 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
|
||||
@@ -25,10 +26,10 @@ object AppModule {
|
||||
@Singleton
|
||||
fun provideAlbumDatabase(app: Application): AlbumDatabase {
|
||||
return Room.databaseBuilder(
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).fallbackToDestructiveMigration().addMigrations().build()
|
||||
app,
|
||||
AlbumDatabase::class.java,
|
||||
AlbumDatabase.DATABASE_NAME
|
||||
).fallbackToDestructiveMigration(true).addMigrations().build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
+8
-1
@@ -6,9 +6,16 @@ import android.os.Bundle
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||
|
||||
class BroadcastActivity : Activity() {
|
||||
companion object {
|
||||
const val ACTION_CUSTOM_BROADCAST = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val intent = Intent("WallpaperBootAndChangeReceiver.intent.action.BROADCAST").setClass(this, WallpaperBootAndChangeReceiver::class.java)
|
||||
val intent = Intent(ACTION_CUSTOM_BROADCAST).apply {
|
||||
setClass(this@BroadcastActivity, WallpaperBootAndChangeReceiver::class.java)
|
||||
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
}
|
||||
sendBroadcast(intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
+7
-3
@@ -21,13 +21,17 @@ class Converters {
|
||||
* Convert json string to list of strings
|
||||
*/
|
||||
@TypeConverter
|
||||
fun jsonStringToList(value: String) = gson.fromJson(value, Array<String>::class.java).toList()
|
||||
fun jsonStringToList(value: String?): List<String> {
|
||||
if (value == null) return emptyList()
|
||||
return gson.fromJson(value, Array<String>::class.java).toList()
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromWallpaperList(value: List<Wallpaper>)= gson.toJson(value)
|
||||
fun fromWallpaperList(value: List<Wallpaper>): String? = gson.toJson(value)
|
||||
|
||||
@TypeConverter
|
||||
fun toWallpaperList(value: String): List<Wallpaper> {
|
||||
fun toWallpaperList(value: String?): List<Wallpaper> {
|
||||
if (value == null) return emptyList()
|
||||
val listType = object : TypeToken<List<Wallpaper>>() {}.type
|
||||
return gson.fromJson(value, listType)
|
||||
}
|
||||
|
||||
+9
-5
@@ -2,11 +2,13 @@ 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.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.database.CursorWindow
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
@@ -35,7 +37,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
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.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
@@ -45,6 +46,7 @@ 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
|
||||
|
||||
|
||||
@@ -104,7 +106,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleWallpaperScheduling(
|
||||
private suspend fun handleWallpaperScheduling(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
@@ -125,7 +127,7 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleWallpaperAlarm(
|
||||
private suspend fun scheduleWallpaperAlarm(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
@@ -139,12 +141,14 @@ class MainActivity : ComponentActivity() {
|
||||
setHome = wallpaperSettings.setHomeWallpaper,
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
changeStartTime = scheduleSettings.changeStartTime,
|
||||
startTime = scheduleSettings.startTime
|
||||
startTime = scheduleSettings.startTime,
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
firstLaunch = true,
|
||||
homeNextTime = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME),
|
||||
lockNextTime = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME)
|
||||
)
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
}
|
||||
|
||||
+8
-20
@@ -33,7 +33,6 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.folder_view_screen.FolderViewModel
|
||||
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.notifications_screen.NotificationScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.privacy_screen.PrivacyScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
@@ -49,7 +48,6 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.AddAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.AlbumView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.FolderView
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Home
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Licenses
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Notification
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Privacy
|
||||
import com.anthonyla.paperize.feature.wallpaper.util.navigation.Settings
|
||||
@@ -521,8 +519,8 @@ fun PaperizeApp(
|
||||
onConfirmation = {
|
||||
navController.navigateUp()
|
||||
},
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
onShowWallpaperView = { uri, name ->
|
||||
navController.navigate(WallpaperView(uri, name))
|
||||
},
|
||||
onShowFolderView = { folder ->
|
||||
if (folder.wallpapers.isNotEmpty()) {
|
||||
@@ -544,7 +542,8 @@ fun PaperizeApp(
|
||||
animatedScreen<WallpaperView>(animate = settingsState.value.themeSettings.animate) { backStackEntry ->
|
||||
val wallpaperView: WallpaperView = backStackEntry.toRoute()
|
||||
WallpaperViewScreen(
|
||||
wallpaperUri = wallpaperView.wallpaper,
|
||||
wallpaperUri = wallpaperView.wallpaperUri,
|
||||
wallpaperName = wallpaperView.wallpaperName,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
animate = settingsState.value.themeSettings.animate
|
||||
)
|
||||
@@ -559,8 +558,8 @@ fun PaperizeApp(
|
||||
FolderViewScreen(
|
||||
folder = folderState.value.folder!!,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
onShowWallpaperView = { uri, name ->
|
||||
navController.navigate(WallpaperView(uri, name))
|
||||
},
|
||||
animate = settingsState.value.themeSettings.animate
|
||||
)
|
||||
@@ -606,8 +605,8 @@ fun PaperizeApp(
|
||||
albumScreenViewModel = albumScreenViewModel ,
|
||||
animate = settingsState.value.themeSettings.animate,
|
||||
onBackClick = { navController.navigateUp() },
|
||||
onShowWallpaperView = {
|
||||
navController.navigate(WallpaperView(it))
|
||||
onShowWallpaperView = { uri, name ->
|
||||
navController.navigate(WallpaperView(uri, name))
|
||||
},
|
||||
onShowFolderView = { folder ->
|
||||
if (folder.wallpapers.isNotEmpty()) {
|
||||
@@ -649,9 +648,6 @@ fun PaperizeApp(
|
||||
onPrivacyClick = {
|
||||
navController.navigate(Privacy)
|
||||
},
|
||||
onLicenseClick = {
|
||||
navController.navigate(Licenses)
|
||||
},
|
||||
onContactClick = {
|
||||
SendContactIntent(context)
|
||||
},
|
||||
@@ -676,13 +672,6 @@ fun PaperizeApp(
|
||||
onBackClick = { navController.navigateUp() },
|
||||
)
|
||||
}
|
||||
|
||||
// Navigate to the licenses screen to view the licenses of the libraries used
|
||||
animatedScreen<Licenses>(animate = settingsState.value.themeSettings.animate) {
|
||||
LicensesScreen(
|
||||
onBackClick = { navController.navigateUp() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,7 +690,6 @@ private fun CoroutineScope.scheduleWallpaperUpdate(
|
||||
job?.cancel()
|
||||
return launch {
|
||||
if (delay > 0) delay(delay)
|
||||
|
||||
if (refreshNextTime) {
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
}
|
||||
|
||||
+2
-2
@@ -47,7 +47,7 @@ fun AddAlbumScreen(
|
||||
initialAlbumName: String,
|
||||
onBackClick: () -> Unit,
|
||||
onConfirmation: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
onShowFolderView: (Folder) -> Unit,
|
||||
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
|
||||
animate: Boolean
|
||||
@@ -234,7 +234,7 @@ fun AddAlbumScreen(
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
if (!addAlbumState.value.isLoading) {
|
||||
onShowWallpaperView(it.wallpaperUri)
|
||||
onShowWallpaperView(it.wallpaperUri, it.fileName)
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
|
||||
+2
-3
@@ -35,6 +35,7 @@ import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -101,9 +102,7 @@ fun AddAlbumSmallTopBar(
|
||||
}
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = {
|
||||
if (!selectionMode) {
|
||||
TextField(
|
||||
|
||||
+17
-2
@@ -66,10 +66,25 @@ class AlbumsViewModel @Inject constructor (
|
||||
repository.updateAlbum(
|
||||
event.album.album.copy(
|
||||
selected = true,
|
||||
homeWallpapersInQueue = homeWallpapers,
|
||||
lockWallpapersInQueue = lockWallpapers
|
||||
lockWallpapersInQueue = lockWallpapers,
|
||||
homeWallpapersInQueue = homeWallpapers
|
||||
)
|
||||
)
|
||||
|
||||
_state.value.albumsWithWallpapers
|
||||
.filter { it.album.initialAlbumName != event.album.album.initialAlbumName }
|
||||
.forEach { album ->
|
||||
val otherHomeWallpapers = if (event.shuffle) album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
val otherLockWallpapers = if (event.shuffle) album.totalWallpapers.shuffled().map { it.wallpaperUri }
|
||||
else album.sortedTotalWallpapers.map { it.wallpaperUri }
|
||||
repository.updateAlbum(
|
||||
album.album.copy(
|
||||
lockWallpapersInQueue = otherLockWallpapers,
|
||||
homeWallpapersInQueue = otherHomeWallpapers
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ fun AlbumViewScreen(
|
||||
albumScreenViewModel: AlbumScreenViewModel,
|
||||
animate: Boolean,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
onShowFolderView: (Folder) -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onSortClick: (List<Folder>, List<Wallpaper>) -> Unit,
|
||||
@@ -237,7 +237,7 @@ fun AlbumViewScreen(
|
||||
},
|
||||
onWallpaperViewClick = {
|
||||
if (!albumViewState.value.isLoading)
|
||||
onShowWallpaperView(album.wallpapers[index].wallpaperUri)
|
||||
onShowWallpaperView(album.wallpapers[index].wallpaperUri, album.wallpapers[index].fileName)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -68,7 +69,7 @@ fun AlbumViewTopBar(
|
||||
var showSelectionDeleteDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = { if (!selectionMode) Text(title) },
|
||||
navigationIcon = {
|
||||
if (!selectionMode) {
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import my.nanihadesuka.compose.ScrollbarSettings
|
||||
fun FolderViewScreen(
|
||||
folder: Folder,
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowWallpaperView: (String, String) -> Unit,
|
||||
animate: Boolean
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
@@ -69,7 +69,7 @@ fun FolderViewScreen(
|
||||
allowHapticFeedback = false,
|
||||
onItemSelection = {},
|
||||
onWallpaperViewClick = {
|
||||
onShowWallpaperView(wallpaper.wallpaperUri)
|
||||
onShowWallpaperView(wallpaper.wallpaperUri, wallpaper.fileName)
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
|
||||
+3
-1
@@ -11,6 +11,8 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -27,7 +29,7 @@ fun FolderViewTopBar(
|
||||
onBackClick: () -> Unit
|
||||
) {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = { Text(title) },
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.licenses_screen
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.lazy.rememberLazyListState
|
||||
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.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
|
||||
import com.mikepenz.aboutlibraries.ui.compose.m3.LibraryDefaults
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LicensesScreen(
|
||||
onBackClick: () -> Unit,
|
||||
) {
|
||||
val lazyListState = rememberLazyListState()
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
scrollStrategy = ScrollStrategy.ExitUntilCollapsed,
|
||||
toolbar = {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(id = R.string.home_screen)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.licenses),
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
fontSize = textSize,
|
||||
modifier = Modifier
|
||||
.road(Alignment.CenterStart, Alignment.BottomStart)
|
||||
.padding(dynamicPaddingStart, 16.dp, 16.dp, 16.dp),
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-10
@@ -27,7 +27,6 @@ import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -41,7 +40,6 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.com
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DarkModeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DynamicThemingListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.LicenseListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ListSectionTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.NotificationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PaperizeListItem
|
||||
@@ -78,7 +76,6 @@ private fun calculateToolbarValues(collapseFraction: Float) = with(ToolbarConfig
|
||||
Pair(dynamicPaddingStart, textSize)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
themeSettings: ThemeSettings,
|
||||
@@ -88,7 +85,6 @@ fun SettingsScreen(
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit
|
||||
) {
|
||||
@@ -138,7 +134,6 @@ fun SettingsScreen(
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick,
|
||||
onContactClick = onContactClick,
|
||||
context = context
|
||||
@@ -155,7 +150,6 @@ private fun SettingsContent(
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
context: android.content.Context
|
||||
@@ -169,7 +163,7 @@ private fun SettingsContent(
|
||||
.padding(horizontal = 24.dp)
|
||||
) {
|
||||
AppearanceSection(themeSettings, onDarkModeClick, onAmoledClick, onDynamicThemingClick, onAnimateClick)
|
||||
AboutSection(context, onPrivacyClick, onLicenseClick, onContactClick, onResetClick)
|
||||
AboutSection(context, onPrivacyClick, onContactClick, onResetClick)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +205,6 @@ private fun AppearanceSection(
|
||||
private fun AboutSection(
|
||||
context: android.content.Context,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onResetClick: () -> Unit
|
||||
) {
|
||||
@@ -231,8 +224,6 @@ private fun AboutSection(
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem(onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LicenseListItem(onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
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.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 = stringResource(R.string.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
|
||||
)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -17,6 +17,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -45,7 +46,7 @@ fun SortViewTopBar(
|
||||
var showSortMenu by remember { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
colors = topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)),
|
||||
title = { Text(title) },
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
|
||||
+18
-2
@@ -15,10 +15,13 @@ import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -26,6 +29,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.net.toUri
|
||||
import com.anthonyla.paperize.R
|
||||
@@ -43,18 +47,30 @@ import net.engawapg.lib.zoomable.zoomable
|
||||
@Composable
|
||||
fun WallpaperViewScreen(
|
||||
wallpaperUri: String,
|
||||
wallpaperName: String,
|
||||
onBackClick: () -> Unit,
|
||||
animate : Boolean
|
||||
) {
|
||||
val showUri = isValidUri(LocalContext.current, wallpaperUri)
|
||||
val zoomState = rememberZoomState()
|
||||
|
||||
BackHandler { onBackClick() }
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(containerColor = Color.Transparent),
|
||||
title = {},
|
||||
colors = topAppBarColors(containerColor = Color.Transparent),
|
||||
title = {
|
||||
if (zoomState.scale == 1f) {
|
||||
Text(
|
||||
text = wallpaperName,
|
||||
color = Color.White,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(
|
||||
onClick = onBackClick,
|
||||
|
||||
+9
-2
@@ -35,11 +35,18 @@ class ActivityConfigBasicAction : Activity(), TaskerPluginConfigNoInput {
|
||||
}
|
||||
|
||||
class ShortcutActionRunner : TaskerPluginRunnerActionNoOutputOrInput() {
|
||||
companion object {
|
||||
private const val ACTION_CHANGE_WALLPAPER = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
|
||||
override fun run(context: Context, input: TaskerInput<Unit>): TaskerPluginResult<Unit> {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
val intent = Intent(context, WallpaperBootAndChangeReceiver::class.java)
|
||||
val intent = Intent(ACTION_CHANGE_WALLPAPER).apply {
|
||||
setClass(context, WallpaperBootAndChangeReceiver::class.java)
|
||||
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
}
|
||||
context.sendBroadcast(intent)
|
||||
}
|
||||
return TaskerPluginResultSucess()
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,6 +2,6 @@ package com.anthonyla.paperize.feature.wallpaper.util.navigation
|
||||
|
||||
object NavConstants {
|
||||
const val NAVIGATION_TIME: Int = 300
|
||||
const val INITIAL_OFFSET = 0.15f
|
||||
const val INITIAL_OFFSET = 0.175f
|
||||
const val OFFSET_LIMIT = 0.4f
|
||||
}
|
||||
+1
-7
@@ -27,12 +27,6 @@ object Home
|
||||
@Serializable
|
||||
object Settings
|
||||
|
||||
/**
|
||||
* Object for Licenses screen
|
||||
*/
|
||||
@Serializable
|
||||
object Licenses
|
||||
|
||||
/**
|
||||
* Object for Privacy screen
|
||||
*/
|
||||
@@ -55,7 +49,7 @@ data class AddAlbum(val initialAlbumName: String)
|
||||
* Data class for WallpaperView screen
|
||||
*/
|
||||
@Serializable
|
||||
data class WallpaperView(val wallpaper: String)
|
||||
data class WallpaperView(val wallpaperUri: String, val wallpaperName: String)
|
||||
|
||||
/**
|
||||
* Object for FolderView screen
|
||||
|
||||
+10
-1
@@ -10,7 +10,16 @@ interface WallpaperAlarmScheduler {
|
||||
* @param setAlarm whether to set the alarm or not
|
||||
* @param firstLaunch whether this is the first launch of the wallpaper changer
|
||||
*/
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false, setAlarm: Boolean = true, firstLaunch: Boolean = false)
|
||||
suspend fun scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem: WallpaperAlarmItem,
|
||||
origin: Int? = null,
|
||||
changeImmediate: Boolean = false,
|
||||
cancelImmediate: Boolean = false,
|
||||
setAlarm: Boolean = true,
|
||||
firstLaunch: Boolean = false,
|
||||
homeNextTime: String? = "",
|
||||
lockNextTime: String? = "",
|
||||
)
|
||||
|
||||
/**
|
||||
* Update the wallpaper alarm with new times without changing the wallpaper
|
||||
|
||||
+71
-24
@@ -5,12 +5,12 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import javax.inject.Inject
|
||||
|
||||
data class ServiceConfig(
|
||||
val homeInterval: Int? = null,
|
||||
@@ -29,21 +29,23 @@ sealed class WallpaperAction {
|
||||
* It uses the AlarmManager to schedule alarms for the [WallpaperReceiver].
|
||||
* It also uses [HomeWallpaperService] and [LockWallpaperService] to change the wallpaper due to receiver limitations.
|
||||
*/
|
||||
class WallpaperAlarmSchedulerImpl (
|
||||
private val context: Context,
|
||||
class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
private val context: Context
|
||||
): WallpaperAlarmScheduler {
|
||||
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on the origin and changeImmediate
|
||||
*/
|
||||
override fun scheduleWallpaperAlarm(
|
||||
override suspend fun scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem: WallpaperAlarmItem,
|
||||
origin: Int?,
|
||||
changeImmediate: Boolean,
|
||||
cancelImmediate: Boolean,
|
||||
setAlarm: Boolean,
|
||||
firstLaunch: Boolean
|
||||
firstLaunch: Boolean,
|
||||
homeNextTime: String?,
|
||||
lockNextTime: String?,
|
||||
) {
|
||||
// Cancel previous alarms before setting new ones to prevent stale alarms
|
||||
if (cancelImmediate) cancelWallpaperAlarm()
|
||||
@@ -64,11 +66,11 @@ class WallpaperAlarmSchedulerImpl (
|
||||
when (origin) {
|
||||
Type.LOCK.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin, firstLaunch)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin, firstLaunch, homeNextTime, lockNextTime)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin, firstLaunch)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin, firstLaunch, homeNextTime, lockNextTime)
|
||||
}
|
||||
null -> {
|
||||
if (changeImmediate) {
|
||||
@@ -76,15 +78,15 @@ class WallpaperAlarmSchedulerImpl (
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
}
|
||||
if (setAlarm) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal, firstLaunch, homeNextTime, lockNextTime)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal, firstLaunch, homeNextTime, lockNextTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.SINGLE)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch, homeNextTime, lockNextTime)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,11 +96,11 @@ class WallpaperAlarmSchedulerImpl (
|
||||
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, firstLaunch: Boolean) {
|
||||
cancelWallpaperAlarm()
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, firstLaunch, "", "")
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, firstLaunch, "", "")
|
||||
}
|
||||
else {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch, "", "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +132,9 @@ class WallpaperAlarmSchedulerImpl (
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on type and time
|
||||
*/
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, firstLaunch: Boolean = false) {
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, firstLaunch: Boolean = false, homeNextTime: String? = null, lockNextTime: String? = null) {
|
||||
try {
|
||||
val nextTime = calculateNextAlarmTime(wallpaperAlarmItem, type, firstLaunch)
|
||||
val nextTime = calculateNextAlarmTime(wallpaperAlarmItem, type, firstLaunch, homeNextTime ?: "", lockNextTime ?: "")
|
||||
val intent = createWallpaperIntent(wallpaperAlarmItem, type, origin)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
@@ -148,21 +150,66 @@ class WallpaperAlarmSchedulerImpl (
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateNextAlarmTime(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, firstLaunch: Boolean): LocalDateTime {
|
||||
private fun calculateNextAlarmTime(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, firstLaunch: Boolean, homeNextTime: String, lockNextTime: String): LocalDateTime {
|
||||
val startTime = LocalDateTime.now()
|
||||
return when {
|
||||
wallpaperAlarmItem.changeStartTime && firstLaunch -> {
|
||||
startTime.withHour(wallpaperAlarmItem.startTime.first)
|
||||
|
||||
if (firstLaunch) {
|
||||
if (wallpaperAlarmItem.changeStartTime) {
|
||||
return startTime.withHour(wallpaperAlarmItem.startTime.first)
|
||||
.withMinute(wallpaperAlarmItem.startTime.second)
|
||||
.let { if (it.isBefore(startTime)) it.plusDays(1) else it }
|
||||
.withSecond(0)
|
||||
.withNano(0)
|
||||
}
|
||||
type == Type.LOCK && wallpaperAlarmItem.scheduleSeparately ->
|
||||
startTime.plusMinutes(wallpaperAlarmItem.lockInterval.toLong()).withSecond(0).withNano(0)
|
||||
type == Type.HOME && wallpaperAlarmItem.scheduleSeparately ->
|
||||
startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).plusSeconds(10).withNano(0)
|
||||
else -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).plusSeconds(10).withNano(0)
|
||||
return when {
|
||||
type == Type.LOCK && wallpaperAlarmItem.scheduleSeparately ->
|
||||
startTime.plusMinutes(wallpaperAlarmItem.lockInterval.toLong()).withSecond(0).withNano(0)
|
||||
type == Type.HOME && wallpaperAlarmItem.scheduleSeparately ->
|
||||
startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).withSecond(0).withNano(0).plusSeconds(10)
|
||||
else -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).withSecond(0).withNano(0)
|
||||
}
|
||||
}
|
||||
else {
|
||||
fun calculateFutureTime(baseTime: LocalDateTime, intervalMinutes: Long, addSeconds: Int = 0, depth: Int = 0): LocalDateTime {
|
||||
if (depth > 100) {
|
||||
return startTime.plusMinutes(intervalMinutes)
|
||||
}
|
||||
|
||||
var nextTime = baseTime.plusMinutes(intervalMinutes).withSecond(0).withNano(0)
|
||||
if (addSeconds > 0) nextTime = nextTime.plusSeconds(addSeconds.toLong())
|
||||
|
||||
return if (nextTime.isBefore(startTime)) {
|
||||
calculateFutureTime(nextTime, intervalMinutes, addSeconds, depth + 1)
|
||||
} else nextTime
|
||||
}
|
||||
|
||||
val nextTime = when {
|
||||
type == Type.LOCK && wallpaperAlarmItem.scheduleSeparately -> {
|
||||
val baseTime = try {
|
||||
if (lockNextTime.isEmpty()) startTime else LocalDateTime.parse(lockNextTime)
|
||||
} catch (e: Exception) {
|
||||
startTime
|
||||
}
|
||||
calculateFutureTime(baseTime, wallpaperAlarmItem.lockInterval.toLong())
|
||||
}
|
||||
type == Type.HOME && wallpaperAlarmItem.scheduleSeparately -> {
|
||||
val baseTime = try {
|
||||
if (homeNextTime.isEmpty()) startTime else LocalDateTime.parse(homeNextTime)
|
||||
} catch (e: Exception) {
|
||||
startTime
|
||||
}
|
||||
calculateFutureTime(baseTime, wallpaperAlarmItem.homeInterval.toLong(), 10)
|
||||
}
|
||||
else -> {
|
||||
val baseTime = try {
|
||||
if (homeNextTime.isEmpty()) startTime else LocalDateTime.parse(homeNextTime)
|
||||
} catch (e: Exception) {
|
||||
startTime
|
||||
}
|
||||
calculateFutureTime(baseTime, wallpaperAlarmItem.homeInterval.toLong())
|
||||
}
|
||||
}
|
||||
return nextTime
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-25
@@ -19,35 +19,46 @@ import kotlin.coroutines.EmptyCoroutineContext
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
|
||||
companion object {
|
||||
const val ACTION_SHORTCUT = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
@SuppressLint("UnsafeProtectedBroadcastReceiver")
|
||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||
try {
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val selectedAlbum = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: ""
|
||||
when(intent.action) {
|
||||
Intent.ACTION_BOOT_COMPLETED,
|
||||
Intent.ACTION_TIME_CHANGED,
|
||||
Intent.ACTION_TIMEZONE_CHANGED,
|
||||
ACTION_SHORTCUT -> {
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||
val selectedAlbum = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: ""
|
||||
|
||||
if (selectedAlbum.isNotEmpty()) {
|
||||
val homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setLock = setLock,
|
||||
setHome = setHome
|
||||
)
|
||||
alarmItem.let{
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
setAlarm = toggleChanger
|
||||
)
|
||||
if (selectedAlbum.isNotEmpty()) {
|
||||
val homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setLock = setLock,
|
||||
setHome = setHome
|
||||
)
|
||||
alarmItem.let{
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
setAlarm = toggleChanger,
|
||||
homeNextTime = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME),
|
||||
lockNextTime = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
+33
-19
@@ -1,20 +1,34 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.Service.NOTIFICATION_SERVICE
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.core.Type
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.HomeWallpaperService
|
||||
import com.anthonyla.paperize.feature.wallpaper.wallpaper_service.LockWallpaperService
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Receiver for the alarm manager to change wallpaper
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class WallpaperReceiver: BroadcastReceiver() {
|
||||
class WallpaperReceiver : BroadcastReceiver() {
|
||||
@Inject
|
||||
lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context != null) {
|
||||
if (intent?.getBooleanExtra("refresh", false) == true) {
|
||||
@@ -23,8 +37,7 @@ class WallpaperReceiver: BroadcastReceiver() {
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleRefresh()
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
val homeInterval = intent?.getIntExtra("homeInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = intent?.getIntExtra("lockInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val scheduleSeparately = intent?.getBooleanExtra("scheduleSeparately", false) ?: false
|
||||
@@ -49,25 +62,26 @@ class WallpaperReceiver: BroadcastReceiver() {
|
||||
|
||||
// Schedule next alarm for next wallpaper change
|
||||
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
changeStartTime = changeStartTime,
|
||||
startTime = Pair(startTime[0], startTime[1]),
|
||||
),
|
||||
origin
|
||||
)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setHome = setHome,
|
||||
setLock = setLock,
|
||||
changeStartTime = changeStartTime,
|
||||
startTime = Pair(startTime[0], startTime[1]),
|
||||
),
|
||||
origin = origin,
|
||||
homeNextTime = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME),
|
||||
lockNextTime = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service to change the wallpaper
|
||||
*/
|
||||
private fun startService(context: Context, serviceClass: Class<*>, action: String, homeInterval: Int? = null, lockInterval: Int? = null, scheduleSeparately: Boolean? = null, type: Int? = null) {
|
||||
val serviceIntent = Intent(context, serviceClass).apply {
|
||||
this.action = action
|
||||
|
||||
+4
-4
@@ -136,7 +136,9 @@ class HomeWallpaperService: Service() {
|
||||
// Creates a notification for the wallpaper service
|
||||
private fun createNotification(nextSetTime: LocalDateTime?): android.app.Notification? {
|
||||
nextSetTime?.let {
|
||||
val changeWallpaperIntent = Intent(this, WallpaperBootAndChangeReceiver::class.java)
|
||||
val changeWallpaperIntent = Intent(this, WallpaperBootAndChangeReceiver::class.java).apply {
|
||||
action = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
val pendingChangeWallpaperIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
0,
|
||||
@@ -150,11 +152,8 @@ class HomeWallpaperService: Service() {
|
||||
mainActivityIntent,
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val formattedNextSetTime = nextSetTime.format(formatter)
|
||||
|
||||
// Build the notification
|
||||
return NotificationCompat.Builder(this, "wallpaper_service_channel").apply {
|
||||
setContentTitle(getString(R.string.app_name))
|
||||
setContentText(getString(R.string.next_wallpaper_change, formattedNextSetTime))
|
||||
@@ -596,6 +595,7 @@ class HomeWallpaperService: Service() {
|
||||
*/
|
||||
private fun refreshAlbum(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
Log.d("PaperizeWallpaperChanger", "Refreshing album")
|
||||
try {
|
||||
val albumWithWallpapers = albumRepository.getAlbumsWithWallpaperAndFolder().first()
|
||||
albumWithWallpapers.forEach { album ->
|
||||
|
||||
+10
-2
@@ -12,7 +12,12 @@ import javax.inject.Inject
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class ChangeWallpaperTileService: TileService() {
|
||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
companion object {
|
||||
const val ACTION_CHANGE_WALLPAPER = "com.anthonyla.paperize.SHORTCUT"
|
||||
}
|
||||
|
||||
@Inject
|
||||
lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
|
||||
override fun onTileAdded() {
|
||||
super.onTileAdded()
|
||||
@@ -28,7 +33,10 @@ class ChangeWallpaperTileService: TileService() {
|
||||
|
||||
override fun onClick() {
|
||||
super.onClick()
|
||||
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java)
|
||||
val intent = Intent(ACTION_CHANGE_WALLPAPER).apply {
|
||||
setClass(this@ChangeWallpaperTileService, WallpaperBootAndChangeReceiver::class.java)
|
||||
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
|
||||
}
|
||||
sendBroadcast(intent)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user