Loading data/src/main/java/util/Preferences.kt +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences) val sia = rxPrefs.getBoolean("sia", false) val autoEmoji = rxPrefs.getBoolean("autoEmoji", true) val delivery = rxPrefs.getBoolean("delivery", false) val systemFont = rxPrefs.getBoolean("systemFont", false) val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL) val qkreply = rxPrefs.getBoolean("qkreply", Build.VERSION.SDK_INT < Build.VERSION_CODES.N) val qkreplyTapDismiss = rxPrefs.getBoolean("qkreplyTapDismiss", true) Loading presentation/src/main/java/common/util/FontProvider.kt +18 −16 Original line number Diff line number Diff line Loading @@ -22,16 +22,28 @@ import android.content.Context import android.graphics.Typeface import android.support.v4.content.res.ResourcesCompat import com.moez.QKSMS.R import io.reactivex.Observable import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject import timber.log.Timber import util.Preferences import util.extensions.Optional import javax.inject.Inject import javax.inject.Singleton @Singleton class FontProvider @Inject constructor(context: Context) { private var lato: Typeface? = null class FontProvider @Inject constructor(context: Context, prefs: Preferences) { val typeface: Observable<Optional<Typeface>> = prefs.systemFont.asObservable() .distinctUntilChanged() .switchMap { systemFont -> when (systemFont) { true -> Observable.just(Optional(null)) false -> lato } } private val pendingCallbacks = ArrayList<(Typeface) -> Unit>() private val lato: Observable<Optional<Typeface>> = BehaviorSubject.create() init { ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() { Loading @@ -40,20 +52,10 @@ class FontProvider @Inject constructor(context: Context) { } override fun onFontRetrieved(typeface: Typeface) { lato = typeface pendingCallbacks.forEach { lato?.run(it) } pendingCallbacks.clear() val subject = lato as Subject<Optional<Typeface>> subject.onNext(Optional(typeface)) } }, null) } fun getLato(callback: (Typeface) -> Unit) { lato?.run(callback) if (lato == null) { pendingCallbacks += callback } } } No newline at end of file presentation/src/main/java/common/widget/QkEditText.kt +4 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet init { if (!isInEditMode) { appComponent.inject(this) fontProvider.getLato { setTypeface(it, typeface?.style ?: Typeface.NORMAL) } context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run { val colorAttr = getInt(R.styleable.QkEditText_textColor, -1) Loading Loading @@ -118,6 +117,10 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet super.onAttachedToWindow() if (isInEditMode) return fontProvider.typeface .autoDisposable(scope()) .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } textColorObservable ?.autoDisposable(scope()) ?.subscribe { color -> setTextColor(color) } Loading presentation/src/main/java/common/widget/QkTextView.kt +4 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,6 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu init { if (!isInEditMode) { appComponent.inject(this) fontProvider.getLato { setTypeface(it, typeface?.style ?: Typeface.NORMAL) } } context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run { Loading Loading @@ -143,6 +142,10 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu updateSubscription() fontProvider.typeface .autoDisposable(scope()) .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } Observables .combineLatest(prefs.textSize.asObservable(), textSizeAttrSubject, { textSizePref, textSizeAttr -> when (textSizeAttr) { Loading presentation/src/main/java/feature/plus/PlusActivity.kt +7 −5 Original line number Diff line number Diff line Loading @@ -57,8 +57,10 @@ class PlusActivity : QkThemedActivity<PlusViewModel>(), PlusView { free.setVisible(false) fontProvider.getLato { lato -> val typeface = Typeface.create(lato, Typeface.BOLD) fontProvider.typeface .autoDisposable(scope()) .subscribe { lato -> val typeface = Typeface.create(lato.value, Typeface.BOLD) collapsingToolbar.setCollapsedTitleTypeface(typeface) collapsingToolbar.setExpandedTitleTypeface(typeface) } Loading Loading
data/src/main/java/util/Preferences.kt +1 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences) val sia = rxPrefs.getBoolean("sia", false) val autoEmoji = rxPrefs.getBoolean("autoEmoji", true) val delivery = rxPrefs.getBoolean("delivery", false) val systemFont = rxPrefs.getBoolean("systemFont", false) val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL) val qkreply = rxPrefs.getBoolean("qkreply", Build.VERSION.SDK_INT < Build.VERSION_CODES.N) val qkreplyTapDismiss = rxPrefs.getBoolean("qkreplyTapDismiss", true) Loading
presentation/src/main/java/common/util/FontProvider.kt +18 −16 Original line number Diff line number Diff line Loading @@ -22,16 +22,28 @@ import android.content.Context import android.graphics.Typeface import android.support.v4.content.res.ResourcesCompat import com.moez.QKSMS.R import io.reactivex.Observable import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject import timber.log.Timber import util.Preferences import util.extensions.Optional import javax.inject.Inject import javax.inject.Singleton @Singleton class FontProvider @Inject constructor(context: Context) { private var lato: Typeface? = null class FontProvider @Inject constructor(context: Context, prefs: Preferences) { val typeface: Observable<Optional<Typeface>> = prefs.systemFont.asObservable() .distinctUntilChanged() .switchMap { systemFont -> when (systemFont) { true -> Observable.just(Optional(null)) false -> lato } } private val pendingCallbacks = ArrayList<(Typeface) -> Unit>() private val lato: Observable<Optional<Typeface>> = BehaviorSubject.create() init { ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() { Loading @@ -40,20 +52,10 @@ class FontProvider @Inject constructor(context: Context) { } override fun onFontRetrieved(typeface: Typeface) { lato = typeface pendingCallbacks.forEach { lato?.run(it) } pendingCallbacks.clear() val subject = lato as Subject<Optional<Typeface>> subject.onNext(Optional(typeface)) } }, null) } fun getLato(callback: (Typeface) -> Unit) { lato?.run(callback) if (lato == null) { pendingCallbacks += callback } } } No newline at end of file
presentation/src/main/java/common/widget/QkEditText.kt +4 −1 Original line number Diff line number Diff line Loading @@ -73,7 +73,6 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet init { if (!isInEditMode) { appComponent.inject(this) fontProvider.getLato { setTypeface(it, typeface?.style ?: Typeface.NORMAL) } context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run { val colorAttr = getInt(R.styleable.QkEditText_textColor, -1) Loading Loading @@ -118,6 +117,10 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet super.onAttachedToWindow() if (isInEditMode) return fontProvider.typeface .autoDisposable(scope()) .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } textColorObservable ?.autoDisposable(scope()) ?.subscribe { color -> setTextColor(color) } Loading
presentation/src/main/java/common/widget/QkTextView.kt +4 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,6 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu init { if (!isInEditMode) { appComponent.inject(this) fontProvider.getLato { setTypeface(it, typeface?.style ?: Typeface.NORMAL) } } context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run { Loading Loading @@ -143,6 +142,10 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu updateSubscription() fontProvider.typeface .autoDisposable(scope()) .subscribe { setTypeface(it.value, typeface?.style ?: Typeface.NORMAL) } Observables .combineLatest(prefs.textSize.asObservable(), textSizeAttrSubject, { textSizePref, textSizeAttr -> when (textSizeAttr) { Loading
presentation/src/main/java/feature/plus/PlusActivity.kt +7 −5 Original line number Diff line number Diff line Loading @@ -57,8 +57,10 @@ class PlusActivity : QkThemedActivity<PlusViewModel>(), PlusView { free.setVisible(false) fontProvider.getLato { lato -> val typeface = Typeface.create(lato, Typeface.BOLD) fontProvider.typeface .autoDisposable(scope()) .subscribe { lato -> val typeface = Typeface.create(lato.value, Typeface.BOLD) collapsingToolbar.setCollapsedTitleTypeface(typeface) collapsingToolbar.setExpandedTitleTypeface(typeface) } Loading