gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-android] branch master updated (a99932b -> 265a515)


From: gnunet
Subject: [taler-taler-android] branch master updated (a99932b -> 265a515)
Date: Thu, 23 Apr 2020 17:09:08 +0200

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a change to branch master
in repository taler-android.

    from a99932b  [cashier] improve strings and error messages after input from 
Christian
     new ffc78da  [cashier] add offline detection to all failing HTTP requests
     new 265a515  [pos] improve strings with feedback from Christian

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/net/taler/cashier/ConfigFragment.kt  |  3 ++
 .../src/main/java/net/taler/cashier/HttpHelper.kt  |  2 +-
 .../main/java/net/taler/cashier/MainViewModel.kt   |  7 +++-
 .../taler/cashier/withdraw/TransactionFragment.kt  | 23 +++++++------
 .../net/taler/cashier/withdraw/WithdrawManager.kt  | 40 +++++++++++++++-------
 cashier/src/main/res/values/strings.xml            | 16 +++++----
 merchant-terminal/src/main/res/values/strings.xml  | 36 +++++++++----------
 7 files changed, 77 insertions(+), 50 deletions(-)

diff --git a/cashier/src/main/java/net/taler/cashier/ConfigFragment.kt 
b/cashier/src/main/java/net/taler/cashier/ConfigFragment.kt
index f435883..501eed7 100644
--- a/cashier/src/main/java/net/taler/cashier/ConfigFragment.kt
+++ b/cashier/src/main/java/net/taler/cashier/ConfigFragment.kt
@@ -131,6 +131,9 @@ class ConfigFragment : Fragment() {
                 val action = 
ConfigFragmentDirections.actionConfigFragmentToBalanceFragment()
                 findNavController().navigate(action)
             }
