All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 2s
51 lines
1.8 KiB
Kotlin
51 lines
1.8 KiB
Kotlin
package sh.sar.basedbank
|
|
|
|
import android.app.Application
|
|
import androidx.appcompat.app.AppCompatDelegate
|
|
import com.google.android.material.color.DynamicColors
|
|
import kotlinx.coroutines.sync.Mutex
|
|
import sh.sar.basedbank.api.bml.BmlSession
|
|
import sh.sar.basedbank.api.fahipay.FahipaySession
|
|
import sh.sar.basedbank.api.mib.MibAccount
|
|
import sh.sar.basedbank.api.mib.MibLoginFlow
|
|
import sh.sar.basedbank.api.mib.MibProfile
|
|
import sh.sar.basedbank.api.mib.MibSession
|
|
import sh.sar.basedbank.util.CredentialStore
|
|
|
|
class BasedBankApp : Application() {
|
|
|
|
// Held in memory after successful login; cleared on logout
|
|
var accounts: List<MibAccount> = emptyList()
|
|
var fullName: String = ""
|
|
var mibSession: MibSession? = null
|
|
var mibProfiles: List<MibProfile> = emptyList()
|
|
var bmlSession: BmlSession? = null
|
|
var bmlAccounts: List<MibAccount> = emptyList()
|
|
var fahipaySession: FahipaySession? = null
|
|
var fahipayAccounts: List<MibAccount> = emptyList()
|
|
|
|
/** Serialises all MIB profile-switch + request sequences to prevent session corruption. */
|
|
val mibMutex = Mutex()
|
|
|
|
val mibLoginFlow by lazy {
|
|
MibLoginFlow(CredentialStore(this)).also { flow ->
|
|
flow.onSessionRefreshed = { session, profiles ->
|
|
mibSession = session
|
|
mibProfiles = profiles
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
DynamicColors.applyToActivitiesIfAvailable(this)
|
|
|
|
val theme = getSharedPreferences("prefs", MODE_PRIVATE).getString("theme", "system")
|
|
AppCompatDelegate.setDefaultNightMode(when (theme) {
|
|
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
|
|
"light" -> AppCompatDelegate.MODE_NIGHT_NO
|
|
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
|
})
|
|
}
|
|
}
|