refactor codebase to be more module for later adding new banks.. add support for single profile mib accounts.. add suport for disabling mib profiles in settings
Auto Tag on Version Change / check-version (push) Successful in 6s
Auto Tag on Version Change / check-version (push) Successful in 6s
This commit is contained in:
@@ -17,8 +17,10 @@ object AccountCache {
|
||||
val arr = JSONArray()
|
||||
for (acc in accounts) {
|
||||
arr.put(JSONObject().apply {
|
||||
put("bank", acc.bank)
|
||||
put("profileName", acc.profileName)
|
||||
put("profileType", acc.profileType)
|
||||
put("cifType", acc.cifType)
|
||||
put("accountNumber", acc.accountNumber)
|
||||
put("accountBriefName", acc.accountBriefName)
|
||||
put("currencyName", acc.currencyName)
|
||||
@@ -68,20 +70,21 @@ object AccountCache {
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
MibAccount(
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
bank = "BML",
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
accountBriefName = o.optString("accountBriefName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
availableBalance = o.optString("availableBalance"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
profileImageHash = null,
|
||||
loginTag = o.optString("loginTag"),
|
||||
internalId = o.optString("internalId", "")
|
||||
loginTag = o.optString("loginTag"),
|
||||
internalId = o.optString("internalId", "")
|
||||
)
|
||||
}
|
||||
} catch (_: Exception) { emptyList() }
|
||||
@@ -121,20 +124,21 @@ object AccountCache {
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
MibAccount(
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
bank = "FAHIPAY",
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
accountBriefName = o.optString("accountBriefName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
availableBalance = o.optString("availableBalance"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
profileImageHash = null,
|
||||
loginTag = o.optString("loginTag"),
|
||||
internalId = o.optString("internalId", "")
|
||||
loginTag = o.optString("loginTag"),
|
||||
internalId = o.optString("internalId", "")
|
||||
)
|
||||
}
|
||||
} catch (_: Exception) { emptyList() }
|
||||
@@ -153,20 +157,22 @@ object AccountCache {
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
MibAccount(
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
bank = o.optString("bank", "MIB"),
|
||||
profileName = o.optString("profileName"),
|
||||
profileType = o.optString("profileType"),
|
||||
cifType = o.optString("cifType", ""),
|
||||
accountNumber = o.optString("accountNumber"),
|
||||
accountBriefName = o.optString("accountBriefName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
currencyName = o.optString("currencyName"),
|
||||
accountTypeName = o.optString("accountTypeName"),
|
||||
availableBalance = o.optString("availableBalance"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
currentBalance = o.optString("currentBalance"),
|
||||
blockedAmount = o.optString("blockedAmount"),
|
||||
mvrBalance = o.optString("mvrBalance"),
|
||||
statusDesc = o.optString("statusDesc"),
|
||||
profileImageHash = o.optString("profileImageHash").takeIf { it.isNotBlank() },
|
||||
loginTag = o.optString("loginTag"),
|
||||
profileId = o.optString("profileId", "")
|
||||
loginTag = o.optString("loginTag"),
|
||||
profileId = o.optString("profileId", "")
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
/**
|
||||
* Standard display model for the account history header card — produced by
|
||||
* per-bank parsers, consumed by AccountHistoryAdapter with no bank logic.
|
||||
*/
|
||||
data class AccountHistoryDisplay(
|
||||
val name: String,
|
||||
val number: String,
|
||||
val bankPill: String?, // "BML", "FP", null for MIB (no pill)
|
||||
val typeLabel: String, // e.g. "Savings", "Current", "Visa Platinum"
|
||||
val availableBalance: String, // formatted "CCY amount"
|
||||
val workingBalance: String, // ledger/working balance — formatted "CCY amount"
|
||||
val blockedBalance: String? // null if zero or not applicable
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.bmlapi.BmlHistoryParser
|
||||
import sh.sar.basedbank.util.fahipayapi.FahipayHistoryParser
|
||||
import sh.sar.basedbank.util.mibapi.MibHistoryParser
|
||||
|
||||
object AccountHistoryParser {
|
||||
|
||||
fun from(account: MibAccount): AccountHistoryDisplay? = when (account.bank) {
|
||||
"BML" -> BmlHistoryParser.displayData(account)
|
||||
"FAHIPAY" -> FahipayHistoryParser.displayData(account)
|
||||
"MIB" -> MibHistoryParser.displayData(account)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
data class AccountListDisplay(
|
||||
val name: String,
|
||||
val number: String,
|
||||
val typeLabel: String,
|
||||
val balance: String,
|
||||
val isCard: Boolean = false,
|
||||
val cardBrandIcon: Int = 0, // drawable res, only meaningful if isCard
|
||||
val statusLabel: String? = null // null = active; shown as status pill if set
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.bmlapi.BmlDashboardParser
|
||||
import sh.sar.basedbank.util.fahipayapi.FahipayAccountParser
|
||||
import sh.sar.basedbank.util.mibapi.MibAccountParser
|
||||
|
||||
object AccountListParser {
|
||||
|
||||
fun from(account: MibAccount): AccountListDisplay? = when (account.bank) {
|
||||
"BML" -> BmlDashboardParser.displayData(account)
|
||||
"FAHIPAY" -> FahipayAccountParser.displayData(account)
|
||||
"MIB" -> MibAccountParser.displayData(account)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
object BmlDashboardParser {
|
||||
|
||||
/**
|
||||
* Returns a display-ready product label for a BML dashboard account or card.
|
||||
* Known BML product names are mapped to short friendly labels.
|
||||
* Everything else is title-cased (first letter of each word capitalised).
|
||||
*/
|
||||
fun productLabel(raw: String): String {
|
||||
val u = raw.trim().uppercase()
|
||||
return when {
|
||||
u == "SAVINGS ACCOUNT" -> "Savings"
|
||||
u == "CURRENT ACCOUNT" ||
|
||||
u == "CURRENT ACCOUNT(PERSONAL)" ||
|
||||
u == "CURRENT ACCOUNT(BUSINESS)" -> "Current"
|
||||
u == "WADIAH RETAIL CURRENT ACCOUNT" ||
|
||||
u == "WADIAH BUSINESS CURRENT ACCOUNT" -> "Islamic Current"
|
||||
u == "BML ISLAMIC SAVINGS ACCOUNT" -> "Islamic Savings"
|
||||
else -> toTitleCase(raw)
|
||||
}
|
||||
}
|
||||
|
||||
fun toTitleCase(input: String): String =
|
||||
input.trim().lowercase().split(" ").joinToString(" ") { word ->
|
||||
word.replaceFirstChar { it.uppercaseChar() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
/**
|
||||
* Standard display model for a contact row — produced by per-bank parsers,
|
||||
* consumed by UI. No bank-specific logic in adapters or fragments.
|
||||
*/
|
||||
data class ContactDisplay(
|
||||
val id: String, // internal contact ID (benefNo)
|
||||
val name: String, // display nickname
|
||||
val realName: String, // legal name — used for search
|
||||
val accountNumber: String,
|
||||
val categoryId: String, // for tab filtering
|
||||
val network: TransferNetwork,
|
||||
val bankColor: String,
|
||||
val detail: String?, // pre-formatted "Name · CCY · Bank" line; null = hide row
|
||||
val imageHash: String?,
|
||||
val profileId: String, // MIB profile ID or BML loginTag (needed by ContactManager)
|
||||
val transferSubtitle: String, // "Bank · accountNumber" shown in transfer screen
|
||||
val canTransfer: Boolean,
|
||||
val canEdit: Boolean,
|
||||
val canDelete: Boolean
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibBeneficiary
|
||||
import sh.sar.basedbank.util.bmlapi.BmlContactParser
|
||||
import sh.sar.basedbank.util.fahipayapi.FahipayContactParser
|
||||
import sh.sar.basedbank.util.mibapi.MibContactParser
|
||||
|
||||
object ContactListParser {
|
||||
|
||||
fun from(contact: MibBeneficiary): ContactDisplay? = when {
|
||||
contact.benefCategoryId == "BML" -> BmlContactParser.displayData(contact)
|
||||
contact.benefType == "FAHIPAY" -> FahipayContactParser.displayData(contact)
|
||||
contact.benefType in setOf("I", "L", "S") -> MibContactParser.displayData(contact)
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun fromList(contacts: List<MibBeneficiary>): List<ContactDisplay> = contacts.mapNotNull { from(it) }
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
import sh.sar.basedbank.BasedBankApp
|
||||
import sh.sar.basedbank.api.bml.BmlLoginFlow
|
||||
import sh.sar.basedbank.api.mib.MibContactsClient
|
||||
|
||||
/**
|
||||
* Behaviour dispatcher for contact operations.
|
||||
* Routes add/delete to the correct bank API based on TransferNetwork.
|
||||
* UI code never inspects the network or bank type directly.
|
||||
*/
|
||||
object ContactManager {
|
||||
|
||||
/** Deletes [contact] via the appropriate bank API. Returns true on success. */
|
||||
suspend fun delete(contact: ContactDisplay, app: BasedBankApp): Boolean = when (contact.network) {
|
||||
TransferNetwork.BML -> deleteBml(contact, app)
|
||||
TransferNetwork.FAHIPAY -> false // Fahipay contacts are read-only
|
||||
TransferNetwork.MIB, TransferNetwork.LOCAL, TransferNetwork.SWIFT -> deleteMib(contact, app)
|
||||
}
|
||||
|
||||
private fun deleteBml(contact: ContactDisplay, app: BasedBankApp): Boolean {
|
||||
val sess = app.bmlSessions[contact.profileId] ?: app.anyBmlSession() ?: return false
|
||||
val contactId = contact.id.removePrefix("bml_")
|
||||
return try { BmlLoginFlow().deleteContact(sess, contactId) } catch (_: Exception) { false }
|
||||
}
|
||||
|
||||
private fun deleteMib(contact: ContactDisplay, app: BasedBankApp): Boolean {
|
||||
val sess = app.mibSession ?: return false
|
||||
return try {
|
||||
if (contact.profileId.isNotBlank()) {
|
||||
val profile = app.mibProfiles.firstOrNull { it.profileId == contact.profileId }
|
||||
if (profile != null) app.mibLoginFlow.switchProfile(sess, profile)
|
||||
}
|
||||
MibContactsClient().deleteContact(sess, contact.id)
|
||||
} catch (_: Exception) { false }
|
||||
}
|
||||
}
|
||||
@@ -329,6 +329,43 @@ class CredentialStore(context: Context) {
|
||||
val birthdate: String
|
||||
)
|
||||
|
||||
// ── MIB operating profiles (all profiles, regardless of visibility) ───────
|
||||
|
||||
fun saveMibProfiles(profiles: List<sh.sar.basedbank.api.mib.MibProfile>) {
|
||||
val arr = org.json.JSONArray()
|
||||
for (p in profiles) {
|
||||
arr.put(org.json.JSONObject().apply {
|
||||
put("profileId", p.profileId)
|
||||
put("name", p.name)
|
||||
put("cifType", p.cifType)
|
||||
put("profileType", p.profileType)
|
||||
put("color", p.color)
|
||||
})
|
||||
}
|
||||
prefs.edit().putString("mib_all_profiles", arr.toString()).apply()
|
||||
}
|
||||
|
||||
fun loadMibProfiles(): List<sh.sar.basedbank.api.mib.MibProfile> {
|
||||
val raw = prefs.getString("mib_all_profiles", null) ?: return emptyList()
|
||||
return try {
|
||||
val arr = org.json.JSONArray(raw)
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
sh.sar.basedbank.api.mib.MibProfile(
|
||||
profileId = o.optString("profileId"),
|
||||
customerProfileId = o.optString("profileId"),
|
||||
annexId = "",
|
||||
customerId = "",
|
||||
name = o.optString("name"),
|
||||
cifType = o.optString("cifType"),
|
||||
profileType = o.optString("profileType"),
|
||||
color = o.optString("color"),
|
||||
customerImage = null
|
||||
)
|
||||
}
|
||||
} catch (_: Exception) { emptyList() }
|
||||
}
|
||||
|
||||
fun saveMibFullName(name: String) {
|
||||
val key = getOrCreateKey()
|
||||
prefs.edit().putString("mib_enc_full_name", encrypt(name, key)).apply()
|
||||
@@ -399,6 +436,15 @@ class CredentialStore(context: Context) {
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
// ── MIB profile visibility ────────────────────────────────────────────────
|
||||
|
||||
/** Returns the set of MIB profile IDs the user has chosen to hide from the app. */
|
||||
fun getHiddenMibProfileIds(): Set<String> =
|
||||
prefs.getStringSet("mib_hidden_profile_ids", emptySet()) ?: emptySet()
|
||||
|
||||
fun setHiddenMibProfileIds(ids: Set<String>) =
|
||||
prefs.edit().putStringSet("mib_hidden_profile_ids", ids).apply()
|
||||
|
||||
// ── Crypto primitives ─────────────────────────────────────────────────────
|
||||
|
||||
private fun getOrCreateKey(): SecretKey {
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import sh.sar.basedbank.BasedBankApp
|
||||
import sh.sar.basedbank.api.bml.BmlLoginFlow
|
||||
import sh.sar.basedbank.api.fahipay.FahipayLoginFlow
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.api.mib.MibHistoryClient
|
||||
import sh.sar.basedbank.api.mib.Transaction
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Encapsulates all bank-specific pagination state and fetch logic for account history.
|
||||
* The fragment holds one instance per account and calls [hasMore] / [fetchNextPage]
|
||||
* without knowing which bank it is talking to.
|
||||
*/
|
||||
class HistoryFetcher(private val account: MibAccount) {
|
||||
|
||||
private val isMib get() = account.bank == "MIB"
|
||||
private val isBmlCard get() = account.profileType == "BML_PREPAID" || account.profileType == "BML_CREDIT"
|
||||
private val isFahipay get() = account.bank == "FAHIPAY"
|
||||
|
||||
// MIB pagination
|
||||
private var mibNextStart = 1
|
||||
private var mibTotalCount = -1
|
||||
|
||||
// BML CASA pagination
|
||||
private var bmlNextPage = 1
|
||||
private var bmlTotalPages = -1
|
||||
|
||||
// BML card pagination (month-based)
|
||||
private var cardMonthOffset = 0
|
||||
|
||||
// Fahipay pagination
|
||||
private var fahipayNextStart = 0
|
||||
private var fahipayTotal = -1
|
||||
|
||||
fun hasMore(): Boolean = when {
|
||||
isFahipay -> fahipayTotal < 0 || fahipayNextStart < fahipayTotal
|
||||
isMib -> mibTotalCount < 0 || mibNextStart <= mibTotalCount
|
||||
isBmlCard -> cardMonthOffset < 3
|
||||
else -> bmlTotalPages < 0 || bmlNextPage <= bmlTotalPages
|
||||
}
|
||||
|
||||
suspend fun fetchNextPage(app: BasedBankApp, pageSize: Int = 10): List<Transaction> = when {
|
||||
isFahipay -> withContext(Dispatchers.IO) { fetchFahipay(app) }
|
||||
isMib -> app.mibMutex.withLock { withContext(Dispatchers.IO) { fetchMib(app, pageSize) } }
|
||||
isBmlCard -> withContext(Dispatchers.IO) { fetchBmlCard(app) }
|
||||
else -> withContext(Dispatchers.IO) { fetchBmlCasa(app) }
|
||||
}
|
||||
|
||||
private fun fetchFahipay(app: BasedBankApp): List<Transaction> {
|
||||
val session = app.fahipaySession ?: return emptyList()
|
||||
val flow = FahipayLoginFlow()
|
||||
flow.setSessionCookie(session.sessionCookie)
|
||||
val (list, total) = flow.fetchHistory(
|
||||
session = session,
|
||||
accountDisplayName = account.accountBriefName,
|
||||
accountNumber = account.accountNumber,
|
||||
start = fahipayNextStart
|
||||
)
|
||||
if (total > 0) fahipayTotal = total
|
||||
fahipayNextStart += list.size
|
||||
return list
|
||||
}
|
||||
|
||||
private fun fetchMib(app: BasedBankApp, pageSize: Int): List<Transaction> {
|
||||
val session = app.mibSession ?: return emptyList()
|
||||
val profile = app.mibProfiles.firstOrNull { it.profileId == account.profileId }
|
||||
if (profile != null) app.mibLoginFlow.switchProfile(session, profile)
|
||||
val (list, total) = MibHistoryClient().fetchHistory(
|
||||
session = session,
|
||||
accountNo = account.accountNumber,
|
||||
accountDisplayName = account.accountBriefName,
|
||||
start = mibNextStart,
|
||||
pageSize = pageSize
|
||||
)
|
||||
if (total > 0) mibTotalCount = total
|
||||
mibNextStart += list.size.coerceAtLeast(pageSize)
|
||||
return list
|
||||
}
|
||||
|
||||
private fun fetchBmlCard(app: BasedBankApp): List<Transaction> {
|
||||
val session = app.bmlSessionFor(account) ?: return emptyList()
|
||||
val cal = Calendar.getInstance()
|
||||
cal.add(Calendar.MONTH, -cardMonthOffset)
|
||||
val month = SimpleDateFormat("yyyyMM", Locale.US).format(cal.time)
|
||||
cardMonthOffset++
|
||||
return BmlLoginFlow().fetchCardHistory(
|
||||
session = session,
|
||||
cardId = account.internalId,
|
||||
accountDisplayName = account.accountBriefName,
|
||||
accountNumber = account.accountNumber,
|
||||
month = month
|
||||
)
|
||||
}
|
||||
|
||||
private fun fetchBmlCasa(app: BasedBankApp): List<Transaction> {
|
||||
val session = app.bmlSessionFor(account) ?: return emptyList()
|
||||
val (list, totalPages) = BmlLoginFlow().fetchAccountHistory(
|
||||
session = session,
|
||||
accountId = account.internalId,
|
||||
accountDisplayName = account.accountBriefName,
|
||||
accountNumber = account.accountNumber,
|
||||
page = bmlNextPage
|
||||
)
|
||||
if (totalPages > 0) bmlTotalPages = totalPages
|
||||
bmlNextPage++
|
||||
return list
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
object MibAccountParser {
|
||||
|
||||
/**
|
||||
* Returns a display-ready product label for a MIB (Faisanet) account type name.
|
||||
* Known MIB accountTypeName values are mapped to short friendly labels.
|
||||
* Everything else is returned trimmed as-is.
|
||||
*/
|
||||
fun productLabel(raw: String): String {
|
||||
val u = raw.trim().uppercase()
|
||||
return when {
|
||||
u == "SAVING ACCOUNT" -> "Savings"
|
||||
u == "CURRENT ACCOUNT" -> "Current"
|
||||
else -> raw.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
/** App-unified term for the transfer routing network a contact uses. */
|
||||
enum class TransferNetwork {
|
||||
MIB, // MIB internal (both parties on MIB)
|
||||
LOCAL, // local inter-bank via IPS (e.g. BML from MIB's side)
|
||||
SWIFT, // international SWIFT
|
||||
BML, // Bank of Maldives
|
||||
FAHIPAY // Fahipay wallet
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package sh.sar.basedbank.util.bmlapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibBeneficiary
|
||||
import sh.sar.basedbank.util.ContactDisplay
|
||||
import sh.sar.basedbank.util.TransferNetwork
|
||||
|
||||
object BmlContactParser {
|
||||
|
||||
fun displayData(contact: MibBeneficiary) = ContactDisplay(
|
||||
id = contact.benefNo,
|
||||
name = contact.benefNickName,
|
||||
realName = contact.benefName,
|
||||
accountNumber = contact.benefAccount,
|
||||
categoryId = contact.benefCategoryId,
|
||||
network = TransferNetwork.BML,
|
||||
bankColor = contact.bankColor,
|
||||
detail = "${contact.benefName} · ${contact.transferCyDesc} · ${contact.benefBankName}",
|
||||
imageHash = contact.customerImgHash,
|
||||
profileId = contact.profileId,
|
||||
transferSubtitle = "${contact.benefBankName} · ${contact.benefAccount}",
|
||||
canTransfer = true,
|
||||
canEdit = true,
|
||||
canDelete = true
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package sh.sar.basedbank.util.bmlapi
|
||||
|
||||
import sh.sar.basedbank.R
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountListDisplay
|
||||
|
||||
object BmlDashboardParser {
|
||||
|
||||
/**
|
||||
* Returns all display fields for an account/card row in the accounts list.
|
||||
* Handles both BML CASA accounts and BML prepaid/credit cards.
|
||||
*/
|
||||
fun displayData(account: MibAccount): AccountListDisplay {
|
||||
val isCard = account.profileType == "BML_PREPAID" || account.profileType == "BML_CREDIT"
|
||||
return if (isCard) {
|
||||
val isActive = account.statusDesc.equals("Active", ignoreCase = true)
|
||||
AccountListDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
typeLabel = productLabel(account.accountTypeName),
|
||||
balance = "${account.currencyName} ${account.availableBalance}",
|
||||
isCard = true,
|
||||
cardBrandIcon = cardBrandIcon(account.accountTypeName),
|
||||
statusLabel = if (isActive) null else account.statusDesc
|
||||
)
|
||||
} else {
|
||||
AccountListDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
typeLabel = productLabel(account.accountTypeName),
|
||||
balance = listBalance(account)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a display-ready product label for a BML dashboard account or card.
|
||||
*/
|
||||
fun productLabel(raw: String): String {
|
||||
val u = raw.trim().uppercase()
|
||||
return when {
|
||||
u == "SAVINGS ACCOUNT" -> "Savings"
|
||||
u == "CURRENT ACCOUNT" ||
|
||||
u == "CURRENT ACCOUNT(PERSONAL)" ||
|
||||
u == "CURRENT ACCOUNT(BUSINESS)" -> "Current"
|
||||
u == "WADIAH RETAIL CURRENT ACCOUNT" ||
|
||||
u == "WADIAH BUSINESS CURRENT ACCOUNT" -> "Islamic Current"
|
||||
u == "BML ISLAMIC SAVINGS ACCOUNT" -> "Islamic Savings"
|
||||
else -> toTitleCase(raw)
|
||||
}
|
||||
}
|
||||
|
||||
/** Balance shown in the accounts list — ledger (working) balance for BML CASA. */
|
||||
fun listBalance(account: MibAccount): String =
|
||||
"${account.currencyName} ${account.currentBalance}"
|
||||
|
||||
fun cardBrandIcon(productName: String): Int = when {
|
||||
productName.contains("AMEX", ignoreCase = true) ||
|
||||
productName.contains("AMERICAN EXPRESS", ignoreCase = true) -> R.drawable.americanexpress
|
||||
productName.contains("VISA", ignoreCase = true) -> R.drawable.visa
|
||||
productName.contains("MASTERCARD", ignoreCase = true) -> R.drawable.mastercard
|
||||
else -> R.drawable.ic_nav_card
|
||||
}
|
||||
|
||||
fun toTitleCase(input: String): String =
|
||||
input.trim().lowercase().split(" ").joinToString(" ") { word ->
|
||||
word.replaceFirstChar { it.uppercaseChar() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sh.sar.basedbank.util.bmlapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountHistoryDisplay
|
||||
|
||||
object BmlHistoryParser {
|
||||
|
||||
fun displayData(account: MibAccount): AccountHistoryDisplay {
|
||||
val blocked = account.blockedAmount.toDoubleOrNull() ?: 0.0
|
||||
return AccountHistoryDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
bankPill = "BML",
|
||||
typeLabel = BmlDashboardParser.productLabel(account.accountTypeName),
|
||||
availableBalance = "${account.currencyName} ${account.availableBalance}",
|
||||
workingBalance = "${account.currencyName} ${account.currentBalance}",
|
||||
blockedBalance = if (blocked > 0.0) "${account.currencyName} ${account.blockedAmount}" else null
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package sh.sar.basedbank.util.fahipayapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountListDisplay
|
||||
|
||||
object FahipayAccountParser {
|
||||
|
||||
fun displayData(account: MibAccount) = AccountListDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
typeLabel = account.accountTypeName,
|
||||
balance = "${account.currencyName} ${account.availableBalance}"
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package sh.sar.basedbank.util.fahipayapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibBeneficiary
|
||||
import sh.sar.basedbank.util.ContactDisplay
|
||||
import sh.sar.basedbank.util.TransferNetwork
|
||||
|
||||
object FahipayContactParser {
|
||||
|
||||
fun displayData(contact: MibBeneficiary) = ContactDisplay(
|
||||
id = contact.benefNo,
|
||||
name = contact.benefNickName,
|
||||
realName = contact.benefName,
|
||||
accountNumber = contact.benefAccount,
|
||||
categoryId = contact.benefCategoryId,
|
||||
network = TransferNetwork.FAHIPAY,
|
||||
bankColor = contact.bankColor,
|
||||
detail = null, // Fahipay contacts show no detail line
|
||||
imageHash = contact.customerImgHash,
|
||||
profileId = contact.profileId,
|
||||
transferSubtitle = contact.benefAccount,
|
||||
canTransfer = false,
|
||||
canEdit = false,
|
||||
canDelete = false
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package sh.sar.basedbank.util.fahipayapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountHistoryDisplay
|
||||
|
||||
object FahipayHistoryParser {
|
||||
|
||||
fun displayData(account: MibAccount) = AccountHistoryDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
bankPill = "FP",
|
||||
typeLabel = account.accountTypeName,
|
||||
availableBalance = "${account.currencyName} ${account.availableBalance}",
|
||||
workingBalance = "${account.currencyName} ${account.currentBalance}",
|
||||
blockedBalance = null
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package sh.sar.basedbank.util.mibapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountListDisplay
|
||||
|
||||
object MibAccountParser {
|
||||
|
||||
fun displayData(account: MibAccount) = AccountListDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
typeLabel = productLabel(account.accountTypeName),
|
||||
balance = "${account.currencyName} ${account.availableBalance}"
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns a display-ready product label for a MIB (Faisanet) account type name.
|
||||
*/
|
||||
fun productLabel(raw: String): String {
|
||||
val u = raw.trim().uppercase()
|
||||
return when {
|
||||
u == "SAVING ACCOUNT" -> "Savings"
|
||||
u == "CURRENT ACCOUNT" -> "Current"
|
||||
else -> raw.trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package sh.sar.basedbank.util.mibapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibBeneficiary
|
||||
import sh.sar.basedbank.util.ContactDisplay
|
||||
import sh.sar.basedbank.util.TransferNetwork
|
||||
|
||||
object MibContactParser {
|
||||
|
||||
fun displayData(contact: MibBeneficiary): ContactDisplay {
|
||||
val network = when (contact.benefType) {
|
||||
"I" -> TransferNetwork.MIB
|
||||
"S" -> TransferNetwork.SWIFT
|
||||
else -> TransferNetwork.LOCAL // "L" and anything else
|
||||
}
|
||||
return ContactDisplay(
|
||||
id = contact.benefNo,
|
||||
name = contact.benefNickName,
|
||||
realName = contact.benefName,
|
||||
accountNumber = contact.benefAccount,
|
||||
categoryId = contact.benefCategoryId,
|
||||
network = network,
|
||||
bankColor = contact.bankColor,
|
||||
detail = "${contact.benefName} · ${contact.transferCyDesc} · ${contact.benefBankName}",
|
||||
imageHash = contact.customerImgHash,
|
||||
profileId = contact.profileId,
|
||||
transferSubtitle = "${contact.benefBankName} · ${contact.benefAccount}",
|
||||
canTransfer = true,
|
||||
canEdit = true,
|
||||
canDelete = true
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package sh.sar.basedbank.util.mibapi
|
||||
|
||||
import sh.sar.basedbank.api.mib.MibAccount
|
||||
import sh.sar.basedbank.util.AccountHistoryDisplay
|
||||
|
||||
object MibHistoryParser {
|
||||
|
||||
fun displayData(account: MibAccount) = AccountHistoryDisplay(
|
||||
name = account.accountBriefName,
|
||||
number = account.accountNumber,
|
||||
bankPill = null, // MIB has no bank pill
|
||||
typeLabel = MibAccountParser.productLabel(account.accountTypeName),
|
||||
availableBalance = "${account.currencyName} ${account.availableBalance}",
|
||||
workingBalance = "${account.currencyName} ${account.currentBalance}",
|
||||
blockedBalance = null
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user