summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-03-16 10:34:33 -0300
committerTorsten Grote <t@grobox.de>2020-03-16 10:34:33 -0300
commit318fc3207e83267a41c85279970d20dd7c5f27f6 (patch)
tree5f175e9706495cac3f2a832ede0506c75825d5f3
parentd041ac62019394f9706eb754c59bcce3d6febe2e (diff)
downloadwallet-android-318fc3207e83267a41c85279970d20dd7c5f27f6.tar.gz
wallet-android-318fc3207e83267a41c85279970d20dd7c5f27f6.tar.bz2
wallet-android-318fc3207e83267a41c85279970d20dd7c5f27f6.zip
Hide wallet reset button when not in developer mode
-rw-r--r--app/src/main/java/net/taler/wallet/Settings.kt83
-rw-r--r--app/src/main/res/layout/fragment_settings.xml1
-rw-r--r--app/src/main/res/values/strings.xml2
3 files changed, 42 insertions, 44 deletions
diff --git a/app/src/main/java/net/taler/wallet/Settings.kt b/app/src/main/java/net/taler/wallet/Settings.kt
index 8a91d62..6d10412 100644
--- a/app/src/main/java/net/taler/wallet/Settings.kt
+++ b/app/src/main/java/net/taler/wallet/Settings.kt
@@ -19,15 +19,22 @@ package net.taler.wallet
import android.app.Dialog
import android.content.Context
import android.content.Intent
+import android.content.Intent.ACTION_CREATE_DOCUMENT
+import android.content.Intent.ACTION_OPEN_DOCUMENT
+import android.content.Intent.CATEGORY_OPENABLE
+import android.content.Intent.EXTRA_TITLE
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
+import android.view.View.GONE
+import android.view.View.VISIBLE
import android.view.ViewGroup
-import android.widget.Button
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
+import androidx.fragment.app.activityViewModels
+import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.fragment_settings.*
@@ -70,47 +77,40 @@ class ResetDialogFragment : DialogFragment() {
}
}
-/**
- * A simple [Fragment] subclass.
- *
- */
class Settings : Fragment() {
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- when (requestCode) {
- CREATE_FILE -> {
- if (data == null) {
- return
- }
- Log.i(TAG, "got createFile result with URL ${data.data}")
- }
- PICK_FILE -> {
- if (data == null) {
- return
- }
- Log.i(TAG, "got pickFile result with URL ${data.data}")
- }
- else -> {
-
- }
- }
+ companion object {
+ private const val TAG = "taler-wallet"
+ private const val CREATE_FILE = 1
+ private const val PICK_FILE = 2
}
+ private val model: WalletViewModel by activityViewModels()
+
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- // Inflate the layout for this fragment
- val view = inflater.inflate(R.layout.fragment_settings, container, false)
- view.findViewById<Button>(R.id.button_reset_wallet_dangerously).setOnClickListener {
+ return inflater.inflate(R.layout.fragment_settings, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
+ val visibility = if (enabled) VISIBLE else GONE
+ devSettingsTitle.visibility = visibility
+ button_reset_wallet_dangerously.visibility = visibility
+ })
+
+ textView4.text = BuildConfig.VERSION_NAME
+ button_reset_wallet_dangerously.setOnClickListener {
val d = ResetDialogFragment()
- d.show(requireActivity().supportFragmentManager, "walletResetDialog")
+ d.show(parentFragmentManager, "walletResetDialog")
}
- view.findViewById<Button>(R.id.button_backup_export).setOnClickListener {
- val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
- addCategory(Intent.CATEGORY_OPENABLE)
+ button_backup_export.setOnClickListener {
+ val intent = Intent(ACTION_CREATE_DOCUMENT).apply {
+ addCategory(CATEGORY_OPENABLE)
type = "application/json"
- putExtra(Intent.EXTRA_TITLE, "taler-wallet-backup.json")
+ putExtra(EXTRA_TITLE, "taler-wallet-backup.json")
// Optionally, specify a URI for the directory that should be opened in
// the system file picker before your app creates the document.
@@ -118,26 +118,23 @@ class Settings : Fragment() {
}
startActivityForResult(intent, CREATE_FILE)
}
- view.findViewById<Button>(R.id.button_backup_import).setOnClickListener {
- val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
- addCategory(Intent.CATEGORY_OPENABLE)
+ button_backup_import.setOnClickListener {
+ val intent = Intent(ACTION_OPEN_DOCUMENT).apply {
+ addCategory(CATEGORY_OPENABLE)
type = "application/json"
//putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
}
-
startActivityForResult(intent, PICK_FILE)
}
- return view
}
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- textView4.text = BuildConfig.VERSION_NAME
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ if (data == null) return
+ when (requestCode) {
+ CREATE_FILE -> Log.i(TAG, "got createFile result with URL ${data.data}")
+ PICK_FILE -> Log.i(TAG, "got pickFile result with URL ${data.data}")
+ }
}
- companion object {
- private const val TAG = "taler-wallet"
- private const val CREATE_FILE = 1
- private const val PICK_FILE = 2
- }
}
diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml
index 12a83ec..2fa0fcc 100644
--- a/app/src/main/res/layout/fragment_settings.xml
+++ b/app/src/main/res/layout/fragment_settings.xml
@@ -81,6 +81,7 @@
<TextView
+ android:id="@+id/devSettingsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5120492..e8f95bb 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -72,7 +72,7 @@
<string name="payment_label_amount_total">Total Amount:</string>
<string name="payment_label_order_summary">Order</string>
<string name="payment_error">Error: %s</string>
- <string name="payment_balance_insufficient">Balance Insufficient!</string>
+ <string name="payment_balance_insufficient">Balance insufficient!</string>
<string name="payment_show_details">Show Details</string>
<string name="payment_hide_details">Hide Details</string>
<string name="payment_successful">Payment was successful</string>