forked from upstream-mirrors/quik
#1341 - Fix UI glitches with widget
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.manager
|
package com.moez.QKSMS.manager
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.klinker.android.send_message.BroadcastUtils
|
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)
|
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.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import com.moez.QKSMS.manager.WidgetManager
|
||||||
import com.moez.QKSMS.receiver.NightModeReceiver
|
import com.moez.QKSMS.receiver.NightModeReceiver
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -32,7 +33,8 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class NightModeManager @Inject constructor(
|
class NightModeManager @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val prefs: Preferences) {
|
private val prefs: Preferences,
|
||||||
|
private val widgetManager: WidgetManager) {
|
||||||
|
|
||||||
fun updateCurrentTheme() {
|
fun updateCurrentTheme() {
|
||||||
// If night mode is not on auto, then there's nothing to do here
|
// 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
|
// If the last nightStart was more recent than the last nightEnd, then it's night time
|
||||||
prefs.night.set(nightStartTime > nightEndTime)
|
prefs.night.set(nightStartTime > nightEndTime)
|
||||||
|
widgetManager.updateTheme()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateNightMode(mode: Int) {
|
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 it's not on auto mode, set the appropriate night mode
|
||||||
if (mode != Preferences.NIGHT_MODE_AUTO) {
|
if (mode != Preferences.NIGHT_MODE_AUTO) {
|
||||||
prefs.night.set(mode == Preferences.NIGHT_MODE_ON)
|
prefs.night.set(mode == Preferences.NIGHT_MODE_ON)
|
||||||
|
widgetManager.updateTheme()
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAlarms()
|
updateAlarms()
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ interface WidgetManager {
|
|||||||
|
|
||||||
fun updateUnreadCount()
|
fun updateUnreadCount()
|
||||||
|
|
||||||
|
fun updateTheme()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -151,8 +151,6 @@
|
|||||||
<receiver android:name=".feature.widget.WidgetProvider">
|
<receiver android:name=".feature.widget.WidgetProvider">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="com.moez.QKSMS.intent.action.ACTION_NOTIFY_DATASET_CHANGED" />
|
<action android:name="com.moez.QKSMS.intent.action.ACTION_NOTIFY_DATASET_CHANGED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
|||||||
+13
-3
@@ -23,6 +23,7 @@ import com.moez.QKSMS.common.Navigator
|
|||||||
import com.moez.QKSMS.common.base.QkPresenter
|
import com.moez.QKSMS.common.base.QkPresenter
|
||||||
import com.moez.QKSMS.common.util.BillingManager
|
import com.moez.QKSMS.common.util.BillingManager
|
||||||
import com.moez.QKSMS.common.util.Colors
|
import com.moez.QKSMS.common.util.Colors
|
||||||
|
import com.moez.QKSMS.manager.WidgetManager
|
||||||
import com.moez.QKSMS.util.Preferences
|
import com.moez.QKSMS.util.Preferences
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
@@ -31,11 +32,12 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
class ThemePickerPresenter @Inject constructor(
|
class ThemePickerPresenter @Inject constructor(
|
||||||
@Named("threadId") threadId: Long,
|
|
||||||
prefs: Preferences,
|
prefs: Preferences,
|
||||||
|
@Named("threadId") private val threadId: Long,
|
||||||
private val billingManager: BillingManager,
|
private val billingManager: BillingManager,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val navigator: Navigator
|
private val navigator: Navigator,
|
||||||
|
private val widgetManager: WidgetManager
|
||||||
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
||||||
|
|
||||||
private val theme: Preference<Int> = prefs.theme(threadId)
|
private val theme: Preference<Int> = prefs.theme(threadId)
|
||||||
@@ -50,7 +52,12 @@ class ThemePickerPresenter @Inject constructor(
|
|||||||
// Update the theme when a material theme is clicked
|
// Update the theme when a material theme is clicked
|
||||||
view.themeSelected()
|
view.themeSelected()
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color -> theme.set(color) }
|
.subscribe { color ->
|
||||||
|
theme.set(color)
|
||||||
|
if (threadId == 0L) {
|
||||||
|
widgetManager.updateTheme()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update the color of the apply button
|
// Update the color of the apply button
|
||||||
view.hsvThemeSelected()
|
view.hsvThemeSelected()
|
||||||
@@ -73,6 +80,9 @@ class ThemePickerPresenter @Inject constructor(
|
|||||||
view.showQksmsPlusSnackbar()
|
view.showQksmsPlusSnackbar()
|
||||||
} else {
|
} else {
|
||||||
theme.set(color)
|
theme.set(color)
|
||||||
|
if (threadId == 0L) {
|
||||||
|
widgetManager.updateTheme()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
|
|||||||
@@ -62,21 +62,18 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
|||||||
private var conversations: List<Conversation> = listOf()
|
private var conversations: List<Conversation> = listOf()
|
||||||
private val appWidgetManager by lazy { AppWidgetManager.getInstance(context) }
|
private val appWidgetManager by lazy { AppWidgetManager.getInstance(context) }
|
||||||
|
|
||||||
// Cache colors, load lazily. This entire class is recreated when the widget is recreated,
|
private val night get() = prefs.night.get()
|
||||||
// so if the theme changes then these values will be correct in the new instance
|
private val black get() = prefs.black.get()
|
||||||
private val night by lazy { prefs.night.get() }
|
private val theme get() = colors.theme()
|
||||||
private val black by lazy { prefs.black.get() }
|
private val background
|
||||||
private val theme by lazy { colors.theme() }
|
get() = context.getColorCompat(when {
|
||||||
private val background by lazy {
|
|
||||||
context.getColorCompat(when {
|
|
||||||
night && black -> R.color.black
|
night && black -> R.color.black
|
||||||
night && !black -> R.color.backgroundDark
|
night && !black -> R.color.backgroundDark
|
||||||
else -> R.color.white
|
else -> R.color.white
|
||||||
})
|
})
|
||||||
}
|
private val textPrimary get() = context.getColorCompat(if (night) R.color.textPrimaryDark else R.color.textPrimary)
|
||||||
private val textPrimary by lazy { context.getColorCompat(if (night) R.color.textPrimaryDark else R.color.textPrimary) }
|
private val textSecondary get() = context.getColorCompat(if (night) R.color.textSecondaryDark else R.color.textSecondary)
|
||||||
private val textSecondary by lazy { context.getColorCompat(if (night) R.color.textSecondaryDark else R.color.textSecondary) }
|
private val textTertiary get() = context.getColorCompat(if (night) R.color.textTertiaryDark else R.color.textTertiary)
|
||||||
private val textTertiary by lazy { context.getColorCompat(if (night) R.color.textTertiaryDark else R.color.textTertiary) }
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class WidgetProvider : AppWidgetProvider() {
|
|||||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||||
|
|
||||||
|
updateData(context)
|
||||||
for (appWidgetId in appWidgetIds) {
|
for (appWidgetId in appWidgetIds) {
|
||||||
updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId))
|
updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user