-
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.
TokenInformationDialogFragment refactor more logic into common-jvm, a…
…dd copy nft hash #9
- Loading branch information
1 parent
71bfd25
commit a6e29db
Showing
8 changed files
with
261 additions
and
222 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
112 changes: 112 additions & 0 deletions
112
android/src/main/java/org/ergoplatform/android/tokens/TokenInformationLayoutView.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,112 @@ | ||
package org.ergoplatform.android.tokens | ||
|
||
import android.graphics.BitmapFactory | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.graphics.drawable.Drawable | ||
import android.view.View | ||
import org.ergoplatform.android.R | ||
import org.ergoplatform.android.databinding.FragmentTokenInformationBinding | ||
import org.ergoplatform.uilogic.tokens.TokenInformationLayoutLogic | ||
import org.ergoplatform.uilogic.tokens.TokenInformationModelLogic | ||
|
||
|
||
class TokenInformationLayoutView(private val binding: FragmentTokenInformationBinding) : | ||
TokenInformationLayoutLogic() { | ||
|
||
override fun setTokenTextFields(displayName: String, tokenId: String, description: String) { | ||
binding.labelTokenName.text = displayName | ||
binding.labelTokenId.text = tokenId | ||
binding.labelTokenDescription.text = description | ||
} | ||
|
||
override fun setLabelSupplyAmountText(supplyAmount: String?) { | ||
binding.labelSupplyAmount.visibility = | ||
if (supplyAmount == null) View.GONE else View.VISIBLE | ||
binding.labelSupplyAmount.text = supplyAmount | ||
binding.titleSupplyAmount.visibility = binding.labelSupplyAmount.visibility | ||
} | ||
|
||
override fun setBalanceAmountAndValue(amount: String?, balanceValue: String?) { | ||
binding.labelBalanceAmount.text = amount | ||
binding.labelBalanceAmount.visibility = if (amount != null) View.VISIBLE else View.GONE | ||
binding.titleBalanceAmount.visibility = binding.labelBalanceAmount.visibility | ||
binding.labelBalanceValue.visibility = | ||
if (balanceValue != null) View.VISIBLE else View.GONE | ||
binding.labelBalanceValue.text = balanceValue | ||
|
||
} | ||
|
||
override fun setTokenGenuine(genuineFlag: Int) { | ||
binding.labelTokenName.setCompoundDrawablesRelativeWithIntrinsicBounds( | ||
0, 0, getGenuineDrawableId(genuineFlag), 0 | ||
) | ||
} | ||
|
||
override fun setNftLayoutVisibility(visible: Boolean) { | ||
binding.layoutNft.visibility = if (visible) View.VISIBLE else View.GONE | ||
} | ||
|
||
override fun setContentLinkText(linkText: String) { | ||
binding.labelContentLink.text = linkText | ||
} | ||
|
||
override fun setContentHashText(hashText: String) { | ||
binding.labelContentHash.text = hashText | ||
} | ||
|
||
override fun setThumbnail(thumbnailType: Int) { | ||
val thumbnailDrawable = getThumbnailDrawableId(thumbnailType) | ||
binding.layoutThumbnail.visibility = | ||
if (thumbnailDrawable == 0) View.GONE else View.VISIBLE | ||
binding.imgThumbnail.setImageResource(thumbnailDrawable) | ||
} | ||
|
||
override fun showNftPreview( | ||
downloadState: TokenInformationModelLogic.StateDownload, | ||
downloadPercent: Float, | ||
content: ByteArray? | ||
) { | ||
binding.layoutPreview.visibility = when (downloadState) { | ||
TokenInformationModelLogic.StateDownload.NOT_AVAILABLE -> View.GONE | ||
TokenInformationModelLogic.StateDownload.NOT_STARTED -> View.GONE | ||
TokenInformationModelLogic.StateDownload.RUNNING -> View.VISIBLE | ||
TokenInformationModelLogic.StateDownload.DONE -> View.VISIBLE | ||
TokenInformationModelLogic.StateDownload.ERROR -> View.VISIBLE | ||
} | ||
|
||
binding.descDownloadContent.visibility = | ||
if (downloadState == TokenInformationModelLogic.StateDownload.NOT_STARTED) View.VISIBLE else View.GONE | ||
binding.buttonDownloadContent.visibility = binding.descDownloadContent.visibility | ||
binding.previewProgress.visibility = | ||
if (downloadState == TokenInformationModelLogic.StateDownload.RUNNING) View.VISIBLE else View.GONE | ||
|
||
val hasError = content?.let { | ||
try { | ||
val image: Drawable = | ||
BitmapDrawable( | ||
binding.root.resources, | ||
BitmapFactory.decodeByteArray(it, 0, it.size) | ||
) | ||
binding.imgPreview.setImageDrawable(image) | ||
false | ||
} catch (t: Throwable) { | ||
true | ||
} | ||
} ?: false | ||
|
||
if (hasError || downloadState == TokenInformationModelLogic.StateDownload.ERROR) { | ||
binding.imgPreview.setImageResource(R.drawable.ic_warning_amber_24) | ||
} | ||
|
||
} | ||
|
||
override fun showNftHashValidation(hashValid: Boolean?) { | ||
binding.labelContentHash.setCompoundDrawablesRelativeWithIntrinsicBounds( | ||
0, 0, when (hashValid) { | ||
true -> R.drawable.ic_verified_18 | ||
false -> R.drawable.ic_suspicious_18 | ||
null -> 0 | ||
}, 0 | ||
) | ||
} | ||
} |
88 changes: 0 additions & 88 deletions
88
android/src/main/java/org/ergoplatform/android/tokens/TokenInformationNftLayoutView.kt
This file was deleted.
Oops, something went wrong.
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.