From a9883ff355cc5802104823f8dcc50cb4c3365e89 Mon Sep 17 00:00:00 2001 From: dankl Date: Wed, 8 Jan 2020 18:02:41 +0100 Subject: [PATCH] Added IBankingClientCreator to get fints4javaBankingClient off MainWindowPresenter --- BankingUiCommon/build.gradle | 3 +++ .../banking/ui/IBankingClientCreator.kt | 20 +++++++++++++++++ fints4javaAndroidApp/build.gradle | 5 ++--- .../fints4java/android/MainActivity.kt | 3 ++- .../android/ui/MainWindowPresenter.kt | 10 +++++---- .../banking/fints4javaBankingClientCreator.kt | 22 +++++++++++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt create mode 100644 fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClientCreator.kt diff --git a/BankingUiCommon/build.gradle b/BankingUiCommon/build.gradle index 458e4005..524fcba8 100644 --- a/BankingUiCommon/build.gradle +++ b/BankingUiCommon/build.gradle @@ -17,4 +17,7 @@ dependencies { api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" api "net.dankito.utils:java-utils:$javaUtilsVersion" + + // TODO: try to get rid of this import + api project(':fints4javaLib') } \ No newline at end of file diff --git a/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt b/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt new file mode 100644 index 00000000..351f7718 --- /dev/null +++ b/BankingUiCommon/src/main/java/net/dankito/banking/ui/IBankingClientCreator.kt @@ -0,0 +1,20 @@ +package net.dankito.banking.ui + +import net.dankito.banking.util.IBase64Service +import net.dankito.fints.model.BankInfo +import net.dankito.utils.IThreadPool +import net.dankito.utils.web.client.IWebClient + + +interface IBankingClientCreator { + + fun createClient(bankInfo: BankInfo, // TODO: create own value object to get rid off fints4java dependency + customerId: String, + pin: String, + webClient: IWebClient, // TODO: wrap away JavaUtils IWebClient + base64Service: IBase64Service, + threadPool: IThreadPool, // TODO: wrap away JavaUtils IThreadPool + callback: BankingClientCallback + ): IBankingClient + +} \ No newline at end of file diff --git a/fints4javaAndroidApp/build.gradle b/fints4javaAndroidApp/build.gradle index ccd7581c..18eae8f7 100644 --- a/fints4javaAndroidApp/build.gradle +++ b/fints4javaAndroidApp/build.gradle @@ -48,10 +48,9 @@ android { } dependencies { - implementation project(':fints4javaBankingClient') + api project(':BankingUiCommon') - // TODO: try to get rid of this import - implementation project(':fints4javaLib') + implementation project(':fints4javaBankingClient') implementation "com.github.clans:fab:$clansFloatingActionButtonVersion" diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt index 90003b11..e5c1786a 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/MainActivity.kt @@ -14,6 +14,7 @@ import net.dankito.banking.fints4java.android.ui.dialogs.AddAccountDialog import net.dankito.banking.fints4java.android.ui.dialogs.EnterAtcDialog import net.dankito.banking.fints4java.android.ui.dialogs.EnterTanDialog import net.dankito.banking.fints4java.android.ui.views.MainActivityFloatingActionMenuButton +import net.dankito.banking.fints4javaBankingClientCreator import net.dankito.banking.ui.BankingClientCallback import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult @@ -31,7 +32,7 @@ class MainActivity : AppCompatActivity() { private lateinit var floatingActionMenuButton: MainActivityFloatingActionMenuButton - val presenter = MainWindowPresenter(Base64ServiceAndroid(), object : BankingClientCallback { + val presenter = MainWindowPresenter(fints4javaBankingClientCreator(), Base64ServiceAndroid(), object : BankingClientCallback { override fun enterTan(account: Account, tanChallenge: TanChallenge): EnterTanResult { return getTanFromUserOffUiThread(account, tanChallenge) diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt index b5333440..692419da 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt @@ -2,6 +2,7 @@ package net.dankito.banking.fints4java.android.ui import net.dankito.banking.ui.BankingClientCallback import net.dankito.banking.ui.IBankingClient +import net.dankito.banking.ui.IBankingClientCreator import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.model.AccountTransaction import net.dankito.banking.ui.model.BankAccount @@ -10,7 +11,6 @@ import net.dankito.banking.ui.model.responses.AddAccountResponse import net.dankito.banking.ui.model.responses.BankingClientResponse import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.util.IBase64Service -import net.dankito.banking.util.UiCommonBase64ServiceWrapper import net.dankito.fints.banks.BankFinder import net.dankito.fints.model.BankInfo import net.dankito.utils.IThreadPool @@ -21,8 +21,10 @@ import java.util.* import kotlin.collections.ArrayList -open class MainWindowPresenter(protected val base64Service: IBase64Service, - protected val callback: BankingClientCallback +open class MainWindowPresenter( + protected val bankingClientCreator: IBankingClientCreator, + protected val base64Service: IBase64Service, + protected val callback: BankingClientCallback ) { companion object { @@ -45,7 +47,7 @@ open class MainWindowPresenter(protected val base64Service: IBase64Service, // TODO: move BankInfo out of fints4javaLib open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) { - val newClient = net.dankito.banking.fints4javaBankingClient(bankInfo, customerId, pin, OkHttpWebClient(), UiCommonBase64ServiceWrapper(base64Service), threadPool, this.callback) + val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, OkHttpWebClient(), base64Service, threadPool, this.callback) newClient.addAccountAsync { response -> val account = response.account diff --git a/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClientCreator.kt b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClientCreator.kt new file mode 100644 index 00000000..b9d79d68 --- /dev/null +++ b/fints4javaBankingClient/src/main/kotlin/net/dankito/banking/fints4javaBankingClientCreator.kt @@ -0,0 +1,22 @@ +package net.dankito.banking + +import net.dankito.banking.ui.BankingClientCallback +import net.dankito.banking.ui.IBankingClient +import net.dankito.banking.ui.IBankingClientCreator +import net.dankito.banking.util.IBase64Service +import net.dankito.banking.util.UiCommonBase64ServiceWrapper +import net.dankito.fints.model.BankInfo +import net.dankito.utils.IThreadPool +import net.dankito.utils.web.client.IWebClient +import net.dankito.utils.web.client.OkHttpWebClient + + +open class fints4javaBankingClientCreator : IBankingClientCreator { + + override fun createClient(bankInfo: BankInfo, customerId: String, pin: String, webClient: IWebClient, + base64Service: IBase64Service, threadPool: IThreadPool, callback: BankingClientCallback): IBankingClient { + + return fints4javaBankingClient(bankInfo, customerId, pin, OkHttpWebClient(), UiCommonBase64ServiceWrapper(base64Service), threadPool, callback) + } + +} \ No newline at end of file