Introduced IAsyncRunner to replace or wrap away IThreadPool
This commit is contained in:
parent
247604e696
commit
8793b3b2a1
|
@ -1,7 +1,7 @@
|
||||||
package net.dankito.banking.ui
|
package net.dankito.banking.ui
|
||||||
|
|
||||||
import net.dankito.banking.bankfinder.BankInfo
|
import net.dankito.banking.bankfinder.BankInfo
|
||||||
import net.dankito.utils.IThreadPool
|
import net.dankito.banking.util.IAsyncRunner
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ interface IBankingClientCreator {
|
||||||
customerId: String,
|
customerId: String,
|
||||||
pin: String,
|
pin: String,
|
||||||
dataFolder: File,
|
dataFolder: File,
|
||||||
threadPool: IThreadPool, // TODO: wrap away JavaUtils IWebClient
|
asyncRunner: IAsyncRunner,
|
||||||
callback: BankingClientCallback
|
callback: BankingClientCallback
|
||||||
): IBankingClient
|
): IBankingClient
|
||||||
|
|
||||||
|
|
|
@ -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.moneytransfer.ExtractTransferMoneyDataFromPdfResultType
|
||||||
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
|
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
|
||||||
import net.dankito.banking.ui.model.settings.AppSettings
|
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.ITextExtractorRegistry
|
||||||
import net.dankito.text.extraction.info.invoice.IInvoiceDataExtractor
|
import net.dankito.text.extraction.info.invoice.IInvoiceDataExtractor
|
||||||
import net.dankito.text.extraction.info.invoice.InvoiceDataExtractor
|
import net.dankito.text.extraction.info.invoice.InvoiceDataExtractor
|
||||||
import net.dankito.text.extraction.model.ErrorType
|
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.containsExactly
|
||||||
import net.dankito.utils.extensions.ofMaxLength
|
import net.dankito.utils.extensions.ofMaxLength
|
||||||
import net.dankito.utils.serialization.ISerializer
|
import net.dankito.utils.serialization.ISerializer
|
||||||
|
@ -54,7 +54,7 @@ open class BankingPresenter(
|
||||||
protected val router: IRouter,
|
protected val router: IRouter,
|
||||||
protected val invoiceDataExtractor: IInvoiceDataExtractor = InvoiceDataExtractor(),
|
protected val invoiceDataExtractor: IInvoiceDataExtractor = InvoiceDataExtractor(),
|
||||||
protected val serializer: ISerializer = JacksonJsonSerializer(),
|
protected val serializer: ISerializer = JacksonJsonSerializer(),
|
||||||
protected val threadPool: IThreadPool = ThreadPool()
|
protected val asyncRunner: IAsyncRunner = CoroutinesAsyncRunner()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -107,7 +107,7 @@ open class BankingPresenter(
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
threadPool.runAsync {
|
asyncRunner.runAsync {
|
||||||
readAppSettings()
|
readAppSettings()
|
||||||
readPersistedAccounts()
|
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
|
// 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()
|
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 bankInfo = BankInfo(customer.bankName, customer.bankCode, customer.bic, "", "", "", customer.finTsServerAddress, "FinTS V3.0", null)
|
||||||
|
|
||||||
val newClient = bankingClientCreator.createClient(bankInfo, customer.customerId, customer.password,
|
val newClient = bankingClientCreator.createClient(bankInfo, customer.customerId, customer.password,
|
||||||
dataFolder, threadPool, callback)
|
dataFolder, asyncRunner, callback)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newClient.restoreData()
|
newClient.restoreData()
|
||||||
|
@ -157,7 +157,7 @@ open class BankingPresenter(
|
||||||
// TODO: move BankInfo out of fints4k
|
// TODO: move BankInfo out of fints4k
|
||||||
open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) {
|
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()
|
val startDate = Date()
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ open class BankingPresenter(
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun findIconForBankAsync(customer: Customer) {
|
protected open fun findIconForBankAsync(customer: Customer) {
|
||||||
threadPool.runAsync {
|
asyncRunner.runAsync {
|
||||||
findIconForBank(customer)
|
findIconForBank(customer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,7 +413,7 @@ open class BankingPresenter(
|
||||||
|
|
||||||
|
|
||||||
open fun findUniqueBankForIbanAsync(iban: String, callback: (BankInfo?) -> Unit) {
|
open fun findUniqueBankForIbanAsync(iban: String, callback: (BankInfo?) -> Unit) {
|
||||||
threadPool.runAsync {
|
asyncRunner.runAsync {
|
||||||
callback(findUniqueBankForIban(iban))
|
callback(findUniqueBankForIban(iban))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package net.dankito.banking.util
|
||||||
|
|
||||||
|
|
||||||
|
interface IAsyncRunner {
|
||||||
|
|
||||||
|
fun runAsync(runnable: () -> Unit)
|
||||||
|
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue