#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
@@ -23,6 +23,7 @@ import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkPresenter
import com.moez.QKSMS.common.util.BillingManager
import com.moez.QKSMS.common.util.Colors
import com.moez.QKSMS.manager.WidgetManager
import com.moez.QKSMS.util.Preferences
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.Observables
@@ -31,11 +32,12 @@ import javax.inject.Inject
import javax.inject.Named
class ThemePickerPresenter @Inject constructor(
@Named("threadId") threadId: Long,
prefs: Preferences,
@Named("threadId") private val threadId: Long,
private val billingManager: BillingManager,
private val colors: Colors,
private val navigator: Navigator
private val navigator: Navigator,
private val widgetManager: WidgetManager
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = 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
view.themeSelected()
.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
view.hsvThemeSelected()
@@ -73,6 +80,9 @@ class ThemePickerPresenter @Inject constructor(
view.showQksmsPlusSnackbar()
} else {
theme.set(color)
if (threadId == 0L) {
widgetManager.updateTheme()
}
}
}
.autoDisposable(view.scope())
@@ -62,21 +62,18 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
private var conversations: List<Conversation> = listOf()
private val appWidgetManager by lazy { AppWidgetManager.getInstance(context) }
// Cache colors, load lazily. This entire class is recreated when the widget is recreated,
// so if the theme changes then these values will be correct in the new instance
private val night by lazy { prefs.night.get() }
private val black by lazy { prefs.black.get() }
private val theme by lazy { colors.theme() }
private val background by lazy {
context.getColorCompat(when {
private val night get() = prefs.night.get()
private val black get() = prefs.black.get()
private val theme get() = colors.theme()
private val background
get() = context.getColorCompat(when {
night && black -> R.color.black
night && !black -> R.color.backgroundDark
else -> R.color.white
})
}
private val textPrimary by lazy { context.getColorCompat(if (night) R.color.textPrimaryDark else R.color.textPrimary) }
private val textSecondary by lazy { context.getColorCompat(if (night) R.color.textSecondaryDark else R.color.textSecondary) }
private val textTertiary by lazy { context.getColorCompat(if (night) R.color.textTertiaryDark else R.color.textTertiary) }
private val textPrimary get() = 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 textTertiary get() = context.getColorCompat(if (night) R.color.textTertiaryDark else R.color.textTertiary)
override fun onCreate() {
appComponent.inject(this)
@@ -59,6 +59,7 @@ class WidgetProvider : AppWidgetProvider() {
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
super.onUpdate(context, appWidgetManager, appWidgetIds)
updateData(context)
for (appWidgetId in appWidgetIds) {
updateWidget(context, appWidgetId, isSmallWidget(appWidgetManager, appWidgetId))
}