Implemented currentOrNextActivity() so that caller gets an activity in either case
This commit is contained in:
parent
8fcdb0f593
commit
e202587572
|
@ -21,51 +21,49 @@ import java.util.concurrent.atomic.AtomicReference
|
|||
open class RouterAndroid(protected val activityTracker: CurrentActivityTracker) : IRouter {
|
||||
|
||||
override fun showAddAccountDialog(presenter: BankingPresenter) {
|
||||
activityTracker.currentActivity?.let { activity ->
|
||||
activityTracker.currentOrNextActivity { activity ->
|
||||
AddAccountDialog().show(activity)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTanFromUserFromNonUiThread(account: Account, tanChallenge: TanChallenge, presenter: BankingPresenter): EnterTanResult {
|
||||
return activityTracker.currentActivity?.let { activity ->
|
||||
val enteredTan = AtomicReference<EnterTanResult>(null)
|
||||
val tanEnteredLatch = CountDownLatch(1)
|
||||
val enteredTan = AtomicReference<EnterTanResult>(null)
|
||||
val tanEnteredLatch = CountDownLatch(1)
|
||||
|
||||
activityTracker.currentOrNextActivity { activity ->
|
||||
activity.runOnUiThread {
|
||||
EnterTanDialog().show(account, tanChallenge, activity, false) {
|
||||
enteredTan.set(it)
|
||||
tanEnteredLatch.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||
|
||||
enteredTan.get()
|
||||
}
|
||||
?: EnterTanResult.userDidNotEnterTan()
|
||||
|
||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||
|
||||
return enteredTan.get()
|
||||
}
|
||||
|
||||
override fun getAtcFromUserFromNonUiThread(tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult {
|
||||
return activityTracker.currentActivity?.let { activity ->
|
||||
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
||||
val tanEnteredLatch = CountDownLatch(1)
|
||||
val result = AtomicReference<EnterTanGeneratorAtcResult>(null)
|
||||
val tanEnteredLatch = CountDownLatch(1)
|
||||
|
||||
activityTracker.currentOrNextActivity { activity ->
|
||||
activity.runOnUiThread {
|
||||
EnterAtcDialog().show(tanMedium, activity, false) { enteredResult ->
|
||||
result.set(enteredResult)
|
||||
tanEnteredLatch.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||
|
||||
result.get()
|
||||
}
|
||||
?: EnterTanGeneratorAtcResult.userDidNotEnterTan()
|
||||
|
||||
try { tanEnteredLatch.await() } catch (ignored: Exception) { }
|
||||
|
||||
return result.get()
|
||||
}
|
||||
|
||||
override fun showTransferMoneyDialog(presenter: BankingPresenter, preselectedBankAccount: BankAccount?, preselectedValues: TransferMoneyData?) {
|
||||
activityTracker.currentActivity?.let { activity ->
|
||||
activityTracker.currentOrNextActivity { activity ->
|
||||
TransferMoneyDialog().show(activity, preselectedBankAccount, preselectedValues)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import kotlin.concurrent.schedule
|
|||
|
||||
open class CurrentActivityTracker {
|
||||
|
||||
protected val nextActivitySetListeners = CopyOnWriteArrayList<(BaseActivity) -> Unit>()
|
||||
|
||||
|
||||
var currentActivity: BaseActivity? = null
|
||||
set(value) {
|
||||
field = value // TODO: check field != value
|
||||
|
@ -18,7 +21,14 @@ open class CurrentActivityTracker {
|
|||
}
|
||||
|
||||
|
||||
protected val nextActivitySetListeners = CopyOnWriteArrayList<(BaseActivity) -> Unit>()
|
||||
open fun currentOrNextActivity(activity: (BaseActivity) -> Unit) {
|
||||
currentActivity?.let {
|
||||
activity(it)
|
||||
}
|
||||
?: addNextActivitySetListener {
|
||||
activity(it)
|
||||
}
|
||||
}
|
||||
|
||||
open fun addNextActivitySetListener(listener: (BaseActivity) -> Unit) {
|
||||
synchronized(nextActivitySetListeners) {
|
||||
|
|
Loading…
Reference in New Issue