forked from thijooree/android
fahipay serialized multi-login added
This commit is contained in:
@@ -176,7 +176,7 @@ class AccountHistoryFragment : Fragment() {
|
||||
return
|
||||
}
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
val sess = app.mibSession ?: return
|
||||
val sess = app.anyMibSession() ?: return
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = MibContactsClient().fetchProfileImageBase64(sess, hash) ?: return@launch
|
||||
|
||||
@@ -50,6 +50,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
val label: String,
|
||||
val isBml: Boolean,
|
||||
val mibProfile: MibProfile? = null,
|
||||
val mibLoginId: String? = null,
|
||||
val bmlLoginId: String? = null,
|
||||
val subtitle: String = ""
|
||||
)
|
||||
@@ -91,8 +92,10 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
|
||||
private fun buildDestinations(): List<DestinationOption> {
|
||||
val list = mutableListOf<DestinationOption>()
|
||||
for (profile in app.mibProfiles) {
|
||||
list.add(DestinationOption("MIB · ${profile.name}", isBml = false, mibProfile = profile, subtitle = profile.cifType))
|
||||
for ((loginId, profiles) in app.mibProfilesMap) {
|
||||
for (profile in profiles) {
|
||||
list.add(DestinationOption("MIB · ${profile.name}", isBml = false, mibProfile = profile, mibLoginId = loginId, subtitle = profile.cifType))
|
||||
}
|
||||
}
|
||||
val store = CredentialStore(requireContext())
|
||||
for ((loginId, _) in app.bmlSessions) {
|
||||
@@ -249,7 +252,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
if (mibVerified != null) return mibVerified
|
||||
|
||||
// 3) Fall back to MIB IPS lookup (for USD MIB accounts not reachable via BML)
|
||||
val mibSess = app.mibSession ?: return null
|
||||
val mibSess = app.anyMibSession() ?: return null
|
||||
return try {
|
||||
val info = MibTransferClient().lookup(mibSess, input)
|
||||
BmlAccountValidation(
|
||||
@@ -266,11 +269,12 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
}
|
||||
|
||||
private fun lookupForMib(dest: DestinationOption, input: String): BmlAccountValidation? {
|
||||
val mibSess = app.mibSession ?: return null
|
||||
val loginId = dest.mibLoginId ?: return null
|
||||
val mibSess = app.mibSessions[loginId] ?: return null
|
||||
val profile = dest.mibProfile ?: return null
|
||||
|
||||
val mibResult = try {
|
||||
app.mibLoginFlow.switchProfile(mibSess, profile)
|
||||
app.mibFlowFor(loginId).switchProfile(mibSess, profile)
|
||||
val info = MibTransferClient().lookup(mibSess, input)
|
||||
BmlAccountValidation(
|
||||
trnType = if (info.bankId == "MADVMVMV") "MIB_INTERNAL" else "MIB_LOCAL",
|
||||
@@ -429,8 +433,9 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
}
|
||||
|
||||
private fun saveToMib(alias: String): Boolean {
|
||||
val mibSess = app.mibSession ?: return false
|
||||
val dest = selectedDest ?: return false
|
||||
val loginId = dest.mibLoginId ?: return false
|
||||
val mibSess = app.mibSessions[loginId] ?: return false
|
||||
val profile = dest.mibProfile ?: return false
|
||||
val account = mibLookupAccount ?: return false
|
||||
val currency = binding.etCurrency.text?.toString()?.trim() ?: "MVR"
|
||||
@@ -442,7 +447,7 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
val name = bmlLookup?.name ?: ""
|
||||
|
||||
return try {
|
||||
app.mibLoginFlow.switchProfile(mibSess, profile)
|
||||
app.mibFlowFor(loginId).switchProfile(mibSess, profile)
|
||||
MibContactsClient().createContact(
|
||||
session = mibSess,
|
||||
benefType = benefType,
|
||||
@@ -488,8 +493,9 @@ class AddContactSheetFragment : BottomSheetDialogFragment() {
|
||||
if (loginId.isNotBlank()) ContactsCache.saveBml(requireContext(), loginId, fresh)
|
||||
} else {
|
||||
val profile = dest.mibProfile ?: return@launch
|
||||
val mibSess = app.mibSession ?: return@launch
|
||||
app.mibLoginFlow.switchProfile(mibSess, profile)
|
||||
val mibLoginId = dest.mibLoginId ?: return@launch
|
||||
val mibSess = app.mibSessions[mibLoginId] ?: return@launch
|
||||
app.mibFlowFor(mibLoginId).switchProfile(mibSess, profile)
|
||||
val fresh = MibContactsClient().fetchContacts(mibSess)
|
||||
.map { it.copy(profileId = profile.profileId) }
|
||||
val existing = viewModel.contacts.value ?: emptyList()
|
||||
|
||||
@@ -36,7 +36,7 @@ class ContactPickerSheetFragment : BottomSheetDialogFragment() {
|
||||
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
|
||||
private val session get() = app.anyMibSession()
|
||||
|
||||
private var fromAccountNumber: String = ""
|
||||
private var mediator: TabLayoutMediator? = null
|
||||
@@ -291,7 +291,7 @@ class ContactPickerSheetFragment : BottomSheetDialogFragment() {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = if (hash in profileImageHashes) {
|
||||
app.mibLoginFlow.fetchProfileImage(sess, hash)
|
||||
app.anyMibFlow()?.fetchProfileImage(sess, hash)
|
||||
} else {
|
||||
MibContactsClient().fetchProfileImageBase64(sess, hash)
|
||||
} ?: return@launch
|
||||
|
||||
@@ -40,7 +40,7 @@ class ContactsFragment : Fragment() {
|
||||
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
|
||||
private val session get() = app.anyMibSession()
|
||||
|
||||
private var allContacts: List<ContactDisplay> = emptyList()
|
||||
private var currentSearch: String = ""
|
||||
|
||||
@@ -128,31 +128,36 @@ class HomeActivity : AppCompatActivity() {
|
||||
|
||||
// Load data
|
||||
val app = application as BasedBankApp
|
||||
if (app.accounts.isNotEmpty() || app.bmlAccounts.isNotEmpty() || app.fahipayAccounts.isNotEmpty()) {
|
||||
if (app.mibAccounts.isNotEmpty() || app.bmlAccounts.isNotEmpty() || app.fahipayAccounts.isNotEmpty()) {
|
||||
// Came from fresh manual login — accounts ready, rest fetched in background
|
||||
val mibAccounts = app.accounts.filter { it.bank == "MIB" }
|
||||
val merged = mibAccounts + app.bmlAccounts + app.fahipayAccounts
|
||||
val merged = app.mibAccounts + app.bmlAccounts + app.fahipayAccounts
|
||||
viewModel.accounts.value = merged.filterVisibleAccounts()
|
||||
if (mibAccounts.isNotEmpty()) AccountCache.save(this, mibAccounts)
|
||||
if (app.mibAccounts.isNotEmpty()) AccountCache.save(this, app.mibAccounts)
|
||||
if (app.bmlAccounts.isNotEmpty()) {
|
||||
val byLoginId = app.bmlAccounts.groupBy { it.loginTag.removePrefix("bml_") }
|
||||
byLoginId.forEach { (loginId, accounts) -> AccountCache.saveBml(this, loginId, accounts) }
|
||||
}
|
||||
if (app.fahipayAccounts.isNotEmpty()) AccountCache.saveFahipay(this, app.fahipayAccounts)
|
||||
if (app.fahipayAccounts.isNotEmpty()) {
|
||||
val byLoginId = app.fahipayAccounts.groupBy { it.loginTag.removePrefix("fahipay_") }
|
||||
byLoginId.forEach { (loginId, accs) -> AccountCache.saveFahipay(this, loginId, accs) }
|
||||
}
|
||||
|
||||
val cachedFinancing = FinancingCache.load(this)
|
||||
if (cachedFinancing.isNotEmpty()) viewModel.financing.value = cachedFinancing
|
||||
val cachedLimits = ForeignLimitsCache.load(this)
|
||||
if (cachedLimits.isNotEmpty()) viewModel.bmlLimits.value = cachedLimits
|
||||
|
||||
refreshFinancing(app.mibSession, app.mibProfiles.filterVisibleProfiles())
|
||||
for ((loginId, session) in app.mibSessions) {
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
refreshFinancing(loginId, session, profiles.filterVisibleProfiles(loginId))
|
||||
}
|
||||
for ((_, session) in app.bmlSessions) refreshBmlLimits(session)
|
||||
} else {
|
||||
// Came from lock screen — show caches immediately, refresh everything in background
|
||||
val store = CredentialStore(this)
|
||||
val cachedMib = AccountCache.load(this)
|
||||
val cachedBml = AccountCache.loadBml(this, store.getBmlLoginIds())
|
||||
val cachedFahipay = AccountCache.loadFahipay(this)
|
||||
val cachedFahipay = AccountCache.loadFahipay(this, store.getFahipayLoginIds())
|
||||
val merged = cachedMib + cachedBml + cachedFahipay
|
||||
if (merged.isNotEmpty()) viewModel.accounts.value = merged
|
||||
val cachedFinancing = FinancingCache.load(this)
|
||||
@@ -160,7 +165,7 @@ class HomeActivity : AppCompatActivity() {
|
||||
val cachedLimits = ForeignLimitsCache.load(this)
|
||||
if (cachedLimits.isNotEmpty()) viewModel.bmlLimits.value = cachedLimits
|
||||
|
||||
autoRefresh(store.loadMibCredentials(), store.loadFahipayCredentials(), store)
|
||||
autoRefresh(store)
|
||||
}
|
||||
|
||||
// Show dashboard on first create
|
||||
@@ -169,27 +174,29 @@ class HomeActivity : AppCompatActivity() {
|
||||
binding.navigationView.setCheckedItem(R.id.nav_dashboard)
|
||||
}
|
||||
|
||||
// Keep MIB session alive every 25 seconds while the app is in the foreground
|
||||
// Keep all MIB sessions alive every 25 seconds while the app is in the foreground
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
while (true) {
|
||||
delay(25_000)
|
||||
val session = (application as BasedBankApp).mibSession ?: continue
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val cookieHeader = "mbmodel=IOS-1.0; xxid=${session.xxid}; " +
|
||||
"IBSID=${session.xxid}; mbnonce=${session.nonceGenerator}; time-tracker=597"
|
||||
val request = Request.Builder()
|
||||
.url("https://faisamobilex-wv.mib.com.mv/aProfile/keepAlive")
|
||||
.post(ByteArray(0).toRequestBody())
|
||||
.header("Cookie", cookieHeader)
|
||||
.header("User-Agent", "okhttp/4.11.0")
|
||||
.header("Accept", "application/json, text/plain, */*")
|
||||
.header("Accept-Encoding", "gzip")
|
||||
.header("Connection", "Keep-Alive")
|
||||
.build()
|
||||
OkHttpClient().newCall(request).execute().close()
|
||||
} catch (_: Exception) {}
|
||||
val sessions = (application as BasedBankApp).mibSessions.values.toList()
|
||||
for (session in sessions) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val cookieHeader = "mbmodel=IOS-1.0; xxid=${session.xxid}; " +
|
||||
"IBSID=${session.xxid}; mbnonce=${session.nonceGenerator}; time-tracker=597"
|
||||
val request = Request.Builder()
|
||||
.url("https://faisamobilex-wv.mib.com.mv/aProfile/keepAlive")
|
||||
.post(ByteArray(0).toRequestBody())
|
||||
.header("Cookie", cookieHeader)
|
||||
.header("User-Agent", "okhttp/4.11.0")
|
||||
.header("Accept", "application/json, text/plain, */*")
|
||||
.header("Accept-Encoding", "gzip")
|
||||
.header("Connection", "Keep-Alive")
|
||||
.build()
|
||||
OkHttpClient().newCall(request).execute().close()
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,51 +360,47 @@ class HomeActivity : AppCompatActivity() {
|
||||
|
||||
fun relogin() {
|
||||
val store = CredentialStore(this)
|
||||
val hasMib = store.hasMibCredentials()
|
||||
val mibLoginIds = store.getMibLoginIds()
|
||||
val bmlLoginIds = store.getBmlLoginIds()
|
||||
val hasFahipay = store.hasFahipayCredentials()
|
||||
if (!hasMib && bmlLoginIds.isEmpty() && !hasFahipay) {
|
||||
val fahipayLoginIds = store.getFahipayLoginIds()
|
||||
if (mibLoginIds.isEmpty() && bmlLoginIds.isEmpty() && fahipayLoginIds.isEmpty()) {
|
||||
startActivity(Intent(this, LoginActivity::class.java))
|
||||
finish()
|
||||
return
|
||||
}
|
||||
// Immediately drop accounts for logged-out banks from the displayed list
|
||||
// Immediately drop accounts for logged-out logins from the displayed list
|
||||
val current = viewModel.accounts.value ?: emptyList()
|
||||
viewModel.accounts.value = current.filter { acc ->
|
||||
if (!hasMib && acc.bank == "MIB") return@filter false
|
||||
if (acc.bank == "BML") {
|
||||
val loginId = acc.loginTag.removePrefix("bml_")
|
||||
return@filter loginId in bmlLoginIds
|
||||
}
|
||||
if (!hasFahipay && acc.bank == "FAHIPAY") return@filter false
|
||||
if (acc.bank == "MIB") return@filter acc.loginTag.removePrefix("mib_") in mibLoginIds
|
||||
if (acc.bank == "BML") return@filter acc.loginTag.removePrefix("bml_") in bmlLoginIds
|
||||
if (acc.bank == "FAHIPAY") return@filter acc.loginTag.removePrefix("fahipay_") in fahipayLoginIds
|
||||
true
|
||||
}
|
||||
autoRefresh(store.loadMibCredentials(), store.loadFahipayCredentials(), store)
|
||||
autoRefresh(store)
|
||||
}
|
||||
|
||||
private fun autoRefresh(
|
||||
mibCreds: CredentialStore.MibCredentials?,
|
||||
fahipayCreds: CredentialStore.FahipayCredentials?,
|
||||
store: CredentialStore
|
||||
) {
|
||||
private fun autoRefresh(store: CredentialStore) {
|
||||
val mibLoginIds = store.getMibLoginIds()
|
||||
val bmlLoginIds = store.getBmlLoginIds()
|
||||
if (mibCreds == null && bmlLoginIds.isEmpty() && fahipayCreds == null) return
|
||||
val fahipayLoginIds = store.getFahipayLoginIds()
|
||||
if (mibLoginIds.isEmpty() && bmlLoginIds.isEmpty() && fahipayLoginIds.isEmpty()) return
|
||||
binding.refreshIndicator.visibility = View.VISIBLE
|
||||
|
||||
lifecycleScope.launch {
|
||||
val mibJob = mibCreds?.let {
|
||||
async(Dispatchers.IO) {
|
||||
// One async job per MIB login, all run in parallel
|
||||
val mibJobs = mibLoginIds.mapNotNull { loginId ->
|
||||
val creds = store.loadMibCredentials(loginId) ?: return@mapNotNull null
|
||||
loginId to async(Dispatchers.IO) {
|
||||
try {
|
||||
val flow = MibLoginFlow(CredentialStore(this@HomeActivity))
|
||||
val accounts = flow.login(it.username, it.passwordHash, it.otpSeed)
|
||||
val accounts = flow.login(creds.username, creds.passwordHash, creds.otpSeed)
|
||||
val app = application as BasedBankApp
|
||||
app.accounts = accounts
|
||||
app.mibSession = flow.lastSession
|
||||
app.mibProfiles = flow.lastProfiles
|
||||
AccountCache.save(this@HomeActivity, accounts)
|
||||
CredentialStore(this@HomeActivity).saveMibProfiles(flow.lastProfiles)
|
||||
app.mibSessions[loginId] = flow.lastSession!!
|
||||
app.mibProfilesMap[loginId] = flow.lastProfiles
|
||||
app.mibLoginFlows[loginId] = flow
|
||||
store.saveMibProfiles(loginId, flow.lastProfiles)
|
||||
accounts
|
||||
} catch (_: Exception) { AccountCache.load(this@HomeActivity) }
|
||||
} catch (_: Exception) { AccountCache.load(this@HomeActivity).filter { it.loginTag == "mib_$loginId" } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,78 +438,87 @@ class HomeActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val fahipayJob = fahipayCreds?.let { creds ->
|
||||
async(Dispatchers.IO) {
|
||||
// One async job per Fahipay login, all run in parallel
|
||||
val fahipayJobs = fahipayLoginIds.mapNotNull { loginId ->
|
||||
val creds = store.loadFahipayCredentials(loginId) ?: return@mapNotNull null
|
||||
loginId to async(Dispatchers.IO) {
|
||||
val fahipayFlow = FahipayLoginFlow()
|
||||
val deviceUuid = store.getOrCreateFahipayDeviceUuid()
|
||||
val loginTag = "fahipay_$loginId"
|
||||
|
||||
val savedSession = store.loadFahipaySession()
|
||||
val savedSession = store.loadFahipaySession(loginId)
|
||||
if (savedSession != null) {
|
||||
try {
|
||||
val session = FahipaySession(savedSession.first, savedSession.second)
|
||||
fahipayFlow.setSessionCookie(session.sessionCookie)
|
||||
val balance = fahipayFlow.fetchBalance(session)
|
||||
val profile = fahipayFlow.fetchProfile(session)
|
||||
val loginTag = "fahipay_${profile.profileId}"
|
||||
val accounts = listOf(fahipayFlow.buildAccount(profile, balance, loginTag))
|
||||
val app = application as BasedBankApp
|
||||
app.fahipaySession = session
|
||||
app.fahipayAccounts = accounts
|
||||
AccountCache.saveFahipay(this@HomeActivity, accounts)
|
||||
return@async Pair(session, accounts)
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
app.fahipaySessions[loginId] = session
|
||||
AccountCache.saveFahipay(this@HomeActivity, loginId, accounts)
|
||||
return@async accounts
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
|
||||
try {
|
||||
val step = fahipayFlow.login(creds.idCard, creds.password, deviceUuid)
|
||||
if (step.twoFactorRequired) {
|
||||
return@async Pair(null, AccountCache.loadFahipay(this@HomeActivity))
|
||||
return@async AccountCache.loadFahipay(this@HomeActivity, loginId)
|
||||
}
|
||||
val authId = step.authId ?: return@async Pair(null, AccountCache.loadFahipay(this@HomeActivity))
|
||||
val authId = step.authId ?: return@async AccountCache.loadFahipay(this@HomeActivity, loginId)
|
||||
val cookieValue = fahipayFlow.getSessionCookieValue() ?: ""
|
||||
val session = FahipaySession(authId, cookieValue)
|
||||
store.saveFahipaySession(authId, cookieValue)
|
||||
store.saveFahipaySession(loginId, authId, cookieValue)
|
||||
val profile = fahipayFlow.fetchProfile(session)
|
||||
val balance = fahipayFlow.fetchBalance(session)
|
||||
val loginTag = "fahipay_${profile.profileId}"
|
||||
val accounts = listOf(fahipayFlow.buildAccount(profile, balance, loginTag))
|
||||
val app = application as BasedBankApp
|
||||
app.fahipaySession = session
|
||||
app.fahipayAccounts = accounts
|
||||
AccountCache.saveFahipay(this@HomeActivity, accounts)
|
||||
Pair(session, accounts)
|
||||
app.fahipaySessions[loginId] = session
|
||||
AccountCache.saveFahipay(this@HomeActivity, loginId, accounts)
|
||||
accounts
|
||||
} catch (_: Exception) {
|
||||
Pair(null, AccountCache.loadFahipay(this@HomeActivity))
|
||||
AccountCache.loadFahipay(this@HomeActivity, loginId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val mibAccounts = mibJob?.await() ?: AccountCache.load(this@HomeActivity)
|
||||
val mibResults = mibJobs.map { (loginId, job) -> loginId to job.await() }
|
||||
val mibAccounts = mibResults.flatMap { it.second }
|
||||
val bmlResults = bmlJobs.map { (_, job) -> job.await() }
|
||||
val bmlAccounts = bmlResults.flatMap { it.second }
|
||||
val (_, fahipayAccounts) = fahipayJob?.await() ?: Pair(null, AccountCache.loadFahipay(this@HomeActivity))
|
||||
val fahipayAccounts = fahipayJobs.flatMap { (_, job) -> job.await() }
|
||||
|
||||
val app = application as BasedBankApp
|
||||
app.mibAccounts = mibAccounts
|
||||
AccountCache.save(this@HomeActivity, mibAccounts)
|
||||
app.bmlAccounts = bmlAccounts
|
||||
app.fahipayAccounts = fahipayAccounts
|
||||
viewModel.accounts.postValue((mibAccounts + bmlAccounts + fahipayAccounts).filterVisibleAccounts())
|
||||
binding.refreshIndicator.visibility = View.GONE
|
||||
|
||||
for ((_, session) in app.bmlSessions) refreshBmlLimits(session)
|
||||
refreshFinancing(app.mibSession, app.mibProfiles.filterVisibleProfiles())
|
||||
for ((loginId, session) in app.mibSessions) {
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
refreshFinancing(loginId, session, profiles.filterVisibleProfiles(loginId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Filters MIB accounts whose profileId the user has hidden in settings. */
|
||||
private fun List<MibAccount>.filterVisibleAccounts(): List<MibAccount> {
|
||||
val hidden = CredentialStore(this@HomeActivity).getHiddenMibProfileIds()
|
||||
if (hidden.isEmpty()) return this
|
||||
return filter { it.bank != "MIB" || it.profileId !in hidden }
|
||||
val store = CredentialStore(this@HomeActivity)
|
||||
return filter { acc ->
|
||||
if (acc.bank != "MIB") return@filter true
|
||||
val loginId = acc.loginTag.removePrefix("mib_")
|
||||
val hidden = store.getHiddenMibProfileIds(loginId)
|
||||
hidden.isEmpty() || acc.profileId !in hidden
|
||||
}
|
||||
}
|
||||
|
||||
/** Filters MIB profiles the user has hidden — prevents API requests for hidden profiles. */
|
||||
private fun List<MibProfile>.filterVisibleProfiles(): List<MibProfile> {
|
||||
val hidden = CredentialStore(this@HomeActivity).getHiddenMibProfileIds()
|
||||
/** Filters MIB profiles the user has hidden for a given loginId. */
|
||||
private fun List<MibProfile>.filterVisibleProfiles(loginId: String): List<MibProfile> {
|
||||
val hidden = CredentialStore(this@HomeActivity).getHiddenMibProfileIds(loginId)
|
||||
if (hidden.isEmpty()) return this
|
||||
return filter { it.profileId !in hidden }
|
||||
}
|
||||
@@ -571,9 +583,12 @@ class HomeActivity : AppCompatActivity() {
|
||||
if (cats.isNotEmpty()) viewModel.contactCategories.value = cats
|
||||
}
|
||||
// Refresh all banks in background
|
||||
refreshContacts(app.mibSession, app.mibProfiles.filterVisibleProfiles())
|
||||
for ((loginId, session) in app.mibSessions) {
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
refreshContacts(loginId, session, profiles.filterVisibleProfiles(loginId))
|
||||
}
|
||||
refreshBmlContacts(app)
|
||||
if (app.fahipaySession != null) refreshFahipayContacts(app.fahipaySession!!)
|
||||
for ((_, session) in app.fahipaySessions) refreshFahipayContacts(session)
|
||||
}
|
||||
|
||||
private fun refreshFahipayContacts(session: FahipaySession) {
|
||||
@@ -609,9 +624,9 @@ class HomeActivity : AppCompatActivity() {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun refreshContacts(session: MibSession?, profiles: List<MibProfile>) {
|
||||
if (session == null || profiles.isEmpty()) return
|
||||
val flow = MibLoginFlow(CredentialStore(this))
|
||||
private fun refreshContacts(loginId: String, session: MibSession, profiles: List<MibProfile>) {
|
||||
if (profiles.isEmpty()) return
|
||||
val flow = (application as BasedBankApp).mibFlowFor(loginId)
|
||||
val contactsClient = MibContactsClient()
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
@@ -636,8 +651,8 @@ class HomeActivity : AppCompatActivity() {
|
||||
}
|
||||
if (allContacts.isNotEmpty()) {
|
||||
ContactsCache.save(this@HomeActivity, allContacts, allCategories)
|
||||
val bmlLoginIds = sh.sar.basedbank.util.CredentialStore(this@HomeActivity).getBmlLoginIds()
|
||||
val bmlContacts = ContactsCache.loadBml(this@HomeActivity, bmlLoginIds)
|
||||
val store = sh.sar.basedbank.util.CredentialStore(this@HomeActivity)
|
||||
val bmlContacts = ContactsCache.loadBml(this@HomeActivity, store.getBmlLoginIds())
|
||||
val fahipayContacts = ContactsCache.loadFahipay(this@HomeActivity)
|
||||
val fahipayCategories = ContactsCache.loadFahipayCategories(this@HomeActivity)
|
||||
viewModel.contacts.postValue(mergeContacts(mergeContacts(allContacts, bmlContacts), fahipayContacts))
|
||||
@@ -653,7 +668,7 @@ class HomeActivity : AppCompatActivity() {
|
||||
val current = viewModel.accounts.value ?: emptyList()
|
||||
if (src.bank == "FAHIPAY") {
|
||||
val fresh = withContext(Dispatchers.IO) {
|
||||
val sess = app.fahipaySession ?: return@withContext null
|
||||
val sess = app.fahipaySessionFor(src) ?: return@withContext null
|
||||
try {
|
||||
val flow = FahipayLoginFlow()
|
||||
flow.setSessionCookie(sess.sessionCookie)
|
||||
@@ -661,8 +676,9 @@ class HomeActivity : AppCompatActivity() {
|
||||
val profile = flow.fetchProfile(sess)
|
||||
val loginTag = "fahipay_${profile.profileId}"
|
||||
val accounts = listOf(flow.buildAccount(profile, balance, loginTag))
|
||||
AccountCache.saveFahipay(this@HomeActivity, accounts)
|
||||
app.fahipayAccounts = accounts
|
||||
val loginId = src.loginTag.removePrefix("fahipay_")
|
||||
AccountCache.saveFahipay(this@HomeActivity, loginId, accounts)
|
||||
app.fahipayAccounts = app.fahipayAccounts.filter { it.loginTag != src.loginTag } + accounts
|
||||
accounts
|
||||
} catch (_: Exception) { null }
|
||||
} ?: return@launch
|
||||
@@ -683,40 +699,43 @@ class HomeActivity : AppCompatActivity() {
|
||||
val otherAccounts = current.filter { it.bank != "BML" || it.loginTag != src.loginTag }
|
||||
viewModel.accounts.postValue(otherAccounts + fresh)
|
||||
} else {
|
||||
val loginId = src.loginTag.removePrefix("mib_")
|
||||
val fresh = withContext(Dispatchers.IO) {
|
||||
val store = CredentialStore(this@HomeActivity)
|
||||
val hidden = store.getHiddenMibProfileIds()
|
||||
val allVisible = app.mibProfiles.filter { hidden.isEmpty() || it.profileId !in hidden }
|
||||
// Try P47 for all visible profiles (fast path, works for multi-profile)
|
||||
val sess = app.mibSession
|
||||
val hidden = store.getHiddenMibProfileIds(loginId)
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
val allVisible = profiles.filter { hidden.isEmpty() || it.profileId !in hidden }
|
||||
val sess = app.mibSessions[loginId]
|
||||
if (sess != null && allVisible.isNotEmpty()) {
|
||||
try {
|
||||
val accounts = MibLoginFlow(store).fetchAllProfiles(sess, allVisible, src.loginTag)
|
||||
val accounts = app.mibFlowFor(loginId).fetchAllProfiles(sess, allVisible, src.loginTag)
|
||||
if (accounts.isNotEmpty()) return@withContext accounts
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
// P47 returned nothing — re-login to get fresh balances (handles single-profile A41 path)
|
||||
val creds = store.loadMibCredentials() ?: return@withContext null
|
||||
val creds = store.loadMibCredentials(loginId) ?: return@withContext null
|
||||
try {
|
||||
val flow = MibLoginFlow(store)
|
||||
val accounts = flow.login(creds.username, creds.passwordHash, creds.otpSeed)
|
||||
app.mibSession = flow.lastSession
|
||||
app.mibProfiles = flow.lastProfiles
|
||||
store.saveMibProfiles(flow.lastProfiles)
|
||||
app.mibSessions[loginId] = flow.lastSession!!
|
||||
app.mibProfilesMap[loginId] = flow.lastProfiles
|
||||
app.mibLoginFlows[loginId] = flow
|
||||
store.saveMibProfiles(loginId, flow.lastProfiles)
|
||||
accounts.takeIf { it.isNotEmpty() }
|
||||
} catch (_: Exception) { null }
|
||||
} ?: return@launch
|
||||
// Replace all MIB accounts with fresh data
|
||||
val others = current.filter { it.bank != "MIB" }
|
||||
AccountCache.save(this@HomeActivity, fresh)
|
||||
// Replace accounts for this MIB login
|
||||
val others = current.filter { it.loginTag != src.loginTag }
|
||||
val newMibAccounts = app.mibAccounts.filter { it.loginTag != src.loginTag } + fresh
|
||||
app.mibAccounts = newMibAccounts
|
||||
AccountCache.save(this@HomeActivity, newMibAccounts)
|
||||
viewModel.accounts.postValue(others + fresh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshFinancing(session: MibSession?, profiles: List<MibProfile>) {
|
||||
if (session == null || profiles.isEmpty()) return
|
||||
val flow = MibLoginFlow(CredentialStore(this))
|
||||
private fun refreshFinancing(loginId: String, session: MibSession, profiles: List<MibProfile>) {
|
||||
if (profiles.isEmpty()) return
|
||||
val flow = (application as BasedBankApp).mibFlowFor(loginId)
|
||||
val client = MibFinancingClient()
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
|
||||
@@ -71,8 +71,9 @@ class OtpFragment : Fragment() {
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
|
||||
val entries = mutableListOf<OtpEntry>()
|
||||
store.loadMibCredentials()?.let { creds ->
|
||||
val name = store.loadMibFullName()
|
||||
for (loginId in store.getMibLoginIds()) {
|
||||
val creds = store.loadMibCredentials(loginId) ?: continue
|
||||
val name = store.loadMibFullName(loginId)
|
||||
entries.add(OtpEntry(if (name != null) "MIB · $name" else "MIB", creds.otpSeed))
|
||||
}
|
||||
for (loginId in store.getBmlLoginIds()) {
|
||||
@@ -88,20 +89,23 @@ class OtpFragment : Fragment() {
|
||||
// Fetch real names in background if not yet cached, then refresh labels
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
var changed = false
|
||||
if (store.loadMibFullName() == null) {
|
||||
app.mibSession?.let { session ->
|
||||
for (loginId in store.getMibLoginIds()) {
|
||||
if (store.loadMibFullName(loginId) == null) {
|
||||
val session = app.mibSessions[loginId] ?: continue
|
||||
val flow = app.mibFlowFor(loginId)
|
||||
val profile = withContext(Dispatchers.IO) {
|
||||
try { app.mibLoginFlow.fetchPersonalProfile(session) } catch (_: Exception) { null }
|
||||
try { flow.fetchPersonalProfile(session) } catch (_: Exception) { null }
|
||||
}
|
||||
if (profile != null) {
|
||||
store.saveMibUserProfile(CredentialStore.MibUserProfile(
|
||||
store.saveMibUserProfile(loginId, CredentialStore.MibUserProfile(
|
||||
fullName = profile.fullName,
|
||||
username = profile.username,
|
||||
email = profile.email,
|
||||
mobile = profile.mobile,
|
||||
enrolled = profile.enrolled
|
||||
))
|
||||
val idx = entries.indexOfFirst { it.seed == store.loadMibCredentials()?.otpSeed }
|
||||
val seed = store.loadMibCredentials(loginId)?.otpSeed
|
||||
val idx = entries.indexOfFirst { it.seed == seed }
|
||||
if (idx >= 0) { entries[idx] = entries[idx].copy(label = "MIB · ${profile.fullName}"); changed = true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,18 +60,18 @@ class SettingsLoginsFragment : Fragment() {
|
||||
val container = binding.loginsContainer
|
||||
container.removeAllViews()
|
||||
|
||||
val hasMib = store.hasMibCredentials()
|
||||
val mibLoginIds = store.getMibLoginIds()
|
||||
val bmlLoginIds = store.getBmlLoginIds()
|
||||
val hasFahipay = store.hasFahipayCredentials()
|
||||
val fahipayLoginIds = store.getFahipayLoginIds()
|
||||
|
||||
binding.tvLoginsTitle.visibility = if (hasMib || bmlLoginIds.isNotEmpty() || hasFahipay) View.VISIBLE else View.GONE
|
||||
binding.tvLoginsTitle.visibility = if (mibLoginIds.isNotEmpty() || bmlLoginIds.isNotEmpty() || fahipayLoginIds.isNotEmpty()) View.VISIBLE else View.GONE
|
||||
|
||||
if (hasMib) {
|
||||
val profile = store.loadMibUserProfile()
|
||||
for (loginId in mibLoginIds) {
|
||||
val profile = store.loadMibUserProfile(loginId)
|
||||
val displayName = profile?.fullName?.takeIf { it.isNotBlank() } ?: getString(R.string.mib_name)
|
||||
val mibProfiles = store.loadMibProfiles()
|
||||
val mibProfiles = store.loadMibProfiles(loginId)
|
||||
addLoginRow(container, R.drawable.mib_logo, displayName) {
|
||||
showMibLoginDetails(store, profile, mibProfiles)
|
||||
showMibLoginDetails(store, loginId, profile, mibProfiles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ class SettingsLoginsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFahipay) {
|
||||
val profile = store.loadFahipayUserProfile()
|
||||
for (loginId in fahipayLoginIds) {
|
||||
val profile = store.loadFahipayUserProfile(loginId)
|
||||
val displayName = profile?.fullName?.takeIf { it.isNotBlank() } ?: getString(R.string.fahipay_name)
|
||||
addLoginRow(container, R.drawable.fahipay_logo, displayName) {
|
||||
showLoginDetails(
|
||||
@@ -111,7 +111,7 @@ class SettingsLoginsFragment : Fragment() {
|
||||
if (!profile?.mobile.isNullOrBlank()) appendLine("${getString(R.string.login_detail_mobile)}: ${profile!!.mobile}")
|
||||
if (!profile?.nid.isNullOrBlank()) appendLine("${getString(R.string.login_detail_id_card)}: ${profile!!.nid}")
|
||||
}.trim(),
|
||||
onLogout = { confirmLogout(getString(R.string.fahipay_name)) { logoutFahipay(store) } }
|
||||
onLogout = { confirmLogout(getString(R.string.fahipay_name)) { logoutFahipay(store, loginId) } }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -145,12 +145,13 @@ class SettingsLoginsFragment : Fragment() {
|
||||
|
||||
private fun showMibLoginDetails(
|
||||
store: CredentialStore,
|
||||
loginId: String,
|
||||
profile: CredentialStore.MibUserProfile?,
|
||||
mibProfiles: List<MibProfile>
|
||||
) {
|
||||
val ctx = requireContext()
|
||||
val dp = ctx.resources.displayMetrics.density
|
||||
val originalHidden = store.getHiddenMibProfileIds()
|
||||
val originalHidden = store.getHiddenMibProfileIds(loginId)
|
||||
val hidden = originalHidden.toMutableSet()
|
||||
|
||||
val scroll = android.widget.ScrollView(ctx)
|
||||
@@ -231,7 +232,7 @@ class SettingsLoginsFragment : Fragment() {
|
||||
.setPositiveButton(R.string.save, null) // null — set manually after show()
|
||||
.setNeutralButton(R.string.close, null)
|
||||
.setNegativeButton(R.string.settings_logout) { _, _ ->
|
||||
confirmLogout(getString(R.string.mib_name)) { logoutMib(store) }
|
||||
confirmLogout(getString(R.string.mib_name)) { logoutMib(store, loginId) }
|
||||
}
|
||||
.show()
|
||||
|
||||
@@ -247,7 +248,7 @@ class SettingsLoginsFragment : Fragment() {
|
||||
}
|
||||
|
||||
saveBtn.setOnClickListener {
|
||||
store.setHiddenMibProfileIds(hidden)
|
||||
store.setHiddenMibProfileIds(loginId, hidden)
|
||||
clearAllCaches(ctx)
|
||||
dialog.dismiss()
|
||||
(activity as? HomeActivity)?.relogin()
|
||||
@@ -272,12 +273,16 @@ class SettingsLoginsFragment : Fragment() {
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun logoutMib(store: CredentialStore) {
|
||||
private fun logoutMib(store: CredentialStore, loginId: String) {
|
||||
val ctx = requireContext()
|
||||
store.clearMibCredentials()
|
||||
store.clearMibCredentials(loginId)
|
||||
ctx.getSharedPreferences("mib_prefs", Context.MODE_PRIVATE).edit().clear().apply()
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
app.accounts = emptyList(); app.mibSession = null; app.mibProfiles = emptyList()
|
||||
app.mibSessions.remove(loginId)
|
||||
app.mibProfilesMap.remove(loginId)
|
||||
app.mibLoginFlows.remove(loginId)
|
||||
app.mibAccounts = app.mibAccounts.filter { it.loginTag != "mib_$loginId" }
|
||||
app.accounts = app.accounts.filter { it.loginTag != "mib_$loginId" }
|
||||
clearAllCaches(ctx)
|
||||
(activity as HomeActivity).relogin()
|
||||
buildLoginsSection()
|
||||
@@ -294,11 +299,12 @@ class SettingsLoginsFragment : Fragment() {
|
||||
buildLoginsSection()
|
||||
}
|
||||
|
||||
private fun logoutFahipay(store: CredentialStore) {
|
||||
private fun logoutFahipay(store: CredentialStore, loginId: String) {
|
||||
val ctx = requireContext()
|
||||
store.clearFahipayCredentials(); store.clearFahipaySession()
|
||||
store.clearFahipayCredentials(loginId)
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
app.fahipaySession = null; app.fahipayAccounts = emptyList()
|
||||
app.fahipaySessions.remove(loginId)
|
||||
app.fahipayAccounts = app.fahipayAccounts.filter { it.loginTag != "fahipay_$loginId" }
|
||||
clearAllCaches(ctx)
|
||||
(activity as HomeActivity).relogin()
|
||||
buildLoginsSection()
|
||||
|
||||
@@ -64,7 +64,9 @@ class TransferFragment : Fragment() {
|
||||
private val viewModel: HomeViewModel by activityViewModels()
|
||||
|
||||
private var selectedAccount: MibAccount? = null
|
||||
private val session get() = (requireActivity().application as BasedBankApp).mibSession
|
||||
private val session get() = selectedAccount
|
||||
?.let { (requireActivity().application as BasedBankApp).mibSessionFor(it) }
|
||||
?: (requireActivity().application as BasedBankApp).anyMibSession()
|
||||
private fun bmlSessionFor(account: MibAccount?) =
|
||||
account?.let { (requireActivity().application as BasedBankApp).bmlSessionFor(it) }
|
||||
?: (requireActivity().application as BasedBankApp).anyBmlSession()
|
||||
@@ -244,7 +246,7 @@ class TransferFragment : Fragment() {
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = app.mibLoginFlow.fetchProfileImage(sess, hash) ?: return@launch
|
||||
val base64 = app.anyMibFlow()?.fetchProfileImage(sess, hash) ?: return@launch
|
||||
val bytes = Base64.decode(base64, Base64.DEFAULT)
|
||||
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) ?: return@launch
|
||||
withContext(Dispatchers.Main) {
|
||||
@@ -706,12 +708,14 @@ class TransferFragment : Fragment() {
|
||||
): Triple<Boolean, String, TransferReceiptData?> {
|
||||
val sess = session ?: return Triple(false, getString(R.string.transfer_session_unavailable), null)
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
val loginId = src.loginTag.removePrefix("mib_")
|
||||
// Switch to the profile that owns the source account
|
||||
if (src.profileId.isNotBlank()) {
|
||||
val profile = app.mibProfiles.firstOrNull { it.profileId == src.profileId }
|
||||
if (profile != null) app.mibLoginFlow.switchProfile(sess, profile)
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
val profile = profiles.firstOrNull { it.profileId == src.profileId }
|
||||
if (profile != null) app.mibFlowFor(loginId).switchProfile(sess, profile)
|
||||
}
|
||||
val otp = CredentialStore(requireContext()).loadMibCredentials()?.otpSeed
|
||||
val otp = CredentialStore(requireContext()).loadMibCredentials(loginId)?.otpSeed
|
||||
?.let { Totp.generate(it) }
|
||||
?: return Triple(false, "OTP unavailable", null)
|
||||
val currencyCode = if (src.currencyName == "USD") "840" else "462"
|
||||
@@ -878,7 +882,7 @@ class TransferFragment : Fragment() {
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = if (isProfile) {
|
||||
app.mibLoginFlow.fetchProfileImage(sess, hash)
|
||||
app.anyMibFlow()?.fetchProfileImage(sess, hash)
|
||||
} else {
|
||||
MibContactsClient().fetchProfileImageBase64(sess, hash)
|
||||
} ?: return@launch
|
||||
|
||||
@@ -142,7 +142,6 @@ class TransferHistoryFragment : Fragment() {
|
||||
}
|
||||
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
val mibSession = app.mibSession
|
||||
|
||||
lifecycleScope.launch {
|
||||
val newTransactions = withContext(Dispatchers.IO) {
|
||||
@@ -189,7 +188,7 @@ class TransferHistoryFragment : Fragment() {
|
||||
// Fahipay accounts
|
||||
val fahipayStates = activeStates.filter { it.account.bank == "FAHIPAY" }
|
||||
for (state in fahipayStates) {
|
||||
val session = app.fahipaySession ?: continue
|
||||
val session = app.fahipaySessionFor(state.account) ?: continue
|
||||
try {
|
||||
val flow = FahipayLoginFlow()
|
||||
flow.setSessionCookie(session.sessionCookie)
|
||||
@@ -207,24 +206,27 @@ class TransferHistoryFragment : Fragment() {
|
||||
|
||||
// MIB accounts: serialized per profile, protected by mutex to prevent session race
|
||||
val mibStates = activeStates.filter { it.account.bank == "MIB" }
|
||||
for ((profileId, states) in mibStates.groupBy { it.account.profileId }) {
|
||||
val session = mibSession ?: break
|
||||
app.mibMutex.withLock {
|
||||
val profile = app.mibProfiles.firstOrNull { it.profileId == profileId }
|
||||
if (profile != null) app.mibLoginFlow.switchProfile(session, profile)
|
||||
for (state in states) {
|
||||
try {
|
||||
val (list, total) = MibHistoryClient().fetchHistory(
|
||||
session = session,
|
||||
accountNo = state.account.accountNumber,
|
||||
accountDisplayName = state.account.accountBriefName,
|
||||
start = state.mibNextStart,
|
||||
pageSize = pageSize
|
||||
)
|
||||
if (total > 0) state.mibTotalCount = total
|
||||
state.mibNextStart += list.size.coerceAtLeast(pageSize)
|
||||
results.addAll(list)
|
||||
} catch (_: Exception) {}
|
||||
for ((loginId, loginStates) in mibStates.groupBy { it.account.loginTag.removePrefix("mib_") }) {
|
||||
val session = app.mibSessions[loginId] ?: continue
|
||||
for ((profileId, states) in loginStates.groupBy { it.account.profileId }) {
|
||||
app.mibMutex.withLock {
|
||||
val profiles = app.mibProfilesMap[loginId] ?: emptyList()
|
||||
val profile = profiles.firstOrNull { it.profileId == profileId }
|
||||
if (profile != null) app.mibFlowFor(loginId).switchProfile(session, profile)
|
||||
for (state in states) {
|
||||
try {
|
||||
val (list, total) = MibHistoryClient().fetchHistory(
|
||||
session = session,
|
||||
accountNo = state.account.accountNumber,
|
||||
accountDisplayName = state.account.accountBriefName,
|
||||
start = state.mibNextStart,
|
||||
pageSize = pageSize
|
||||
)
|
||||
if (total > 0) state.mibTotalCount = total
|
||||
state.mibNextStart += list.size.coerceAtLeast(pageSize)
|
||||
results.addAll(list)
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,7 +280,7 @@ class TransferHistoryFragment : Fragment() {
|
||||
return
|
||||
}
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
val sess = app.mibSession ?: return
|
||||
val sess = app.anyMibSession() ?: return
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = MibContactsClient().fetchProfileImageBase64(sess, hash) ?: return@launch
|
||||
|
||||
@@ -154,11 +154,11 @@ class TransferReceiptFragment : Fragment() {
|
||||
|
||||
private fun loadProfileImage(hash: String, isProfile: Boolean, onLoaded: (Bitmap) -> Unit) {
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
val sess = app.mibSession ?: return
|
||||
val sess = app.anyMibSession() ?: return
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
val base64 = if (isProfile) {
|
||||
app.mibLoginFlow.fetchProfileImage(sess, hash)
|
||||
app.anyMibFlow()?.fetchProfileImage(sess, hash)
|
||||
} else {
|
||||
MibContactsClient().fetchProfileImageBase64(sess, hash)
|
||||
} ?: return@launch
|
||||
|
||||
@@ -170,6 +170,7 @@ class CredentialsFragment : Fragment() {
|
||||
binding.btnLogin.isEnabled = false
|
||||
|
||||
val passwordHash = MibLoginFlow.hashPassword(password)
|
||||
val loginId = username
|
||||
val flow = MibLoginFlow(CredentialStore(requireContext()))
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
@@ -178,11 +179,12 @@ class CredentialsFragment : Fragment() {
|
||||
flow.login(username, passwordHash, otpSeed)
|
||||
}
|
||||
val store = CredentialStore(requireContext())
|
||||
store.saveMibCredentials(username, passwordHash, otpSeed)
|
||||
store.saveMibCredentials(loginId, username, passwordHash, otpSeed)
|
||||
withContext(Dispatchers.IO) {
|
||||
flow.lastSession?.let { s ->
|
||||
val profile = flow.fetchPersonalProfile(s)
|
||||
if (profile != null) store.saveMibUserProfile(
|
||||
loginId,
|
||||
CredentialStore.MibUserProfile(
|
||||
fullName = profile.fullName,
|
||||
username = profile.username,
|
||||
@@ -193,12 +195,15 @@ class CredentialsFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
}
|
||||
AccountCache.save(requireContext(), accounts)
|
||||
CredentialStore(requireContext()).saveMibProfiles(flow.lastProfiles)
|
||||
store.saveMibProfiles(loginId, flow.lastProfiles)
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
app.accounts = accounts
|
||||
app.mibSession = flow.lastSession
|
||||
app.mibProfiles = flow.lastProfiles
|
||||
// Merge with any existing MIB accounts from other logins
|
||||
app.mibAccounts = app.mibAccounts.filter { it.loginTag != "mib_$loginId" } + accounts
|
||||
app.accounts = app.accounts.filter { it.loginTag != "mib_$loginId" } + accounts
|
||||
AccountCache.save(requireContext(), app.mibAccounts)
|
||||
app.mibSessions[loginId] = flow.lastSession!!
|
||||
app.mibProfilesMap[loginId] = flow.lastProfiles
|
||||
app.mibLoginFlows[loginId] = flow
|
||||
val intent = Intent(requireContext(), HomeActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(intent)
|
||||
@@ -375,11 +380,13 @@ class CredentialsFragment : Fragment() {
|
||||
val b = flow.fetchBalance(session)
|
||||
Pair(p, b)
|
||||
}
|
||||
val loginTag = "fahipay_${profile.profileId}"
|
||||
val loginId = profile.profileId
|
||||
val loginTag = "fahipay_$loginId"
|
||||
val account = flow.buildAccount(profile, balance, loginTag)
|
||||
store.saveFahipayCredentials(idCard, password)
|
||||
store.saveFahipaySession(session.authId, session.sessionCookie)
|
||||
store.saveFahipayCredentials(loginId, idCard, password)
|
||||
store.saveFahipaySession(loginId, session.authId, session.sessionCookie)
|
||||
store.saveFahipayUserProfile(
|
||||
loginId,
|
||||
CredentialStore.FahipayUserProfile(
|
||||
fullName = profile.fullName,
|
||||
email = profile.email,
|
||||
@@ -390,11 +397,11 @@ class CredentialsFragment : Fragment() {
|
||||
linkedAccounts = profile.linkedAccounts
|
||||
)
|
||||
)
|
||||
AccountCache.saveFahipay(requireContext(), listOf(account))
|
||||
AccountCache.saveFahipay(requireContext(), loginId, listOf(account))
|
||||
val app = requireActivity().application as BasedBankApp
|
||||
app.fahipaySession = session
|
||||
app.fahipayAccounts = listOf(account)
|
||||
app.accounts = app.accounts + listOf(account)
|
||||
app.fahipaySessions[loginId] = session
|
||||
app.fahipayAccounts = app.fahipayAccounts.filter { it.loginTag != loginTag } + listOf(account)
|
||||
app.accounts = app.accounts.filter { it.loginTag != loginTag } + listOf(account)
|
||||
val intent = Intent(requireContext(), HomeActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(intent)
|
||||
|
||||
Reference in New Issue
Block a user