diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt index e19ef27b..f2497c05 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt @@ -1,7 +1,7 @@ package net.dankito.banking.ui import net.dankito.banking.bankfinder.BankInfo -import net.dankito.utils.IThreadPool +import net.dankito.banking.util.IAsyncRunner import java.io.File @@ -12,7 +12,7 @@ interface IBankingClientCreator { customerId: String, pin: String, dataFolder: File, - threadPool: IThreadPool, // TODO: wrap away JavaUtils IWebClient + asyncRunner: IAsyncRunner, callback: BankingClientCallback ): IBankingClient diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 6169a542..174c16a2 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -23,12 +23,12 @@ import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPd import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPdfResultType import net.dankito.banking.ui.model.parameters.GetTransactionsParameter import net.dankito.banking.ui.model.settings.AppSettings +import net.dankito.banking.util.CoroutinesAsyncRunner +import net.dankito.banking.util.IAsyncRunner import net.dankito.text.extraction.ITextExtractorRegistry import net.dankito.text.extraction.info.invoice.IInvoiceDataExtractor import net.dankito.text.extraction.info.invoice.InvoiceDataExtractor import net.dankito.text.extraction.model.ErrorType -import net.dankito.utils.IThreadPool -import net.dankito.utils.ThreadPool import net.dankito.utils.extensions.containsExactly import net.dankito.utils.extensions.ofMaxLength import net.dankito.utils.serialization.ISerializer @@ -54,7 +54,7 @@ open class BankingPresenter( protected val router: IRouter, protected val invoiceDataExtractor: IInvoiceDataExtractor = InvoiceDataExtractor(), protected val serializer: ISerializer = JacksonJsonSerializer(), - protected val threadPool: IThreadPool = ThreadPool() + protected val asyncRunner: IAsyncRunner = CoroutinesAsyncRunner() ) { companion object { @@ -107,7 +107,7 @@ open class BankingPresenter( init { - threadPool.runAsync { + asyncRunner.runAsync { readAppSettings() readPersistedAccounts() @@ -115,7 +115,7 @@ open class BankingPresenter( } // preloadBankList asynchronously; on Android it takes approximately 18 seconds till banks are indexed for first time -> do it as early as possible - threadPool.runAsync { + asyncRunner.runAsync { bankFinder.preloadBankList() } } @@ -129,7 +129,7 @@ open class BankingPresenter( val bankInfo = BankInfo(customer.bankName, customer.bankCode, customer.bic, "", "", "", customer.finTsServerAddress, "FinTS V3.0", null) val newClient = bankingClientCreator.createClient(bankInfo, customer.customerId, customer.password, - dataFolder, threadPool, callback) + dataFolder, asyncRunner, callback) try { newClient.restoreData() @@ -157,7 +157,7 @@ open class BankingPresenter( // TODO: move BankInfo out of fints4k open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) { - val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, dataFolder, threadPool, this.callback) + val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, dataFolder, asyncRunner, this.callback) val startDate = Date() @@ -191,7 +191,7 @@ open class BankingPresenter( } protected open fun findIconForBankAsync(customer: Customer) { - threadPool.runAsync { + asyncRunner.runAsync { findIconForBank(customer) } } @@ -413,7 +413,7 @@ open class BankingPresenter( open fun findUniqueBankForIbanAsync(iban: String, callback: (BankInfo?) -> Unit) { - threadPool.runAsync { + asyncRunner.runAsync { callback(findUniqueBankForIban(iban)) } } diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/CoroutinesAsyncRunner.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/CoroutinesAsyncRunner.kt new file mode 100644 index 00000000..979465d3 --- /dev/null +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/CoroutinesAsyncRunner.kt @@ -0,0 +1,16 @@ +package net.dankito.banking.util + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch + + +open class CoroutinesAsyncRunner : IAsyncRunner { + + override fun runAsync(runnable: () -> Unit) { + GlobalScope.launch(Dispatchers.IO) { + runnable() + } + } + +} \ No newline at end of file diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/IAsyncRunner.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/IAsyncRunner.kt new file mode 100644 index 00000000..3fa8f3f2 --- /dev/null +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/IAsyncRunner.kt @@ -0,0 +1,8 @@ +package net.dankito.banking.util + + +interface IAsyncRunner { + + fun runAsync(runnable: () -> Unit) + +} \ No newline at end of file diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/ThreadPoolAsyncRunner.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/ThreadPoolAsyncRunner.kt new file mode 100644 index 00000000..2341f851 --- /dev/null +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/ThreadPoolAsyncRunner.kt @@ -0,0 +1,12 @@ +package net.dankito.banking.util + +import net.dankito.utils.IThreadPool + + +open class ThreadPoolAsyncRunner(protected val threadPool: IThreadPool) : IAsyncRunner { + + override fun runAsync(runnable: () -> Unit) { + threadPool.runAsync(runnable) + } + +} \ No newline at end of file