diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/BankingDatabase.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/BankingDatabase.kt index 4207f244..6045d5f5 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/BankingDatabase.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/BankingDatabase.kt @@ -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 } \ No newline at end of file diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt index 1d7577bc..27d99008 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt @@ -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) diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AppSettingsDao.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AppSettingsDao.kt new file mode 100644 index 00000000..200db798 --- /dev/null +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/dao/AppSettingsDao.kt @@ -0,0 +1,13 @@ +package net.dankito.banking.persistence.dao + +import androidx.room.* +import net.dankito.banking.persistence.model.AppSettings + + +@Dao +interface AppSettingsDao : BaseDao { + + @Query("SELECT * FROM AppSettings") + fun getAll(): List + +} \ No newline at end of file diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/AppSettings.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/AppSettings.kt new file mode 100644 index 00000000..859aee9c --- /dev/null +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/model/AppSettings.kt @@ -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 + +} \ No newline at end of file diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/settings/AppSettings.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/settings/AppSettings.kt index 48d7c8d5..e0d49696 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/settings/AppSettings.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/settings/AppSettings.kt @@ -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() diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 904676bb..300ef6da 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -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 } diff --git a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents index 5337954e..d0f44c3d 100644 --- a/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents +++ b/ui/BankingiOSApp/BankingiOSApp/BankingiOSApp.xcdatamodeld/BankingiOSApp.xcdatamodel/contents @@ -37,6 +37,8 @@ + + @@ -104,11 +106,11 @@ + - \ No newline at end of file diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift index 318ef1ba..9ca0b6d6 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Mapper.swift @@ -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)