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
|
return R.layout.fragment_icon_grid
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun defineIconList(): List<IconImageCustom> {
|
override fun defineIconList() {
|
||||||
return mDatabase?.getCustomIconList() ?: listOf()
|
mDatabase?.doForEachCustomIcons { customIcon ->
|
||||||
|
iconPickerAdapter.addIcon(customIcon, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
|||||||
|
|
||||||
abstract fun retrieveMainLayoutId(): Int
|
abstract fun retrieveMainLayoutId(): Int
|
||||||
|
|
||||||
abstract fun defineIconList(): List<T>
|
abstract fun defineIconList()
|
||||||
|
|
||||||
override fun onAttach(context: Context) {
|
override fun onAttach(context: Context) {
|
||||||
super.onAttach(context)
|
super.onAttach(context)
|
||||||
@@ -69,7 +69,8 @@ abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
|||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val populateList = launch {
|
val populateList = launch {
|
||||||
iconPickerAdapter.setList(defineIconList())
|
iconPickerAdapter.clear()
|
||||||
|
defineIconList()
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
populateList.join()
|
populateList.join()
|
||||||
|
|||||||
@@ -29,8 +29,10 @@ class IconStandardFragment : IconFragment<IconImageStandard>() {
|
|||||||
return R.layout.fragment_icon_grid
|
return R.layout.fragment_icon_grid
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun defineIconList(): List<IconImageStandard> {
|
override fun defineIconList() {
|
||||||
return mDatabase?.getStandardIconList() ?: listOf()
|
mDatabase?.doForEachStandardIcons { standardIcon ->
|
||||||
|
iconPickerAdapter.addIcon(standardIcon, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onIconClickListener(icon: IconImageStandard) {
|
override fun onIconClickListener(icon: IconImageStandard) {
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ class IconPickerAdapter<I: IconImageDraw>(val context: Context, private val tint
|
|||||||
val lastPosition: Int
|
val lastPosition: Int
|
||||||
get() = iconList.lastIndex
|
get() = iconList.lastIndex
|
||||||
|
|
||||||
fun addIcon(icon: I) {
|
fun addIcon(icon: I, notify: Boolean = true) {
|
||||||
if (!iconList.contains(icon)) {
|
if (!iconList.contains(icon)) {
|
||||||
iconList.add(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 }
|
return iconList.filter { it.selected }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
iconList.clear()
|
||||||
|
}
|
||||||
|
|
||||||
fun setList(icons: List<I>) {
|
fun setList(icons: List<I>) {
|
||||||
iconList.clear()
|
iconList.clear()
|
||||||
icons.forEach { iconImage ->
|
icons.forEach { iconImage ->
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ class Database {
|
|||||||
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
|
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStandardIconList(): List<IconImageStandard> {
|
fun doForEachStandardIcons(action: (IconImageStandard) -> Unit) {
|
||||||
return iconsManager.getStandardIconList()
|
return iconsManager.doForEachStandardIcon(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStandardIcon(iconId: Int): IconImageStandard {
|
fun getStandardIcon(iconId: Int): IconImageStandard {
|
||||||
@@ -114,8 +114,8 @@ class Database {
|
|||||||
val allowCustomIcons: Boolean
|
val allowCustomIcons: Boolean
|
||||||
get() = mDatabaseKDBX != null
|
get() = mDatabaseKDBX != null
|
||||||
|
|
||||||
fun getCustomIconList(): List<IconImageCustom> {
|
fun doForEachCustomIcons(action: (IconImageCustom) -> Unit) {
|
||||||
return iconsManager.getCustomIconList()
|
return iconsManager.doForEachCustomIcon(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCustomIcon(iconId: UUID): IconImageCustom {
|
fun getCustomIcon(iconId: UUID): IconImageCustom {
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ class IconsManager {
|
|||||||
return standardCache[searchIconId]
|
return standardCache[searchIconId]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStandardIconList(): List<IconImageStandard> {
|
fun doForEachStandardIcon(action: (IconImageStandard) -> Unit) {
|
||||||
return standardCache
|
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) {
|
fun doForEachCustomIcon(action: (IconImageCustom) -> Unit) {
|
||||||
customCache.doForEachBinary { key, binary ->
|
customCache.doForEachBinary { key, binary ->
|
||||||
action.invoke(IconImageCustom(key, binary))
|
action.invoke(IconImageCustom(key, binary))
|
||||||
|
|||||||
Reference in New Issue
Block a user