auto-reformat code

This commit is contained in:
pokkst 2022-10-01 22:17:07 -05:00
parent 316fb994da
commit 58e4954084
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
28 changed files with 158 additions and 144 deletions

View File

@ -60,7 +60,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
Intent intent = getIntent();
Uri uri = intent.getData();
if(uri != null) {
if (uri != null) {
uriData = UriData.parse(uri.toString());
if (uriData != null) {
proceedToSend = true;
@ -122,7 +122,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
init(walletFile, password);
restartEvents.call();
if(proceedToSend) {
if (proceedToSend) {
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
sendDialog.uriData = uriData;
sendDialog.show(getSupportFragmentManager(), null);

View File

@ -106,19 +106,19 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
amountTextView.setText(itemView.getResources().getString(R.string.tx_amount_no_prefix, Wallet.getDisplayAmount(coinsInfo.getAmount())));
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()));
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex()));
itemView.setOnLongClickListener(view -> {
boolean unlocked = coinsInfo.isUnlocked();
if(unlocked) {
if (unlocked) {
listener.onUtxoSelected(coinsInfo);
}
return unlocked;
});
if(!coinsInfo.isUnlocked()) {
if (!coinsInfo.isUnlocked()) {
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_locked_utxo));
} else if(selected) {
} else if (selected) {
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_negativeColor));
} else {
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), android.R.color.transparent));

View File

@ -87,6 +87,7 @@ public class NodeSelectionAdapter extends RecyclerView.Adapter<NodeSelectionAdap
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final NodeSelectionAdapterListener listener;
public ViewHolder(NodeSelectionAdapterListener listener, View view) {
super(view);
this.listener = listener;
@ -96,7 +97,7 @@ public class NodeSelectionAdapter extends RecyclerView.Adapter<NodeSelectionAdap
String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE, DefaultNodes.XMRTW.getAddress());
Node currentNode = Node.fromString(currentNodeString);
boolean match = node.equals(currentNode);
if(match) {
if (match) {
itemView.setBackgroundColor(itemView.getResources().getColor(R.color.oled_colorSecondary));
} else {
itemView.setBackgroundColor(itemView.getResources().getColor(android.R.color.transparent));

View File

@ -113,14 +113,14 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
public void bind(TransactionInfo txInfo) {
String displayAmount = Helper.getDisplayAmount(txInfo.amount, Helper.DISPLAY_DIGITS_INFO);
TextView confirmationsTextView = ((TextView) itemView.findViewById(R.id.tvConfirmations));
CircularProgressIndicator confirmationsProgressBar = ((CircularProgressIndicator) itemView.findViewById(R.id.pbConfirmations));
TextView confirmationsTextView = itemView.findViewById(R.id.tvConfirmations);
CircularProgressIndicator confirmationsProgressBar = itemView.findViewById(R.id.pbConfirmations);
confirmationsProgressBar.setMax(TransactionInfo.CONFIRMATION);
this.amountTextView = ((TextView) itemView.findViewById(R.id.tx_amount));
((TextView) itemView.findViewById(R.id.tx_failed)).setVisibility(View.GONE);
this.amountTextView = itemView.findViewById(R.id.tx_amount);
itemView.findViewById(R.id.tx_failed).setVisibility(View.GONE);
if (txInfo.isFailed) {
((TextView) itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_negative, displayAmount));
((TextView) itemView.findViewById(R.id.tx_failed)).setVisibility(View.VISIBLE);
itemView.findViewById(R.id.tx_failed).setVisibility(View.VISIBLE);
setTxColour(failedColour);
confirmationsTextView.setVisibility(View.GONE);
confirmationsProgressBar.setVisibility(View.GONE);
@ -158,7 +158,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
((TextView) itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_positive, displayAmount));
}
TextView paymentIdTextView = ((TextView) itemView.findViewById(R.id.tx_paymentid));
TextView paymentIdTextView = itemView.findViewById(R.id.tx_paymentid);
String tag = null;
String info = "";
UserNotes userNotes = new UserNotes(txInfo.notes);

View File

@ -30,6 +30,7 @@ public enum DefaultNodes {
boldsuck("6dsdenp6vjkvqzy4wzsnzn6wixkdzihx3khiumyzieauxuxslmcaeiad.onion:18081/mainnet/boldsuck.onion");
private final String uri;
DefaultNodes(String uri) {
this.uri = uri;
}

View File

@ -24,7 +24,6 @@ import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.util.Helper;
import java.util.ArrayList;
import java.util.List;
// https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents
public class TxData implements Parcelable {

View File

@ -14,6 +14,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.mynero.wallet.R;
import net.mynero.wallet.service.PrefService;
import net.mynero.wallet.util.Constants;
@ -39,42 +40,42 @@ public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment {
ImageButton pasteAddressImageButton = view.findViewById(R.id.paste_address_imagebutton);
pasteAddressImageButton.setOnClickListener(view1 -> {
Context ctx = getContext();
if(ctx != null) {
if (ctx != null) {
addressEditText.setText(Helper.getClipBoardText(ctx));
}
});
addNodeButton.setOnClickListener(view1 -> {
String node = addressEditText.getText().toString();
String name = nodeNameEditText.getText().toString();
if(node.contains(":") && !name.isEmpty()) {
if (node.contains(":") && !name.isEmpty()) {
String[] nodeParts = node.split(":");
if(nodeParts.length == 2) {
if (nodeParts.length == 2) {
try {
String address = nodeParts[0];
int port = Integer.parseInt(nodeParts[1]);
String newNodeString = address + ":" + port + "/mainnet/" + name;
boolean validAddress = Patterns.IP_ADDRESS.matcher(address).matches() || Patterns.DOMAIN_NAME.matcher(address).matches();
if(validAddress) {
if (validAddress) {
String nodesArray = PrefService.getInstance().getString(Constants.PREF_CUSTOM_NODES, "[]");
JSONArray jsonArray = new JSONArray(nodesArray);
boolean exists = false;
for(int i = 0; i < jsonArray.length(); i++) {
for (int i = 0; i < jsonArray.length(); i++) {
String nodeString = jsonArray.getString(i);
if(nodeString.equals(newNodeString))
if (nodeString.equals(newNodeString))
exists = true;
}
if(!exists) {
if (!exists) {
jsonArray.put(newNodeString);
}
PrefService.getInstance().edit().putString(Constants.PREF_CUSTOM_NODES, jsonArray.toString()).apply();
if(listener != null) {
if (listener != null) {
listener.onNodeAdded();
}
dismiss();
}
} catch(NumberFormatException | JSONException e) {
} catch (NumberFormatException | JSONException e) {
e.printStackTrace();
}
}

View File

@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.mynero.wallet.R;
import net.mynero.wallet.util.Helper;

View File

@ -14,6 +14,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.mynero.wallet.R;
import net.mynero.wallet.adapter.NodeSelectionAdapter;
import net.mynero.wallet.data.DefaultNodes;
@ -28,8 +29,8 @@ import org.json.JSONException;
import java.util.ArrayList;
public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment implements NodeSelectionAdapter.NodeSelectionAdapterListener {
private NodeSelectionAdapter adapter = null;
public NodeSelectionDialogListener listener = null;
private NodeSelectionAdapter adapter = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -48,7 +49,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
Button addNodeButton = view.findViewById(R.id.add_node_button);
addNodeButton.setOnClickListener(view1 -> {
if(listener != null) {
if (listener != null) {
listener.onClickedAddNode();
}
dismiss();
@ -57,10 +58,10 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
try {
String nodesArray = PrefService.getInstance().getString(Constants.PREF_CUSTOM_NODES, "[]");
JSONArray jsonArray = new JSONArray(nodesArray);
for(int i = 0; i < jsonArray.length(); i++) {
for (int i = 0; i < jsonArray.length(); i++) {
String nodeString = jsonArray.getString(i);
Node node = Node.fromString(nodeString);
if(node != null) {
if (node != null) {
nodes.add(node);
}
}
@ -68,7 +69,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
e.printStackTrace();
}
for(DefaultNodes defaultNode : DefaultNodes.values()) {
for (DefaultNodes defaultNode : DefaultNodes.values()) {
nodes.add(Node.fromString(defaultNode.getUri()));
}
adapter.submitList(nodes);
@ -77,7 +78,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
@Override
public void onSelectNode(Node node) {
Activity activity = getActivity();
if(activity != null) {
if (activity != null) {
activity.runOnUiThread(() -> {
Toast.makeText(activity, getString(R.string.node_selected), Toast.LENGTH_SHORT).show();
});
@ -90,6 +91,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
public interface NodeSelectionDialogListener {
void onNodeSelected();
void onClickedAddNode();
}
}

View File

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.mynero.wallet.R;
import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.util.Constants;

View File

@ -19,17 +19,15 @@ import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import net.mynero.wallet.R;
import net.mynero.wallet.data.Subaddress;
import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.service.AddressService;
import net.mynero.wallet.util.DayNightMode;
import net.mynero.wallet.util.Helper;
import net.mynero.wallet.util.NightmodeHelper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import timber.log.Timber;

View File

@ -4,7 +4,6 @@ import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -21,17 +20,16 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.ScanContract;
import com.journeyapps.barcodescanner.ScanOptions;
import net.mynero.wallet.R;
import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.model.PendingTransaction;
import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.service.BalanceService;
import net.mynero.wallet.service.TxService;
import net.mynero.wallet.service.UTXOService;
@ -42,8 +40,9 @@ import java.util.ArrayList;
import java.util.List;
public class SendBottomSheetDialog extends BottomSheetDialogFragment {
public ArrayList<String> selectedUtxos = new ArrayList<>();
private final MutableLiveData<Boolean> _sendingMax = new MutableLiveData<>(false);
private final MutableLiveData<PendingTransaction> _pendingTransaction = new MutableLiveData<>(null);
public ArrayList<String> selectedUtxos = new ArrayList<>();
public LiveData<Boolean> sendingMax = _sendingMax; private final ActivityResultLauncher<String> cameraPermissionsLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(),
granted -> {
if (granted) {
@ -52,16 +51,17 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
Toast.makeText(getActivity(), getString(R.string.no_camera_permission), Toast.LENGTH_SHORT).show();
}
});
private final MutableLiveData<PendingTransaction> _pendingTransaction = new MutableLiveData<>(null);
public LiveData<PendingTransaction> pendingTransaction = _pendingTransaction;
public UriData uriData = null;
public PendingTransaction.Priority priority;
private EditText addressEditText;
private EditText amountEditText;
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
result -> {
if (result.getContents() != null) {
pasteAddress(result.getContents());
}
});
private EditText amountEditText;
private TextView sendAllTextView;
private TextView feeTextView;
private TextView addressTextView;
@ -75,9 +75,6 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
private ImageButton scanAddressImageButton;
private RadioGroup feeRadioGroup;
public UriData uriData = null;
public PendingTransaction.Priority priority;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.send_bottom_sheet_dialog, null);
@ -103,16 +100,16 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
if (uriData != null) {
addressEditText.setText(uriData.getAddress());
if(uriData.hasAmount()) {
if (uriData.hasAmount()) {
amountEditText.setText(uriData.getAmount());
}
}
if(!selectedUtxos.isEmpty()) {
if (!selectedUtxos.isEmpty()) {
long selectedValue = 0;
for(CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
if(selectedUtxos.contains(coinsInfo.getKeyImage())) {
for (CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
if (selectedUtxos.contains(coinsInfo.getKeyImage())) {
selectedValue += coinsInfo.getAmount();
}
}
@ -165,11 +162,11 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
feeRadioGroup.check(R.id.low_fee_radiobutton);
priority = PendingTransaction.Priority.Priority_Low;
feeRadioGroup.setOnCheckedChangeListener((radioGroup, i) -> {
if(i == R.id.low_fee_radiobutton) {
if (i == R.id.low_fee_radiobutton) {
priority = PendingTransaction.Priority.Priority_Low;
} else if(i == R.id.med_fee_radiobutton) {
} else if (i == R.id.med_fee_radiobutton) {
priority = PendingTransaction.Priority.Priority_Medium;
} else if(i == R.id.high_fee_radiobutton) {
} else if (i == R.id.high_fee_radiobutton) {
priority = PendingTransaction.Priority.Priority_High;
}
});
@ -309,7 +306,7 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
feeTextView.setVisibility(View.GONE);
addressTextView.setVisibility(View.GONE);
amountTextView.setVisibility(View.GONE);
if(!selectedUtxos.isEmpty()) {
if (!selectedUtxos.isEmpty()) {
selectedUtxosValueTextView.setVisibility(View.VISIBLE);
}
feeRadioGroup.setVisibility(View.VISIBLE);
@ -321,11 +318,13 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
UriData uriData = UriData.parse(address);
if (uriData != null) {
addressEditText.setText(uriData.getAddress());
if(uriData.hasAmount()) {
if (uriData.hasAmount()) {
amountEditText.setText(uriData.getAmount());
}
} else {
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
}
}
}

View File

@ -16,10 +16,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import net.mynero.wallet.MainActivity;
import net.mynero.wallet.R;
@ -98,7 +95,7 @@ public class OnboardingFragment extends Fragment {
private void createOrImportWallet(String walletPassword, String walletSeed, String restoreHeightText) {
MainActivity mainActivity = (MainActivity) getActivity();
if(mainActivity != null) {
if (mainActivity != null) {
if (!walletPassword.isEmpty()) {
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply();
}

View File

@ -21,7 +21,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavDirections;
import androidx.navigation.fragment.NavHostFragment;
import net.mynero.wallet.R;
@ -43,20 +42,34 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
private SettingsViewModel mViewModel;
TextWatcher proxyAddressListener = new TextWatcher() {
@Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override public void afterTextChanged(Editable editable) {
if(mViewModel != null) {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (mViewModel != null) {
mViewModel.setProxyAddress(editable.toString());
mViewModel.updateProxy();
}
}
};
TextWatcher proxyPortListener = new TextWatcher() {
@Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
@Override public void afterTextChanged(Editable editable) {
if(mViewModel != null) {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (mViewModel != null) {
mViewModel.setProxyPort(editable.toString());
mViewModel.updateProxy();
}
@ -97,13 +110,13 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
String proxy = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
if(proxy.contains(":")) {
if (proxy.contains(":")) {
String proxyAddress = proxy.split(":")[0];
String proxyPort = proxy.split(":")[1];
initProxyStuff(proxyAddress, proxyPort);
}
torSwitch.setChecked(usesProxy);
if(usesProxy) {
if (usesProxy) {
proxySettingsLayout.setVisibility(View.VISIBLE);
} else {
proxySettingsLayout.setVisibility(View.GONE);
@ -113,9 +126,9 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
torSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_TOR, b).apply();
if(b) {
if (b) {
String proxyString = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
if(proxyString.contains(":")) {
if (proxyString.contains(":")) {
removeProxyTextListeners();
String proxyAddress = proxyString.split(":")[0];
@ -150,11 +163,11 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
TextView statusTextView = view.findViewById(R.id.status_textview);
BlockchainService.getInstance().connectionStatus.observe(getViewLifecycleOwner(), connectionStatus -> {
if(connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
if (connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
statusTextView.setText(getResources().getText(R.string.connected));
} else if(connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_Disconnected) {
} else if (connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_Disconnected) {
statusTextView.setText(getResources().getText(R.string.disconnected));
} else if(connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_WrongVersion) {
} else if (connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_WrongVersion) {
statusTextView.setText(getResources().getText(R.string.version_mismatch));
}
});
@ -186,7 +199,7 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
private void initProxyStuff(String proxyAddress, String proxyPort) {
boolean validIpAddress = Patterns.IP_ADDRESS.matcher(proxyAddress).matches();
if(validIpAddress) {
if (validIpAddress) {
mViewModel.setProxyAddress(proxyAddress);
mViewModel.setProxyPort(proxyPort);
walletProxyAddressEditText.setText(proxyAddress);

View File

@ -14,23 +14,24 @@ public class SettingsViewModel extends ViewModel {
private String proxyAddress = "";
private String proxyPort = "";
public void updateProxy() {
AsyncTask.execute(() -> {
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
String currentNodeString = PrefService.getInstance().getString(Constants.PREF_NODE, DefaultNodes.XMRTW.getAddress());
boolean isNodeLocalIp = currentNodeString.startsWith("10.") || currentNodeString.startsWith("192.168.") || currentNodeString.equals("localhost") || currentNodeString.equals("127.0.0.1");
if(!usesProxy || isNodeLocalIp) {
if (!usesProxy || isNodeLocalIp) {
WalletManager.getInstance().setProxy("");
WalletManager.getInstance().getWallet().setProxy("");
return;
}
if(proxyAddress.isEmpty()) proxyAddress = "127.0.0.1";
if(proxyPort.isEmpty()) proxyPort = "9050";
if (proxyAddress.isEmpty()) proxyAddress = "127.0.0.1";
if (proxyPort.isEmpty()) proxyPort = "9050";
boolean validIpAddress = Patterns.IP_ADDRESS.matcher(proxyAddress).matches();
if(validIpAddress) {
if (validIpAddress) {
String proxy = proxyAddress + ":" + proxyPort;
PrefService.getInstance().edit().putString(Constants.PREF_PROXY, proxy).apply();
WalletManager.getInstance().setProxy(proxy);

View File

@ -43,7 +43,7 @@ public class TransactionFragment extends Fragment {
mViewModel = new ViewModelProvider(this).get(TransactionViewModel.class);
Bundle args = getArguments();
if(args != null) {
if (args != null) {
TransactionInfo txInfo = getArguments().getParcelable(Constants.NAV_ARG_TXINFO);
mViewModel.init(txInfo);
}
@ -56,7 +56,7 @@ public class TransactionFragment extends Fragment {
ImageButton copyTxHashImageButton = view.findViewById(R.id.copy_txhash_imagebutton);
copyTxHashImageButton.setOnClickListener(view1 -> {
TransactionInfo txInfo = mViewModel.transaction.getValue();
if(txInfo != null) {
if (txInfo != null) {
Helper.clipBoardCopy(getContext(), "transaction_hash", txInfo.hash);
}
});
@ -64,9 +64,9 @@ public class TransactionFragment extends Fragment {
ImageButton copyTxAddressImageButton = view.findViewById(R.id.copy_txaddress_imagebutton);
copyTxAddressImageButton.setOnClickListener(view1 -> {
TransactionInfo txInfo = mViewModel.transaction.getValue();
if(txInfo != null) {
if (txInfo != null) {
String destination = mViewModel.destination.getValue();
if(destination != null) {
if (destination != null) {
Helper.clipBoardCopy(getContext(), "transaction_address", destination);
}
}
@ -83,14 +83,14 @@ public class TransactionFragment extends Fragment {
mViewModel.transaction.observe(getViewLifecycleOwner(), transactionInfo -> {
txHashTextView.setText(transactionInfo.hash);
txConfTextView.setText(""+transactionInfo.confirmations);
txConfTextView.setText("" + transactionInfo.confirmations);
txDateTextView.setText(getDateTime(transactionInfo.timestamp));
txAmountTextView.setText(getResources().getString(R.string.tx_amount_no_prefix, Helper.getDisplayAmount(transactionInfo.amount)));
});
mViewModel.destination.observe(getViewLifecycleOwner(), s -> {
txAddressTextView.setText(Objects.requireNonNullElse(s, "-"));
if(s == null) {
if (s == null) {
copyTxAddressImageButton.setVisibility(View.INVISIBLE);
}
});

View File

@ -10,21 +10,21 @@ import net.mynero.wallet.model.WalletManager;
public class TransactionViewModel extends ViewModel {
private final MutableLiveData<TransactionInfo> _transaction = new MutableLiveData<>(null);
public LiveData<TransactionInfo> transaction = _transaction;
private final MutableLiveData<String> _destination = new MutableLiveData<>(null);
public LiveData<TransactionInfo> transaction = _transaction;
public LiveData<String> destination = _destination;
public void init(TransactionInfo info) {
Wallet wallet = WalletManager.getInstance().getWallet();
if(info.txKey == null) {
if (info.txKey == null) {
info.txKey = wallet.getTxKey(info.hash);
}
if(info.address == null && info.direction == TransactionInfo.Direction.Direction_In) {
if (info.address == null && info.direction == TransactionInfo.Direction.Direction_In) {
_destination.setValue(wallet.getSubaddress(info.accountIndex, info.addressIndex));
} else if(info.address != null && info.direction == TransactionInfo.Direction.Direction_In) {
} else if (info.address != null && info.direction == TransactionInfo.Direction.Direction_In) {
_destination.setValue(info.address);
} else if(info.transfers != null && info.direction == TransactionInfo.Direction.Direction_Out) {
if(info.transfers.size() == 1) {
} else if (info.transfers != null && info.direction == TransactionInfo.Direction.Direction_Out) {
if (info.transfers.size() == 1) {
_destination.setValue(info.transfers.get(0).address);
}
}

View File

@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import net.mynero.wallet.R;
import net.mynero.wallet.adapter.CoinsInfoAdapter;
import net.mynero.wallet.fragment.dialog.SendBottomSheetDialog;
@ -24,8 +25,8 @@ import java.util.Collections;
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener {
private UtxosViewModel mViewModel;
private ArrayList<String> selectedUtxos = new ArrayList<>();
private CoinsInfoAdapter adapter = new CoinsInfoAdapter(this);
private final ArrayList<String> selectedUtxos = new ArrayList<>();
private final CoinsInfoAdapter adapter = new CoinsInfoAdapter(this);
private Button sendUtxosButton;
@Override
@ -60,8 +61,8 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
if (utxoService != null) {
utxoService.utxos.observe(getViewLifecycleOwner(), utxos -> {
ArrayList<CoinsInfo> filteredUtxos = new ArrayList<>();
for(CoinsInfo coinsInfo : utxos) {
if(!coinsInfo.isSpent()) {
for (CoinsInfo coinsInfo : utxos) {
if (!coinsInfo.isSpent()) {
filteredUtxos.add(coinsInfo);
}
}
@ -79,13 +80,13 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
@Override
public void onUtxoSelected(CoinsInfo coinsInfo) {
boolean selected = selectedUtxos.contains(coinsInfo.getKeyImage());
if(selected) {
if (selected) {
selectedUtxos.remove(coinsInfo.getKeyImage());
} else {
selectedUtxos.add(coinsInfo.getKeyImage());
}
if(selectedUtxos.isEmpty()) {
if (selectedUtxos.isEmpty()) {
sendUtxosButton.setVisibility(View.GONE);
} else {
sendUtxosButton.setVisibility(View.VISIBLE);

View File

@ -17,7 +17,6 @@
package net.mynero.wallet.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import timber.log.Timber;

View File

@ -21,10 +21,19 @@ import android.os.Parcelable;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
public class CoinsInfo implements Parcelable, Comparable<CoinsInfo> {
public static final Creator<CoinsInfo> CREATOR = new Creator<CoinsInfo>() {
@Override
public CoinsInfo createFromParcel(Parcel in) {
return new CoinsInfo(in);
}
@Override
public CoinsInfo[] newArray(int size) {
return new CoinsInfo[size];
}
};
public class CoinsInfo implements Parcelable, Comparable<CoinsInfo> {
static {
System.loadLibrary("monerujo");
}
@ -53,18 +62,6 @@ public class CoinsInfo implements Parcelable, Comparable<CoinsInfo> {
globalOutputIndex = in.readLong();
}
public static final Creator<CoinsInfo> CREATOR = new Creator<CoinsInfo>() {
@Override
public CoinsInfo createFromParcel(Parcel in) {
return new CoinsInfo(in);
}
@Override
public CoinsInfo[] newArray(int size) {
return new CoinsInfo[size];
}
};
public long getGlobalOutputIndex() {
return globalOutputIndex;
}

View File

@ -341,6 +341,7 @@ public class Wallet {
}
return coins;
}
private native long getCoinsJ();
//virtual bool exportKeyImages(const std::string &filename) = 0;
@ -354,7 +355,7 @@ public class Wallet {
}
public void refreshCoins() {
if(this.isSynchronized()) {
if (this.isSynchronized()) {
getCoins().refresh();
}
}
@ -486,6 +487,7 @@ public class Wallet {
final private String errorString;
@Nullable
private ConnectionStatus connectionStatus; // optional
Status(int status, String errorString) {
this.status = StatusEnum.values()[status];
this.errorString = errorString;

View File

@ -6,7 +6,6 @@ import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.model.WalletManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class AddressService extends ServiceBase {

View File

@ -11,6 +11,7 @@ public class BalanceService extends ServiceBase {
private final MutableLiveData<Long> _lockedBalance = new MutableLiveData<>(0L);
public LiveData<Long> balance = _balance;
public LiveData<Long> lockedBalance = _lockedBalance;
public BalanceService(MoneroHandlerThread thread) {
super(thread);
instance = this;

View File

@ -9,11 +9,12 @@ import net.mynero.wallet.model.WalletManager;
public class BlockchainService extends ServiceBase {
public static BlockchainService instance = null;
private final MutableLiveData<Long> _currentHeight = new MutableLiveData<>(0L);
public LiveData<Long> height = _currentHeight;
private final MutableLiveData<Wallet.ConnectionStatus> _connectionStatus = new MutableLiveData<>(Wallet.ConnectionStatus.ConnectionStatus_Disconnected);
public LiveData<Long> height = _currentHeight;
public LiveData<Wallet.ConnectionStatus> connectionStatus = _connectionStatus;
private long daemonHeight = 0;
private long lastDaemonHeightUpdateTimeMs = 0;
public BlockchainService(MoneroHandlerThread thread) {
super(thread);
instance = this;

View File

@ -12,6 +12,7 @@ public class HistoryService extends ServiceBase {
public static HistoryService instance = null;
private final MutableLiveData<List<TransactionInfo>> _history = new MutableLiveData<>();
public LiveData<List<TransactionInfo>> history = _history;
public HistoryService(MoneroHandlerThread thread) {
super(thread);
instance = this;

View File

@ -28,7 +28,6 @@ import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.util.Constants;
import java.util.ArrayList;
import java.util.List;
/**
@ -39,9 +38,9 @@ import java.util.List;
public class MoneroHandlerThread extends Thread implements WalletListener {
// from src/cryptonote_config.h
static public final long THREAD_STACK_SIZE = 5 * 1024 * 1024;
private final Wallet wallet;
int triesLeft = 5;
private Listener listener = null;
private final Wallet wallet;
public MoneroHandlerThread(String name, Listener listener, Wallet wallet) {
super(null, null, name, THREAD_STACK_SIZE);
@ -117,7 +116,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
private void refresh(boolean refreshCoins) {
wallet.refreshHistory();
if(refreshCoins) {
if (refreshCoins) {
wallet.refreshCoins();
}
listener.onRefresh();
@ -126,7 +125,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) throws Exception {
long amount = sendAll ? Wallet.SWEEP_ALL : Wallet.getAmountFromString(amountStr);
ArrayList<String> preferredInputs;
if(selectedUtxos.isEmpty()) {
if (selectedUtxos.isEmpty()) {
// no inputs manually selected, we are sending from home screen most likely, or user somehow broke the app
preferredInputs = UTXOService.getInstance().selectUtxos(amount, sendAll);
} else {
@ -137,15 +136,15 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
}
private void checkSelectedAmounts(ArrayList<String> selectedUtxos, long amount, boolean sendAll) throws Exception {
if(!sendAll) {
if (!sendAll) {
long amountSelected = 0;
for(CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
if(selectedUtxos.contains(coinsInfo.getKeyImage())) {
for (CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
if (selectedUtxos.contains(coinsInfo.getKeyImage())) {
amountSelected += coinsInfo.getAmount();
}
}
if(amountSelected <= amount) {
if (amountSelected <= amount) {
throw new Exception("insufficient wallet balance");
}
}

View File

@ -7,7 +7,6 @@ import androidx.lifecycle.MutableLiveData;
import net.mynero.wallet.model.CoinsInfo;
import net.mynero.wallet.model.PendingTransaction;
import net.mynero.wallet.model.TransactionInfo;
import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.model.WalletManager;
@ -19,6 +18,7 @@ public class UTXOService extends ServiceBase {
public static UTXOService instance = null;
private final MutableLiveData<List<CoinsInfo>> _utxos = new MutableLiveData<>();
public LiveData<List<CoinsInfo>> utxos = _utxos;
public UTXOService(MoneroHandlerThread thread) {
super(thread);
instance = this;
@ -46,7 +46,7 @@ public class UTXOService extends ServiceBase {
Collections.sort(utxos);
//loop through each utxo
for (CoinsInfo coinsInfo : utxos) {
if(!coinsInfo.isSpent() && coinsInfo.isUnlocked()) { //filter out spent and locked outputs
if (!coinsInfo.isSpent() && coinsInfo.isUnlocked()) { //filter out spent and locked outputs
if (sendAll) {
// if send all, add all utxos and set amount to send all
selectedUtxos.add(coinsInfo.getKeyImage());

View File

@ -13,32 +13,12 @@ public class UriData {
this.params = params;
}
public HashMap<String, String> getParams() {
return params;
}
public String getAddress() {
return address;
}
public String getAmount() {
String txAmount = params.get(Constants.URI_ARG_AMOUNT);
if(txAmount == null) {
return params.get(Constants.URI_ARG_AMOUNT2);
}
return txAmount;
}
public boolean hasAmount() {
return params.containsKey(Constants.URI_ARG_AMOUNT) || params.containsKey(Constants.URI_ARG_AMOUNT2);
}
public static UriData parse(String uri) {
HashMap<String, String> params = new HashMap<>();
String[] uriParts = uri.replace(Constants.URI_PREFIX, "").split("\\?");
String finalAddress = uriParts[0];
String queryParams = "";
if(uriParts.length > 1) {
if (uriParts.length > 1) {
queryParams = uriParts[1];
String[] queryParts = queryParams.split("&");
for (String param : queryParts) {
@ -49,10 +29,30 @@ public class UriData {
}
}
boolean valid = Wallet.isAddressValid(finalAddress);
if(valid) {
if (valid) {
return new UriData(finalAddress, params);
} else {
return null;
}
}
public HashMap<String, String> getParams() {
return params;
}
public String getAddress() {
return address;
}
public String getAmount() {
String txAmount = params.get(Constants.URI_ARG_AMOUNT);
if (txAmount == null) {
return params.get(Constants.URI_ARG_AMOUNT2);
}
return txAmount;
}
public boolean hasAmount() {
return params.containsKey(Constants.URI_ARG_AMOUNT) || params.containsKey(Constants.URI_ARG_AMOUNT2);
}
}