mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Icon list optimization
This commit is contained in:
@@ -31,8 +31,10 @@ class IconCustomFragment : IconFragment<IconImageCustom>() {
|
||||
return R.layout.fragment_icon_grid
|
||||
}
|
||||
|
||||
override fun defineIconList(): List<IconImageCustom> {
|
||||
return mDatabase?.getCustomIconList() ?: listOf()
|
||||
override fun defineIconList() {
|
||||
mDatabase?.doForEachCustomIcons { customIcon ->
|
||||
iconPickerAdapter.addIcon(customIcon, false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -51,7 +51,7 @@ abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
||||
|
||||
abstract fun retrieveMainLayoutId(): Int
|
||||
|
||||
abstract fun defineIconList(): List<T>
|
||||
abstract fun defineIconList()
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
@@ -69,7 +69,8 @@ abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val populateList = launch {
|
||||
iconPickerAdapter.setList(defineIconList())
|
||||
iconPickerAdapter.clear()
|
||||
defineIconList()
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
populateList.join()
|
||||
|
||||
@@ -29,8 +29,10 @@ class IconStandardFragment : IconFragment<IconImageStandard>() {
|
||||
return R.layout.fragment_icon_grid
|
||||
}
|
||||
|
||||
override fun defineIconList(): List<IconImageStandard> {
|
||||
return mDatabase?.getStandardIconList() ?: listOf()
|
||||
override fun defineIconList() {
|
||||
mDatabase?.doForEachStandardIcons { standardIcon ->
|
||||
iconPickerAdapter.addIcon(standardIcon, false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onIconClickListener(icon: IconImageStandard) {
|
||||
|
||||
@@ -23,10 +23,12 @@ class IconPickerAdapter<I: IconImageDraw>(val context: Context, private val tint
|
||||
val lastPosition: Int
|
||||
get() = iconList.lastIndex
|
||||
|
||||
fun addIcon(icon: I) {
|
||||
fun addIcon(icon: I, notify: Boolean = true) {
|
||||
if (!iconList.contains(icon)) {
|
||||
iconList.add(icon)
|
||||
notifyItemInserted(iconList.indexOf(icon))
|
||||
if (notify) {
|
||||
notifyItemInserted(iconList.indexOf(icon))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +76,10 @@ class IconPickerAdapter<I: IconImageDraw>(val context: Context, private val tint
|
||||
return iconList.filter { it.selected }
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
iconList.clear()
|
||||
}
|
||||
|
||||
fun setList(icons: List<I>) {
|
||||
iconList.clear()
|
||||
icons.forEach { iconImage ->
|
||||
|
||||
@@ -103,8 +103,8 @@ class Database {
|
||||
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
|
||||
}
|
||||
|
||||
fun getStandardIconList(): List<IconImageStandard> {
|
||||
return iconsManager.getStandardIconList()
|
||||
fun doForEachStandardIcons(action: (IconImageStandard) -> Unit) {
|
||||
return iconsManager.doForEachStandardIcon(action)
|
||||
}
|
||||
|
||||
fun getStandardIcon(iconId: Int): IconImageStandard {
|
||||
@@ -114,8 +114,8 @@ class Database {
|
||||
val allowCustomIcons: Boolean
|
||||
get() = mDatabaseKDBX != null
|
||||
|
||||
fun getCustomIconList(): List<IconImageCustom> {
|
||||
return iconsManager.getCustomIconList()
|
||||
fun doForEachCustomIcons(action: (IconImageCustom) -> Unit) {
|
||||
return iconsManager.doForEachCustomIcon(action)
|
||||
}
|
||||
|
||||
fun getCustomIcon(iconId: UUID): IconImageCustom {
|
||||
|
||||
@@ -39,8 +39,10 @@ class IconsManager {
|
||||
return standardCache[searchIconId]
|
||||
}
|
||||
|
||||
fun getStandardIconList(): List<IconImageStandard> {
|
||||
return standardCache
|
||||
fun doForEachStandardIcon(action: (IconImageStandard) -> Unit) {
|
||||
standardCache.forEach { icon ->
|
||||
action.invoke(icon)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -73,14 +75,6 @@ class IconsManager {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCustomIconList(): List<IconImageCustom> {
|
||||
val list = ArrayList<IconImageCustom>()
|
||||
customCache.doForEachBinary { key, binary ->
|
||||
list.add(IconImageCustom(key, binary))
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun doForEachCustomIcon(action: (IconImageCustom) -> Unit) {
|
||||
customCache.doForEachBinary { key, binary ->
|
||||
action.invoke(IconImageCustom(key, binary))
|
||||
|
||||
Reference in New Issue
Block a user