Fix icon selection and icon removed no longer accessible

This commit is contained in:
J-Jamet
2021-03-07 17:15:48 +01:00
parent 76d60ded4c
commit e5184a1568
2 changed files with 15 additions and 12 deletions

View File

@@ -34,9 +34,9 @@ class IconStandardFragment : IconFragment<IconImageStandard>() {
return database.getStandardIconList() return database.getStandardIconList()
} }
override fun onIconLongClickListener(icon: IconImageStandard) { override fun onIconClickListener(icon: IconImageStandard) {
iconPickerViewModel.pickStandardIcon(icon) iconPickerViewModel.pickStandardIcon(icon)
} }
override fun onIconClickListener(icon: IconImageStandard) {} override fun onIconLongClickListener(icon: IconImageStandard) {}
} }

View File

@@ -66,22 +66,23 @@ class IconDrawableFactory(private val retrieveCipherKey : () -> Database.LoadedK
*/ */
private fun getIconSuperDrawable(context: Context, iconDraw: IconImageDraw, width: Int, tintColor: Int = Color.WHITE): SuperDrawable { private fun getIconSuperDrawable(context: Context, iconDraw: IconImageDraw, width: Int, tintColor: Int = Color.WHITE): SuperDrawable {
val icon = iconDraw.getIconImageToDraw() val icon = iconDraw.getIconImageToDraw()
return if (!icon.custom.isUnknown) { if (!icon.custom.isUnknown) {
SuperDrawable(getIconDrawable(context.resources, icon.custom)) getIconDrawable(context.resources, icon.custom)?.let {
} else { return SuperDrawable(it)
val iconPack = IconPackChooser.getSelectedIconPack(context)
iconPack?.iconToResId(icon.standard.id)?.let { iconId ->
SuperDrawable(getIconDrawable(context.resources, iconId, width, tintColor), iconPack.tintable())
} ?: run {
SuperDrawable(PatternIcon(context.resources).blankDrawable)
} }
} }
val iconPack = IconPackChooser.getSelectedIconPack(context)
iconPack?.iconToResId(icon.standard.id)?.let { iconId ->
return SuperDrawable(getIconDrawable(context.resources, iconId, width, tintColor), iconPack.tintable())
} ?: run {
return SuperDrawable(PatternIcon(context.resources).blankDrawable)
}
} }
/** /**
* Build a custom [Drawable] from custom [icon] * Build a custom [Drawable] from custom [icon]
*/ */
private fun getIconDrawable(resources: Resources, icon: IconImageCustom): Drawable { private fun getIconDrawable(resources: Resources, icon: IconImageCustom): Drawable? {
val patternIcon = PatternIcon(resources) val patternIcon = PatternIcon(resources)
val cipherKey = retrieveCipherKey.invoke() val cipherKey = retrieveCipherKey.invoke()
if (cipherKey != null) { if (cipherKey != null) {
@@ -93,12 +94,14 @@ class IconDrawableFactory(private val retrieveCipherKey : () -> Database.LoadedK
val createdDraw = BitmapDrawable(resources, bitmap) val createdDraw = BitmapDrawable(resources, bitmap)
customIconMap[icon.uuid] = WeakReference(createdDraw) customIconMap[icon.uuid] = WeakReference(createdDraw)
return createdDraw return createdDraw
} ?: run {
} }
} else { } else {
return draw return draw
} }
} }
return patternIcon.blankDrawable return null
} }
/** /**