Loading domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +2 −20 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Build import android.provider.Settings import android.util.TypedValue import android.view.ContextThemeWrapper import androidx.core.content.res.ResourcesCompat import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.RxSharedPreferences import com.moez.QKSMS.common.util.extensions.versionCode Loading Loading @@ -76,6 +77,7 @@ class Preferences @Inject constructor(private val context: Context, private val val canUseSubId = rxPrefs.getBoolean("canUseSubId", true) val version = rxPrefs.getInteger("version", context.versionCode) val changelogVersion = rxPrefs.getInteger("changelogVersion", context.versionCode) @Deprecated("This should only be accessed when migrating to @blockingManager") val sia = rxPrefs.getBoolean("sia", false) Loading Loading @@ -121,26 +123,6 @@ class Preferences @Inject constructor(private val context: Context, private val } } fun systemColor(): Int { val typedValue = TypedValue() val contextThemeWrapper = ContextThemeWrapper(context, R.style.Theme_DeviceDefault) contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true) return typedValue.data } fun theme( recipientId: Long = 0, default: Int = rxPrefs.getInteger("theme", 0xFF7bb6ff.toInt()).get() ): Preference<Int> { return when (recipientId) { 0L -> rxPrefs.getInteger("theme", systemColor()) // 0L -> rxPrefs.getInteger("theme", 0xFF0097A7.toInt()) else -> rxPrefs.getInteger("theme_$recipientId", default) } } fun notifications(threadId: Long = 0): Preference<Boolean> { val default = rxPrefs.getBoolean("notifications", true) Loading presentation/src/main/java/com/moez/QKSMS/common/MenuItemAdapter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private intArrayOf(-android.R.attr.state_activated)) val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary) view.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text)) view.check.imageTintList = ColorStateList(states, intArrayOf(context.getColor(R.color.tools_theme), text)) return QkViewHolder(view).apply { view.setOnClickListener { Loading presentation/src/main/java/com/moez/QKSMS/common/QKApplication.kt +15 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.moez.QKSMS.R import com.moez.QKSMS.common.util.CrashlyticsTree import com.moez.QKSMS.common.util.FileLoggingTree import com.moez.QKSMS.injection.AppComponentManager import com.moez.QKSMS.injection.AppModule_ProvideRxPreferencesFactory import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.manager.AnalyticsManager import com.moez.QKSMS.migration.QkMigration Loading @@ -52,16 +53,24 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn * Inject these so that they are forced to initialize */ @Suppress("unused") @Inject lateinit var analyticsManager: AnalyticsManager @Inject lateinit var analyticsManager: AnalyticsManager @Suppress("unused") @Inject lateinit var qkMigration: QkMigration @Inject lateinit var qkMigration: QkMigration @Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity> @Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver> @Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service> @Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity> @Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver> @Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service> @Inject lateinit var fileLoggingTree: FileLoggingTree @Inject lateinit var nightModeManager: NightModeManager @Inject lateinit var nightModeManager: NightModeManager override fun onCreate() { super.onCreate() Loading presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt +4 −21 Original line number Diff line number Diff line Loading @@ -50,8 +50,10 @@ import javax.inject.Inject */ abstract class QkThemedActivity : QkActivity() { @Inject lateinit var colors: Colors @Inject lateinit var prefs: Preferences @Inject lateinit var colors: Colors @Inject lateinit var prefs: Preferences /** * In case the activity should be themed for a specific conversation, the selected conversation Loading @@ -59,13 +61,6 @@ abstract class QkThemedActivity : QkActivity() { */ val threadId: Subject<Long> = BehaviorSubject.createDefault(0) /** * Switch the theme if the threadId changes */ val theme = threadId .distinctUntilChanged() .switchMap { threadId -> colors.themeObservable(threadId) } @SuppressLint("InlinedApi") override fun onCreate(savedInstanceState: Bundle?) { setTheme(getActivityThemeRes(prefs.black.get())) Loading Loading @@ -104,18 +99,6 @@ abstract class QkThemedActivity : QkActivity() { // Set the color for the overflow and navigation icon val textSecondary = resolveThemeColor(android.R.attr.textColorSecondary) toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(textSecondary) } // Update the colours of the menu items Observables.combineLatest(menu, theme) { menu, theme -> menu.iterator().forEach { menuItem -> val tint = when (menuItem.itemId) { in getColoredMenuItems() -> prefs.systemColor() else -> textSecondary } menuItem.icon = menuItem.icon?.apply { setTint(tint) } } }.autoDisposable(scope(Lifecycle.Event.ON_DESTROY)).subscribe() } open fun getColoredMenuItems(): List<Int> { Loading presentation/src/main/java/com/moez/QKSMS/common/util/Colors.kt +8 −11 Original line number Diff line number Diff line Loading @@ -30,11 +30,15 @@ import javax.inject.Singleton @Singleton class Colors @Inject constructor(private val context: Context, private val prefs: Preferences) { /* init { prefs.setSystemColor(R.color.tools_theme) }*/ data class Theme(val theme: Int, private val colors: Colors) { val highlight by lazy { colors.highlightColorForTheme(theme) } val textPrimary by lazy { colors.textPrimaryOnThemeForColor(theme) } val textSecondary by lazy { colors.textSecondaryOnThemeForColor(theme) } val textTertiary by lazy { colors.textTertiaryOnThemeForColor(theme) } val highlight by lazy { colors.highlightColorForTheme(R.color.tools_theme) } val textPrimary by lazy { colors.textPrimaryOnThemeForColor(R.color.textPrimary) } val textSecondary by lazy { colors.textSecondaryOnThemeForColor(R.color.textSecondary) } val textTertiary by lazy { colors.textTertiaryOnThemeForColor(R.color.textTertiary) } } val materialColors = listOf( Loading Loading @@ -66,13 +70,6 @@ class Colors @Inject constructor(private val context: Context, private val prefs private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark)) private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark)) fun theme(threadId: Long = 0): Theme = Theme(prefs.theme(threadId).get(), this) fun themeObservable(threadId: Long = 0): Observable<Theme> { return prefs.theme(threadId).asObservable() .map { color -> Theme(color, this) } } fun highlightColorForTheme(theme: Int): Int = FloatArray(3) .apply { Color.colorToHSV(theme, this) } .let { hsv -> hsv.apply { set(2, 0.75f) } } // 75% value Loading Loading
domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +2 −20 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Build import android.provider.Settings import android.util.TypedValue import android.view.ContextThemeWrapper import androidx.core.content.res.ResourcesCompat import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.RxSharedPreferences import com.moez.QKSMS.common.util.extensions.versionCode Loading Loading @@ -76,6 +77,7 @@ class Preferences @Inject constructor(private val context: Context, private val val canUseSubId = rxPrefs.getBoolean("canUseSubId", true) val version = rxPrefs.getInteger("version", context.versionCode) val changelogVersion = rxPrefs.getInteger("changelogVersion", context.versionCode) @Deprecated("This should only be accessed when migrating to @blockingManager") val sia = rxPrefs.getBoolean("sia", false) Loading Loading @@ -121,26 +123,6 @@ class Preferences @Inject constructor(private val context: Context, private val } } fun systemColor(): Int { val typedValue = TypedValue() val contextThemeWrapper = ContextThemeWrapper(context, R.style.Theme_DeviceDefault) contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true) return typedValue.data } fun theme( recipientId: Long = 0, default: Int = rxPrefs.getInteger("theme", 0xFF7bb6ff.toInt()).get() ): Preference<Int> { return when (recipientId) { 0L -> rxPrefs.getInteger("theme", systemColor()) // 0L -> rxPrefs.getInteger("theme", 0xFF0097A7.toInt()) else -> rxPrefs.getInteger("theme_$recipientId", default) } } fun notifications(threadId: Long = 0): Preference<Boolean> { val default = rxPrefs.getBoolean("notifications", true) Loading
presentation/src/main/java/com/moez/QKSMS/common/MenuItemAdapter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class MenuItemAdapter @Inject constructor(private val context: Context, private intArrayOf(-android.R.attr.state_activated)) val text = parent.context.resolveThemeColor(android.R.attr.textColorTertiary) view.check.imageTintList = ColorStateList(states, intArrayOf(colors.theme().theme, text)) view.check.imageTintList = ColorStateList(states, intArrayOf(context.getColor(R.color.tools_theme), text)) return QkViewHolder(view).apply { view.setOnClickListener { Loading
presentation/src/main/java/com/moez/QKSMS/common/QKApplication.kt +15 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.moez.QKSMS.R import com.moez.QKSMS.common.util.CrashlyticsTree import com.moez.QKSMS.common.util.FileLoggingTree import com.moez.QKSMS.injection.AppComponentManager import com.moez.QKSMS.injection.AppModule_ProvideRxPreferencesFactory import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.manager.AnalyticsManager import com.moez.QKSMS.migration.QkMigration Loading @@ -52,16 +53,24 @@ class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverIn * Inject these so that they are forced to initialize */ @Suppress("unused") @Inject lateinit var analyticsManager: AnalyticsManager @Inject lateinit var analyticsManager: AnalyticsManager @Suppress("unused") @Inject lateinit var qkMigration: QkMigration @Inject lateinit var qkMigration: QkMigration @Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity> @Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver> @Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service> @Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity> @Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver> @Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service> @Inject lateinit var fileLoggingTree: FileLoggingTree @Inject lateinit var nightModeManager: NightModeManager @Inject lateinit var nightModeManager: NightModeManager override fun onCreate() { super.onCreate() Loading
presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt +4 −21 Original line number Diff line number Diff line Loading @@ -50,8 +50,10 @@ import javax.inject.Inject */ abstract class QkThemedActivity : QkActivity() { @Inject lateinit var colors: Colors @Inject lateinit var prefs: Preferences @Inject lateinit var colors: Colors @Inject lateinit var prefs: Preferences /** * In case the activity should be themed for a specific conversation, the selected conversation Loading @@ -59,13 +61,6 @@ abstract class QkThemedActivity : QkActivity() { */ val threadId: Subject<Long> = BehaviorSubject.createDefault(0) /** * Switch the theme if the threadId changes */ val theme = threadId .distinctUntilChanged() .switchMap { threadId -> colors.themeObservable(threadId) } @SuppressLint("InlinedApi") override fun onCreate(savedInstanceState: Bundle?) { setTheme(getActivityThemeRes(prefs.black.get())) Loading Loading @@ -104,18 +99,6 @@ abstract class QkThemedActivity : QkActivity() { // Set the color for the overflow and navigation icon val textSecondary = resolveThemeColor(android.R.attr.textColorSecondary) toolbar?.overflowIcon = toolbar?.overflowIcon?.apply { setTint(textSecondary) } // Update the colours of the menu items Observables.combineLatest(menu, theme) { menu, theme -> menu.iterator().forEach { menuItem -> val tint = when (menuItem.itemId) { in getColoredMenuItems() -> prefs.systemColor() else -> textSecondary } menuItem.icon = menuItem.icon?.apply { setTint(tint) } } }.autoDisposable(scope(Lifecycle.Event.ON_DESTROY)).subscribe() } open fun getColoredMenuItems(): List<Int> { Loading
presentation/src/main/java/com/moez/QKSMS/common/util/Colors.kt +8 −11 Original line number Diff line number Diff line Loading @@ -30,11 +30,15 @@ import javax.inject.Singleton @Singleton class Colors @Inject constructor(private val context: Context, private val prefs: Preferences) { /* init { prefs.setSystemColor(R.color.tools_theme) }*/ data class Theme(val theme: Int, private val colors: Colors) { val highlight by lazy { colors.highlightColorForTheme(theme) } val textPrimary by lazy { colors.textPrimaryOnThemeForColor(theme) } val textSecondary by lazy { colors.textSecondaryOnThemeForColor(theme) } val textTertiary by lazy { colors.textTertiaryOnThemeForColor(theme) } val highlight by lazy { colors.highlightColorForTheme(R.color.tools_theme) } val textPrimary by lazy { colors.textPrimaryOnThemeForColor(R.color.textPrimary) } val textSecondary by lazy { colors.textSecondaryOnThemeForColor(R.color.textSecondary) } val textTertiary by lazy { colors.textTertiaryOnThemeForColor(R.color.textTertiary) } } val materialColors = listOf( Loading Loading @@ -66,13 +70,6 @@ class Colors @Inject constructor(private val context: Context, private val prefs private val secondaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textSecondaryDark)) private val tertiaryTextLuminance = measureLuminance(context.getColorCompat(R.color.textTertiaryDark)) fun theme(threadId: Long = 0): Theme = Theme(prefs.theme(threadId).get(), this) fun themeObservable(threadId: Long = 0): Observable<Theme> { return prefs.theme(threadId).asObservable() .map { color -> Theme(color, this) } } fun highlightColorForTheme(theme: Int): Int = FloatArray(3) .apply { Color.colorToHSV(theme, this) } .let { hsv -> hsv.apply { set(2, 0.75f) } } // 75% value Loading