Skip to content

Commit

Permalink
iOS TokenInformationLayoutView show NFT content link and thumbnail #9
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Mar 4, 2022
1 parent 333fac8 commit 42f9e0d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class ThumbnailContainer(private val baseSize: Double = 24.0) : UIView(CGRect.Ze
private val thumbnailPicture = UIImageView(CGRect.Zero()).apply {
contentMode = UIViewContentMode.ScaleAspectFit
tintColor = UIColor.systemBackground()
fixedWidth(baseSize * 2 / 3)
fixedHeight(baseSize * 2 / 3)
fixedWidth(baseSize / 2)
fixedHeight(baseSize / 2)
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package org.ergoplatform.ios.tokens
import org.ergoplatform.getExplorerTokenUrl
import org.ergoplatform.getExplorerTxUrl
import org.ergoplatform.ios.ui.*
import org.ergoplatform.persistance.TokenInformation
import org.ergoplatform.uilogic.STRING_LABEL_MINTING_TX
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_DESCRIPTION
import org.ergoplatform.uilogic.STRING_LABEL_TOKEN_SUPPLY
import org.ergoplatform.uilogic.STRING_TITLE_WALLET_BALANCE
import org.ergoplatform.tokens.getHttpContentLink
import org.ergoplatform.uilogic.*
import org.ergoplatform.uilogic.tokens.TokenInformationLayoutLogic
import org.ergoplatform.uilogic.tokens.TokenInformationModelLogic
import org.robovm.apple.coregraphics.CGRect
import org.robovm.apple.foundation.NSArray
import org.robovm.apple.uikit.*

class TokenInformationLayoutView : UIView(CGRect.Zero()) {
class TokenInformationLayoutView(private val modelLogic: TokenInformationModelLogic) : UIView(CGRect.Zero()) {
private val layoutLogic = IosTokenInformationLayoutLogic()
private val texts = getAppDelegate().texts
private val nameLabel = Headline2Label().apply {
Expand Down Expand Up @@ -53,8 +50,7 @@ class TokenInformationLayoutView : UIView(CGRect.Zero()) {
textAlignment = NSTextAlignment.Center
text = texts.get(STRING_TITLE_WALLET_BALANCE)
}

private var tokenInformation: TokenInformation? = null
private val nftLayout = NftLayoutView()

init {

Expand All @@ -71,7 +67,12 @@ class TokenInformationLayoutView : UIView(CGRect.Zero()) {

val optionalEntriesStack = UIStackView(
NSArray(
balanceAmountTitle, balanceAmountLabel, balanceAmountValue, supplyAmountTitle, supplyAmountLabel
nftLayout,
balanceAmountTitle,
balanceAmountLabel,
balanceAmountValue,
supplyAmountTitle,
supplyAmountLabel
)
).apply {
axis = UILayoutConstraintAxis.Vertical
Expand Down Expand Up @@ -117,16 +118,52 @@ class TokenInformationLayoutView : UIView(CGRect.Zero()) {
mintingTxLabel.apply {
isUserInteractionEnabled = true
addGestureRecognizer(UITapGestureRecognizer {
tokenInformation?.let { openUrlInBrowser(getExplorerTxUrl(it.mintingTxId)) }
modelLogic.tokenInformation?.let { openUrlInBrowser(getExplorerTxUrl(it.mintingTxId)) }
})
}
nftLayout.contentLinkLabel.apply {
isUserInteractionEnabled = true
addGestureRecognizer(UITapGestureRecognizer {
modelLogic.eip4Token?.getHttpContentLink(getAppDelegate().prefs)?.let {
openUrlInBrowser(it)
}
})
}
}

fun updateTokenInformation(modelLogic: TokenInformationModelLogic, balanceAmount: Long?) {
tokenInformation = modelLogic.tokenInformation
fun updateTokenInformation(balanceAmount: Long?) {
layoutLogic.updateLayout(modelLogic, IosStringProvider(texts), balanceAmount ?: 0)
}

fun updateNftPreview() {
layoutLogic.updateNftPreview(modelLogic)
}

inner class NftLayoutView : UIStackView() {
val thumbnailContainer = ThumbnailContainer(90.0)
val contentLinkLabel = Body1Label().apply {
textAlignment = NSTextAlignment.Center
numberOfLines = 3
lineBreakMode = NSLineBreakMode.TruncatingMiddle
lineBreakStrategy = NSLineBreakStrategy.None
}

init {
axis = UILayoutConstraintAxis.Vertical
spacing = DEFAULT_MARGIN * 3

val contentLinkTitle = Body1BoldLabel().apply {
textAlignment = NSTextAlignment.Center
text = texts.get(STRING_LABEL_CONTENT_LINK)
}

addArrangedSubview(thumbnailContainer)
addArrangedSubview(contentLinkTitle)
addArrangedSubview(contentLinkLabel)
setCustomSpacing(DEFAULT_MARGIN / 2, contentLinkTitle)
}
}

inner class IosTokenInformationLayoutLogic : TokenInformationLayoutLogic() {
override fun setTokenTextFields(displayName: String, tokenId: String, description: String) {
nameLabel.text = displayName
Expand Down Expand Up @@ -161,19 +198,19 @@ class TokenInformationLayoutView : UIView(CGRect.Zero()) {
}

override fun setContentLinkText(linkText: String) {
// todo token
nftLayout.contentLinkLabel.text = linkText
}

override fun setNftLayoutVisibility(visible: Boolean) {
// TODO("Not yet implemented")
nftLayout.isHidden = !visible
}

override fun setContentHashText(hashText: String) {
// TODO("Not yet implemented")
}

override fun setThumbnail(thumbnailType: Int) {
// TODO("Not yet implemented")
nftLayout.thumbnailContainer.setThumbnail(thumbnailType)
}

override fun showNftPreview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class TokenInformationViewController(
view.addSubview(activityView)
activityView.centerVertical().centerHorizontal()

tokenInfoLayout = TokenInformationLayoutView()
tokenInfoLayout = TokenInformationLayoutView(uiLogic)
val scrollView = tokenInfoLayout.wrapInVerticalScrollView()
view.addSubview(scrollView)
scrollView.edgesToSuperview(false)
closeButton = addCloseButton()
scrollView.topToBottomOf(closeButton).widthMatchesSuperview().bottomToSuperview()

tokenInfoLayout.isHidden = true

closeButton = addCloseButton()
}

override fun viewWillAppear(animated: Boolean) {
Expand All @@ -50,7 +50,7 @@ class TokenInformationViewController(
activityView.isHidden = true
tokenInformation?.let {
tokenInfoLayout.isHidden = false
tokenInfoLayout.updateTokenInformation(this, tokenAmount)
tokenInfoLayout.updateTokenInformation(tokenAmount)
} ?: run {
val errorView = UIImageView(getIosSystemImage(IMAGE_WARNING, UIImageSymbolScale.Large)).apply {
contentMode = UIViewContentMode.ScaleAspectFit
Expand All @@ -64,7 +64,7 @@ class TokenInformationViewController(
}

override fun onDownloadStateUpdated() {
// TODO token information
tokenInfoLayout.updateNftPreview()
}
}
}

0 comments on commit 42f9e0d

Please sign in to comment.