Loading domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +21 −6 Original line number Diff line number Diff line Loading @@ -18,9 +18,12 @@ */ package com.moez.QKSMS.util import android.R import android.content.Context import android.os.Build import android.provider.Settings import android.util.TypedValue import android.view.ContextThemeWrapper import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.RxSharedPreferences import com.moez.QKSMS.common.util.extensions.versionCode Loading @@ -28,7 +31,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton class Preferences @Inject constructor(context: Context, private val rxPrefs: RxSharedPreferences) { class Preferences @Inject constructor(private val context: Context, private val rxPrefs: RxSharedPreferences) { companion object { const val NIGHT_MODE_SYSTEM = 0 Loading Loading @@ -118,12 +121,24 @@ class Preferences @Inject constructor(context: Context, private val rxPrefs: RxS } } fun theme(threadId: Long = 0): Preference<Int> { val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt()) fun systemColor(): Int { val typedValue = TypedValue() val contextThemeWrapper = ContextThemeWrapper(context, R.style.Theme_DeviceDefault) contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true) return when (threadId) { 0L -> default else -> rxPrefs.getInteger("theme_$threadId", default.get()) 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) } } Loading presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ abstract class QkThemedActivity : QkActivity() { Observables.combineLatest(menu, theme) { menu, theme -> menu.iterator().forEach { menuItem -> val tint = when (menuItem.itemId) { in getColoredMenuItems() -> theme.theme in getColoredMenuItems() -> prefs.systemColor() else -> textSecondary } Loading presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt +6 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget import android.content.Context import android.util.AttributeSet import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.View import android.widget.FrameLayout import com.bumptech.glide.signature.ObjectKey Loading @@ -32,6 +34,7 @@ import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.model.Contact import com.moez.QKSMS.model.Recipient import com.moez.QKSMS.util.GlideApp import com.moez.QKSMS.util.Preferences import kotlinx.android.synthetic.main.avatar_view.view.* import javax.inject.Inject Loading @@ -39,6 +42,8 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet @Inject lateinit var colors: Colors @Inject lateinit var navigator: Navigator @Inject lateinit var prefs: Preferences /** * This value can be changes if we should use the theme from a particular conversation Loading Loading @@ -115,6 +120,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet } private fun updateView() { setBackgroundTint(prefs.systemColor()) if (name?.isNotEmpty() == true) { initial.text = name?.substring(0, 1) icon.visibility = GONE Loading presentation/src/main/java/com/moez/QKSMS/common/widget/PreferenceView.kt +8 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget import android.content.Context import android.util.AttributeSet import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.Gravity import android.view.View import android.widget.TextView Loading @@ -29,11 +31,16 @@ import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.util.Preferences import kotlinx.android.synthetic.main.preference_view.view.* import javax.inject.Inject class PreferenceView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : LinearLayoutCompat(context, attrs) { @Inject lateinit var prefs: Preferences var title: String? = null set(value) { Loading Loading @@ -72,7 +79,7 @@ class PreferenceView @JvmOverloads constructor( orientation = HORIZONTAL gravity = Gravity.CENTER_VERTICAL icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary) icon.setColorFilter(prefs.systemColor()) context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run { title = getString(R.styleable.PreferenceView_title) Loading @@ -92,5 +99,4 @@ class PreferenceView @JvmOverloads constructor( recycle() } } } No newline at end of file presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +5 −4 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ import android.provider.ContactsContract import android.provider.MediaStore import android.text.format.DateFormat import android.util.Log import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AlertDialog Loading Loading @@ -147,10 +149,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView { message.supportsInputContent = true theme .doOnNext { loading.setTint(it.theme) } .doOnNext { attach.setBackgroundTint(it.theme) } .doOnNext { attach.setTint(it.textPrimary) } .doOnNext { messageAdapter.theme = it } .doOnNext { loading.setTint(prefs.systemColor()) } .doOnNext { attach.setBackgroundTint(prefs.systemColor()) } .doOnNext { send.setTint(prefs.systemColor()) } .autoDisposable(scope()) .subscribe { messageList.scrapViews() } Loading Loading
domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +21 −6 Original line number Diff line number Diff line Loading @@ -18,9 +18,12 @@ */ package com.moez.QKSMS.util import android.R import android.content.Context import android.os.Build import android.provider.Settings import android.util.TypedValue import android.view.ContextThemeWrapper import com.f2prateek.rx.preferences2.Preference import com.f2prateek.rx.preferences2.RxSharedPreferences import com.moez.QKSMS.common.util.extensions.versionCode Loading @@ -28,7 +31,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton class Preferences @Inject constructor(context: Context, private val rxPrefs: RxSharedPreferences) { class Preferences @Inject constructor(private val context: Context, private val rxPrefs: RxSharedPreferences) { companion object { const val NIGHT_MODE_SYSTEM = 0 Loading Loading @@ -118,12 +121,24 @@ class Preferences @Inject constructor(context: Context, private val rxPrefs: RxS } } fun theme(threadId: Long = 0): Preference<Int> { val default = rxPrefs.getInteger("theme", 0xFF0097A7.toInt()) fun systemColor(): Int { val typedValue = TypedValue() val contextThemeWrapper = ContextThemeWrapper(context, R.style.Theme_DeviceDefault) contextThemeWrapper.theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true) return when (threadId) { 0L -> default else -> rxPrefs.getInteger("theme_$threadId", default.get()) 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) } } Loading
presentation/src/main/java/com/moez/QKSMS/common/base/QkThemedActivity.kt +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ abstract class QkThemedActivity : QkActivity() { Observables.combineLatest(menu, theme) { menu, theme -> menu.iterator().forEach { menuItem -> val tint = when (menuItem.itemId) { in getColoredMenuItems() -> theme.theme in getColoredMenuItems() -> prefs.systemColor() else -> textSecondary } Loading
presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt +6 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget import android.content.Context import android.util.AttributeSet import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.View import android.widget.FrameLayout import com.bumptech.glide.signature.ObjectKey Loading @@ -32,6 +34,7 @@ import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.model.Contact import com.moez.QKSMS.model.Recipient import com.moez.QKSMS.util.GlideApp import com.moez.QKSMS.util.Preferences import kotlinx.android.synthetic.main.avatar_view.view.* import javax.inject.Inject Loading @@ -39,6 +42,8 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet @Inject lateinit var colors: Colors @Inject lateinit var navigator: Navigator @Inject lateinit var prefs: Preferences /** * This value can be changes if we should use the theme from a particular conversation Loading Loading @@ -115,6 +120,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet } private fun updateView() { setBackgroundTint(prefs.systemColor()) if (name?.isNotEmpty() == true) { initial.text = name?.substring(0, 1) icon.visibility = GONE Loading
presentation/src/main/java/com/moez/QKSMS/common/widget/PreferenceView.kt +8 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ package com.moez.QKSMS.common.widget import android.content.Context import android.util.AttributeSet import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.Gravity import android.view.View import android.widget.TextView Loading @@ -29,11 +31,16 @@ import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute import com.moez.QKSMS.common.util.extensions.resolveThemeColorStateList import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.util.Preferences import kotlinx.android.synthetic.main.preference_view.view.* import javax.inject.Inject class PreferenceView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : LinearLayoutCompat(context, attrs) { @Inject lateinit var prefs: Preferences var title: String? = null set(value) { Loading Loading @@ -72,7 +79,7 @@ class PreferenceView @JvmOverloads constructor( orientation = HORIZONTAL gravity = Gravity.CENTER_VERTICAL icon.imageTintList = context.resolveThemeColorStateList(android.R.attr.textColorSecondary) icon.setColorFilter(prefs.systemColor()) context.obtainStyledAttributes(attrs, R.styleable.PreferenceView).run { title = getString(R.styleable.PreferenceView_title) Loading @@ -92,5 +99,4 @@ class PreferenceView @JvmOverloads constructor( recycle() } } } No newline at end of file
presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt +5 −4 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ import android.provider.ContactsContract import android.provider.MediaStore import android.text.format.DateFormat import android.util.Log import android.util.TypedValue import android.view.ContextThemeWrapper import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AlertDialog Loading Loading @@ -147,10 +149,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView { message.supportsInputContent = true theme .doOnNext { loading.setTint(it.theme) } .doOnNext { attach.setBackgroundTint(it.theme) } .doOnNext { attach.setTint(it.textPrimary) } .doOnNext { messageAdapter.theme = it } .doOnNext { loading.setTint(prefs.systemColor()) } .doOnNext { attach.setBackgroundTint(prefs.systemColor()) } .doOnNext { send.setTint(prefs.systemColor()) } .autoDisposable(scope()) .subscribe { messageList.scrapViews() } Loading