General bug fixes.

This commit is contained in:
Kevin Gorham 2020-02-21 18:53:29 -05:00
parent 2fc572e434
commit 6d08591452
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
5 changed files with 39 additions and 32 deletions

View File

@ -0,0 +1,3 @@
package cash.z.ecc.android.ext
fun Boolean.asString(ifTrue: String = "", ifFalse: String = "") = if(this) ifTrue else ifFalse

View File

@ -22,16 +22,18 @@ fun View.disabledIf(isDisabled: Boolean) {
isEnabled = !isDisabled isEnabled = !isDisabled
} }
fun View.onClickNavTo(navResId: Int) { fun View.onClickNavTo(navResId: Int, block: (() -> Any) = {}) {
setOnClickListener { setOnClickListener {
block()
(context as? MainActivity)?.safeNavigate(navResId) (context as? MainActivity)?.safeNavigate(navResId)
?: throw IllegalStateException("Cannot navigate from this activity. " + ?: throw IllegalStateException("Cannot navigate from this activity. " +
"Expected MainActivity but found ${context.javaClass.simpleName}") "Expected MainActivity but found ${context.javaClass.simpleName}")
} }
} }
fun View.onClickNavUp() { fun View.onClickNavUp(block: (() -> Any) = {}) {
setOnClickListener { setOnClickListener {
block()
(context as? MainActivity)?.navController?.navigateUp() (context as? MainActivity)?.navController?.navigateUp()
?: throw IllegalStateException( ?: throw IllegalStateException(
"Cannot navigate from this activity. " + "Cannot navigate from this activity. " +
@ -40,8 +42,9 @@ fun View.onClickNavUp() {
} }
} }
fun View.onClickNavBack() { fun View.onClickNavBack(block: (() -> Any) = {}) {
setOnClickListener { setOnClickListener {
block()
(context as? MainActivity)?.navController?.popBackStack() (context as? MainActivity)?.navController?.popBackStack()
?: throw IllegalStateException( ?: throw IllegalStateException(
"Cannot navigate from this activity. " + "Cannot navigate from this activity. " +

View File

@ -8,10 +8,7 @@ import cash.z.ecc.android.ext.goneIf
import cash.z.ecc.android.ext.toAppColor import cash.z.ecc.android.ext.toAppColor
import cash.z.ecc.android.ui.MainActivity import cash.z.ecc.android.ui.MainActivity
import cash.z.wallet.sdk.entity.ConfirmedTransaction import cash.z.wallet.sdk.entity.ConfirmedTransaction
import cash.z.wallet.sdk.ext.ZcashSdk import cash.z.wallet.sdk.ext.*
import cash.z.wallet.sdk.ext.convertZatoshiToZecString
import cash.z.wallet.sdk.ext.isShielded
import cash.z.wallet.sdk.ext.toAbbreviatedAddress
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.nio.charset.Charset import java.nio.charset.Charset
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -30,7 +27,8 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
// update view // update view
var lineOne: String = "" var lineOne: String = ""
var lineTwo: String = "" var lineTwo: String = ""
var amount: String = "" var amountZec: String = ""
var amountDisplay: String = ""
var amountColor: Int = 0 var amountColor: Int = 0
var indicatorBackground: Int = 0 var indicatorBackground: Int = 0
@ -38,7 +36,7 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
itemView.setOnClickListener { itemView.setOnClickListener {
onTransactionClicked(this) onTransactionClicked(this)
} }
amount = value.convertZatoshiToZecString() amountZec = value.convertZatoshiToZecString()
// TODO: these might be good extension functions // TODO: these might be good extension functions
val timestamp = formatter.format(blockTimeInSeconds * 1000L) val timestamp = formatter.format(blockTimeInSeconds * 1000L)
val isMined = blockTimeInSeconds != 0L val isMined = blockTimeInSeconds != 0L
@ -46,14 +44,14 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
!toAddress.isNullOrEmpty() -> { !toAddress.isNullOrEmpty() -> {
lineOne = "You paid ${toAddress?.toAbbreviatedAddress()}" lineOne = "You paid ${toAddress?.toAbbreviatedAddress()}"
lineTwo = if (isMined) "Sent $timestamp" else "Pending confirmation" lineTwo = if (isMined) "Sent $timestamp" else "Pending confirmation"
amount = "- $amount" amountDisplay = "- $amountZec"
amountColor = R.color.zcashRed amountColor = R.color.zcashRed
indicatorBackground = R.drawable.background_indicator_outbound indicatorBackground = R.drawable.background_indicator_outbound
} }
raw == null || raw?.isEmpty() == true -> { raw == null || raw?.isEmpty() == true -> {
lineOne = "Unknown paid you" lineOne = "Unknown paid you"
lineTwo = "Received $timestamp" lineTwo = "Received $timestamp"
amount = "+ $amount" amountDisplay = "+ $amountZec"
amountColor = R.color.zcashGreen amountColor = R.color.zcashGreen
indicatorBackground = R.drawable.background_indicator_inbound indicatorBackground = R.drawable.background_indicator_inbound
} }
@ -64,14 +62,16 @@ class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : Recycler
} }
// sanitize amount // sanitize amount
if (value < ZcashSdk.MINERS_FEE_ZATOSHI) amount = "< 0.001" if (value < ZcashSdk.MINERS_FEE_ZATOSHI) amountDisplay = "< 0.001"
else if (amount.length > 8) amount = "tap to view" 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 topText.text = lineOne
bottomText.text = lineTwo bottomText.text = lineTwo
amountText.text = amount amountText.text = amountDisplay
amountText.setTextColor(amountColor.toAppColor()) amountText.setTextColor(amountColor.toAppColor())
val context = itemView.context val context = itemView.context
indicator.background = context.resources.getDrawable(indicatorBackground) indicator.background = context.resources.getDrawable(indicatorBackground)

View File

@ -85,7 +85,6 @@ class MagicSnakeLoader(
} else { } else {
// once we're ready to show scan progress, do it! Don't do extra loops. // once we're ready to show scan progress, do it! Don't do extra loops.
if (frame >= scanningStartFrame || frame in acceptablePauseFrames) { if (frame >= scanningStartFrame || frame in acceptablePauseFrames) {
twig("ZZZ pausing so we can scan! ${if(frame<scanningStartFrame) "WE STOPPED EARLY!" else ""}")
pause() pause()
} }
} }
@ -107,17 +106,14 @@ class MagicSnakeLoader(
private fun playToCompletion() { private fun playToCompletion() {
removeLoops() removeLoops()
twig("ZZZ playing to completion")
unpause() unpause()
} }
private fun removeLoops() { private fun removeLoops() {
lottie.frame.let {frame -> lottie.frame.let {frame ->
if (frame in 33..67) { if (frame in 33..67) {
twig("ZZZ removing 1 loop!")
lottie.frame = frame + 34 lottie.frame = frame + 34
} else if (frame in 0..33) { } else if (frame in 0..33) {
twig("ZZZ removing 2 loops!")
lottie.frame = frame + 67 lottie.frame = frame + 67
} }
} }

View File

@ -2,6 +2,8 @@ package cash.z.ecc.android.ui.scan
import androidx.camera.core.ImageAnalysis import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy 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 cash.z.wallet.sdk.ext.twig
import com.google.android.gms.tasks.Task import com.google.android.gms.tasks.Task
import com.google.firebase.ml.vision.FirebaseVision import com.google.firebase.ml.vision.FirebaseVision
@ -27,22 +29,25 @@ class QrAnalyzer(val scanCallback: (qrContent: String, image: ImageProxy) -> Uni
if (rotation < 0) { if (rotation < 0) {
rotation += 360 rotation += 360
} }
val mediaImage = FirebaseVisionImage.fromMediaImage(
image.image!!, when (rotation) { retrySimple {
0 -> FirebaseVisionImageMetadata.ROTATION_0 val mediaImage = FirebaseVisionImage.fromMediaImage(
90 -> FirebaseVisionImageMetadata.ROTATION_90 image.image!!, when (rotation) {
180 -> FirebaseVisionImageMetadata.ROTATION_180 0 -> FirebaseVisionImageMetadata.ROTATION_0
270 -> FirebaseVisionImageMetadata.ROTATION_270 90 -> FirebaseVisionImageMetadata.ROTATION_90
else -> { 180 -> FirebaseVisionImageMetadata.ROTATION_180
FirebaseVisionImageMetadata.ROTATION_0 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)
} }
} }