Fixed WallpaperBootAndChangeReceiver not changing wallpaper immediately

Refactored WallpaperAlarmSchedulerImpl.kt name
This commit is contained in:
Anthonyy232 committed 2024-07-19 20:28:29 -07:00
1 parent 4c3d5af7f7
commit 48a730e4a9
6 files changed
+10 -11

No files matched your search

@@ -42,7 +42,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.Wa
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
@@ -81,7 +81,7 @@ class MainActivity : ComponentActivity() {
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent {
val scheduler = WallpaperScheduler(context)
val scheduler = WallpaperAlarmSchedulerImpl(context)
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
if (isFirstLaunch) {
@@ -55,7 +55,7 @@ import com.anthonyla.paperize.feature.wallpaper.util.navigation.WallpaperView
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionIn
import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperScheduler
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@@ -65,7 +65,7 @@ import kotlinx.coroutines.withContext
@Composable
fun PaperizeApp(
firstLaunch: Boolean,
scheduler : WallpaperScheduler,
scheduler : WallpaperAlarmSchedulerImpl,
topInsets: Dp,
albumsViewModel: AlbumsViewModel = hiltViewModel(),
settingsViewModel: SettingsViewModel = hiltViewModel(),
@@ -16,7 +16,7 @@ import java.time.ZoneId
* It uses the AlarmManager to schedule alarms for the WallpaperReceiver.
* It also uses the WallpaperService to change the wallpaper due to receiver limitations.
*/
class WallpaperScheduler (
class WallpaperAlarmSchedulerImpl (
private val context: Context,
): WallpaperAlarmScheduler {
private val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
@@ -23,7 +23,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
@SuppressLint("UnsafeProtectedBroadcastReceiver")
override fun onReceive(context: Context, intent: Intent) = goAsync {
try {
val scheduler = WallpaperScheduler(context)
val scheduler = WallpaperAlarmSchedulerImpl(context)
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
if (toggleChanger) {
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
@@ -34,8 +34,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
timeInMinutes2 = timeInMinutes2,
scheduleSeparately = scheduleSeparately
)
val changeImmediate = intent.getBooleanExtra("changeImmediate", false)
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, changeImmediate, true)}
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, true, true)}
}
} catch (e: Exception) {
e.printStackTrace()
@@ -22,7 +22,7 @@ class WallpaperReceiver: BroadcastReceiver() {
action = WallpaperService1.Actions.REFRESH.toString()
}
context.startService(serviceIntent)
WallpaperScheduler(context).scheduleRefresh()
WallpaperAlarmSchedulerImpl(context).scheduleRefresh()
}
else {
val timeInMinutes1 = intent?.getIntExtra("timeInMinutes1", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
@@ -48,7 +48,7 @@ class WallpaperReceiver: BroadcastReceiver() {
// Schedule next alarm for next wallpaper change
val origin = intent?.getIntExtra("origin", -1)?.takeIf { it != -1 }
WallpaperScheduler(context).scheduleWallpaperAlarm(
WallpaperAlarmSchedulerImpl(context).scheduleWallpaperAlarm(
WallpaperAlarmItem(
timeInMinutes1 = timeInMinutes1,
timeInMinutes2 = timeInMinutes2,
@@ -28,7 +28,7 @@ class ChangeWallpaperTileService: TileService() {
override fun onClick() {
super.onClick()
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java).putExtra("changeImmediate", true)
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java)
sendBroadcast(intent)
}