mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-29 13:22:59 -08:00
Load icons as coroutine
This commit is contained in:
1 parent
ccc8e4664d
commit
e9fc6bed23
4 files changed
+22
-11
No files matched your search
@@ -22,7 +22,6 @@ package com.kunzisoft.keepass.activities.fragments
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
|
||||
|
||||
@@ -32,8 +31,8 @@ class IconCustomFragment : IconFragment<IconImageCustom>() {
|
||||
return R.layout.fragment_icon_grid
|
||||
}
|
||||
|
||||
override fun defineIconList(database: Database): List<IconImageCustom> {
|
||||
return database.getCustomIconList()
|
||||
override fun defineIconList(): List<IconImageCustom> {
|
||||
return mDatabase?.getCustomIconList() ?: listOf()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -33,6 +33,10 @@ import com.kunzisoft.keepass.adapters.IconPickerAdapter
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageDraw
|
||||
import com.kunzisoft.keepass.viewmodels.IconPickerViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
||||
IconPickerAdapter.IconPickerListener<T> {
|
||||
@@ -41,27 +45,37 @@ abstract class IconFragment<T: IconImageDraw> : StylishFragment(),
|
||||
protected lateinit var iconPickerAdapter: IconPickerAdapter<T>
|
||||
protected var iconActionSelectionMode = false
|
||||
|
||||
protected val database = Database.getInstance()
|
||||
protected var mDatabase: Database? = null
|
||||
|
||||
protected val iconPickerViewModel: IconPickerViewModel by activityViewModels()
|
||||
|
||||
abstract fun retrieveMainLayoutId(): Int
|
||||
|
||||
abstract fun defineIconList(database: Database): List<T>
|
||||
abstract fun defineIconList(): List<T>
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
|
||||
mDatabase = Database.getInstance()
|
||||
|
||||
// Retrieve the textColor to tint the icon
|
||||
val ta = contextThemed?.obtainStyledAttributes(intArrayOf(android.R.attr.textColor))
|
||||
val tintColor = ta?.getColor(0, Color.BLACK) ?: Color.BLACK
|
||||
ta?.recycle()
|
||||
|
||||
iconPickerAdapter = IconPickerAdapter<T>(context, tintColor).apply {
|
||||
iconDrawableFactory = database.iconDrawableFactory
|
||||
iconDrawableFactory = mDatabase?.iconDrawableFactory
|
||||
}
|
||||
|
||||
iconPickerAdapter.setList(defineIconList(database))
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val populateList = launch {
|
||||
iconPickerAdapter.setList(defineIconList())
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
populateList.join()
|
||||
iconPickerAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater,
|
||||
|
||||
+2
-3
@@ -20,7 +20,6 @@
|
||||
package com.kunzisoft.keepass.activities.fragments
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
|
||||
|
||||
@@ -30,8 +29,8 @@ class IconStandardFragment : IconFragment<IconImageStandard>() {
|
||||
return R.layout.fragment_icon_grid
|
||||
}
|
||||
|
||||
override fun defineIconList(database: Database): List<IconImageStandard> {
|
||||
return database.getStandardIconList()
|
||||
override fun defineIconList(): List<IconImageStandard> {
|
||||
return mDatabase?.getStandardIconList() ?: listOf()
|
||||
}
|
||||
|
||||
override fun onIconClickListener(icon: IconImageStandard) {
|
||||
|
||||
@@ -79,7 +79,6 @@ class IconPickerAdapter<I: IconImageDraw>(val context: Context, private val tint
|
||||
icons.forEach { iconImage ->
|
||||
iconList.add(iconImage)
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CustomIconViewHolder {
|
||||
|
||||
Reference in new issue
Block a user