Implemented setting if accounts should be updated automatically at start up
This commit is contained in:
parent
7f6ea74aa8
commit
b39c3f700a
|
@ -10,7 +10,7 @@ import net.dankito.banking.persistence.model.*
|
|||
@Database(entities = [
|
||||
Bank::class, BankAccount::class, AccountTransaction::class,
|
||||
TanMethod::class, TanMedium::class,
|
||||
TanMethodSettings::class
|
||||
AppSettings::class, TanMethodSettings::class
|
||||
], version = 1, exportSchema = false)
|
||||
@TypeConverters(net.dankito.banking.persistence.TypeConverters::class)
|
||||
abstract class BankingDatabase : RoomDatabase() {
|
||||
|
@ -26,6 +26,8 @@ abstract class BankingDatabase : RoomDatabase() {
|
|||
abstract fun tanMediumDao(): TanMediumDao
|
||||
|
||||
|
||||
abstract fun appSettingsDao(): AppSettingsDao
|
||||
|
||||
abstract fun tanMethodSettingsDao(): TanMethodSettingsDao
|
||||
|
||||
}
|
|
@ -22,6 +22,8 @@ import net.sqlcipher.database.SupportFactory
|
|||
open class RoomBankingPersistence(applicationContext: Context, password: String? = null) : IBankingPersistence, ITransactionPartySearcher {
|
||||
|
||||
companion object {
|
||||
const val AppSettingsId = 1
|
||||
|
||||
const val FlickerCodeTanMethodSettingsId = 1
|
||||
const val QrCodeTanMethodSettingsId = 2
|
||||
const val PhotoTanTanMethodSettingsId = 3
|
||||
|
@ -157,6 +159,9 @@ open class RoomBankingPersistence(applicationContext: Context, password: String?
|
|||
|
||||
|
||||
override fun saveOrUpdateAppSettings(appSettings: AppSettings) {
|
||||
val mapped = net.dankito.banking.persistence.model.AppSettings(appSettings.updateAccountsAutomatically, appSettings.refreshAccountsAfterMinutes)
|
||||
db.appSettingsDao().saveOrUpdate(mapped)
|
||||
|
||||
saveOrUpdateTanMethodSettings(appSettings.flickerCodeSettings, FlickerCodeTanMethodSettingsId)
|
||||
saveOrUpdateTanMethodSettings(appSettings.qrCodeSettings, QrCodeTanMethodSettingsId)
|
||||
saveOrUpdateTanMethodSettings(appSettings.photoTanSettings, PhotoTanTanMethodSettingsId)
|
||||
|
@ -174,6 +179,12 @@ open class RoomBankingPersistence(applicationContext: Context, password: String?
|
|||
val tanMethodSettings = db.tanMethodSettingsDao().getAll()
|
||||
|
||||
val settings = AppSettings()
|
||||
|
||||
db.appSettingsDao().getAll().firstOrNull { it.id == AppSettingsId }?.let { persistedSettings ->
|
||||
settings.updateAccountsAutomatically = persistedSettings.updateAccountsAutomatically
|
||||
settings.refreshAccountsAfterMinutes = persistedSettings.refreshAccountsAfterMinutes
|
||||
}
|
||||
|
||||
settings.flickerCodeSettings = findTanMethodSettings(FlickerCodeTanMethodSettingsId, tanMethodSettings)
|
||||
settings.qrCodeSettings = findTanMethodSettings(QrCodeTanMethodSettingsId, tanMethodSettings)
|
||||
settings.photoTanSettings = findTanMethodSettings(PhotoTanTanMethodSettingsId, tanMethodSettings)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package net.dankito.banking.persistence.dao
|
||||
|
||||
import androidx.room.*
|
||||
import net.dankito.banking.persistence.model.AppSettings
|
||||
|
||||
|
||||
@Dao
|
||||
interface AppSettingsDao : BaseDao<AppSettings> {
|
||||
|
||||
@Query("SELECT * FROM AppSettings")
|
||||
fun getAll(): List<AppSettings>
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.dankito.banking.persistence.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import net.dankito.banking.persistence.RoomBankingPersistence
|
||||
import net.dankito.banking.ui.model.settings.AppSettings
|
||||
|
||||
|
||||
@Entity
|
||||
open class AppSettings(
|
||||
open var updateAccountsAutomatically: Boolean = true,
|
||||
open var refreshAccountsAfterMinutes: Int = AppSettings.DefaultRefreshAccountsAfterMinutes
|
||||
) {
|
||||
|
||||
internal constructor() : this(true, AppSettings.DefaultRefreshAccountsAfterMinutes)
|
||||
|
||||
@PrimaryKey
|
||||
open var id: Int = RoomBankingPersistence.AppSettingsId
|
||||
|
||||
}
|
|
@ -4,12 +4,19 @@ import net.dankito.utils.multiplatform.UUID
|
|||
|
||||
|
||||
open class AppSettings(
|
||||
open var updateAccountsAutomatically: Boolean = true,
|
||||
open var refreshAccountsAfterMinutes: Int = DefaultRefreshAccountsAfterMinutes,
|
||||
open var flickerCodeSettings: TanMethodSettings? = null,
|
||||
open var qrCodeSettings: TanMethodSettings? = null,
|
||||
open var photoTanSettings: TanMethodSettings? = null
|
||||
) {
|
||||
|
||||
internal constructor() : this(null, null, null) // for object deserializers
|
||||
companion object {
|
||||
const val DefaultRefreshAccountsAfterMinutes = 8 * 60 // 8 hours
|
||||
}
|
||||
|
||||
|
||||
internal constructor() : this(true, DefaultRefreshAccountsAfterMinutes, null, null) // for object deserializers
|
||||
|
||||
|
||||
open var technicalId: String = UUID.random()
|
||||
|
|
|
@ -123,7 +123,9 @@ open class BankingPresenter(
|
|||
readAppSettings()
|
||||
readPersistedBanks()
|
||||
|
||||
updateAllAccountsTransactionsAsync()
|
||||
if (appSettings.updateAccountsAutomatically) {
|
||||
doAutomaticAccountsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
// preloadBankList asynchronously; on Android it takes approximately 18 seconds till banks are indexed for first time -> do it as early as possible
|
||||
|
@ -342,6 +344,10 @@ open class BankingPresenter(
|
|||
}
|
||||
|
||||
|
||||
protected open fun doAutomaticAccountsUpdate() {
|
||||
updateAllAccountsTransactionsAsync()
|
||||
}
|
||||
|
||||
open fun updateAllAccountsTransactionsAsync(callback: ((GetTransactionsResponse) -> Unit)? = null) {
|
||||
val accountsToUpdate = allAccounts.filter { it.hideAccount == false && it.updateAccountAutomatically }
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
<relationship name="account" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="PersistedBankAccount" inverseName="transactions" inverseEntity="PersistedBankAccount"/>
|
||||
</entity>
|
||||
<entity name="PersistedAppSettings" representedClassName="PersistedAppSettings" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="refreshAccountsAfterMinutes" attributeType="Integer 32" defaultValueString="480" usesScalarValueType="YES"/>
|
||||
<attribute name="updateAccountsAutomatically" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
|
||||
<relationship name="flickerCodeSettings" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="PersistedTanMethodSettings"/>
|
||||
<relationship name="photoTanSettings" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="PersistedTanMethodSettings"/>
|
||||
<relationship name="qrCodeSettings" optional="YES" maxCount="1" deletionRule="Cascade" destinationEntity="PersistedTanMethodSettings"/>
|
||||
|
@ -104,11 +106,11 @@
|
|||
</entity>
|
||||
<elements>
|
||||
<element name="PersistedAccountTransaction" positionX="-36" positionY="45" width="128" height="553"/>
|
||||
<element name="PersistedAppSettings" positionX="-45" positionY="144" width="128" height="118"/>
|
||||
<element name="PersistedBankAccount" positionX="-54" positionY="63" width="128" height="403"/>
|
||||
<element name="PersistedBankData" positionX="-63" positionY="-18" width="128" height="283"/>
|
||||
<element name="PersistedTanMedium" positionX="-45" positionY="144" width="128" height="28"/>
|
||||
<element name="PersistedTanMethod" positionX="-54" positionY="135" width="128" height="118"/>
|
||||
<element name="PersistedTanMethodSettings" positionX="-54" positionY="135" width="128" height="103"/>
|
||||
<element name="PersistedAppSettings" positionX="-45" positionY="144" width="128" height="88"/>
|
||||
</elements>
|
||||
</model>
|
|
@ -318,6 +318,8 @@ class Mapper {
|
|||
|
||||
func map(_ settings: PersistedAppSettings) -> AppSettings {
|
||||
let mapped = AppSettings(
|
||||
updateAccountsAutomatically: settings.updateAccountsAutomatically,
|
||||
refreshAccountsAfterMinutes: settings.refreshAccountsAfterMinutes,
|
||||
flickerCodeSettings: map(settings.flickerCodeSettings),
|
||||
qrCodeSettings: map(settings.qrCodeSettings),
|
||||
photoTanSettings: map(settings.photoTanSettings))
|
||||
|
@ -330,6 +332,9 @@ class Mapper {
|
|||
func map(_ settings: AppSettings, _ context: NSManagedObjectContext) -> PersistedAppSettings {
|
||||
let mapped = context.objectByID(settings.technicalId) ?? PersistedAppSettings(context: context)
|
||||
|
||||
mapped.updateAccountsAutomatically = settings.updateAccountsAutomatically
|
||||
mapped.refreshAccountsAfterMinutes = settings.refreshAccountsAfterMinutes
|
||||
|
||||
mapped.flickerCodeSettings = map(settings.flickerCodeSettings, context)
|
||||
mapped.qrCodeSettings = map(settings.qrCodeSettings, context)
|
||||
mapped.photoTanSettings = map(settings.photoTanSettings, context)
|
||||
|
|
Loading…
Reference in New Issue