summaryrefslogtreecommitdiff
path: root/app/src/main/java/net/taler/wallet/Settings.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/taler/wallet/Settings.kt')
-rw-r--r--app/src/main/java/net/taler/wallet/Settings.kt83
1 files changed, 40 insertions, 43 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
- }
}