summaryrefslogtreecommitdiff
path: root/wallet/src/main/java
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-04-15 10:25:20 -0300
committerTorsten Grote <t@grobox.de>2020-04-15 10:25:20 -0300
commit8e4f85d467c8e8109026a7195757ce9448ad7b19 (patch)
tree24b7e18e7a5620f659bd4fe4a839f7e0ef8f8d40 /wallet/src/main/java
parent8b7947a14349877120e74127a3949a73f917c3d2 (diff)
downloadtaler-android-8e4f85d467c8e8109026a7195757ce9448ad7b19.tar.gz
taler-android-8e4f85d467c8e8109026a7195757ce9448ad7b19.tar.bz2
taler-android-8e4f85d467c8e8109026a7195757ce9448ad7b19.zip
[wallet] move dev mode and TESTKUDOS into proper settings screen
Diffstat (limited to 'wallet/src/main/java')
-rw-r--r--wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt2
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt12
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainFragment.kt33
-rw-r--r--wallet/src/main/java/net/taler/wallet/SettingsFragment.kt144
4 files changed, 49 insertions, 142 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt b/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt
index 96cfb99..b7b2ef0 100644
--- a/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt
+++ b/wallet/src/main/java/net/taler/wallet/BalanceAdapter.kt
@@ -59,7 +59,7 @@ class BalanceAdapter(private val listener: BalanceClickListener) : Adapter<Balan
private val balanceInboundLabel: TextView = v.findViewById(R.id.balanceInboundLabel)
fun bind(item: BalanceItem) {
- v.setOnClickListener { listener.onBalanceClick() }
+ v.setOnClickListener { listener.onBalanceClick(item.available.currency) }
currencyView.text = item.available.currency
amountView.text = item.available.amountStr
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index a43cbf2..fa78b16 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -54,8 +54,7 @@ import net.taler.wallet.HostCardEmulatorService.Companion.TRIGGER_PAYMENT_ACTION
import net.taler.wallet.refund.RefundStatus
import java.util.Locale.ROOT
-class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
- ResetDialogEventListener {
+class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener {
private val model: MainViewModel by viewModels()
@@ -205,13 +204,4 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
}
}
- override fun onResetConfirmed() {
- model.dangerouslyReset()
- Snackbar.make(nav_view, "Wallet has been reset", LENGTH_SHORT).show()
- }
-
- override fun onResetCancelled() {
- Snackbar.make(nav_view, "Reset cancelled", LENGTH_SHORT).show()
- }
-
}
diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
index a0eb8ff..f587aca 100644
--- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
@@ -38,15 +38,13 @@ import com.google.zxing.integration.android.IntentIntegrator.QR_CODE
import kotlinx.android.synthetic.main.fragment_show_balance.*
interface BalanceClickListener {
- fun onBalanceClick()
+ fun onBalanceClick(currency: String)
}
class MainFragment : Fragment(), BalanceClickListener {
private val model: MainViewModel by activityViewModels()
- private val withdrawManager by lazy { model.withdrawManager }
- private var reloadBalanceMenuItem: MenuItem? = null
private val balancesAdapter = BalanceAdapter(this)
override fun onCreate(savedInstanceState: Bundle?) {
@@ -73,20 +71,6 @@ class MainFragment : Fragment(), BalanceClickListener {
onBalancesChanged(it)
})
-// model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
-// delayedTransition()
-// testWithdrawButton.visibility = if (enabled) VISIBLE else GONE
-// reloadBalanceMenuItem?.isVisible = enabled
-// })
-// testWithdrawButton.setOnClickListener {
-// withdrawManager.withdrawTestkudos()
-// }
-// withdrawManager.testWithdrawalInProgress.observe(viewLifecycleOwner, Observer { loading ->
-// Log.v("taler-wallet", "observing balance loading $loading in show balance")
-// testWithdrawButton.isEnabled = !loading
-// model.showProgressBar.value = loading
-// })
-
mainFab.setOnClickListener {
onScanButtonClicked()
}
@@ -99,25 +83,12 @@ class MainFragment : Fragment(), BalanceClickListener {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
- R.id.reload_balance -> {
- model.loadBalances()
- true
- }
- R.id.developer_mode -> {
- item.isChecked = !item.isChecked
- model.devMode.value = item.isChecked
- true
- }
else -> super.onOptionsItemSelected(item)
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.balance, menu)
- menu.findItem(R.id.developer_mode).isChecked = model.devMode.value!!
- reloadBalanceMenuItem = menu.findItem(R.id.reload_balance).apply {
- isVisible = model.devMode.value!!
- }
super.onCreateOptionsMenu(menu, inflater)
}
@@ -145,7 +116,7 @@ class MainFragment : Fragment(), BalanceClickListener {
beginDelayedTransition(view as ViewGroup)
}
- override fun onBalanceClick() {
+ override fun onBalanceClick(currency: String) {
findNavController().navigate(R.id.walletHistory)
}
diff --git a/wallet/src/main/java/net/taler/wallet/SettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/SettingsFragment.kt
index 559b162..a38a5a3 100644
--- a/wallet/src/main/java/net/taler/wallet/SettingsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/SettingsFragment.kt
@@ -16,127 +16,73 @@
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 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.*
+import androidx.preference.Preference
+import androidx.preference.PreferenceFragmentCompat
+import androidx.preference.SwitchPreferenceCompat
+import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT
+import com.google.android.material.snackbar.Snackbar
-interface ResetDialogEventListener {
- fun onResetConfirmed()
- fun onResetCancelled()
-}
-
-
-class ResetDialogFragment : DialogFragment() {
- private lateinit var listener: ResetDialogEventListener
-
- override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
- return activity?.let {
- // Use the Builder class for convenient dialog construction
- val builder = AlertDialog.Builder(it)
- builder.setMessage("Do you really want to reset the wallet and lose all coins and purchases? Consider making a backup first.")
- .setPositiveButton("Reset") { _, _ ->
- listener.onResetConfirmed()
- }
- .setNegativeButton("Cancel") { _, _ ->
- listener.onResetCancelled()
- }
- // Create the AlertDialog object and return it
- builder.create()
- } ?: throw IllegalStateException("Activity cannot be null")
- }
-
- override fun onAttach(context: Context) {
- super.onAttach(context)
- // Verify that the host activity implements the callback interface
- try {
- // Instantiate the NoticeDialogListener so we can send events to the host
- listener = context as ResetDialogEventListener
- } catch (e: ClassCastException) {
- // The activity doesn't implement the interface, throw exception
- throw ClassCastException(
- (context.toString() +
- " must implement ResetDialogEventListener")
- )
- }
- }
-}
-
-class SettingsFragment : Fragment() {
-
- companion object {
- private const val TAG = "taler-wallet"
- private const val CREATE_FILE = 1
- private const val PICK_FILE = 2
- }
+class SettingsFragment : PreferenceFragmentCompat() {
private val model: MainViewModel by activityViewModels()
+ private val withdrawManager by lazy { model.withdrawManager }
+
+ private lateinit var prefDevMode: SwitchPreferenceCompat
+ private lateinit var prefWithdrawTest: Preference
+ private lateinit var prefReset: Preference
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- return inflater.inflate(R.layout.fragment_settings, container, false)
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.settings_main, rootKey)
+ prefDevMode = findPreference("pref_dev_mode")!!
+ prefWithdrawTest = findPreference("pref_testkudos")!!
+ prefReset = findPreference("pref_reset")!!
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
- val visibility = if (enabled) VISIBLE else GONE
- devSettingsTitle.visibility = visibility
- button_reset_wallet_dangerously.visibility = visibility
+ prefDevMode.isChecked = enabled
+ prefWithdrawTest.isVisible = enabled
+ prefReset.isVisible = enabled
})
-
- textView4.text = BuildConfig.VERSION_NAME
- button_reset_wallet_dangerously.setOnClickListener {
- val d = ResetDialogFragment()
- d.show(parentFragmentManager, "walletResetDialog")
+ prefDevMode.setOnPreferenceChangeListener { _, newValue ->
+ model.devMode.value = newValue as Boolean
+ true
}
- button_backup_export.setOnClickListener {
- val intent = Intent(ACTION_CREATE_DOCUMENT).apply {
- addCategory(CATEGORY_OPENABLE)
- type = "application/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.
- //putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri)
- }
- startActivityForResult(intent, CREATE_FILE)
+ withdrawManager.testWithdrawalInProgress.observe(viewLifecycleOwner, Observer { loading ->
+ prefWithdrawTest.isEnabled = !loading
+ model.showProgressBar.value = loading
+ })
+ prefWithdrawTest.setOnPreferenceClickListener {
+ withdrawManager.withdrawTestkudos()
+ true
}
- 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)
+ prefReset.setOnPreferenceClickListener {
+ showResetDialog()
+ true
}
}
- 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}")
- }
+ private fun showResetDialog() {
+ AlertDialog.Builder(requireContext())
+ .setMessage("Do you really want to reset the wallet and lose all coins and purchases?")
+ .setPositiveButton("Reset") { _, _ ->
+ model.dangerouslyReset()
+ Snackbar.make(view!!, "Wallet has been reset", LENGTH_SHORT).show()
+ }
+ .setNegativeButton("Cancel") { _, _ ->
+ Snackbar.make(view!!, "Reset cancelled", LENGTH_SHORT).show()
+ }
+ .show()
}
}