mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-11-21 23:12:26 +00:00
Merge branch 'feature/street-mode' into rc/0.4.0
This commit is contained in:
commit
db10e1eb03
10 changed files with 114 additions and 26 deletions
|
@ -27,6 +27,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.service.PrefService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -102,8 +104,9 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
|
|||
TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview);
|
||||
TextView globalIdxTextView = itemView.findViewById(R.id.utxo_global_index_textview);
|
||||
TextView outpointTextView = itemView.findViewById(R.id.utxo_outpoint_textview);
|
||||
|
||||
amountTextView.setText(itemView.getResources().getString(R.string.tx_amount_no_prefix, Wallet.getDisplayAmount(coinsInfo.getAmount())));
|
||||
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
|
||||
String balanceString = streetModeEnabled ? Constants.STREET_MODE_BALANCE : Wallet.getDisplayAmount(coinsInfo.getAmount());
|
||||
amountTextView.setText(itemView.getResources().getString(R.string.tx_amount_no_prefix, balanceString));
|
||||
pubKeyTextView.setText(coinsInfo.getPubKey());
|
||||
globalIdxTextView.setText(itemView.getResources().getString(R.string.global_index_text, coinsInfo.getGlobalOutputIndex()));
|
||||
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex()));
|
||||
|
|
|
@ -38,8 +38,6 @@ import net.mynero.wallet.util.UriData;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
||||
private final MutableLiveData<Boolean> _sendingMax = new MutableLiveData<>(false);
|
||||
|
@ -136,11 +134,10 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
}
|
||||
|
||||
private void bindObservers() {
|
||||
|
||||
BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> {
|
||||
createButton.setEnabled(balance != 0);
|
||||
BalanceService.getInstance().balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> {
|
||||
createButton.setEnabled(balanceInfo.getRawUnlocked() != 0);
|
||||
if(!isChurning) {
|
||||
sendMaxButton.setEnabled(balance != 0);
|
||||
sendMaxButton.setEnabled(balanceInfo.getRawUnlocked() != 0);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.mynero.wallet.model.WalletManager;
|
|||
import net.mynero.wallet.service.BalanceService;
|
||||
import net.mynero.wallet.service.BlockchainService;
|
||||
import net.mynero.wallet.service.HistoryService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -91,16 +92,16 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
|
|||
BlockchainService blockchainService = BlockchainService.getInstance();
|
||||
|
||||
if (balanceService != null) {
|
||||
balanceService.balance.observe(getViewLifecycleOwner(), balance -> {
|
||||
unlockedBalanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance)));
|
||||
});
|
||||
balanceService.balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> {
|
||||
if(balanceInfo != null) {
|
||||
unlockedBalanceTextView.setText(getString(R.string.wallet_balance_text, balanceInfo.getUnlockedDisplay()));
|
||||
|
||||
balanceService.lockedBalance.observe(getViewLifecycleOwner(), lockedBalance -> {
|
||||
if (lockedBalance == 0) {
|
||||
lockedBalanceTextView.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
lockedBalanceTextView.setText(getString(R.string.wallet_locked_balance_text, Wallet.getDisplayAmount(lockedBalance)));
|
||||
lockedBalanceTextView.setVisibility(View.VISIBLE);
|
||||
if (balanceInfo.getLockedDisplay().equals(Constants.STREET_MODE_BALANCE) || balanceInfo.isLockedBalanceZero()) {
|
||||
lockedBalanceTextView.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
lockedBalanceTextView.setText(getString(R.string.wallet_locked_balance_text, balanceInfo.getLockedDisplay()));
|
||||
lockedBalanceTextView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import net.mynero.wallet.fragment.dialog.NodeSelectionBottomSheetDialog;
|
|||
import net.mynero.wallet.fragment.dialog.PasswordBottomSheetDialog;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.model.WalletManager;
|
||||
import net.mynero.wallet.service.BalanceService;
|
||||
import net.mynero.wallet.service.BlockchainService;
|
||||
import net.mynero.wallet.service.PrefService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
|
@ -97,6 +98,7 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
|||
|
||||
selectNodeButton = view.findViewById(R.id.select_node_button);
|
||||
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
||||
SwitchCompat streetModeSwitch = view.findViewById(R.id.street_mode_switch);
|
||||
SwitchCompat torSwitch = view.findViewById(R.id.tor_switch);
|
||||
ConstraintLayout proxySettingsLayout = view.findViewById(R.id.wallet_proxy_settings_layout);
|
||||
walletProxyAddressEditText = view.findViewById(R.id.wallet_proxy_address_edittext);
|
||||
|
@ -111,6 +113,12 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
|||
}
|
||||
});
|
||||
|
||||
streetModeSwitch.setChecked(PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false));
|
||||
streetModeSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
PrefService.getInstance().edit().putBoolean(Constants.PREF_STREET_MODE, b).apply();
|
||||
BalanceService.getInstance().refreshBalance();
|
||||
});
|
||||
|
||||
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
|
||||
String proxy = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
|
||||
if (proxy.contains(":")) {
|
||||
|
|
|
@ -18,6 +18,8 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.model.TransactionInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.service.PrefService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
import net.mynero.wallet.util.Helper;
|
||||
|
||||
|
@ -100,12 +102,14 @@ public class TransactionFragment extends Fragment {
|
|||
|
||||
Context ctx = getContext();
|
||||
if(ctx != null) {
|
||||
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
|
||||
String balanceString = streetModeEnabled ? Constants.STREET_MODE_BALANCE : Wallet.getDisplayAmount(transactionInfo.amount);
|
||||
if (transactionInfo.direction == TransactionInfo.Direction.Direction_In) {
|
||||
txAmountTextView.setTextColor(ContextCompat.getColor(ctx, R.color.oled_positiveColor));
|
||||
txAmountTextView.setText(getString(R.string.tx_list_amount_positive, Helper.getDisplayAmount(transactionInfo.amount)));
|
||||
txAmountTextView.setText(getString(R.string.tx_list_amount_positive, balanceString));
|
||||
} else {
|
||||
txAmountTextView.setTextColor(ContextCompat.getColor(ctx, R.color.oled_negativeColor));
|
||||
txAmountTextView.setText(getString(R.string.tx_list_amount_negative, Helper.getDisplayAmount(transactionInfo.amount)));
|
||||
txAmountTextView.setText(getString(R.string.tx_list_amount_negative, balanceString));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
48
app/src/main/java/net/mynero/wallet/model/BalanceInfo.java
Normal file
48
app/src/main/java/net/mynero/wallet/model/BalanceInfo.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package net.mynero.wallet.model;
|
||||
|
||||
import net.mynero.wallet.service.PrefService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
|
||||
public class BalanceInfo {
|
||||
private final long rawUnlocked;
|
||||
private final long rawLocked;
|
||||
|
||||
public BalanceInfo(long rawUnlocked, long rawLocked) {
|
||||
this.rawUnlocked = rawUnlocked;
|
||||
this.rawLocked = rawLocked;
|
||||
}
|
||||
|
||||
public long getRawLocked() {
|
||||
return rawLocked;
|
||||
}
|
||||
|
||||
public long getRawUnlocked() {
|
||||
return rawUnlocked;
|
||||
}
|
||||
|
||||
public boolean isUnlockedBalanceZero() {
|
||||
return rawUnlocked == 0;
|
||||
}
|
||||
|
||||
public boolean isLockedBalanceZero() {
|
||||
return rawLocked == 0;
|
||||
}
|
||||
|
||||
public String getUnlockedDisplay() {
|
||||
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
|
||||
if(streetModeEnabled) {
|
||||
return Constants.STREET_MODE_BALANCE;
|
||||
} else {
|
||||
return Wallet.getDisplayAmount(rawUnlocked);
|
||||
}
|
||||
}
|
||||
|
||||
public String getLockedDisplay() {
|
||||
boolean streetModeEnabled = PrefService.getInstance().getBoolean(Constants.PREF_STREET_MODE, false);
|
||||
if(streetModeEnabled) {
|
||||
return Constants.STREET_MODE_BALANCE;
|
||||
} else {
|
||||
return Wallet.getDisplayAmount(rawLocked);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,14 +3,15 @@ package net.mynero.wallet.service;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import net.mynero.wallet.model.BalanceInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.model.WalletManager;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
|
||||
public class BalanceService extends ServiceBase {
|
||||
public static BalanceService instance = null;
|
||||
private final MutableLiveData<Long> _balance = new MutableLiveData<>(0L);
|
||||
private final MutableLiveData<Long> _lockedBalance = new MutableLiveData<>(0L);
|
||||
public LiveData<Long> balance = _balance;
|
||||
public LiveData<Long> lockedBalance = _lockedBalance;
|
||||
private final MutableLiveData<BalanceInfo> _balanceInfo = new MutableLiveData<>(null);
|
||||
public LiveData<BalanceInfo> balanceInfo = _balanceInfo;
|
||||
|
||||
public BalanceService(MoneroHandlerThread thread) {
|
||||
super(thread);
|
||||
|
@ -22,8 +23,9 @@ public class BalanceService extends ServiceBase {
|
|||
}
|
||||
|
||||
public void refreshBalance() {
|
||||
_balance.postValue(getUnlockedBalanceRaw());
|
||||
_lockedBalance.postValue(getLockedBalanceRaw());
|
||||
long rawUnlocked = getUnlockedBalanceRaw();
|
||||
long rawLocked = getLockedBalanceRaw();
|
||||
_balanceInfo.postValue(new BalanceInfo(rawUnlocked, rawLocked));
|
||||
}
|
||||
|
||||
public long getUnlockedBalanceRaw() {
|
||||
|
|
|
@ -10,9 +10,12 @@ public class Constants {
|
|||
public static final String PREF_NODE_2 = "pref_node_2";
|
||||
public static final String PREF_CUSTOM_NODES = "pref_custom_nodes";
|
||||
public static final String PREF_USES_OFFSET = "pref_uses_offset";
|
||||
public static final String PREF_STREET_MODE = "pref_street_mode";
|
||||
|
||||
public static final String URI_PREFIX = "monero:";
|
||||
public static final String URI_ARG_AMOUNT = "tx_amount";
|
||||
public static final String URI_ARG_AMOUNT2 = "amount";
|
||||
public static final String NAV_ARG_TXINFO = "nav_arg_txinfo";
|
||||
|
||||
public static final String STREET_MODE_BALANCE = "#.############";
|
||||
}
|
||||
|
|
|
@ -112,6 +112,27 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/appearance_settings_textview" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/street_mode_label_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/street_mode"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginStart="24dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/street_mode_switch"
|
||||
app:layout_constraintEnd_toStartOf="@id/street_mode_switch"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/street_mode_switch" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/street_mode_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:minHeight="48dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/day_night_switch" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/network_settings_textview"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -124,7 +145,7 @@
|
|||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/day_night_switch" />
|
||||
app:layout_constraintTop_toBottomOf="@id/street_mode_switch" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/select_node_button"
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<string name="invalid_confirmed_password">Passwords do not match</string>
|
||||
<string name="copied_to_clipboard">Copied to clipboard</string>
|
||||
<string name="night_mode">Night mode</string>
|
||||
<string name="street_mode">Street mode (hide balances)</string>
|
||||
<string name="display_recovery_phrase">Display wallet keys</string>
|
||||
<string name="tor_switch_label">Connect to proxy</string>
|
||||
<string name="connection_failed">Connection failed</string>
|
||||
|
|
Loading…
Reference in a new issue