forked from upstream-mirrors/quik
Update typeface to Lato
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.support.v4.content.res.ResourcesCompat
|
||||
import com.moez.QKSMS.R
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class FontProvider @Inject constructor(private val context: Context) {
|
||||
|
||||
private var lato: Typeface? = null
|
||||
|
||||
private val pendingCallbacks = ArrayList<(Typeface) -> Unit>()
|
||||
|
||||
init {
|
||||
ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() {
|
||||
override fun onFontRetrievalFailed(reason: Int) {
|
||||
Timber.w("Font retrieval failed: $reason")
|
||||
}
|
||||
|
||||
override fun onFontRetrieved(typeface: Typeface) {
|
||||
lato = typeface
|
||||
|
||||
pendingCallbacks.forEach { lato?.run(it) }
|
||||
pendingCallbacks.clear()
|
||||
}
|
||||
}, null)
|
||||
}
|
||||
|
||||
fun getLato(callback: (Typeface) -> Unit) {
|
||||
lato?.run(callback)
|
||||
|
||||
if (lato == null) {
|
||||
pendingCallbacks += callback
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.FontProvider
|
||||
import io.reactivex.Observable
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -38,12 +39,14 @@ import javax.inject.Inject
|
||||
class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : EditText(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
|
||||
private var textColorObservable: Observable<Int>? = null
|
||||
private var textColorHintObservable: Observable<Int>? = null
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
fontProvider.getLato { setTypeface(it, typeface.style) }
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||
textColorObservable = when (getInt(R.styleable.QkEditText_textColor, -1)) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.util.AttributeSet
|
||||
import com.moez.QKSMS.R
|
||||
import common.di.appComponent
|
||||
import common.util.Colors
|
||||
import common.util.FontProvider
|
||||
import common.util.extensions.getColorCompat
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.disposables.Disposable
|
||||
@@ -42,6 +43,7 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
}
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
|
||||
private var textColorDisposable: Disposable? = null
|
||||
private var textColorObservable: Observable<Int>? = null
|
||||
@@ -64,6 +66,7 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
fontProvider.getLato { setTypeface(it, typeface.style) }
|
||||
}
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package presentation.feature.plus
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
@@ -25,15 +26,19 @@ import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.di.appComponent
|
||||
import common.util.BillingManager
|
||||
import common.util.FontProvider
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setTint
|
||||
import common.util.extensions.setVisible
|
||||
import kotlinx.android.synthetic.main.qksms_plus_activity.*
|
||||
import presentation.common.base.QkActivity
|
||||
import presentation.common.widget.QkTextView
|
||||
import javax.inject.Inject
|
||||
|
||||
class PlusActivity : QkActivity<PlusViewModel>(), PlusView {
|
||||
|
||||
@Inject lateinit var fontProvider: FontProvider
|
||||
|
||||
override val viewModelClass = PlusViewModel::class
|
||||
override val supporterSelectedIntent by lazy { supporter.clicks() }
|
||||
override val donorSelectedIntent by lazy { donor.clicks() }
|
||||
@@ -47,6 +52,12 @@ class PlusActivity : QkActivity<PlusViewModel>(), PlusView {
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
fontProvider.getLato {
|
||||
val typeface = Typeface.create(it, Typeface.BOLD)
|
||||
collapsingToolbar.setCollapsedTitleTypeface(typeface)
|
||||
collapsingToolbar.setExpandedTitleTypeface(typeface)
|
||||
}
|
||||
|
||||
colors.textPrimary
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color ->
|
||||
|
||||
Reference in New Issue
Block a user