#1341 - Fix UI glitches with widget

This commit is contained in:
moezbhatti
2018-11-18 20:13:48 -05:00
parent e610a373ca
commit 7bc0b2181b
7 changed files with 40 additions and 17 deletions
@@ -18,6 +18,8 @@
*/
package com.moez.QKSMS.manager
import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import com.klinker.android.send_message.BroadcastUtils
@@ -29,4 +31,13 @@ class WidgetManagerImpl @Inject constructor(private val context: Context) : Widg
BroadcastUtils.sendExplicitBroadcast(context, Intent(), WidgetManager.ACTION_NOTIFY_DATASET_CHANGED)
}
override fun updateTheme() {
val ids = AppWidgetManager.getInstance(context)
.getAppWidgetIds(ComponentName("com.moez.QKSMS", "com.moez.QKSMS.feature.widget.WidgetProvider"))
val intent = Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
BroadcastUtils.sendExplicitBroadcast(context, intent, AppWidgetManager.ACTION_APPWIDGET_UPDATE)
}
}
@@ -22,6 +22,7 @@ import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import com.moez.QKSMS.manager.WidgetManager
import com.moez.QKSMS.receiver.NightModeReceiver
import java.text.SimpleDateFormat
import java.util.*
@@ -32,7 +33,8 @@ import javax.inject.Singleton
@Singleton
class NightModeManager @Inject constructor(
private val context: Context,
private val prefs: Preferences) {
private val prefs: Preferences,
private val widgetManager: WidgetManager) {
fun updateCurrentTheme() {
// If night mode is not on auto, then there's nothing to do here
@@ -45,6 +47,7 @@ class NightModeManager @Inject constructor(
// If the last nightStart was more recent than the last nightEnd, then it's night time
prefs.night.set(nightStartTime > nightEndTime)
widgetManager.updateTheme()
}
fun updateNightMode(mode: Int) {
@@ -53,6 +56,7 @@ class NightModeManager @Inject constructor(
// If it's not on auto mode, set the appropriate night mode
if (mode != Preferences.NIGHT_MODE_AUTO) {
prefs.night.set(mode == Preferences.NIGHT_MODE_ON)
widgetManager.updateTheme()
}
updateAlarms()