forked from upstream-mirrors/quik
Improve performance for color observables
This commit is contained in:
@@ -3,8 +3,6 @@ package com.moez.QKSMS.common.util
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -12,68 +10,79 @@ import javax.inject.Singleton
|
|||||||
class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||||
|
|
||||||
val theme: Observable<Int> = prefs.theme.asObservable()
|
val theme: Observable<Int> = prefs.theme.asObservable()
|
||||||
.buffer(80, TimeUnit.MILLISECONDS)
|
.distinctUntilChanged()
|
||||||
.filter { it.isNotEmpty() }
|
|
||||||
.map { it.last() }
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
|
|
||||||
val background: Observable<Int> = prefs.dark.asObservable()
|
val background: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.backgroundDark else R.color.white }
|
.map { dark -> if (dark) R.color.backgroundDark else R.color.white }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val composeBackground: Observable<Int> = prefs.dark.asObservable()
|
val composeBackground: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.backgroundDark else R.color.backgroundLight }
|
.map { dark -> if (dark) R.color.backgroundDark else R.color.backgroundLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val separator: Observable<Int> = prefs.dark.asObservable()
|
val separator: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.separatorDark else R.color.separatorLight }
|
.map { dark -> if (dark) R.color.separatorDark else R.color.separatorLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val textPrimary: Observable<Int> = prefs.dark.asObservable()
|
val textPrimary: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.textPrimaryDark else R.color.textPrimary }
|
.map { dark -> if (dark) R.color.textPrimaryDark else R.color.textPrimary }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val textSecondary: Observable<Int> = prefs.dark.asObservable()
|
val textSecondary: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.textSecondaryDark else R.color.textSecondary }
|
.map { dark -> if (dark) R.color.textSecondaryDark else R.color.textSecondary }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val textTertiary: Observable<Int> = prefs.dark.asObservable()
|
val textTertiary: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.textTertiaryDark else R.color.textTertiary }
|
.map { dark -> if (dark) R.color.textTertiaryDark else R.color.textTertiary }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
// TODO make this result depend on the theme color
|
// TODO make this result depend on the theme color
|
||||||
val textPrimaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
val textPrimaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
||||||
.map { theme -> R.color.textPrimaryDark }
|
.map { theme -> R.color.textPrimaryDark }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
// TODO make this result depend on the theme color
|
// TODO make this result depend on the theme color
|
||||||
val textSecondaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
val textSecondaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { theme -> R.color.textSecondaryDark }
|
.map { theme -> R.color.textSecondaryDark }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
// TODO make this result depend on the theme color
|
// TODO make this result depend on the theme color
|
||||||
val textTertiaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
val textTertiaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { theme -> R.color.textTertiaryDark }
|
.map { theme -> R.color.textTertiaryDark }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val bubble: Observable<Int> = prefs.dark.asObservable()
|
val bubble: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.bubbleDark else R.color.bubbleLight }
|
.map { dark -> if (dark) R.color.bubbleDark else R.color.bubbleLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val switchThumbEnabled: Observable<Int> = prefs.dark.asObservable()
|
val switchThumbEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight }
|
.map { dark -> if (dark) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val switchThumbDisabled: Observable<Int> = prefs.dark.asObservable()
|
val switchThumbDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight }
|
.map { dark -> if (dark) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val switchTrackEnabled: Observable<Int> = prefs.dark.asObservable()
|
val switchTrackEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight }
|
.map { dark -> if (dark) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
val switchTrackDisabled: Observable<Int> = prefs.dark.asObservable()
|
val switchTrackDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||||
.map { dark -> if (dark) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight }
|
.map { dark -> if (dark) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight }
|
||||||
.map { res -> context.resources.getColor(res) }
|
.map { res -> context.resources.getColor(res) }
|
||||||
|
.distinctUntilChanged()
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user