From 968019255fe169fcd5392634e7f5c14a1a0dcfa0 Mon Sep 17 00:00:00 2001 From: anoncontributorxmr Date: Sat, 12 Oct 2024 12:54:05 +0000 Subject: [PATCH] feat: rework fees and hide manual fee selection behind a setting --- .../java/net/mynero/wallet/SendActivity.kt | 27 ++++++++++++++----- .../net/mynero/wallet/SettingsActivity.kt | 14 +++++++--- .../mynero/wallet/model/PendingTransaction.kt | 1 + .../java/net/mynero/wallet/util/Constants.kt | 1 + app/src/main/res/layout/activity_send.xml | 10 +++---- app/src/main/res/layout/activity_settings.xml | 27 +++++++++++++++++-- app/src/main/res/values/strings.xml | 9 ++++--- 7 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/SendActivity.kt b/app/src/main/java/net/mynero/wallet/SendActivity.kt index 46f25d8..7e9028c 100644 --- a/app/src/main/java/net/mynero/wallet/SendActivity.kt +++ b/app/src/main/java/net/mynero/wallet/SendActivity.kt @@ -29,6 +29,7 @@ import com.ncorti.slidetoact.SlideToActView.OnSlideCompleteListener import net.mynero.wallet.model.PendingTransaction import net.mynero.wallet.model.Wallet import net.mynero.wallet.service.BalanceService +import net.mynero.wallet.service.PrefService import net.mynero.wallet.service.TxService import net.mynero.wallet.service.UTXOService import net.mynero.wallet.util.Constants @@ -37,7 +38,7 @@ import net.mynero.wallet.util.UriData class SendActivity : AppCompatActivity() { - var priority: PendingTransaction.Priority = PendingTransaction.Priority.Priority_Low + var priority: PendingTransaction.Priority = PendingTransaction.Priority.Priority_Default private lateinit var mViewModel: SendViewModel private lateinit var sendMaxButton: Button private lateinit var addOutputImageView: ImageButton @@ -125,15 +126,22 @@ class SendActivity : AppCompatActivity() { } private fun bindListeners() { - feeRadioGroup.check(R.id.low_fee_radiobutton) - priority = PendingTransaction.Priority.Priority_Low + feeRadioGroup.check(R.id.default_fee_radiobutton) + priority = PendingTransaction.Priority.Priority_Default feeRadioGroup.setOnCheckedChangeListener { _: RadioGroup?, i: Int -> when (i) { - R.id.low_fee_radiobutton -> priority = PendingTransaction.Priority.Priority_Low - R.id.med_fee_radiobutton -> priority = PendingTransaction.Priority.Priority_Medium + R.id.default_fee_radiobutton -> priority = PendingTransaction.Priority.Priority_Default + R.id.medium_fee_radiobutton -> priority = PendingTransaction.Priority.Priority_Medium R.id.high_fee_radiobutton -> priority = PendingTransaction.Priority.Priority_High } } + if (PrefService.instance.getBoolean(Constants.PREF_ALLOW_FEE_OVERRIDE, false)) { + feeRadioGroup.visibility = View.VISIBLE + feeRadioGroupLabelTextView.visibility = View.VISIBLE + } else { + feeRadioGroup.visibility = View.GONE + feeRadioGroupLabelTextView.visibility = View.GONE + } addOutputImageView.setOnClickListener { sendMaxButton.visibility = View.GONE val outputCount = destCount @@ -430,8 +438,13 @@ class SendActivity : AppCompatActivity() { setAddOutputButtonVisibility(View.VISIBLE) sendMaxButton.visibility = View.VISIBLE createButton.visibility = View.VISIBLE - feeRadioGroup.visibility = View.VISIBLE - feeRadioGroupLabelTextView.visibility = View.VISIBLE + if (PrefService.instance.getBoolean(Constants.PREF_ALLOW_FEE_OVERRIDE, false)) { + feeRadioGroup.visibility = View.VISIBLE + feeRadioGroupLabelTextView.visibility = View.VISIBLE + } else { + feeRadioGroup.visibility = View.GONE + feeRadioGroupLabelTextView.visibility = View.GONE + } sendTxSlider.visibility = View.GONE feeTextView.visibility = View.GONE addressTextView.visibility = View.GONE diff --git a/app/src/main/java/net/mynero/wallet/SettingsActivity.kt b/app/src/main/java/net/mynero/wallet/SettingsActivity.kt index 452ca00..1c3a9af 100644 --- a/app/src/main/java/net/mynero/wallet/SettingsActivity.kt +++ b/app/src/main/java/net/mynero/wallet/SettingsActivity.kt @@ -37,6 +37,7 @@ class SettingsActivity : AppCompatActivity() { private lateinit var selectNodeButton: Button private lateinit var streetModeSwitch: SwitchCompat private lateinit var monerochanSwitch: SwitchCompat + private lateinit var allowFeeOverrideSwitch: SwitchCompat private lateinit var useBundledTor: CheckBox private lateinit var displaySeedButton: Button private lateinit var displayUtxosButton: Button @@ -59,6 +60,7 @@ class SettingsActivity : AppCompatActivity() { selectNodeButton = findViewById(R.id.select_node_button) streetModeSwitch = findViewById(R.id.street_mode_switch) monerochanSwitch = findViewById(R.id.monerochan_switch) + allowFeeOverrideSwitch = findViewById(R.id.allow_fee_override_switch) torSwitch = findViewById(R.id.tor_switch) val proxySettingsLayout = findViewById(R.id.wallet_proxy_settings_layout) walletProxyAddressEditText = findViewById(R.id.wallet_proxy_address_edittext) @@ -74,10 +76,9 @@ class SettingsActivity : AppCompatActivity() { walletProxyAddressEditText.isEnabled = !cachedUsingBundledTor && cachedUsingProxy proxySettingsLayout.visibility = View.VISIBLE - streetModeSwitch.isChecked = - PrefService.instance.getBoolean(Constants.PREF_STREET_MODE, false) == true - monerochanSwitch.isChecked = - PrefService.instance.getBoolean(Constants.PREF_MONEROCHAN, Constants.DEFAULT_PREF_MONEROCHAN) == true + streetModeSwitch.isChecked = PrefService.instance.getBoolean(Constants.PREF_STREET_MODE, false) + monerochanSwitch.isChecked = PrefService.instance.getBoolean(Constants.PREF_MONEROCHAN, Constants.DEFAULT_PREF_MONEROCHAN) + allowFeeOverrideSwitch.isChecked = PrefService.instance.getBoolean(Constants.PREF_ALLOW_FEE_OVERRIDE, false) useBundledTor.isChecked = cachedUsingBundledTor torSwitch.isChecked = cachedUsingProxy updateProxy(cachedProxyAddress, cachedProxyPort) @@ -108,6 +109,11 @@ class SettingsActivity : AppCompatActivity() { HistoryService.instance?.refreshHistory() } + allowFeeOverrideSwitch.setOnCheckedChangeListener { _: CompoundButton?, b: Boolean -> + PrefService.instance.edit().putBoolean(Constants.PREF_ALLOW_FEE_OVERRIDE, b).apply() + HistoryService.instance?.refreshHistory() + } + selectNodeButton.setOnClickListener { val listener = NodeSelectionDialogListenerAdapter( activity = this, diff --git a/app/src/main/java/net/mynero/wallet/model/PendingTransaction.kt b/app/src/main/java/net/mynero/wallet/model/PendingTransaction.kt index 2e2c69f..563f694 100644 --- a/app/src/main/java/net/mynero/wallet/model/PendingTransaction.kt +++ b/app/src/main/java/net/mynero/wallet/model/PendingTransaction.kt @@ -48,6 +48,7 @@ class PendingTransaction internal constructor(var handle: Long) { 1 -> return Priority_Low 2 -> return Priority_Medium 3 -> return Priority_High + 4 -> return Priority_Last } return null } diff --git a/app/src/main/java/net/mynero/wallet/util/Constants.kt b/app/src/main/java/net/mynero/wallet/util/Constants.kt index 950996a..0c111ff 100644 --- a/app/src/main/java/net/mynero/wallet/util/Constants.kt +++ b/app/src/main/java/net/mynero/wallet/util/Constants.kt @@ -11,6 +11,7 @@ object Constants { const val PREF_USES_OFFSET = "pref_uses_offset" const val PREF_STREET_MODE = "pref_street_mode" const val PREF_MONEROCHAN = "pref_monerochan" + const val PREF_ALLOW_FEE_OVERRIDE = "pref_allow_fee_override" const val PREF_FROZEN_COINS = "pref_frozen_coins" const val PREF_USE_BUNDLED_TOR = "pref_use_bundled_tor" diff --git a/app/src/main/res/layout/activity_send.xml b/app/src/main/res/layout/activity_send.xml index ef6094b..974b74f 100644 --- a/app/src/main/res/layout/activity_send.xml +++ b/app/src/main/res/layout/activity_send.xml @@ -98,19 +98,19 @@ app:layout_constraintStart_toEndOf="@id/tx_fee_radiogroup_label_textview"> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index c38d6dc..6a7f40e 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -137,6 +137,19 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/monerochan_switch" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/allow_fee_override_switch" />