Skip to content

Commit

Permalink
Send funds/Wallet details filter tokens by type (iOS) #171
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Jun 7, 2023
1 parent 3a53055 commit baf67d7
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface FilterTokenListUiLogic {
tokenFilterMap[filterType] ?: false

fun isTokenInFilter(ti: TokenInformation?): Boolean {
println(tokenFilterMap.values)
return tokenFilterMap.values.none { it }
|| ti?.thumbnailType?.let { tokenFilterMap[it] == true } ?: false
}
Expand Down
83 changes: 83 additions & 0 deletions ios/src/main/java/org/ergoplatform/ios/tokens/TokenFilterButton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.ergoplatform.ios.tokens

import org.ergoplatform.ios.ui.IMAGE_FILTER
import org.ergoplatform.ios.ui.getAppDelegate
import org.ergoplatform.ios.ui.getIosSystemImage
import org.ergoplatform.persistance.THUMBNAIL_TYPE_NFT_AUDIO
import org.ergoplatform.persistance.THUMBNAIL_TYPE_NFT_IMG
import org.ergoplatform.persistance.THUMBNAIL_TYPE_NFT_VID
import org.ergoplatform.persistance.THUMBNAIL_TYPE_NONE
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_AUDIO
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_GENERIC
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_IMAGE
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_VIDEO
import org.ergoplatform.uilogic.tokens.FilterTokenListUiLogic
import org.robovm.apple.foundation.Foundation
import org.robovm.apple.foundation.NSArray
import org.robovm.apple.uikit.UIAction
import org.robovm.apple.uikit.UIButton
import org.robovm.apple.uikit.UIColor
import org.robovm.apple.uikit.UIControlState
import org.robovm.apple.uikit.UIImageSymbolScale
import org.robovm.apple.uikit.UIMenu
import org.robovm.apple.uikit.UIMenuElementState

class TokenFilterButton(val uiLogic: FilterTokenListUiLogic) : UIButton() {
var onChange: (() -> Unit)? = null

init {
setImage(
getIosSystemImage(IMAGE_FILTER, UIImageSymbolScale.Small, pointSize = 25.0),
UIControlState.Normal
)
tintColor = UIColor.label()
if (Foundation.getMajorSystemVersion() >= 14) {
setShowsMenuAsPrimaryAction(true)
buildMenu()
} else {
isHidden = true
}
}

private fun buildMenu() {
val texts = getAppDelegate().texts
val genericAction =
buildAction(texts.get(STRING_LABEL_TOKEN_GENERIC), THUMBNAIL_TYPE_NONE)
val imageAction = buildAction(
texts.get(STRING_LABEL_TOKEN_IMAGE),
THUMBNAIL_TYPE_NFT_IMG,
)
val audioAction = buildAction(
texts.get(STRING_LABEL_TOKEN_AUDIO),
THUMBNAIL_TYPE_NFT_AUDIO,
)
val videoAction = buildAction(
texts.get(STRING_LABEL_TOKEN_VIDEO),
THUMBNAIL_TYPE_NFT_VID,
)
menu = UIMenu(NSArray(genericAction, imageAction, audioAction, videoAction))
}

private fun buildAction(text: String, tokenType: Int): UIAction =
UIAction(text,
getTokenThumbnailImageName(tokenType)?.let {
getIosSystemImage(it, UIImageSymbolScale.Small)
}, null
) { toggleToken(tokenType) }.apply {
state = if (uiLogic.hasTokenFilter(tokenType))
UIMenuElementState.On
else UIMenuElementState.Off
}

private fun toggleToken(type: Int) {
uiLogic.toggleTokenFilter(type)
buildMenu()
onChange?.invoke()
}

override fun setHidden(v: Boolean) {
super.setHidden(
if (Foundation.getMajorSystemVersion() >= 14) v else true
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,57 @@ package org.ergoplatform.ios.transactions
import com.badlogic.gdx.utils.I18NBundle
import org.ergoplatform.ios.tokens.GenuineImageContainer
import org.ergoplatform.ios.tokens.ThumbnailContainer
import org.ergoplatform.ios.ui.*
import org.ergoplatform.ios.tokens.TokenFilterButton
import org.ergoplatform.ios.ui.AbstractTableViewCell
import org.ergoplatform.ios.ui.Body1Label
import org.ergoplatform.ios.ui.Body2Label
import org.ergoplatform.ios.ui.DEFAULT_MARGIN
import org.ergoplatform.ios.ui.Headline2Label
import org.ergoplatform.ios.ui.IosStringProvider
import org.ergoplatform.ios.ui.addCloseButton
import org.ergoplatform.ios.ui.bottomToSuperview
import org.ergoplatform.ios.ui.centerHorizontal
import org.ergoplatform.ios.ui.getAppDelegate
import org.ergoplatform.ios.ui.leftToRightOf
import org.ergoplatform.ios.ui.leftToSuperview
import org.ergoplatform.ios.ui.rightToSuperview
import org.ergoplatform.ios.ui.topToBottomOf
import org.ergoplatform.ios.ui.topToSuperview
import org.ergoplatform.ios.ui.widthMatchesSuperview
import org.ergoplatform.persistance.TokenInformation
import org.ergoplatform.persistance.WalletToken
import org.ergoplatform.uilogic.STRING_TITLE_ADD_TOKEN
import org.ergoplatform.uilogic.StringProvider
import org.ergoplatform.uilogic.tokens.TokenEntryViewUiLogic
import org.ergoplatform.uilogic.transactions.SendFundsUiLogic
import org.robovm.apple.coregraphics.CGRect
import org.robovm.apple.foundation.NSArray
import org.robovm.apple.foundation.NSIndexPath
import org.robovm.apple.uikit.*
import org.robovm.apple.uikit.NSLineBreakMode
import org.robovm.apple.uikit.NSTextAlignment
import org.robovm.apple.uikit.UIColor
import org.robovm.apple.uikit.UILayoutConstraintAxis
import org.robovm.apple.uikit.UIStackView
import org.robovm.apple.uikit.UITableView
import org.robovm.apple.uikit.UITableViewCell
import org.robovm.apple.uikit.UITableViewCellSeparatorStyle
import org.robovm.apple.uikit.UITableViewDataSourceAdapter
import org.robovm.apple.uikit.UITapGestureRecognizer
import org.robovm.apple.uikit.UIViewController

const val TOKEN_CELL = "TOKEN_CELL"

/**
* Let the user choose one or more token(s) from a list of tokens
*/
class ChooseTokenListViewController(
val tokensToChooseFrom: List<WalletToken>,
val tokenInfoMap: HashMap<String, TokenInformation>,
val uiLogic: SendFundsUiLogic,
val onChoose: (String) -> Unit
) : UIViewController() {

private val texts = getAppDelegate().texts
private var tokensToChooseFrom = uiLogic.getTokensToChooseFrom()
private val tokenInfoMap = uiLogic.tokensInfo

override fun viewDidLoad() {
super.viewDidLoad()
Expand All @@ -38,10 +66,15 @@ class ChooseTokenListViewController(
textAlignment = NSTextAlignment.Center
}

val filterButton = TokenFilterButton(uiLogic)

view.addSubview(titleLabel)
view.addSubview(filterButton)

titleLabel.topToSuperview(topInset = DEFAULT_MARGIN * 2)
.widthMatchesSuperview(inset = DEFAULT_MARGIN)
.leftToSuperview(inset = DEFAULT_MARGIN)
filterButton.topToSuperview(topInset = DEFAULT_MARGIN).rightToSuperview()
.leftToRightOf(titleLabel, inset = DEFAULT_MARGIN)

val tableView = UITableView(CGRect.Zero())
view.addSubview(tableView)
Expand All @@ -56,6 +89,10 @@ class ChooseTokenListViewController(
estimatedRowHeight = UITableView.getAutomaticDimension()
}

filterButton.onChange = {
tokensToChooseFrom = uiLogic.getTokensToChooseFrom()
tableView.reloadData()
}
}

inner class TokenDataSource : UITableViewDataSourceAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,119 @@ package org.ergoplatform.ios.transactions

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.ergoplatform.*
import org.ergoplatform.ApiServiceManager
import org.ergoplatform.ErgoAmount
import org.ergoplatform.URL_COLD_WALLET_HELP
import org.ergoplatform.WalletStateSyncManager
import org.ergoplatform.addressbook.getAddressLabelFromDatabase
import org.ergoplatform.getExplorerTxUrl
import org.ergoplatform.ios.addressbook.ChooseAddressDialogViewController
import org.ergoplatform.ios.tokens.SendTokenEntryView
import org.ergoplatform.ios.ui.*
import org.ergoplatform.ios.ui.Body1BoldLabel
import org.ergoplatform.ios.ui.Body1Label
import org.ergoplatform.ios.ui.CardView
import org.ergoplatform.ios.ui.CommonButton
import org.ergoplatform.ios.ui.DEFAULT_MARGIN
import org.ergoplatform.ios.ui.EndIconTextField
import org.ergoplatform.ios.ui.ErgoAmountView
import org.ergoplatform.ios.ui.FONT_SIZE_BODY1
import org.ergoplatform.ios.ui.FONT_SIZE_HEADLINE1
import org.ergoplatform.ios.ui.IMAGE_ADDRESSBOOK
import org.ergoplatform.ios.ui.IMAGE_EDIT_CIRCLE
import org.ergoplatform.ios.ui.IMAGE_FULL_AMOUNT
import org.ergoplatform.ios.ui.IMAGE_INFORMATION
import org.ergoplatform.ios.ui.IMAGE_PLUS
import org.ergoplatform.ios.ui.IMAGE_QR_SCAN
import org.ergoplatform.ios.ui.IMAGE_SEND
import org.ergoplatform.ios.ui.IMAGE_TX_DONE
import org.ergoplatform.ios.ui.IosStringProvider
import org.ergoplatform.ios.ui.MAX_WIDTH
import org.ergoplatform.ios.ui.OnlyNumericInputTextFieldDelegate
import org.ergoplatform.ios.ui.PrimaryButton
import org.ergoplatform.ios.ui.ProgressViewController
import org.ergoplatform.ios.ui.QrScannerViewController
import org.ergoplatform.ios.ui.TextButton
import org.ergoplatform.ios.ui.animateLayoutChanges
import org.ergoplatform.ios.ui.bottomToKeyboard
import org.ergoplatform.ios.ui.bottomToSuperview
import org.ergoplatform.ios.ui.buildAddressSelectorView
import org.ergoplatform.ios.ui.buildSimpleAlertController
import org.ergoplatform.ios.ui.centerHorizontal
import org.ergoplatform.ios.ui.centerVertical
import org.ergoplatform.ios.ui.centerVerticallyTo
import org.ergoplatform.ios.ui.clearArrangedSubviews
import org.ergoplatform.ios.ui.edgesToSuperview
import org.ergoplatform.ios.ui.fixedHeight
import org.ergoplatform.ios.ui.fixedWidth
import org.ergoplatform.ios.ui.getAppDelegate
import org.ergoplatform.ios.ui.getIosSystemImage
import org.ergoplatform.ios.ui.leftToSuperview
import org.ergoplatform.ios.ui.openStorePage
import org.ergoplatform.ios.ui.rightToSuperview
import org.ergoplatform.ios.ui.runOnMainThread
import org.ergoplatform.ios.ui.setHiddenAnimated
import org.ergoplatform.ios.ui.setHtmlText
import org.ergoplatform.ios.ui.shareText
import org.ergoplatform.ios.ui.topToSuperview
import org.ergoplatform.ios.ui.uiColorErgo
import org.ergoplatform.ios.ui.widthMatchesSuperview
import org.ergoplatform.ios.ui.wrapInVerticalScrollView
import org.ergoplatform.ios.ui.wrapWithTrailingImage
import org.ergoplatform.transactions.TransactionInfo
import org.ergoplatform.transactions.TransactionResult
import org.ergoplatform.transactions.reduceBoxes
import org.ergoplatform.uilogic.*
import org.ergoplatform.uilogic.STRING_BUTTON_DONE
import org.ergoplatform.uilogic.STRING_BUTTON_PLEASE_RATE
import org.ergoplatform.uilogic.STRING_BUTTON_SEND
import org.ergoplatform.uilogic.STRING_DESC_PLEASE_RATE
import org.ergoplatform.uilogic.STRING_DESC_SEND_FUNDS
import org.ergoplatform.uilogic.STRING_DESC_TRANSACTION_SEND
import org.ergoplatform.uilogic.STRING_ERROR_TOKEN_AMOUNT
import org.ergoplatform.uilogic.STRING_HINT_AMOUNT_CURRENCY
import org.ergoplatform.uilogic.STRING_HINT_READ_ONLY
import org.ergoplatform.uilogic.STRING_INFO_PURPOSE_MESSAGE
import org.ergoplatform.uilogic.STRING_INFO_PURPOSE_MESSAGE_ACCEPT
import org.ergoplatform.uilogic.STRING_INFO_PURPOSE_MESSAGE_DECLINE
import org.ergoplatform.uilogic.STRING_LABEL_ADD_TOKEN
import org.ergoplatform.uilogic.STRING_LABEL_ALL_ADDRESSES
import org.ergoplatform.uilogic.STRING_LABEL_AMOUNT
import org.ergoplatform.uilogic.STRING_LABEL_PURPOSE
import org.ergoplatform.uilogic.STRING_LABEL_RECEIVER_ADDRESS
import org.ergoplatform.uilogic.STRING_LABEL_SEND_FROM
import org.ergoplatform.uilogic.STRING_LABEL_WALLET_BALANCE
import org.ergoplatform.uilogic.transactions.SendFundsUiLogic
import org.ergoplatform.utils.LogUtils
import org.ergoplatform.wallet.addresses.getAddressLabel
import org.ergoplatform.wallet.getNumOfAddresses
import org.ergoplatform.wallet.isReadOnly
import org.robovm.apple.coregraphics.CGRect
import org.robovm.apple.foundation.NSArray
import org.robovm.apple.uikit.*
import org.robovm.apple.uikit.NSTextAlignment
import org.robovm.apple.uikit.UIAlertAction
import org.robovm.apple.uikit.UIAlertActionStyle
import org.robovm.apple.uikit.UIAlertController
import org.robovm.apple.uikit.UIAlertControllerStyle
import org.robovm.apple.uikit.UIBarButtonItem
import org.robovm.apple.uikit.UIBarButtonItemStyle
import org.robovm.apple.uikit.UIButton
import org.robovm.apple.uikit.UIColor
import org.robovm.apple.uikit.UIControlEvents
import org.robovm.apple.uikit.UIEdgeInsets
import org.robovm.apple.uikit.UIFont
import org.robovm.apple.uikit.UIFontWeight
import org.robovm.apple.uikit.UIImageSymbolScale
import org.robovm.apple.uikit.UIImageView
import org.robovm.apple.uikit.UIKeyboardType
import org.robovm.apple.uikit.UILabel
import org.robovm.apple.uikit.UILayoutConstraintAxis
import org.robovm.apple.uikit.UIReturnKeyType
import org.robovm.apple.uikit.UIStackView
import org.robovm.apple.uikit.UITapGestureRecognizer
import org.robovm.apple.uikit.UITextField
import org.robovm.apple.uikit.UITextFieldDelegateAdapter
import org.robovm.apple.uikit.UITextFieldViewMode
import org.robovm.apple.uikit.UITextView
import org.robovm.apple.uikit.UIView
import org.robovm.apple.uikit.UIViewContentMode

class SendFundsViewController(
private val walletId: Int,
Expand Down Expand Up @@ -266,9 +362,7 @@ class SendFundsViewController(
addTokenButton.isHidden = true
addTokenButton.addOnTouchUpInsideListener { _, _ ->
presentViewController(
ChooseTokenListViewController(
uiLogic.getTokensToChooseFrom(), uiLogic.tokensInfo
) { tokenToAdd ->
ChooseTokenListViewController(uiLogic) { tokenToAdd ->
tokensUiList.superview.animateLayoutChanges {
uiLogic.newTokenChosen(tokenToAdd)
}
Expand Down
1 change: 1 addition & 0 deletions ios/src/main/java/org/ergoplatform/ios/ui/UIUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const val IMAGE_STAR_FILLED = "star.fill"
const val IMAGE_SHARE = "square.and.arrow.up"
const val IMAGE_PASTE = "doc.on.clipboard"
val IMAGE_RESET_DATA = if (Foundation.getMajorSystemVersion() >= 14) "leaf.arrow.triangle.circlepath" else "flame"
const val IMAGE_FILTER = "slider.horizontal.3"

const val FONT_SIZE_BODY1 = 18.0
const val FONT_SIZE_HEADLINE1 = 30.0
Expand Down
Loading

0 comments on commit baf67d7

Please sign in to comment.