aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-03-28 14:08:37 -0300
committerTorsten Grote <t@grobox.de>2023-03-28 15:05:46 -0300
commit4d0fabf804e1afffd91927d9805a026e8aaad777 (patch)
tree2789741ff1840bef31ed2e5d97048c175eb11e3d
parent5ed3f1b65c0eb5e68da23bd597c59381d2c98441 (diff)
downloadtaler-android-4d0fabf804e1afffd91927d9805a026e8aaad777.tar.gz
taler-android-4d0fabf804e1afffd91927d9805a026e8aaad777.zip
[wallet] Add test option in dev mode and remove backup option
to not give false impression that there's an actual backup/
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt1
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainViewModel.kt24
-rw-r--r--wallet/src/main/java/net/taler/wallet/settings/BackupSettingsFragment.kt29
-rw-r--r--wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt25
-rw-r--r--wallet/src/main/res/navigation/nav_graph.xml8
-rw-r--r--wallet/src/main/res/values/strings.xml5
-rw-r--r--wallet/src/main/res/xml/settings_backup.xml51
-rw-r--r--wallet/src/main/res/xml/settings_main.xml14
8 files changed, 35 insertions, 122 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index e91b9831..bf954758 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -344,7 +344,6 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
344 pref: Preference, 344 pref: Preference,
345 ): Boolean { 345 ): Boolean {
346 when (pref.key) { 346 when (pref.key) {
347 "pref_backup" -> nav.navigate(R.id.action_nav_settings_to_nav_settings_backup)
348 "pref_exchanges" -> nav.navigate(R.id.action_nav_settings_to_nav_settings_exchanges) 347 "pref_exchanges" -> nav.navigate(R.id.action_nav_settings_to_nav_settings_exchanges)
349 } 348 }
350 return true 349 return true
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
index bbd3ca3f..2ad6f6b9 100644
--- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
@@ -50,9 +50,6 @@ import net.taler.wallet.tip.TipManager
50import net.taler.wallet.transactions.TransactionManager 50import net.taler.wallet.transactions.TransactionManager
51import net.taler.wallet.withdraw.WithdrawManager 51import net.taler.wallet.withdraw.WithdrawManager
52import org.json.JSONObject 52import org.json.JSONObject
53import java.util.concurrent.TimeUnit.DAYS
54import java.util.concurrent.TimeUnit.MINUTES
55import kotlin.random.Random
56 53
57const val TAG = "taler-wallet" 54const val TAG = "taler-wallet"
58 55
@@ -97,13 +94,6 @@ class MainViewModel(
97 private val mScanCodeEvent = MutableLiveData<Event<Boolean>>() 94 private val mScanCodeEvent = MutableLiveData<Event<Boolean>>()
98 val scanCodeEvent: LiveData<Event<Boolean>> = mScanCodeEvent 95 val scanCodeEvent: LiveData<Event<Boolean>> = mScanCodeEvent
99 96
100 private val mLastBackup = MutableLiveData(
101 // fake backup time until we actually do backup
102 System.currentTimeMillis() -
103 Random.nextLong(MINUTES.toMillis(5), DAYS.toMillis(2))
104 )
105 val lastBackup: LiveData<Long> = mLastBackup
106
107 override fun onVersionReceived(versionInfo: WalletCoreVersion) { 97 override fun onVersionReceived(versionInfo: WalletCoreVersion) {
108 exchangeVersion = versionInfo.exchange 98 exchangeVersion = versionInfo.exchange
109 merchantVersion = versionInfo.merchant 99 merchantVersion = versionInfo.merchant
@@ -207,6 +197,20 @@ class MainViewModel(
207 mScanCodeEvent.value = true.toEvent() 197 mScanCodeEvent.value = true.toEvent()
208 } 198 }
209 199
200 fun runIntegrationTest() {
201 viewModelScope.launch {
202 api.request<Unit>("runIntegrationTest") {
203 put("amountToWithdraw", "KUDOS:42")
204 put("amountToSpend", "KUDOS:23")
205 put("bankBaseUrl", "https://bank.demo.taler.net/")
206 put("bankAccessApiBaseUrl", "https://bank.demo.taler.net/demobanks/default/access-api/")
207 put("exchangeBaseUrl", "https://exchange.demo.taler.net/")
208 put("merchantBaseUrl", "https://backend.demo.taler.net/")
209 put("merchantAuthToken", "secret-token:sandbox")
210 }
211 }
212 }
213
210} 214}
211 215
212sealed class AmountResult { 216sealed class AmountResult {
diff --git a/wallet/src/main/java/net/taler/wallet/settings/BackupSettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/BackupSettingsFragment.kt
deleted file mode 100644
index e9641a35..00000000
--- a/wallet/src/main/java/net/taler/wallet/settings/BackupSettingsFragment.kt
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * This file is part of GNU Taler
3 * (C) 2020 Taler Systems S.A.
4 *
5 * GNU Taler is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3, or (at your option) any later version.
8 *
9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 */
16
17package net.taler.wallet.settings
18
19import android.os.Bundle
20import androidx.preference.PreferenceFragmentCompat
21import net.taler.wallet.R
22
23class BackupSettingsFragment : PreferenceFragmentCompat() {
24
25 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
26 setPreferencesFromResource(R.xml.settings_backup, rootKey)
27 }
28
29}
diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
index 11c252bc..927d4a99 100644
--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
@@ -27,7 +27,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
27import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT 27import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT
28import com.google.android.material.snackbar.Snackbar 28import com.google.android.material.snackbar.Snackbar
29import net.taler.common.showError 29import net.taler.common.showError
30import net.taler.common.toRelativeTime
31import net.taler.qtart.BuildConfig.WALLET_CORE_VERSION 30import net.taler.qtart.BuildConfig.WALLET_CORE_VERSION
32import net.taler.wallet.BuildConfig.FLAVOR 31import net.taler.wallet.BuildConfig.FLAVOR
33import net.taler.wallet.BuildConfig.VERSION_CODE 32import net.taler.wallet.BuildConfig.VERSION_CODE
@@ -44,7 +43,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
44 private val settingsManager get() = model.settingsManager 43 private val settingsManager get() = model.settingsManager
45 private val withdrawManager by lazy { model.withdrawManager } 44 private val withdrawManager by lazy { model.withdrawManager }
46 45
47 private lateinit var prefBackup: Preference
48 private lateinit var prefDevMode: SwitchPreferenceCompat 46 private lateinit var prefDevMode: SwitchPreferenceCompat
49 private lateinit var prefWithdrawTest: Preference 47 private lateinit var prefWithdrawTest: Preference
50 private lateinit var prefLogcat: Preference 48 private lateinit var prefLogcat: Preference
@@ -53,10 +51,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
53 private lateinit var prefVersionCore: Preference 51 private lateinit var prefVersionCore: Preference
54 private lateinit var prefVersionExchange: Preference 52 private lateinit var prefVersionExchange: Preference
55 private lateinit var prefVersionMerchant: Preference 53 private lateinit var prefVersionMerchant: Preference
54 private lateinit var prefTest: Preference
56 private lateinit var prefReset: Preference 55 private lateinit var prefReset: Preference
57 private val devPrefs by lazy { 56 private val devPrefs by lazy {
58 listOf( 57 listOf(
59 prefBackup,
60 prefWithdrawTest, 58 prefWithdrawTest,
61 prefLogcat, 59 prefLogcat,
62 prefExportDb, 60 prefExportDb,
@@ -64,20 +62,21 @@ class SettingsFragment : PreferenceFragmentCompat() {
64 prefVersionCore, 62 prefVersionCore,
65 prefVersionExchange, 63 prefVersionExchange,
66 prefVersionMerchant, 64 prefVersionMerchant,
67 prefReset 65 prefTest,
66 prefReset,
68 ) 67 )
69 } 68 }
70 69
71 private val logLauncher = registerForActivityResult(CreateDocument("text/plain")) { uri -> 70 private val logLauncher = registerForActivityResult(CreateDocument("text/plain")) { uri ->
72 settingsManager.exportLogcat(uri) 71 settingsManager.exportLogcat(uri)
73 } 72 }
74 private val dbExportLauncher = registerForActivityResult(CreateDocument("application/json")) { uri -> 73 private val dbExportLauncher =
75 settingsManager.exportDb(uri) 74 registerForActivityResult(CreateDocument("application/json")) { uri ->
76 } 75 settingsManager.exportDb(uri)
76 }
77 77
78 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 78 override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
79 setPreferencesFromResource(R.xml.settings_main, rootKey) 79 setPreferencesFromResource(R.xml.settings_main, rootKey)
80 prefBackup = findPreference("pref_backup")!!
81 prefDevMode = findPreference("pref_dev_mode")!! 80 prefDevMode = findPreference("pref_dev_mode")!!
82 prefWithdrawTest = findPreference("pref_testkudos")!! 81 prefWithdrawTest = findPreference("pref_testkudos")!!
83 prefLogcat = findPreference("pref_logcat")!! 82 prefLogcat = findPreference("pref_logcat")!!
@@ -86,17 +85,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
86 prefVersionCore = findPreference("pref_version_core")!! 85 prefVersionCore = findPreference("pref_version_core")!!
87 prefVersionExchange = findPreference("pref_version_protocol_exchange")!! 86 prefVersionExchange = findPreference("pref_version_protocol_exchange")!!
88 prefVersionMerchant = findPreference("pref_version_protocol_merchant")!! 87 prefVersionMerchant = findPreference("pref_version_protocol_merchant")!!
88 prefTest = findPreference("pref_test")!!
89 prefReset = findPreference("pref_reset")!! 89 prefReset = findPreference("pref_reset")!!
90 } 90 }
91 91
92 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 92 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
93 super.onViewCreated(view, savedInstanceState) 93 super.onViewCreated(view, savedInstanceState)
94 94
95 model.lastBackup.observe(viewLifecycleOwner) {
96 val time = it.toRelativeTime(requireContext())
97 prefBackup.summary = getString(R.string.backup_last, time)
98 }
99
100 model.devMode.observe(viewLifecycleOwner) { enabled -> 95 model.devMode.observe(viewLifecycleOwner) { enabled ->
101 prefDevMode.isChecked = enabled 96 prefDevMode.isChecked = enabled
102 if (enabled) { 97 if (enabled) {
@@ -136,6 +131,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
136 true 131 true
137 } 132 }
138 133
134 prefTest.setOnPreferenceClickListener {
135 model.runIntegrationTest()
136 true
137 }
139 prefReset.setOnPreferenceClickListener { 138 prefReset.setOnPreferenceClickListener {
140 showResetDialog() 139 showResetDialog()
141 true 140 true
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
index 2b9463b9..6508539d 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -106,9 +106,6 @@
106 <action 106 <action
107 android:id="@+id/action_nav_settings_to_nav_settings_exchanges" 107 android:id="@+id/action_nav_settings_to_nav_settings_exchanges"
108 app:destination="@id/nav_settings_exchanges" /> 108 app:destination="@id/nav_settings_exchanges" />
109 <action
110 android:id="@+id/action_nav_settings_to_nav_settings_backup"
111 app:destination="@id/nav_settings_backup" />
112 </fragment> 109 </fragment>
113 110
114 <fragment 111 <fragment
@@ -168,11 +165,6 @@
168 </fragment> 165 </fragment>
169 166
170 <fragment 167 <fragment
171 android:id="@+id/nav_settings_backup"
172 android:name="net.taler.wallet.settings.BackupSettingsFragment"
173 android:label="@string/nav_settings_backup" />
174
175 <fragment
176 android:id="@+id/nav_peer_pull" 168 android:id="@+id/nav_peer_pull"
177 android:name="net.taler.wallet.peer.OutgoingPullFragment" 169 android:name="net.taler.wallet.peer.OutgoingPullFragment"
178 android:label="@string/receive_peer_title"> 170 android:label="@string/receive_peer_title">
diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml
index c313248f..67d2033f 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -245,12 +245,11 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card
245 <string name="settings_version_protocol_exchange">Supported Exchange Versions</string> 245 <string name="settings_version_protocol_exchange">Supported Exchange Versions</string>
246 <string name="settings_version_protocol_merchant">Supported Merchant Versions</string> 246 <string name="settings_version_protocol_merchant">Supported Merchant Versions</string>
247 <string name="settings_version_unknown">Unknown</string> 247 <string name="settings_version_unknown">Unknown</string>
248 <string name="settings_test">Run integration test</string>
249 <string name="settings_test_summary">Performs test transactions with demo setup</string>
248 <string name="settings_reset">Reset Wallet (dangerous!)</string> 250 <string name="settings_reset">Reset Wallet (dangerous!)</string>
249 <string name="settings_reset_summary">Throws away your money</string> 251 <string name="settings_reset_summary">Throws away your money</string>
250 252
251 <string name="nav_settings_backup">Backup</string>
252 <string name="backup_last">Last Backup: %s</string>
253
254 <string name="refund_title">Refund</string> 253 <string name="refund_title">Refund</string>
255 <string name="refund_error">Error processing refund</string> 254 <string name="refund_error">Error processing refund</string>
256 <string name="refund_success">Refund received: %s</string> 255 <string name="refund_success">Refund received: %s</string>
diff --git a/wallet/src/main/res/xml/settings_backup.xml b/wallet/src/main/res/xml/settings_backup.xml
deleted file mode 100644
index aa9b129a..00000000
--- a/wallet/src/main/res/xml/settings_backup.xml
+++ /dev/null
@@ -1,51 +0,0 @@
1<?xml version="1.0" encoding="utf-8"?><!--
2 ~ This file is part of GNU Taler
3 ~ (C) 2020 Taler Systems S.A.
4 ~
5 ~ GNU Taler is free software; you can redistribute it and/or modify it under the
6 ~ terms of the GNU General Public License as published by the Free Software
7 ~ Foundation; either version 3, or (at your option) any later version.
8 ~
9 ~ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
10 ~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 ~ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 ~
13 ~ You should have received a copy of the GNU General Public License along with
14 ~ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 -->
16
17<PreferenceScreen
18 xmlns:app="http://schemas.android.com/apk/res-auto">
19
20 <SwitchPreferenceCompat
21 app:defaultValue="@bool/settings_backup_default"
22 app:fragment="net.taler.wallet.settings.BackupSettingsFragment"
23 app:icon="@drawable/ic_baseline_backup"
24 app:key="pref_backup_switch"
25 app:summaryOff="Backup is disabled"
26 app:summaryOn="Backup is enabled"
27 app:title="Backup my wallet" />
28
29 <Preference
30 app:dependency="pref_backup_switch"
31 app:icon="@drawable/ic_baseline_account_tree"
32 app:key="pref_backup_services"
33 app:selectable="false"
34 app:summary="1 backup service set up"
35 app:title="Backup services" />
36
37 <PreferenceCategory
38 app:iconSpaceReserved="false"
39 app:summary="At least one of these is required to restore from backup"
40 app:title="Recovery Options">
41
42 <Preference
43 app:dependency="pref_backup_switch"
44 app:icon="@drawable/ic_baseline_vpn_key"
45 app:key="pref_backup_secret"
46 app:selectable="false"
47 app:title="Show backup secret" />
48
49 </PreferenceCategory>
50
51</PreferenceScreen>
diff --git a/wallet/src/main/res/xml/settings_main.xml b/wallet/src/main/res/xml/settings_main.xml
index 101aa377..3a6d991b 100644
--- a/wallet/src/main/res/xml/settings_main.xml
+++ b/wallet/src/main/res/xml/settings_main.xml
@@ -24,13 +24,6 @@
24 app:summary="@string/exchange_settings_summary" 24 app:summary="@string/exchange_settings_summary"
25 app:title="@string/exchange_settings_title" /> 25 app:title="@string/exchange_settings_title" />
26 26
27 <Preference
28 app:fragment="net.taler.wallet.settings.BackupSettingsFragment"
29 app:icon="@drawable/ic_baseline_backup"
30 app:isPreferenceVisible="false"
31 app:key="pref_backup"
32 app:title="Backup"
33 tools:isPreferenceVisible="true" />
34 27
35 <SwitchPreferenceCompat 28 <SwitchPreferenceCompat
36 app:icon="@drawable/ic_developer_mode" 29 app:icon="@drawable/ic_developer_mode"
@@ -99,6 +92,13 @@
99 tools:isPreferenceVisible="true" /> 92 tools:isPreferenceVisible="true" />
100 93
101 <Preference 94 <Preference
95 app:isPreferenceVisible="false"
96 app:key="pref_test"
97 app:summary="@string/settings_test_summary"
98 app:title="@string/settings_test"
99 tools:isPreferenceVisible="true" />
100
101 <Preference
102 app:icon="@drawable/ic_nuke" 102 app:icon="@drawable/ic_nuke"
103 app:isPreferenceVisible="false" 103 app:isPreferenceVisible="false"
104 app:key="pref_reset" 104 app:key="pref_reset"