-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5558bbe
commit 25f954d
Showing
3 changed files
with
107 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
ios/src/main/java/org/ergoplatform/ios/wallet/ChooseWalletViewController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.ergoplatform.ios.wallet | ||
|
||
import kotlinx.coroutines.launch | ||
import org.ergoplatform.ios.transactions.ChooseSpendingWalletViewController | ||
import org.ergoplatform.ios.ui.* | ||
import org.ergoplatform.persistance.WalletConfig | ||
import org.ergoplatform.uilogic.StringProvider | ||
import org.robovm.apple.coregraphics.CGRect | ||
import org.robovm.apple.uikit.* | ||
|
||
class ChooseWalletViewController( | ||
val callback: ((WalletConfig) -> Unit) | ||
) : CoroutineViewController() { | ||
private lateinit var walletsStackView: UIStackView | ||
private lateinit var texts: StringProvider | ||
|
||
override fun viewDidLoad() { | ||
super.viewDidLoad() | ||
texts = IosStringProvider(getAppDelegate().texts) | ||
|
||
view.backgroundColor = UIColor.systemBackground() | ||
val closeButton = addCloseButton() | ||
|
||
walletsStackView = UIStackView(CGRect.Zero()).apply { | ||
axis = UILayoutConstraintAxis.Vertical | ||
} | ||
val scrollView = walletsStackView.wrapInVerticalScrollView() | ||
|
||
view.addSubview(scrollView) | ||
|
||
scrollView.topToBottomOf(closeButton, DEFAULT_MARGIN) | ||
.widthMatchesSuperview(inset = DEFAULT_MARGIN * 2, maxWidth = MAX_WIDTH) | ||
.bottomToSuperview(bottomInset = DEFAULT_MARGIN) | ||
|
||
} | ||
|
||
override fun viewWillAppear(animated: Boolean) { | ||
super.viewWillAppear(animated) | ||
viewControllerScope.launch { | ||
val wallets = getAppDelegate().database.walletDbProvider.getWalletsWithStates() | ||
|
||
runOnMainThread { | ||
walletsStackView.clearArrangedSubviews() | ||
wallets.sortedBy { it.walletConfig.displayName?.lowercase() }.forEach { wallet -> | ||
walletsStackView.addArrangedSubview( | ||
ChooseSpendingWalletViewController.ChooseWalletItem( | ||
wallet, | ||
texts, | ||
true | ||
).apply { | ||
isUserInteractionEnabled = true | ||
addGestureRecognizer(UITapGestureRecognizer { | ||
callback.invoke(wallet.walletConfig) | ||
dismissViewController(true) {} | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |