Added quick-setting tile for changing wallpaper
This commit is contained in:
1 parent
cd06c87263
commit
984e34f425
3 files changed
+63
-17
No files matched your search
@@ -30,7 +30,15 @@
|
|||||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver" />
|
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperReceiver" />
|
||||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService1"/>
|
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService1"/>
|
||||||
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService2"/>
|
<service android:name=".feature.wallpaper.wallpaper_service.WallpaperService2"/>
|
||||||
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndTimeChangeReceiver"
|
<service
|
||||||
|
android:name=".feature.wallpaper.wallpaper_tile.ChangeWallpaperTileService"
|
||||||
|
android:exported="true"
|
||||||
|
android:label="@string/change_wallpaper"
|
||||||
|
android:icon="@drawable/notification_icon"
|
||||||
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||||
|
<intent-filter> <action android:name="android.service.quicksettings.action.QS_TILE" /> </intent-filter>
|
||||||
|
</service>
|
||||||
|
<receiver android:name=".feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
|||||||
+16
-16
@@ -2,6 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
import com.anthonyla.paperize.core.SettingsConstants
|
import com.anthonyla.paperize.core.SettingsConstants
|
||||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
@@ -14,27 +15,26 @@ import kotlin.coroutines.CoroutineContext
|
|||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receiver for boot and time change events to restart alarm manager
|
* Receiver for boot and time change and wallpaper change events to restart alarm manager
|
||||||
*/
|
*/
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class WallpaperBootAndTimeChangeReceiver : BroadcastReceiver() {
|
class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
|
||||||
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||||
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
override fun onReceive(context: Context, intent: Intent) = goAsync {
|
||||||
try {
|
try {
|
||||||
if (Intent.ACTION_BOOT_COMPLETED == intent.action || Intent.ACTION_TIME_CHANGED == intent.action || Intent.ACTION_TIMEZONE_CHANGED == intent.action) {
|
val scheduler = WallpaperScheduler(context)
|
||||||
val scheduler = WallpaperScheduler(context)
|
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
||||||
val toggleChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false
|
if (toggleChanger) {
|
||||||
if (toggleChanger) {
|
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||||
val timeInMinutes1 = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
val timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||||
val timeInMinutes2 = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
val alarmItem = WallpaperAlarmItem(
|
||||||
val alarmItem = WallpaperAlarmItem(
|
timeInMinutes1 = timeInMinutes1,
|
||||||
timeInMinutes1 = timeInMinutes1,
|
timeInMinutes2 = timeInMinutes2,
|
||||||
timeInMinutes2 = timeInMinutes2,
|
scheduleSeparately = scheduleSeparately
|
||||||
scheduleSeparately = scheduleSeparately
|
)
|
||||||
)
|
val changeImmediate = intent.getBooleanExtra("changeImmediate", false)
|
||||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, false, true)}
|
alarmItem.let{scheduler.scheduleWallpaperAlarm(it, null, changeImmediate, true)}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package com.anthonyla.paperize.feature.wallpaper.wallpaper_tile
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.service.quicksettings.TileService
|
||||||
|
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||||
|
import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperBootAndChangeReceiver
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service for the quick settings tile to change the wallpaper
|
||||||
|
*/
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class ChangeWallpaperTileService: TileService() {
|
||||||
|
@Inject lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||||
|
|
||||||
|
override fun onTileAdded() {
|
||||||
|
super.onTileAdded()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartListening() {
|
||||||
|
super.onStartListening()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStopListening() {
|
||||||
|
super.onStopListening()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick() {
|
||||||
|
super.onClick()
|
||||||
|
val intent = Intent(this, WallpaperBootAndChangeReceiver::class.java).putExtra("changeImmediate", true)
|
||||||
|
sendBroadcast(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTileRemoved() {
|
||||||
|
super.onTileRemoved()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user