feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 96a9b5ffff
commit e01954c90f
  1. 9
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt

@ -26,7 +26,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
private var iconNames: Array<CharSequence>
private val mEntryDrawables = arrayListOf<Drawable>()
private val mEntryDrawables = arrayListOf<Drawable?>()
init {
widgetLayoutResource = R.layout.view_icon
@ -42,8 +42,11 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference
for (iconName in iconNames) {
val resId = context.resources
.getIdentifier(iconName.toString(), "mipmap", context.packageName)
val d = context.getCompatDrawable(resId)
mEntryDrawables.add(d!!)
var d: Drawable? = null
kotlin.runCatching {
d = context.getCompatDrawable(resId)
}
mEntryDrawables.add(d)
}
}

Loading…
Cancel
Save