optimize contacts page and contact picker
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 3s
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 3s
This commit is contained in:
@@ -14,6 +14,7 @@ import sh.sar.basedbank.databinding.ItemPickerRowBinding
|
||||
import sh.sar.basedbank.databinding.ItemPickerSectionHeaderBinding
|
||||
|
||||
class ContactPickerAdapter(
|
||||
private val imageCache: MutableMap<String, Bitmap>,
|
||||
private val onItemClick: (accountNumber: String, label: String) -> Unit,
|
||||
private val onSameAsFrom: () -> Unit,
|
||||
private val onImageNeeded: ((hash: String) -> Unit)? = null,
|
||||
@@ -35,7 +36,6 @@ class ContactPickerAdapter(
|
||||
}
|
||||
|
||||
private var items: List<PickerItem> = emptyList()
|
||||
private val imageCache = mutableMapOf<String, Bitmap>()
|
||||
|
||||
fun updateImage(hash: String, bitmap: Bitmap) {
|
||||
imageCache[hash] = bitmap
|
||||
|
||||
@@ -33,6 +33,7 @@ class ContactPickerSheetFragment : BottomSheetDialogFragment() {
|
||||
private val viewModel: HomeViewModel by activityViewModels()
|
||||
|
||||
private val pendingHashes = mutableSetOf<String>()
|
||||
private val sharedImageCache = mutableMapOf<String, Bitmap>()
|
||||
private val profileImageHashes = mutableSetOf<String>()
|
||||
private val app get() = requireActivity().application as BasedBankApp
|
||||
private val session get() = app.mibSession
|
||||
@@ -48,6 +49,7 @@ class ContactPickerSheetFragment : BottomSheetDialogFragment() {
|
||||
|
||||
val pageAdapters: List<ContactPickerAdapter> = pages.mapIndexed { i, page ->
|
||||
ContactPickerAdapter(
|
||||
imageCache = sharedImageCache,
|
||||
onItemClick = { accountNumber, label -> handlePickerSelection(accountNumber, label) },
|
||||
onSameAsFrom = {},
|
||||
onImageNeeded = { hash -> fetchImage(hash) },
|
||||
|
||||
@@ -16,6 +16,7 @@ import sh.sar.basedbank.api.mib.MibBeneficiary
|
||||
import sh.sar.basedbank.databinding.ItemContactBinding
|
||||
|
||||
class ContactsAdapter(
|
||||
private val imageCache: MutableMap<String, Bitmap>,
|
||||
private val onImageNeeded: (hash: String) -> Unit,
|
||||
private val onDeleteClick: (MibBeneficiary) -> Unit,
|
||||
private val onTransferClick: (MibBeneficiary) -> Unit
|
||||
@@ -23,7 +24,6 @@ class ContactsAdapter(
|
||||
|
||||
private var allContacts: List<MibBeneficiary> = emptyList()
|
||||
private var displayed: List<MibBeneficiary> = emptyList()
|
||||
private val imageCache = mutableMapOf<String, Bitmap>()
|
||||
|
||||
private var activeCategoryId: String? = null
|
||||
private var searchQuery: String = ""
|
||||
|
||||
@@ -36,6 +36,7 @@ class ContactsFragment : Fragment() {
|
||||
private val viewModel: HomeViewModel by activityViewModels()
|
||||
|
||||
private val pendingHashes = mutableSetOf<String>()
|
||||
private val sharedImageCache = mutableMapOf<String, Bitmap>()
|
||||
private val app get() = requireActivity().application as BasedBankApp
|
||||
private val session get() = app.mibSession
|
||||
|
||||
@@ -52,6 +53,7 @@ class ContactsFragment : Fragment() {
|
||||
private val density get() = resources.displayMetrics.density
|
||||
val contactAdapters: List<ContactsAdapter> = pages.map { page ->
|
||||
ContactsAdapter(
|
||||
imageCache = sharedImageCache,
|
||||
onImageNeeded = { hash -> fetchImage(hash) },
|
||||
onDeleteClick = { contact -> confirmDelete(contact) },
|
||||
onTransferClick = { contact -> openTransfer(contact) }
|
||||
|
||||
@@ -450,8 +450,9 @@ class HomeActivity : AppCompatActivity() {
|
||||
val bmlContacts = withContext(Dispatchers.IO) { bmlFlow.fetchContacts(session) }
|
||||
if (bmlContacts.isNotEmpty()) {
|
||||
ContactsCache.saveBml(this@HomeActivity, bmlContacts)
|
||||
val mibContacts = viewModel.contacts.value ?: ContactsCache.loadContacts(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(mibContacts, bmlContacts))
|
||||
val mibContacts = ContactsCache.loadContacts(this@HomeActivity)
|
||||
val fahipayContacts = ContactsCache.loadFahipay(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(mergeContacts(mibContacts, bmlContacts), fahipayContacts))
|
||||
}
|
||||
} catch (_: Exception) { /* keep cached */ }
|
||||
}
|
||||
@@ -489,12 +490,11 @@ class HomeActivity : AppCompatActivity() {
|
||||
val contacts = groups.flatMap { it.contacts }
|
||||
val categories = groups.map { MibBeneficiaryCategory(it.categoryId, it.label, it.contacts.size) }
|
||||
ContactsCache.saveFahipay(this@HomeActivity, contacts, categories)
|
||||
val existing = viewModel.contacts.value ?: emptyList()
|
||||
val nonFahipay = existing.filter { it.benefType != "FAHIPAY" }
|
||||
viewModel.contacts.postValue(mergeContacts(nonFahipay, contacts))
|
||||
val existingCats = viewModel.contactCategories.value ?: emptyList()
|
||||
val nonFahipayCats = existingCats.filter { !it.id.startsWith("FAHIPAY_") }
|
||||
viewModel.contactCategories.postValue(nonFahipayCats + categories)
|
||||
val mibContacts = ContactsCache.loadContacts(this@HomeActivity)
|
||||
val bmlContacts = ContactsCache.loadBml(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(mergeContacts(mibContacts, bmlContacts), contacts))
|
||||
val mibCategories = ContactsCache.loadCategories(this@HomeActivity)
|
||||
viewModel.contactCategories.postValue(mibCategories + categories)
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
@@ -538,8 +538,10 @@ class HomeActivity : AppCompatActivity() {
|
||||
if (allContacts.isNotEmpty()) {
|
||||
ContactsCache.save(this@HomeActivity, allContacts, allCategories)
|
||||
val bmlContacts = ContactsCache.loadBml(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(allContacts, bmlContacts))
|
||||
viewModel.contactCategories.postValue(allCategories)
|
||||
val fahipayContacts = ContactsCache.loadFahipay(this@HomeActivity)
|
||||
val fahipayCategories = ContactsCache.loadFahipayCategories(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(mergeContacts(allContacts, bmlContacts), fahipayContacts))
|
||||
viewModel.contactCategories.postValue(allCategories + fahipayCategories)
|
||||
}
|
||||
} catch (_: Exception) { /* keep cached data */ }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user