+            ConfigResult.Offline -> {
+                Snackbar.make(view!!, R.string.config_error_offline, 
LENGTH_LONG).show()
+            }
             is ConfigResult.Error -> {
                 if (result.authError) {
                     Snackbar.make(view!!, R.string.config_error_auth, 
LENGTH_LONG).show()
diff --git a/cashier/src/main/java/net/taler/cashier/HttpHelper.kt 
b/cashier/src/main/java/net/taler/cashier/HttpHelper.kt
index 49a43d1..003c2f6 100644
--- a/cashier/src/main/java/net/taler/cashier/HttpHelper.kt
+++ b/cashier/src/main/java/net/taler/cashier/HttpHelper.kt
@@ -112,7 +112,7 @@ object HttpHelper {
 sealed class HttpJsonResult {
     class Error(val statusCode: Int, private val errorMsg: String? = null) : 
HttpJsonResult() {
         val msg: String
-            get() = errorMsg?.let { "\n\n$statusCode $it" } ?: ": $statusCode"
+            get() = errorMsg?.let { "\n\n$statusCode $it" } ?: "$statusCode"
     }
 
     class Success(val json: JSONObject) : HttpJsonResult()
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt 
b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
index 3587e95..c8d9a3b 100644
--- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
+++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
@@ -103,7 +103,11 @@ class MainViewModel(private val app: Application) : 
AndroidViewModel(app) {
                     }
                 }
                 is HttpJsonResult.Error -> {
-                    ConfigResult.Error(response.statusCode == 401, 
response.msg)
+                    if (response.statusCode > 0 && app.isOnline()) {
+                        ConfigResult.Error(response.statusCode == 401, 
response.msg)
+                    } else {
+                        ConfigResult.Offline
+                    }
                 }
             }
             mConfigResult.postValue(result)
@@ -156,5 +160,6 @@ data class Config(
 
 sealed class ConfigResult {
     class Error(val authError: Boolean, val msg: String) : ConfigResult()
+    object Offline : ConfigResult()
     object Success : ConfigResult()
 }
diff --git 
a/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt 
b/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
index e433540..0726a77 100644
--- a/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
+++ b/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
@@ -36,6 +36,7 @@ import net.taler.cashier.withdraw.WithdrawResult.Error
 import net.taler.cashier.withdraw.WithdrawResult.InsufficientBalance
 import net.taler.cashier.withdraw.WithdrawResult.Success
 import net.taler.common.NfcManager
+import net.taler.common.exhaustive
 import net.taler.common.fadeIn
 import net.taler.common.fadeOut
 
@@ -101,16 +102,9 @@ class TransactionFragment : Fragment() {
                 .start()
         }
         when (result) {
-            is InsufficientBalance -> {
-                val c = getColor(requireContext(), 
R.color.design_default_color_error)
-                introView.setTextColor(c)
-                introView.text = 
getString(R.string.withdraw_error_insufficient_balance)
-            }
-            is Error -> {
-                val c = getColor(requireContext(), 
R.color.design_default_color_error)
-                introView.setTextColor(c)
-                introView.text = result.msg
-            }
+            is InsufficientBalance -> 
setErrorMsg(getString(R.string.withdraw_error_insufficient_balance))
+            is WithdrawResult.Offline -> 
setErrorMsg(getString(R.string.withdraw_error_offline))
+            is Error -> setErrorMsg(result.msg)
             is Success -> {
                 // start NFC
                 nfcManager.setTagString(result.talerUri)
@@ -129,7 +123,14 @@ class TransactionFragment : Fragment() {
                     .setDuration(750)
                     .start()
             }
-        }
+            null -> return
+        }.exhaustive
+    }
+
+    private fun setErrorMsg(str: String) {
+        val c = getColor(requireContext(), R.color.design_default_color_error)
+        introView.setTextColor(c)
+        introView.text = str
     }
 
     private fun onWithdrawStatusChanged(status: WithdrawStatus?): Any = when 
(status) {
diff --git 
a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt 
b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
index 32e0802..59e0c50 100644
--- a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
+++ b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
@@ -36,6 +36,7 @@ import net.taler.cashier.MainViewModel
 import net.taler.cashier.R
 import net.taler.common.Amount
 import net.taler.common.QrCodeManager.makeQrCode
+import net.taler.common.isOnline
 import org.json.JSONObject
 import java.util.concurrent.TimeUnit.MINUTES
 import java.util.concurrent.TimeUnit.SECONDS
@@ -90,22 +91,27 @@ class WithdrawManager(
             Log.d(TAG, "Starting withdrawal at $url")
             val map = mapOf("amount" to amount.toJSONString())
             val body = JSONObject(map)
-            when (val result = makeJsonPostRequest(url, body, config)) {
+            val result = when (val response = makeJsonPostRequest(url, body, 
config)) {
                 is Success -> {
-                    val talerUri = result.json.getString("taler_withdraw_uri")
+                    val talerUri = 
response.json.getString("taler_withdraw_uri")
                     val withdrawResult = WithdrawResult.Success(
-                        id = result.json.getString("withdrawal_id"),
+                        id = response.json.getString("withdrawal_id"),
                         talerUri = talerUri,
                         qrCode = makeQrCode(talerUri)
                     )
-                    mWithdrawResult.postValue(withdrawResult)
-                    timer.start()
+                    withdrawResult
                 }
                 is Error -> {
-                    val errorStr = 
app.getString(R.string.withdraw_error_fetch, result.msg)
-                    mWithdrawResult.postValue(WithdrawResult.Error(errorStr))
+                    if (response.statusCode > 0 && app.isOnline()) {
+                        val errorStr = 
app.getString(R.string.withdraw_error_fetch, response.msg)
+                        WithdrawResult.Error(errorStr)
+                    } else {
+                        WithdrawResult.Offline
+                    }
                 }
             }
+            mWithdrawResult.postValue(result)
+            if (result is WithdrawResult.Success) timer.start()
         }
     }
 
@@ -125,8 +131,12 @@ class WithdrawManager(
 
         override fun onFinish() {
             abort()
-            val str = app.getString(R.string.withdraw_error_timeout)
-            mWithdrawStatus.postValue(WithdrawStatus.Error(str))
+            val result = if (app.isOnline()) {
+                
WithdrawStatus.Error(app.getString(R.string.withdraw_error_timeout))
+            } else {
+                
WithdrawStatus.Error(app.getString(R.string.withdraw_error_offline))
+            }
+            mWithdrawStatus.postValue(result)
             cancel()
         }
     }
@@ -191,13 +201,18 @@ class WithdrawManager(
             val url =
                 
"${config.bankUrl}/accounts/${config.username}/withdrawals/${withdrawalId}/confirm"
             Log.d(TAG, "Confirming withdrawal at $url")
-            when (val result = makeJsonPostRequest(url, JSONObject(), config)) 
{
+            when (val response = makeJsonPostRequest(url, JSONObject(), 
config)) {
                 is Success -> {
                     // no-op still waiting for [timer] to confirm our 
confirmation
                 }
                 is Error -> {
-                    Log.e(TAG, "Error confirming withdrawal. Status code: 
${result.statusCode}")
-                    mWithdrawStatus.postValue(WithdrawStatus.Error(result.msg))
+                    Log.e(TAG, "Error confirming withdrawal. Status code: 
${response.statusCode}")
+                    val result = if (response.statusCode > 0 && 
app.isOnline()) {
+                        WithdrawStatus.Error(response.msg)
+                    } else {
+                        
WithdrawStatus.Error(app.getString(R.string.withdraw_error_offline))
+                    }
+                    mWithdrawStatus.postValue(result)
                 }
             }
         }
@@ -216,6 +231,7 @@ class WithdrawManager(
 
 sealed class WithdrawResult {
     object InsufficientBalance : WithdrawResult()
+    object Offline : WithdrawResult()
     class Error(val msg: String) : WithdrawResult()
     class Success(val id: String, val talerUri: String, val qrCode: Bitmap) : 
WithdrawResult()
 }
diff --git a/cashier/src/main/res/values/strings.xml 
b/cashier/src/main/res/values/strings.xml
index d0ac3ae..b4964d8 100644
--- a/cashier/src/main/res/values/strings.xml
+++ b/cashier/src/main/res/values/strings.xml
@@ -7,12 +7,13 @@
     <string name="config_button_save">Save</string>
     <string name="config_bank_url_error">The address is invalid.</string>
     <string name="config_username_error">Please enter your username!</string>
-    <string name="config_error">Error retrieving configuration%s</string>
+    <string name="config_error">Error retrieving configuration: %s</string>
     <string name="config_error_auth">Invalid username or password!</string>
+    <string name="config_error_offline" 
translatable="false">@string/balance_offline</string>
     <string name="config_demo_hint" tools:ignore="StringFormatInvalid">For 
testing, you can <![CDATA[<a href="%s">create a test account at the demo 
bank</a>]]>.</string>
 
     <string name="balance_current_label">Current balance</string>
-    <string name="balance_error">ERROR%s</string>
+    <string name="balance_error">ERROR: %s</string>
     <string name="balance_offline">Offline. Please connect to the 
Internet.</string>
     <string name="action_reconfigure">Reconfigure</string>
     <string name="action_lock">Lock</string>
@@ -21,14 +22,15 @@
     <string name="withdraw_into">How much e-cash should be withdrawn?</string>
     <string name="withdraw_error_zero">Enter positive amount!</string>
     <string name="withdraw_error_insufficient_balance">Insufficient 
balance</string>
-    <string name="withdraw_error_fetch">Error communicating with 
bank%s</string>
+    <string name="withdraw_error_fetch">Error communicating with bank: 
%s</string>
     <string name="withdraw_error_timeout">No wallet tried to withdraw. Please 
try again.</string>
+    <string name="withdraw_error_offline" 
translatable="false">@string/balance_offline</string>
     <string name="withdraw_button_confirm">Withdraw</string>
 
-    <!-- "to get" refers to the amount that will be withdrawn, e.g. to get 12 
EUR -->
-    <string name="transaction_intro">Scan code with the Taler wallet app to 
get</string>
-    <!-- "to get" refers to the amount that will be withdrawn, e.g. to get 12 
EUR -->
-    <string name="transaction_intro_nfc">Scan code or use NFC with the Taler 
wallet app to get</string>
+    <!-- "to withdraw" refers to the amount that will be withdrawn, e.g. to 
withdraw 12 EUR -->
+    <string name="transaction_intro">Scan code with the Taler wallet app to 
withdraw:</string>
+    <!-- "to withdraw" refers to the amount that will be withdrawn, e.g. to 
withdraw 12 EUR -->
+    <string name="transaction_intro_nfc">Scan code or use NFC with the Taler 
wallet app to withdraw:</string>
     <string name="transaction_intro_scanned">Please confirm the 
transaction!</string>
     <string name="transaction_confirm">Confirm</string>
     <string name="transaction_abort">Abort</string>
diff --git a/merchant-terminal/src/main/res/values/strings.xml 
b/merchant-terminal/src/main/res/values/strings.xml
index 712a2fc..1c76a51 100644
--- a/merchant-terminal/src/main/res/values/strings.xml
+++ b/merchant-terminal/src/main/res/values/strings.xml
@@ -16,11 +16,11 @@
     <string name="order_next">Next</string>
     <string name="order_complete">Complete</string>
 
-    <string name="config_label">Merchant Settings</string>
+    <string name="config_label">Merchant settings</string>
     <string name="config_url">Configuration URL</string>
     <string name="config_username">Username</string>
     <string name="config_password">Password</string>
-    <string name="config_ok">Fetch Configuration</string>
+    <string name="config_ok">Fetch configuration</string>
     <string name="config_auth_error">Error: Invalid username or 
password</string>
     <string name="config_error_network">Error: Could not connect to 
configuration server</string>
     <string name="config_error_category">Error: No valid product category 
found</string>
@@ -28,31 +28,31 @@
     <string name="config_error_currency">Error: Product %1$s has currency 
%2$s, but %3$s expected</string>
     <string name="config_error_product_category_id">Error: Product %1$s 
references unknown category ID %2$d</string>
     <string name="config_error_product_zero">Error: No valid products 
found</string>
-    <string name="config_error_unknown">Error: Invalid Configuration</string>
-    <string name="config_fetching">Fetching Configuration…</string>
-    <string name="config_save_password">Remember Password</string>
+    <string name="config_error_unknown">Error: Invalid configuration</string>
+    <string name="config_fetching">Fetching configuration…</string>
+    <string name="config_save_password">Remember password</string>
     <string name="config_forget_password">Forget</string>
     <string name="config_changed">Changed to new merchant using %s</string>
-    <string name="config_fetching_label">Fetching Configuration</string>
+    <string name="config_fetching_label">Fetching configuration</string>
     <string name="config_docs">Please refer to <a 
href="https://docs.taler.net/taler-merchant-pos-terminal.html#apis-and-data-formats";>the
 documentation</a> for the configuration format.</string>
 
-    <string name="payment_intro_nfc">Please let customer scan QR Code or use 
NFC to pay</string>
-    <string name="payment_intro">Please let customer scan QR Code to 
pay</string>
-    <string name="payment_cancel">Cancel Payment</string>
+    <string name="payment_intro_nfc">Please let customer scan QR Code or use 
NFC to pay.</string>
+    <string name="payment_intro">Please let customer scan QR Code to 
pay.</string>
+    <string name="payment_cancel">Cancel payment</string>
     <string name="payment_received">Payment received</string>
     <string name="payment_back_button">Continue</string>
-    <string name="payment_order_ref">Order Reference: %s</string>
-    <string name="payment_process_label">Customer Payment Required</string>
-    <string name="payment_canceled">Payment Canceled</string>
+    <string name="payment_order_ref">Purchase reference: %s</string>
+    <string name="payment_process_label">Payment required</string>
+    <string name="payment_canceled">Payment canceled</string>
 
-    <string name="history_label">Payment History</string>
+    <string name="history_label">Payment history</string>
     <string name="history_ref_no">Ref. No: %s</string>
-    <string name="history_refund">Refund Order</string>
+    <string name="history_refund">Refund</string>
     <string name="refund_amount">Amount</string>
     <string name="refund_reason">Refund reason</string>
     <string name="refund_abort">Abort</string>
     <string name="refund_complete">Received</string>
-    <string name="refund_confirm">Give Refund</string>
+    <string name="refund_confirm">Approve refund</string>
     <string name="refund_error_max_amount">Greater than order amount of 
%s</string>
     <string name="refund_error_invalid_amount">Invalid amount</string>
     <string name="refund_error_zero">Needs to be positive amount</string>
@@ -61,10 +61,10 @@
     <string name="refund_error_already_refunded">Already refunded</string>
     <string name="refund_intro_nfc">Please let customer scan QR Code or use 
NFC to give refund</string>
     <string name="refund_intro">Please let customer scan QR Code to give 
refund</string>
-    <string name="refund_order_ref">Order Reference: %1$s\n\n%2$s</string>
+    <string name="refund_order_ref">Purchase reference: %1$s\n\n%2$s</string>
 
-    <string name="error_network">Network Error</string>
+    <string name="error_network">Network error</string>
 
-    <string name="toast_back_to_exit">Click BACK again to exit</string>
+    <string name="toast_back_to_exit">Click «back» again to exit</string>
 
 </resources>

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]