aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-09-08 15:40:27 -0300
committerTorsten Grote <t@grobox.de>2020-09-08 15:49:38 -0300
commit310775d1cb7a177641c704efb1a98a7ccaac67b3 (patch)
treea9a390c74ae214168b6b9a312842c315c51baf01
parent0030ad13496571616501500dfd9df18652869004 (diff)
downloadtaler-android-310775d1cb7a177641c704efb1a98a7ccaac67b3.tar.gz
taler-android-310775d1cb7a177641c704efb1a98a7ccaac67b3.tar.bz2
taler-android-310775d1cb7a177641c704efb1a98a7ccaac67b3.zip
[wallet] Use bottom sheet to show errors instead of snackbar
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt10
-rw-r--r--wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt13
-rw-r--r--wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt5
-rw-r--r--wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt9
-rw-r--r--wallet/src/main/res/values/strings.xml1
5 files changed, 16 insertions, 22 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index 0605976..1dafce0 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -43,11 +43,11 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback
import com.google.android.material.navigation.NavigationView.OnNavigationItemSelectedListener
import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_LONG
-import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT
import com.google.android.material.snackbar.Snackbar
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentIntegrator.parseActivityResult
import net.taler.common.isOnline
+import net.taler.common.showError
import net.taler.wallet.BuildConfig.VERSION_CODE
import net.taler.wallet.BuildConfig.VERSION_NAME
import net.taler.wallet.HostCardEmulatorService.Companion.HTTP_TUNNEL_RESPONSE
@@ -167,11 +167,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
model.refundManager.refund(url).observe(this, Observer(::onRefundResponse))
}
else -> {
- Snackbar.make(
- ui.navView,
- "URL from $from doesn't contain a supported Taler Uri.",
- LENGTH_SHORT
- ).show()
+ showError(R.string.error_unsupported_uri, "From: $from\nURI: $url")
}
}
}
@@ -180,7 +176,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
model.showProgressBar.value = false
when (status) {
is RefundStatus.Error -> {
- Snackbar.make(ui.navView, R.string.refund_error, LENGTH_LONG).show()
+ showError(R.string.refund_error, status.msg)
}
is RefundStatus.Success -> {
val amount = status.response.amountRefundGranted
diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
index 2476607..ab1ac80 100644
--- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
+++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt
@@ -73,13 +73,16 @@ data class TalerErrorInfo(
get() {
return StringBuilder().apply {
append(code)
+ hint?.let { append(" (").append(it).append(")") }
message?.let { append(" ").append(it) }
details?.let { details ->
- append("\n\n")
- details.optJSONObject("errorResponse")?.let { errorResponse ->
- append(errorResponse.optString("code")).append(" ")
- append(errorResponse.optString("hint"))
- } ?: append(details.toString(2))
+ if (details.length() > 0) {
+ append("\n\n")
+ details.optJSONObject("errorResponse")?.let { errorResponse ->
+ append(errorResponse.optString("code")).append(" ")
+ append(errorResponse.optString("hint"))
+ } ?: append(details.toString(2))
+ }
}
}.toString()
}
diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt
index e2f3ca1..e3b5dc2 100644
--- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsFragment.kt
@@ -33,8 +33,7 @@ import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
-import com.google.android.material.snackbar.Snackbar
-import com.google.android.material.snackbar.Snackbar.LENGTH_SHORT
+import net.taler.common.showError
import net.taler.wallet.MainViewModel
import net.taler.wallet.R
import net.taler.wallet.TAG
@@ -110,7 +109,7 @@ class PendingOperationsFragment : Fragment(), PendingOperationClickListener {
}
override fun onPendingOperationClick(type: String, detail: JSONObject) {
- Snackbar.make(requireView(), "No detail view for $type implemented yet.", LENGTH_SHORT).show()
+ requireActivity().showError("No detail view for $type implemented yet.")
}
override fun onPendingOperationActionClick(type: String, detail: JSONObject) {
diff --git a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
index 559b91d..9c292aa 100644
--- a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
@@ -16,18 +16,16 @@
package net.taler.wallet.refund
-import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import net.taler.lib.common.Amount
-import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
sealed class RefundStatus {
- object Error : RefundStatus()
+ data class Error(val msg: String) : RefundStatus()
data class Success(val response: RefundResponse) : RefundStatus()
}
@@ -50,11 +48,8 @@ class RefundManager(
api.request("applyRefund", RefundResponse.serializer()) {
put("talerRefundUri", refundUri)
}.onError {
- Log.e(TAG, "Refund Error: $it")
- // TODO show error string
- liveData.postValue(RefundStatus.Error)
+ liveData.postValue(RefundStatus.Error(it.userFacingMsg))
}.onSuccess {
- Log.e(TAG, "Refund Success: $it")
liveData.postValue(RefundStatus.Success(it))
}
}
diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml
index b419766..9844cfa 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -55,6 +55,7 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card
<string name="or">or</string>
<string name="offline">Operation requires internet access. Please ensure your internet connection works and try again.</string>
+ <string name="error_unsupported_uri">Error: This Taler URI is not supported.</string>
<string name="menu_settings">Settings</string>
<string name="menu_retry_pending_operations">Retry Pending Operations</string>