-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send funds/Wallet details filter tokens by type (iOS) #171
- Loading branch information
1 parent
3a53055
commit baf67d7
Showing
6 changed files
with
322 additions
and
20 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
83 changes: 83 additions & 0 deletions
83
ios/src/main/java/org/ergoplatform/ios/tokens/TokenFilterButton.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,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 | ||
) | ||
} | ||
} |
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
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
Oops, something went wrong.