General bug fixes.
This commit is contained in:
parent
2fc572e434
commit
6d08591452
|
@ -0,0 +1,3 @@
|
|||
package cash.z.ecc.android.ext
|
||||
|
||||
fun Boolean.asString(ifTrue: String = "", ifFalse: String = "") = if(this) ifTrue else ifFalse
|
|
@ -22,16 +22,18 @@ fun View.disabledIf(isDisabled: Boolean) {
|
|||
isEnabled = !isDisabled
|
||||
}
|
||||
|
||||
fun View.onClickNavTo(navResId: Int) {
|
||||
fun View.onClickNavTo(navResId: Int, block: (() -> Any) = {}) {
|
||||
setOnClickListener {
|
||||
block()
|
||||
(context as? MainActivity)?.safeNavigate(navResId)
|
||||
?: throw IllegalStateException("Cannot navigate from this activity. " +
|
||||
"Expected MainActivity but found ${context.javaClass.simpleName}")
|
||||
}
|
||||
}
|
||||
|
||||
fun View.onClickNavUp() {
|
||||
fun View.onClickNavUp(block: (() -> Any) = {}) {
|
||||
setOnClickListener {
|
||||
block()
|
||||
(context as? MainActivity)?.navController?.navigateUp()
|
||||
?: throw IllegalStateException(
|
||||
"Cannot navigate from this activity. " +
|
||||
|
@ -40,8 +42,9 @@ fun View.onClickNavUp() {
|
|||
}
|
||||
}
|
||||
|
||||
fun View.onClickNavBack() {
|
||||
fun View.onClickNavBack(block: (() -> Any) = {}) {
|
||||
setOnClickListener {
|
||||
block()
|
||||
(context as? MainActivity)?.navController?.popBackStack()
|
||||
?: throw IllegalStateException(
|
||||
"Cannot navigate from this activity. " +
|
||||
|
|
|
@ -8,10 +8,7 @@ import cash.z.ecc.android.ext.goneIf
|
|||
import cash.z.ecc.android.ext.toAppColor
|
||||
import cash.z.ecc.android.ui.MainActivity
|
||||
import cash.z.wallet.sdk.entity.ConfirmedTransaction
|
||||
import cash.z.wallet.sdk.ext.ZcashSdk
|
||||
import cash.z.wallet.sdk.ext.convertZatoshiToZecString
|
||||
import cash.z.wallet.sdk.ext.isShielded
|
||||
import cash.z.wallet.sdk.ext.toAbbreviatedAddress
|
||||
import cash.z.wallet.sdk.ext.*
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.nio.charset.Charset
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -30,7 +27,8 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
|
|||
// update view
|
||||
var lineOne: String = ""
|
||||
var lineTwo: String = ""
|
||||
var amount: String = ""
|
||||
var amountZec: String = ""
|
||||
var amountDisplay: String = ""
|
||||
var amountColor: Int = 0
|
||||
var indicatorBackground: Int = 0
|
||||
|
||||
|
@ -38,7 +36,7 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
|
|||
itemView.setOnClickListener {
|
||||
onTransactionClicked(this)
|
||||
}
|
||||
amount = value.convertZatoshiToZecString()
|
||||
amountZec = value.convertZatoshiToZecString()
|
||||
// TODO: these might be good extension functions
|
||||
val timestamp = formatter.format(blockTimeInSeconds * 1000L)
|
||||
val isMined = blockTimeInSeconds != 0L
|
||||
|
@ -46,14 +44,14 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
|
|||
!toAddress.isNullOrEmpty() -> {
|
||||
lineOne = "You paid ${toAddress?.toAbbreviatedAddress()}"
|
||||
lineTwo = if (isMined) "Sent $timestamp" else "Pending confirmation"
|
||||
amount = "- $amount"
|
||||
amountDisplay = "- $amountZec"
|
||||
amountColor = R.color.zcashRed
|
||||
indicatorBackground = R.drawable.background_indicator_outbound
|
||||
}
|
||||
raw == null || raw?.isEmpty() == true -> {
|
||||
lineOne = "Unknown paid you"
|
||||
lineTwo = "Received $timestamp"
|
||||
amount = "+ $amount"
|
||||
amountDisplay = "+ $amountZec"
|
||||
amountColor = R.color.zcashGreen
|
||||
indicatorBackground = R.drawable.background_indicator_inbound
|
||||
}
|
||||
|
@ -64,14 +62,16 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
|
|||
}
|
||||
|
||||
// sanitize amount
|
||||
if (value < ZcashSdk.MINERS_FEE_ZATOSHI) amount = "< 0.001"
|
||||
else if (amount.length > 8) amount = "tap to view"
|
||||
if (value < ZcashSdk.MINERS_FEE_ZATOSHI) amountDisplay = "< 0.001"
|
||||
else if (amountZec.length > 10) { // 10 allows 3 digits to the left and 6 to the right of the decimal
|
||||
amountDisplay = "tap to view"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
topText.text = lineOne
|
||||
bottomText.text = lineTwo
|
||||
amountText.text = amount
|
||||
amountText.text = amountDisplay
|
||||
amountText.setTextColor(amountColor.toAppColor())
|
||||
val context = itemView.context
|
||||
indicator.background = context.resources.getDrawable(indicatorBackground)
|
||||
|
|
|
@ -85,7 +85,6 @@ class MagicSnakeLoader(
|
|||
} else {
|
||||
// once we're ready to show scan progress, do it! Don't do extra loops.
|
||||
if (frame >= scanningStartFrame || frame in acceptablePauseFrames) {
|
||||
twig("ZZZ pausing so we can scan! ${if(frame<scanningStartFrame) "WE STOPPED EARLY!" else ""}")
|
||||
pause()
|
||||
}
|
||||
}
|
||||
|
@ -107,17 +106,14 @@ class MagicSnakeLoader(
|
|||
|
||||
private fun playToCompletion() {
|
||||
removeLoops()
|
||||
twig("ZZZ playing to completion")
|
||||
unpause()
|
||||
}
|
||||
|
||||
private fun removeLoops() {
|
||||
lottie.frame.let {frame ->
|
||||
if (frame in 33..67) {
|
||||
twig("ZZZ removing 1 loop!")
|
||||
lottie.frame = frame + 34
|
||||
} else if (frame in 0..33) {
|
||||
twig("ZZZ removing 2 loops!")
|
||||
lottie.frame = frame + 67
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cash.z.ecc.android.ui.scan
|
|||
|
||||
import androidx.camera.core.ImageAnalysis
|
||||
import androidx.camera.core.ImageProxy
|
||||
import cash.z.wallet.sdk.ext.retrySimple
|
||||
import cash.z.wallet.sdk.ext.retryUpTo
|
||||
import cash.z.wallet.sdk.ext.twig
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.firebase.ml.vision.FirebaseVision
|
||||
|
@ -27,22 +29,25 @@ class QrAnalyzer(val scanCallback: (qrContent: String, image: ImageProxy) -> Uni
|
|||
if (rotation < 0) {
|
||||
rotation += 360
|
||||
}
|
||||
val mediaImage = FirebaseVisionImage.fromMediaImage(
|
||||
image.image!!, when (rotation) {
|
||||
0 -> FirebaseVisionImageMetadata.ROTATION_0
|
||||
90 -> FirebaseVisionImageMetadata.ROTATION_90
|
||||
180 -> FirebaseVisionImageMetadata.ROTATION_180
|
||||
270 -> FirebaseVisionImageMetadata.ROTATION_270
|
||||
else -> {
|
||||
FirebaseVisionImageMetadata.ROTATION_0
|
||||
|
||||
retrySimple {
|
||||
val mediaImage = FirebaseVisionImage.fromMediaImage(
|
||||
image.image!!, when (rotation) {
|
||||
0 -> FirebaseVisionImageMetadata.ROTATION_0
|
||||
90 -> FirebaseVisionImageMetadata.ROTATION_90
|
||||
180 -> FirebaseVisionImageMetadata.ROTATION_180
|
||||
270 -> FirebaseVisionImageMetadata.ROTATION_270
|
||||
else -> {
|
||||
FirebaseVisionImageMetadata.ROTATION_0
|
||||
}
|
||||
}
|
||||
)
|
||||
pendingTask = detector.detectInImage(mediaImage).also {
|
||||
it.addOnSuccessListener { result ->
|
||||
onImageScan(result, image)
|
||||
}
|
||||
it.addOnFailureListener(::onImageScanFailure)
|
||||
}
|
||||
)
|
||||
pendingTask = detector.detectInImage(mediaImage).also {
|
||||
it.addOnSuccessListener { result ->
|
||||
onImageScan(result, image)
|
||||
}
|
||||
it.addOnFailureListener(::onImageScanFailure)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue