forked from upstream-mirrors/quik
Allow null typeface to be passed in FontProvider callback
This commit is contained in:
@@ -27,11 +27,11 @@ import javax.inject.Inject
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class FontProvider @Inject constructor(private val context: Context) {
|
class FontProvider @Inject constructor(context: Context) {
|
||||||
|
|
||||||
private var lato: Typeface? = null
|
private var lato: Typeface? = null
|
||||||
|
|
||||||
private val pendingCallbacks = ArrayList<(Typeface) -> Unit>()
|
private val pendingCallbacks = ArrayList<(Typeface?) -> Unit>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() {
|
ResourcesCompat.getFont(context, R.font.lato, object : ResourcesCompat.FontCallback() {
|
||||||
@@ -48,11 +48,11 @@ class FontProvider @Inject constructor(private val context: Context) {
|
|||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLato(callback: (Typeface) -> Unit) {
|
fun getLato(callback: (Typeface?) -> Unit) {
|
||||||
lato?.run(callback)
|
lato?.run(callback)
|
||||||
|
|
||||||
if (lato == null) {
|
if (lato == null) {
|
||||||
pendingCallbacks += callback
|
pendingCallbacks.add(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user