Background colour respects dark mode

This commit is contained in:
Moez Bhatti
2017-12-05 18:09:31 -05:00
parent 2f9e559894
commit aea338c247
12 changed files with 44 additions and 34 deletions
@@ -17,40 +17,28 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
.map { it.last() }
.observeOn(AndroidSchedulers.mainThread())
val background: Observable<Int> = prefs.dark.asObservable()
.map { dark -> if (dark) R.color.backgroundDark else R.color.white }
.map { res -> context.resources.getColor(res) }
val composeBackground: Observable<Int> = prefs.dark.asObservable()
.map { dark -> if (dark) R.color.backgroundDark else R.color.backgroundLight }
.map { res -> context.resources.getColor(res) }
val switchThumbEnabled: Observable<Int> = prefs.dark.asObservable()
.map { dark ->
when (dark) {
true -> R.color.switch_thumb_enabled_dark
false -> R.color.switch_thumb_enabled_light
}
}
.map { dark -> if (dark) R.color.switch_thumb_enabled_dark else R.color.switch_thumb_enabled_light }
.map { res -> context.resources.getColor(res) }
val switchThumbDisabled: Observable<Int> = prefs.dark.asObservable()
.map { dark ->
when (dark) {
true -> R.color.switch_thumb_disabled_dark
false -> R.color.switch_thumb_disabled_light
}
}
.map { dark -> if (dark) R.color.switch_thumb_disabled_dark else R.color.switch_thumb_disabled_light }
.map { res -> context.resources.getColor(res) }
val switchTrackEnabled: Observable<Int> = prefs.dark.asObservable()
.map { dark ->
when (dark) {
true -> R.color.switch_track_enabled_dark
false -> R.color.switch_track_enabled_light
}
}
.map { dark -> if (dark) R.color.switch_track_enabled_dark else R.color.switch_track_enabled_light }
.map { res -> context.resources.getColor(res) }
val switchTrackDisabled: Observable<Int> = prefs.dark.asObservable()
.map { dark ->
when (dark) {
true -> R.color.switch_track_disabled_dark
false -> R.color.switch_track_disabled_light
}
}
.map { dark -> if (dark) R.color.switch_track_disabled_dark else R.color.switch_track_disabled_light }
.map { res -> context.resources.getColor(res) }
val bubbleColor = 0xFFFFFFFF.toInt()
@@ -45,6 +45,15 @@ abstract class QkActivity<VM : QkViewModel<*, *>> : AppCompatActivity() {
}
}
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
disposables += colors.background
.doOnNext { color -> window.statusBarColor = color }
.doOnNext { color -> toolbar?.setBackgroundColor(color) }
.subscribe()
}
override fun onDestroy() {
super.onDestroy()
disposables.dispose()
@@ -72,7 +72,6 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
messageList.layoutManager = layoutManager
messageList.adapter = messageAdapter
val states = arrayOf(
intArrayOf(android.R.attr.state_enabled),
intArrayOf(-android.R.attr.state_enabled))
@@ -81,6 +80,12 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
.map { color -> ColorStateList(states, intArrayOf(color, colors.textTertiary)) }
.subscribe { tintList -> send.imageTintList = tintList }
disposables += colors.background
.subscribe { color -> composeBar.setBackgroundColor(color) }
disposables += colors.composeBackground
.subscribe { color -> window.decorView.setBackgroundColor(color) }
window.callback = ComposeWindowCallback(window.callback, this)
}
@@ -66,6 +66,11 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
// Don't allow clicks to pass through the drawer layout
drawer.clicks().subscribe()
disposables += colors.background
.doOnNext { color -> window.decorView.setBackgroundColor(color) }
.doOnNext { color -> drawer.setBackgroundColor(color) }
.subscribe()
val states = arrayOf(
intArrayOf(android.R.attr.state_selected),
intArrayOf(-android.R.attr.state_selected))
@@ -10,6 +10,7 @@ import com.moez.QKSMS.R
import com.moez.QKSMS.common.di.appComponent
import com.moez.QKSMS.presentation.base.QkActivity
import com.moez.QKSMS.presentation.view.PreferenceView
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.settings_activity.*
@@ -59,6 +60,9 @@ class SettingsActivity : QkActivity<SettingsViewModel>(), SettingsView {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
viewModel.bindView(this)
disposables += colors.background
.subscribe { color -> window.decorView.setBackgroundColor(color) }
// Listen to clicks for all of the preferences
(0 until preferences.childCount)
.map { index -> preferences.getChildAt(index) }
@@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundLight"
android:orientation="vertical">
<include
@@ -52,14 +51,13 @@
android:id="@+id/composeBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center_vertical">
<ImageView
android:id="@+id/attach"
android:layout_width="56dp"
android:layout_height="56dp"
android:background="?selectableItemBackgroundBorderless"
android:background="@drawable/ripple"
android:padding="16dp"
android:src="@drawable/ic_add_circle_black_24dp"
android:tint="@color/textSecondary" />
@@ -85,7 +83,7 @@
android:id="@+id/send"
android:layout_width="56dp"
android:layout_height="56dp"
android:background="?selectableItemBackgroundBorderless"
android:background="@drawable/ripple"
android:padding="16dp"
android:src="@drawable/ic_send_black_24dp"
android:tint="@color/textTertiary" />
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:background="@drawable/ripple"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="8dp"
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:background="@drawable/ripple"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="8dp"
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:background="@drawable/ripple"
android:orientation="vertical"
android:paddingBottom="16dp">
@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:background="@drawable/ripple"
android:orientation="vertical"
android:paddingBottom="16dp">
+1
View File
@@ -13,6 +13,7 @@
<color name="bubbleLight">#F4F4F4</color>
<color name="backgroundLight">#F2F2F2</color>
<color name="backgroundDark">#212121</color>
<color name="statusLight">#F1F1F1</color>
<color name="list_separator">#F2F2F2</color>
+1 -1
View File
@@ -28,7 +28,7 @@
<style name="DrawerRow">
<item name="android:layout_height">48dp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:background">@drawable/ripple</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>