forked from upstream-mirrors/quik
Remove Observables from Views
commit 6bb74ca5201cba2fc5de2db349bb7627c028b617 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 15:15:27 2018 -0400 Fix crash when tapping on selected contact commit f5a45e2a600a8d373160dcb0273bab232e6cc0c5 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 15:10:44 2018 -0400 Add missing attributes for dialog themes commit 2188adbe5948b9b71f816dad5fb115829ba57e30 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:59:39 2018 -0400 Refresh settings activity when theme changed commit a9541019c566a3a6e41e64ea8136f7fd50a6d364 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:56:33 2018 -0400 Don't use themed attributes in widget commit 4823a3034848efac624eb82856f692c7f9e775a5 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sun May 27 14:29:00 2018 -0400 Refresh adapter in conversation info when theme changed commit 7ea5837b99c2b6eac547dad383515ee7b79ff6e4 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 18:27:08 2018 -0400 Bundle theme colors into data class commit 6a832fdde98622c5a252aca0cac3150a6eb0f554 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 17:16:21 2018 -0400 Update conversation UI when theme changed commit ef6948e80ed8734a7fefbec1b00f1b32e8209072 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 16:15:39 2018 -0400 Fix avatar not respecting theme commit 4ea21b6a9963f91d3b9cdaf0ba4749a6f24e8a74 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 15:52:40 2018 -0400 Fix checkmark color in theme picker commit 270a9d3037439f165a110c7d7dcaf7dd84dad29f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri May 25 13:39:12 2018 -0400 Update views in MainActivity when theme changed commit cdc1187ccaee800e4305da5fab5d22220d04440f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 23:36:17 2018 -0400 Remove unnecessary programmatic creation of drawer item background commit bc6fbfa75c66bb81db9591617f8c1de4c0f2746f Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 23:28:44 2018 -0400 Temporarily disable RxJava2Debug commit eae422be0bab8cedb3cb5ddf5f4ae61368ab5d1e Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 21:16:46 2018 -0400 Remove observable usage inside of custom views commit 2e65d55b9b283e74fb395d4828eb310395b4902b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 24 02:27:26 2018 -0400 Migrate ripple and text size to no longer use observables
This commit is contained in:
@@ -19,178 +19,27 @@
|
||||
package common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.support.text.emoji.widget.EmojiAppCompatTextView
|
||||
import android.util.AttributeSet
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.util.Colors
|
||||
import common.util.FontProvider
|
||||
import common.util.extensions.getColorCompat
|
||||
import common.util.TextViewStyler
|
||||
import injection.appComponent
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import util.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
||||
: EmojiAppCompatTextView(context, attrs) {
|
||||
|
||||
companion object {
|
||||
const val COLOR_PRIMARY = 0
|
||||
const val COLOR_SECONDARY = 1
|
||||
const val COLOR_TERTIARY = 2
|
||||
const val COLOR_PRIMARY_ON_THEME = 3
|
||||
const val COLOR_SECONDARY_ON_THEME = 4
|
||||
const val COLOR_TERTIARY_ON_THEME = 5
|
||||
const val COLOR_THEME = 6
|
||||
|
||||
const val SIZE_PRIMARY = 0
|
||||
const val SIZE_SECONDARY = 1
|
||||
const val SIZE_TERTIARY = 2
|
||||
const val SIZE_TOOLBAR = 3
|
||||
}
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
var textColorObservable: Observable<Int>? = null
|
||||
set(value) {
|
||||
field = value
|
||||
updateSubscription()
|
||||
}
|
||||
|
||||
private var textColorDisposable: Disposable? = null
|
||||
set(value) {
|
||||
field?.dispose()
|
||||
field = value
|
||||
}
|
||||
|
||||
private var textSizeAttrSubject: Subject<Int> = BehaviorSubject.create()
|
||||
@Inject lateinit var textViewStyler: TextViewStyler
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
val colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||
val textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||
|
||||
if (isInEditMode) {
|
||||
setTextColor(context.getColorCompat(when (colorAttr) {
|
||||
COLOR_PRIMARY -> R.color.textPrimary
|
||||
COLOR_SECONDARY -> R.color.textSecondary
|
||||
COLOR_TERTIARY -> R.color.textTertiary
|
||||
COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark
|
||||
COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark
|
||||
COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark
|
||||
COLOR_THEME -> R.color.tools_theme
|
||||
else -> R.color.textPrimary
|
||||
}))
|
||||
|
||||
textSize = when (textSizeAttr) {
|
||||
SIZE_PRIMARY -> 16f
|
||||
SIZE_SECONDARY -> 14f
|
||||
SIZE_TERTIARY -> 12f
|
||||
SIZE_TOOLBAR -> 20f
|
||||
else -> textSize
|
||||
}
|
||||
} else {
|
||||
textColorObservable = when (colorAttr) {
|
||||
COLOR_PRIMARY -> colors.textPrimary
|
||||
COLOR_SECONDARY -> colors.textSecondary
|
||||
COLOR_TERTIARY -> colors.textTertiary
|
||||
COLOR_PRIMARY_ON_THEME -> colors.textPrimaryOnTheme
|
||||
COLOR_SECONDARY_ON_THEME -> colors.textSecondaryOnTheme
|
||||
COLOR_TERTIARY_ON_THEME -> colors.textTertiaryOnTheme
|
||||
COLOR_THEME -> colors.theme
|
||||
else -> null
|
||||
}
|
||||
|
||||
setTextSize(textSizeAttr)
|
||||
}
|
||||
|
||||
recycle()
|
||||
textViewStyler.applyAttributes(this, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SIZE_PRIMARY
|
||||
* @see SIZE_SECONDARY
|
||||
* @see SIZE_TERTIARY
|
||||
* @see SIZE_TOOLBAR
|
||||
*/
|
||||
fun setTextSize(size: Int) {
|
||||
textSizeAttrSubject.onNext(size)
|
||||
override fun setTextColor(color: Int) {
|
||||
super.setTextColor(color)
|
||||
setLinkTextColor(color)
|
||||
}
|
||||
|
||||
private fun updateSubscription() {
|
||||
if (isAttachedToWindow) {
|
||||
textColorDisposable = textColorObservable?.subscribe { color ->
|
||||
setTextColor(color)
|
||||
setLinkTextColor(color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
if (isInEditMode) return
|
||||
|
||||
updateSubscription()
|
||||
|
||||
fontProvider.typeface
|
||||
.autoDisposable(scope())
|
||||
.subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) }
|
||||
|
||||
Observables
|
||||
.combineLatest(prefs.textSize.asObservable(), textSizeAttrSubject, { textSizePref, textSizeAttr ->
|
||||
when (textSizeAttr) {
|
||||
SIZE_PRIMARY -> textSize = when (textSizePref) {
|
||||
Preferences.TEXT_SIZE_SMALL -> 14f
|
||||
Preferences.TEXT_SIZE_NORMAL -> 16f
|
||||
Preferences.TEXT_SIZE_LARGE -> 18f
|
||||
Preferences.TEXT_SIZE_LARGER -> 20f
|
||||
else -> 16f
|
||||
}
|
||||
|
||||
SIZE_SECONDARY -> textSize = when (textSizePref) {
|
||||
Preferences.TEXT_SIZE_SMALL -> 12f
|
||||
Preferences.TEXT_SIZE_NORMAL -> 14f
|
||||
Preferences.TEXT_SIZE_LARGE -> 16f
|
||||
Preferences.TEXT_SIZE_LARGER -> 18f
|
||||
else -> 14f
|
||||
}
|
||||
|
||||
SIZE_TERTIARY -> textSize = when (textSizePref) {
|
||||
Preferences.TEXT_SIZE_SMALL -> 10f
|
||||
Preferences.TEXT_SIZE_NORMAL -> 12f
|
||||
Preferences.TEXT_SIZE_LARGE -> 14f
|
||||
Preferences.TEXT_SIZE_LARGER -> 16f
|
||||
else -> 12f
|
||||
}
|
||||
|
||||
SIZE_TOOLBAR -> textSize = when (textSizePref) {
|
||||
Preferences.TEXT_SIZE_SMALL -> 18f
|
||||
Preferences.TEXT_SIZE_NORMAL -> 20f
|
||||
Preferences.TEXT_SIZE_LARGE -> 22f
|
||||
Preferences.TEXT_SIZE_LARGER -> 26f
|
||||
else -> 20f
|
||||
}
|
||||
}
|
||||
})
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
textColorDisposable?.dispose()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user