mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Make all text respect dark mode
This commit is contained in:
@@ -5,13 +5,14 @@ import com.moez.QKSMS.presentation.compose.ComposeActivity
|
||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
||||
import com.moez.QKSMS.presentation.compose.MessagesAdapter
|
||||
import com.moez.QKSMS.presentation.main.ConversationsAdapter
|
||||
import com.moez.QKSMS.presentation.main.MainActivity
|
||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||
import com.moez.QKSMS.presentation.settings.SettingsActivity
|
||||
import com.moez.QKSMS.presentation.settings.SettingsViewModel
|
||||
import com.moez.QKSMS.presentation.view.AvatarView
|
||||
import com.moez.QKSMS.presentation.view.QkEditText
|
||||
import com.moez.QKSMS.presentation.view.QkSwitch
|
||||
import com.moez.QKSMS.presentation.view.QkTextView
|
||||
import com.moez.QKSMS.receiver.*
|
||||
import dagger.Component
|
||||
import javax.inject.Singleton
|
||||
@@ -35,7 +36,9 @@ interface AppComponent {
|
||||
fun inject(receiver: RemoteMessagingReceiver)
|
||||
|
||||
fun inject(view: AvatarView)
|
||||
fun inject(view: QkEditText)
|
||||
fun inject(view: QkSwitch)
|
||||
fun inject(view: QkTextView)
|
||||
|
||||
fun inject(viewModel: MainViewModel)
|
||||
fun inject(viewModel: ComposeViewModel)
|
||||
|
||||
@@ -26,15 +26,30 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val textPrimary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textPrimaryLight else R.color.textPrimary }
|
||||
.map { dark -> if (dark) R.color.textPrimaryDark else R.color.textPrimary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val textSecondary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textSecondaryLight else R.color.textSecondary }
|
||||
.map { dark -> if (dark) R.color.textSecondaryDark else R.color.textSecondary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val textTertiary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textTertiaryLight else R.color.textTertiary }
|
||||
.map { dark -> if (dark) R.color.textTertiaryDark else R.color.textTertiary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
// TODO make this result depend on the theme color
|
||||
val textPrimaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
||||
.map { theme -> R.color.textPrimaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
// TODO make this result depend on the theme color
|
||||
val textSecondaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { theme -> R.color.textSecondaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
// TODO make this result depend on the theme color
|
||||
val textTertiaryOnTheme: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { theme -> R.color.textTertiaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val bubble: Observable<Int> = prefs.dark.asObservable()
|
||||
@@ -42,19 +57,19 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val switchThumbEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switch_thumb_enabled_dark else R.color.switch_thumb_enabled_light }
|
||||
.map { dark -> if (dark) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val switchThumbDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switch_thumb_disabled_dark else R.color.switch_thumb_disabled_light }
|
||||
.map { dark -> if (dark) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val switchTrackEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switch_track_enabled_dark else R.color.switch_track_enabled_light }
|
||||
.map { dark -> if (dark) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
val switchTrackDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switch_track_disabled_dark else R.color.switch_track_disabled_light }
|
||||
.map { dark -> if (dark) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.moez.QKSMS.presentation.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.AppCompatEditText
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.text.InputType
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
@@ -34,7 +33,7 @@ class ChipsAdapter(
|
||||
}
|
||||
|
||||
private val hint: String = context.getString(R.string.title_compose)
|
||||
private val editText: EditText = AppCompatEditText(context)
|
||||
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as EditText
|
||||
|
||||
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
||||
val textChanges = editText.textChanges()
|
||||
@@ -48,8 +47,6 @@ class ChipsAdapter(
|
||||
|
||||
editText.hint = hint
|
||||
editText.textSize = 16f
|
||||
editText.setTextColor(ContextCompat.getColor(context, R.color.textPrimary))
|
||||
editText.setHintTextColor(ContextCompat.getColor(context, R.color.textTertiary))
|
||||
editText.setBackgroundResource(android.R.color.transparent)
|
||||
editText.inputType = InputType.TYPE_TEXT_VARIATION_FILTER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
|
||||
editText.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
||||
|
||||
@@ -81,7 +81,9 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
.combineLatest(colors.theme, colors.textTertiary, { theme, textTertiary ->
|
||||
ColorStateList(states, intArrayOf(theme, textTertiary))
|
||||
})
|
||||
.subscribe { tintList -> send.imageTintList = tintList }
|
||||
.doOnNext { tintList -> attach.imageTintList = tintList }
|
||||
.doOnNext { tintList -> send.imageTintList = tintList }
|
||||
.subscribe()
|
||||
|
||||
disposables += colors.background
|
||||
.subscribe { color -> composeBar.setBackgroundColor(color) }
|
||||
|
||||
@@ -78,7 +78,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
|
||||
val rowBackground = {
|
||||
StateListDrawable().apply {
|
||||
addState(intArrayOf(android.R.attr.state_selected), getDrawable(R.color.row_selected))
|
||||
addState(intArrayOf(android.R.attr.state_selected), getDrawable(R.color.rowSelected))
|
||||
addState(intArrayOf(-android.R.attr.state_selected), getDrawable(R.drawable.ripple))
|
||||
mutate()
|
||||
}
|
||||
@@ -96,6 +96,7 @@ class MainActivity : QkActivity<MainViewModel>(), MainView {
|
||||
.doOnNext { tintList -> archivedIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> blockedIcon.imageTintList = tintList }
|
||||
.doOnNext { tintList -> settingsIcon.imageTintList = tintList }
|
||||
.subscribe()
|
||||
|
||||
inbox.background = rowBackground()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.moez.QKSMS.presentation.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.EditText
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.di.appComponent
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
open class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : EditText(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
private var textColorObservable: Observable<Int>? = null
|
||||
private var textColorHintObservable: Observable<Int>? = null
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
textColorObservable = when (getInt(R.styleable.QkEditText_textColor, -1)) {
|
||||
0 -> colors.textPrimary
|
||||
1 -> colors.textSecondary
|
||||
2 -> colors.textTertiary
|
||||
3 -> colors.textPrimaryOnTheme
|
||||
4 -> colors.textSecondaryOnTheme
|
||||
5 -> colors.textTertiaryOnTheme
|
||||
else -> null
|
||||
}
|
||||
textColorHintObservable = when (getInt(R.styleable.QkEditText_textColorHint, -1)) {
|
||||
0 -> colors.textPrimary
|
||||
1 -> colors.textSecondary
|
||||
2 -> colors.textTertiary
|
||||
else -> null
|
||||
}
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
textColorObservable?.let { observable ->
|
||||
disposables += observable.subscribe { color -> setTextColor(color) }
|
||||
}
|
||||
|
||||
textColorHintObservable?.let { observable ->
|
||||
disposables += observable.subscribe { color -> setHintTextColor(color) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
|
||||
disposables.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.moez.QKSMS.presentation.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.di.appComponent
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : TextView(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
private var textColorObservable: Observable<Int>? = null
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
textColorObservable = when (getInt(R.styleable.QkTextView_textColor, -1)) {
|
||||
0 -> colors.textPrimary
|
||||
1 -> colors.textSecondary
|
||||
2 -> colors.textTertiary
|
||||
3 -> colors.textPrimaryOnTheme
|
||||
4 -> colors.textSecondaryOnTheme
|
||||
5 -> colors.textTertiaryOnTheme
|
||||
else -> null
|
||||
}
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
textColorObservable?.let { observable ->
|
||||
disposables += observable.subscribe { color -> setTextColor(color) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
|
||||
disposables.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,9 +2,8 @@ package com.moez.QKSMS.presentation.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
|
||||
class TightTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : TextView(context, attrs) {
|
||||
class TightTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : QkTextView(context, attrs) {
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
|
||||
Reference in New Issue
Block a user