Added IRouter to move navigation out of UI code
This commit is contained in:
parent
eed03d348e
commit
3f4553281d
|
@ -0,0 +1,16 @@
|
||||||
|
package net.dankito.banking.ui
|
||||||
|
|
||||||
|
import net.dankito.banking.ui.model.Account
|
||||||
|
import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult
|
||||||
|
import net.dankito.banking.ui.model.tan.EnterTanResult
|
||||||
|
import net.dankito.banking.ui.model.tan.TanChallenge
|
||||||
|
import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium
|
||||||
|
|
||||||
|
|
||||||
|
interface IRouter {
|
||||||
|
|
||||||
|
fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult
|
||||||
|
|
||||||
|
fun getAtcFromUserOffUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult
|
||||||
|
|
||||||
|
}
|
|
@ -33,7 +33,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
private lateinit var floatingActionMenuButton: MainActivityFloatingActionMenuButton
|
private lateinit var floatingActionMenuButton: MainActivityFloatingActionMenuButton
|
||||||
|
|
||||||
|
|
||||||
val presenter = MainWindowPresenter(fints4javaBankingClientCreator(), Base64ServiceAndroid(), object : BankingClientCallback {
|
val presenter = MainWindowPresenter(fints4javaBankingClientCreator(),
|
||||||
|
Base64ServiceAndroid(), object : BankingClientCallback {
|
||||||
|
|
||||||
override fun enterTan(account: Account, tanChallenge: TanChallenge): EnterTanResult {
|
override fun enterTan(account: Account, tanChallenge: TanChallenge): EnterTanResult {
|
||||||
return getTanFromUserOffUiThread(account, tanChallenge)
|
return getTanFromUserOffUiThread(account, tanChallenge)
|
||||||
|
@ -45,6 +46,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private val router = RouterAndroid(this, presenter)
|
||||||
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -108,35 +111,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
|
||||||
private fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult {
|
private fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult {
|
||||||
val enteredTan = AtomicReference<EnterTanResult>(null)
|
return router.getTanFromUserOffUiThread(account, tanChallenge)
|
||||||
val tanEnteredLatch = CountDownLatch(1)
|
|
||||||
|
|
||||||
runOnUiThread {
|
|
||||||
EnterTanDialog().show(account, tanChallenge, presenter, this@MainActivity, false) {
|
|
||||||
enteredTan.set(it)
|
|
||||||
tanEnteredLatch.countDown()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
|
||||||
|
|
||||||
return enteredTan.get()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAtcFromUserOffUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
private fun getAtcFromUserOffUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||||
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
return router.getAtcFromUserOffUiThread(tanMedium)
|
||||||
val tanEnteredLatch = CountDownLatch(1)
|
|
||||||
|
|
||||||
runOnUiThread {
|
|
||||||
EnterAtcDialog().show(tanMedium, this@MainActivity, false) { enteredResult ->
|
|
||||||
result.set(enteredResult)
|
|
||||||
tanEnteredLatch.countDown()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
|
||||||
|
|
||||||
return result.get()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package net.dankito.banking.fints4java.android
|
||||||
|
|
||||||
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import net.dankito.banking.fints4java.android.ui.MainWindowPresenter
|
||||||
|
import net.dankito.banking.fints4java.android.ui.dialogs.EnterAtcDialog
|
||||||
|
import net.dankito.banking.fints4java.android.ui.dialogs.EnterTanDialog
|
||||||
|
import net.dankito.banking.ui.IRouter
|
||||||
|
import net.dankito.banking.ui.model.Account
|
||||||
|
import net.dankito.banking.ui.model.tan.EnterTanGeneratorAtcResult
|
||||||
|
import net.dankito.banking.ui.model.tan.EnterTanResult
|
||||||
|
import net.dankito.banking.ui.model.tan.TanChallenge
|
||||||
|
import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium
|
||||||
|
import java.util.concurrent.CountDownLatch
|
||||||
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
|
|
||||||
|
open class RouterAndroid(protected val activity: AppCompatActivity, protected val presenter: MainWindowPresenter) : IRouter {
|
||||||
|
|
||||||
|
override fun getTanFromUserOffUiThread(account: Account, tanChallenge: TanChallenge): EnterTanResult {
|
||||||
|
val enteredTan = AtomicReference<EnterTanResult>(null)
|
||||||
|
val tanEnteredLatch = CountDownLatch(1)
|
||||||
|
|
||||||
|
activity.runOnUiThread {
|
||||||
|
EnterTanDialog().show(account, tanChallenge, presenter, activity, false) {
|
||||||
|
enteredTan.set(it)
|
||||||
|
tanEnteredLatch.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||||
|
|
||||||
|
return enteredTan.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAtcFromUserOffUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||||
|
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
||||||
|
val tanEnteredLatch = CountDownLatch(1)
|
||||||
|
|
||||||
|
activity.runOnUiThread {
|
||||||
|
EnterAtcDialog().show(tanMedium, activity, false) { enteredResult ->
|
||||||
|
result.set(enteredResult)
|
||||||
|
tanEnteredLatch.countDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||||
|
|
||||||
|
return result.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue