From 58e4954084b0ad421818b7baf74e4e319f5b8e74 Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 1 Oct 2022 22:17:07 -0500 Subject: [PATCH] auto-reformat code --- .../java/net/mynero/wallet/MainActivity.java | 4 +- .../wallet/adapter/CoinsInfoAdapter.java | 8 ++-- .../wallet/adapter/NodeSelectionAdapter.java | 3 +- .../adapter/TransactionInfoAdapter.java | 12 ++--- .../net/mynero/wallet/data/DefaultNodes.java | 1 + .../java/net/mynero/wallet/data/TxData.java | 1 - .../dialog/AddNodeBottomSheetDialog.java | 19 ++++---- .../dialog/InformationBottomSheetDialog.java | 1 + .../NodeSelectionBottomSheetDialog.java | 14 +++--- .../dialog/PasswordBottomSheetDialog.java | 1 + .../dialog/ReceiveBottomSheetDialog.java | 4 +- .../dialog/SendBottomSheetDialog.java | 35 +++++++------- .../onboarding/OnboardingFragment.java | 5 +- .../fragment/settings/SettingsFragment.java | 47 ++++++++++++------- .../fragment/settings/SettingsViewModel.java | 9 ++-- .../transaction/TransactionFragment.java | 12 ++--- .../transaction/TransactionViewModel.java | 12 ++--- .../wallet/fragment/utxos/UtxosFragment.java | 13 ++--- .../java/net/mynero/wallet/model/Coins.java | 1 - .../net/mynero/wallet/model/CoinsInfo.java | 27 +++++------ .../java/net/mynero/wallet/model/Wallet.java | 4 +- .../mynero/wallet/service/AddressService.java | 1 - .../mynero/wallet/service/BalanceService.java | 1 + .../wallet/service/BlockchainService.java | 3 +- .../mynero/wallet/service/HistoryService.java | 1 + .../wallet/service/MoneroHandlerThread.java | 15 +++--- .../mynero/wallet/service/UTXOService.java | 4 +- .../java/net/mynero/wallet/util/UriData.java | 44 ++++++++--------- 28 files changed, 158 insertions(+), 144 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/MainActivity.java b/app/src/main/java/net/mynero/wallet/MainActivity.java index 5f4a8a4..212fcf1 100644 --- a/app/src/main/java/net/mynero/wallet/MainActivity.java +++ b/app/src/main/java/net/mynero/wallet/MainActivity.java @@ -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); diff --git a/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java b/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java index b4e993c..69e1a60 100644 --- a/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java +++ b/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java @@ -106,19 +106,19 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter { 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)); diff --git a/app/src/main/java/net/mynero/wallet/adapter/NodeSelectionAdapter.java b/app/src/main/java/net/mynero/wallet/adapter/NodeSelectionAdapter.java index a32cb43..431f70d 100644 --- a/app/src/main/java/net/mynero/wallet/adapter/NodeSelectionAdapter.java +++ b/app/src/main/java/net/mynero/wallet/adapter/NodeSelectionAdapter.java @@ -87,6 +87,7 @@ public class NodeSelectionAdapter extends RecyclerView.Adapter { 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(); } } diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/InformationBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/InformationBottomSheetDialog.java index e24d5fd..2c21839 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/InformationBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/InformationBottomSheetDialog.java @@ -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; diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/NodeSelectionBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/NodeSelectionBottomSheetDialog.java index 5a9f617..f5fb79d 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/NodeSelectionBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/NodeSelectionBottomSheetDialog.java @@ -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(); } } \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/PasswordBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/PasswordBottomSheetDialog.java index affb5d5..805a0f9 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/PasswordBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/PasswordBottomSheetDialog.java @@ -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; diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java index 1fbec63..744593d 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java @@ -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; diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java index a66d3d6..8139962 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java @@ -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 selectedUtxos = new ArrayList<>(); private final MutableLiveData _sendingMax = new MutableLiveData<>(false); + private final MutableLiveData _pendingTransaction = new MutableLiveData<>(null); + public ArrayList selectedUtxos = new ArrayList<>(); public LiveData sendingMax = _sendingMax; private final ActivityResultLauncher 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 = new MutableLiveData<>(null); public LiveData pendingTransaction = _pendingTransaction; + public UriData uriData = null; + public PendingTransaction.Priority priority; private EditText addressEditText; + private EditText amountEditText; private final ActivityResultLauncher 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(); } } + + } \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java index 6c6afb6..57ee921 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java @@ -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(); } diff --git a/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsFragment.java b/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsFragment.java index dfdf77c..1865ba7 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsFragment.java @@ -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); diff --git a/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsViewModel.java b/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsViewModel.java index d1a48a8..0410940 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsViewModel.java +++ b/app/src/main/java/net/mynero/wallet/fragment/settings/SettingsViewModel.java @@ -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); diff --git a/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionFragment.java b/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionFragment.java index c6f9c5e..bad3905 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionFragment.java @@ -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); } }); diff --git a/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionViewModel.java b/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionViewModel.java index dc7d070..9f35b33 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionViewModel.java +++ b/app/src/main/java/net/mynero/wallet/fragment/transaction/TransactionViewModel.java @@ -10,21 +10,21 @@ import net.mynero.wallet.model.WalletManager; public class TransactionViewModel extends ViewModel { private final MutableLiveData _transaction = new MutableLiveData<>(null); - public LiveData transaction = _transaction; private final MutableLiveData _destination = new MutableLiveData<>(null); + public LiveData transaction = _transaction; public LiveData 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); } } diff --git a/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java b/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java index 58e6bf6..4e6de83 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java @@ -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 selectedUtxos = new ArrayList<>(); - private CoinsInfoAdapter adapter = new CoinsInfoAdapter(this); + private final ArrayList 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 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); diff --git a/app/src/main/java/net/mynero/wallet/model/Coins.java b/app/src/main/java/net/mynero/wallet/model/Coins.java index 9483fb5..f6fb33f 100644 --- a/app/src/main/java/net/mynero/wallet/model/Coins.java +++ b/app/src/main/java/net/mynero/wallet/model/Coins.java @@ -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; diff --git a/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java b/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java index b4c6e83..c572120 100644 --- a/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java +++ b/app/src/main/java/net/mynero/wallet/model/CoinsInfo.java @@ -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 { + public static final Creator CREATOR = new Creator() { + @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 { static { System.loadLibrary("monerujo"); } @@ -53,18 +62,6 @@ public class CoinsInfo implements Parcelable, Comparable { globalOutputIndex = in.readLong(); } - public static final Creator CREATOR = new Creator() { - @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; } diff --git a/app/src/main/java/net/mynero/wallet/model/Wallet.java b/app/src/main/java/net/mynero/wallet/model/Wallet.java index 11d5462..500bf62 100644 --- a/app/src/main/java/net/mynero/wallet/model/Wallet.java +++ b/app/src/main/java/net/mynero/wallet/model/Wallet.java @@ -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; diff --git a/app/src/main/java/net/mynero/wallet/service/AddressService.java b/app/src/main/java/net/mynero/wallet/service/AddressService.java index 5176b89..f10efd0 100644 --- a/app/src/main/java/net/mynero/wallet/service/AddressService.java +++ b/app/src/main/java/net/mynero/wallet/service/AddressService.java @@ -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 { diff --git a/app/src/main/java/net/mynero/wallet/service/BalanceService.java b/app/src/main/java/net/mynero/wallet/service/BalanceService.java index cd08215..ac4a9fb 100644 --- a/app/src/main/java/net/mynero/wallet/service/BalanceService.java +++ b/app/src/main/java/net/mynero/wallet/service/BalanceService.java @@ -11,6 +11,7 @@ public class BalanceService extends ServiceBase { private final MutableLiveData _lockedBalance = new MutableLiveData<>(0L); public LiveData balance = _balance; public LiveData lockedBalance = _lockedBalance; + public BalanceService(MoneroHandlerThread thread) { super(thread); instance = this; diff --git a/app/src/main/java/net/mynero/wallet/service/BlockchainService.java b/app/src/main/java/net/mynero/wallet/service/BlockchainService.java index 64b8b27..0897cf8 100644 --- a/app/src/main/java/net/mynero/wallet/service/BlockchainService.java +++ b/app/src/main/java/net/mynero/wallet/service/BlockchainService.java @@ -9,11 +9,12 @@ import net.mynero.wallet.model.WalletManager; public class BlockchainService extends ServiceBase { public static BlockchainService instance = null; private final MutableLiveData _currentHeight = new MutableLiveData<>(0L); - public LiveData height = _currentHeight; private final MutableLiveData _connectionStatus = new MutableLiveData<>(Wallet.ConnectionStatus.ConnectionStatus_Disconnected); + public LiveData height = _currentHeight; public LiveData connectionStatus = _connectionStatus; private long daemonHeight = 0; private long lastDaemonHeightUpdateTimeMs = 0; + public BlockchainService(MoneroHandlerThread thread) { super(thread); instance = this; diff --git a/app/src/main/java/net/mynero/wallet/service/HistoryService.java b/app/src/main/java/net/mynero/wallet/service/HistoryService.java index 7f0893a..b874e7a 100644 --- a/app/src/main/java/net/mynero/wallet/service/HistoryService.java +++ b/app/src/main/java/net/mynero/wallet/service/HistoryService.java @@ -12,6 +12,7 @@ public class HistoryService extends ServiceBase { public static HistoryService instance = null; private final MutableLiveData> _history = new MutableLiveData<>(); public LiveData> history = _history; + public HistoryService(MoneroHandlerThread thread) { super(thread); instance = this; diff --git a/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java b/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java index e22efbb..49a0967 100644 --- a/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java +++ b/app/src/main/java/net/mynero/wallet/service/MoneroHandlerThread.java @@ -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 selectedUtxos) throws Exception { long amount = sendAll ? Wallet.SWEEP_ALL : Wallet.getAmountFromString(amountStr); ArrayList 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 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"); } } diff --git a/app/src/main/java/net/mynero/wallet/service/UTXOService.java b/app/src/main/java/net/mynero/wallet/service/UTXOService.java index 00a52bf..057a412 100644 --- a/app/src/main/java/net/mynero/wallet/service/UTXOService.java +++ b/app/src/main/java/net/mynero/wallet/service/UTXOService.java @@ -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> _utxos = new MutableLiveData<>(); public LiveData> 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()); diff --git a/app/src/main/java/net/mynero/wallet/util/UriData.java b/app/src/main/java/net/mynero/wallet/util/UriData.java index b519210..4372346 100644 --- a/app/src/main/java/net/mynero/wallet/util/UriData.java +++ b/app/src/main/java/net/mynero/wallet/util/UriData.java @@ -13,32 +13,12 @@ public class UriData { this.params = params; } - public HashMap 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 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 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); + } }