diff --git a/app/src/main/java/net/mynero/wallet/data/Node.kt b/app/src/main/java/net/mynero/wallet/data/Node.kt index 14b6d3a..1383ebc 100644 --- a/app/src/main/java/net/mynero/wallet/data/Node.kt +++ b/app/src/main/java/net/mynero/wallet/data/Node.kt @@ -245,7 +245,6 @@ class Node { private var DEFAULT_LEVIN_PORT = 0 private var DEFAULT_RPC_PORT = 0 - @JvmStatic fun fromString(nodeString: String?): Node? { return try { Node(nodeString) diff --git a/app/src/main/java/net/mynero/wallet/data/Subaddress.kt b/app/src/main/java/net/mynero/wallet/data/Subaddress.kt index 074a801..851ec97 100644 --- a/app/src/main/java/net/mynero/wallet/data/Subaddress.kt +++ b/app/src/main/java/net/mynero/wallet/data/Subaddress.kt @@ -23,7 +23,6 @@ class Subaddress( @JvmField val address: String, val label: String ) : Comparable { - @JvmField var amount: Long = 0 override fun compareTo(other: Subaddress): Int { // newer is < diff --git a/app/src/main/java/net/mynero/wallet/data/TxData.kt b/app/src/main/java/net/mynero/wallet/data/TxData.kt deleted file mode 100644 index 1cb1ce4..0000000 --- a/app/src/main/java/net/mynero/wallet/data/TxData.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2017 m2049r - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.mynero.wallet.data - -import android.os.Parcel -import android.os.Parcelable -import android.os.Parcelable.Creator -import net.mynero.wallet.model.PendingTransaction -import net.mynero.wallet.model.Wallet -import net.mynero.wallet.util.Helper - -// https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents -class TxData : Parcelable { - var destinationAddress: String? = null - var amount: Long = 0 - var mixin = 0 - var priority: PendingTransaction.Priority? = null - var userNotes: UserNotes? = null - var preferredInputs: ArrayList? = null - private set - - constructor() - constructor(txData: TxData) { - destinationAddress = txData.destinationAddress - amount = txData.amount - mixin = txData.mixin - priority = txData.priority - preferredInputs = txData.preferredInputs - } - - constructor( - dstAddr: String?, - amount: Long, - mixin: Int, - priority: PendingTransaction.Priority?, - preferredInputs: ArrayList? - ) { - destinationAddress = dstAddr - this.amount = amount - this.mixin = mixin - this.priority = priority - this.preferredInputs = preferredInputs - } - - protected constructor(`in`: Parcel) { - destinationAddress = `in`.readString() - amount = `in`.readLong() - mixin = `in`.readInt() - priority = PendingTransaction.Priority.fromInteger(`in`.readInt()) - `in`.readStringList(preferredInputs!!) - } - - fun setAmount(amount: Double) { - this.amount = Wallet.getAmountFromDouble(amount) - } - - val amountAsDouble: Double - get() = 1.0 * amount / Helper.ONE_XMR - - override fun writeToParcel(out: Parcel, flags: Int) { - out.writeString(destinationAddress) - out.writeLong(amount) - out.writeInt(mixin) - out.writeInt(priority!!.value) - } - - override fun describeContents(): Int { - return 0 - } - - override fun toString(): String { - val sb = StringBuffer() - sb.append("dstAddr:") - sb.append(destinationAddress) - sb.append(",amount:") - sb.append(amount) - sb.append(",mixin:") - sb.append(mixin) - sb.append(",priority:") - sb.append(priority) - return sb.toString() - } - - companion object CREATOR : Creator { - override fun createFromParcel(parcel: Parcel): TxData { - return TxData(parcel) - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/data/UserNotes.kt b/app/src/main/java/net/mynero/wallet/data/UserNotes.kt index 83e5ea5..41a6cf7 100644 --- a/app/src/main/java/net/mynero/wallet/data/UserNotes.kt +++ b/app/src/main/java/net/mynero/wallet/data/UserNotes.kt @@ -71,7 +71,7 @@ class UserNotes(txNotes: String?) { sb.append(",") sb.append(xmrtoDestination) sb.append("}") - if (note != null && !note!!.isEmpty()) sb.append(" ") + if (note != null && note?.isNotEmpty() == true) sb.append(" ") } sb.append(note) return sb.toString() diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java deleted file mode 100644 index 51c9937..0000000 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java +++ /dev/null @@ -1,155 +0,0 @@ -package net.mynero.wallet.fragment.dialog; - -import android.content.Context; -import android.os.Bundle; -import android.text.Editable; -import android.text.TextWatcher; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.google.android.material.bottomsheet.BottomSheetDialogFragment; - -import net.mynero.wallet.R; -import net.mynero.wallet.data.Node; -import net.mynero.wallet.service.PrefService; -import net.mynero.wallet.util.Constants; -import net.mynero.wallet.util.Helper; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment { - public AddNodeListener listener = null; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.add_node_bottom_sheet_dialog, null); - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Button addNodeButton = view.findViewById(R.id.add_node_button); - EditText addressEditText = view.findViewById(R.id.address_edittext); - EditText portEditText = view.findViewById(R.id.node_port_edittext); - EditText nodeNameEditText = view.findViewById(R.id.node_name_edittext); - EditText usernameEditText = view.findViewById(R.id.username_edittext); - EditText passwordEditText = view.findViewById(R.id.password_edittext); - ImageButton pastePasswordImageButton = view.findViewById(R.id.paste_password_imagebutton); - - usernameEditText.addTextChangedListener(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 (editable.toString().isEmpty()) { - passwordEditText.setText(null); - passwordEditText.setVisibility(View.GONE); - pastePasswordImageButton.setVisibility(View.GONE); - } else { - passwordEditText.setVisibility(View.VISIBLE); - pastePasswordImageButton.setVisibility(View.VISIBLE); - } - } - }); - - addPasteListener(view, addressEditText, R.id.paste_address_imagebutton); - addPasteListener(view, usernameEditText, R.id.paste_username_imagebutton); - addPasteListener(view, passwordEditText, R.id.paste_password_imagebutton); - - addNodeButton.setOnClickListener(view1 -> { - String nodeAddr = addressEditText.getText().toString(); - String portString = portEditText.getText().toString(); - String name = nodeNameEditText.getText().toString(); - String user = usernameEditText.getText().toString(); - String pass = passwordEditText.getText().toString(); - if (name.isEmpty()) { - Toast.makeText(getContext(), "Enter node name", Toast.LENGTH_SHORT).show(); - return; - } else if (nodeAddr.isEmpty() || portString.isEmpty()) { - Toast.makeText(getContext(), "Enter node address", Toast.LENGTH_SHORT).show(); - return; - } else if (!user.isEmpty() && pass.isEmpty()) { - Toast.makeText(getContext(), "Enter password", Toast.LENGTH_SHORT).show(); - return; - } - - JSONObject jsonObject = new JSONObject(); - try { - if (!user.isEmpty()) { - jsonObject.put("username", user); - jsonObject.put("password", pass); - } - - if (nodeAddr.contains(":") && !nodeAddr.startsWith("[") && !nodeAddr.endsWith("]")) - nodeAddr = "[" + nodeAddr + "]"; - - jsonObject.put("host", nodeAddr); - jsonObject.put("rpcPort", Integer.parseInt(portString)); - jsonObject.put("network", "mainnet"); - jsonObject.put("name", name); - - addNodeToSaved(jsonObject); - - if (listener != null) { - listener.onNodeAdded(); - dismiss(); - } - } catch (JSONException e) { - throw new RuntimeException(e); - } - }); - } - - private void addNodeToSaved(JSONObject newNodeJsonObject) throws JSONException { - Node newNode = Node.fromJson(newNodeJsonObject); - - 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++) { - JSONObject nodeJsonObject = jsonArray.getJSONObject(i); - Node node = Node.fromJson(nodeJsonObject); - if (node.toNodeString().equals(newNode.toNodeString())) - exists = true; - } - - if (!exists) { - jsonArray.put(newNodeJsonObject); - } else { - Toast.makeText(getContext(), "Node already exists", Toast.LENGTH_SHORT).show(); - return; - } - - PrefService.getInstance().edit().putString(Constants.PREF_CUSTOM_NODES, jsonArray.toString()).apply(); - } - - private void addPasteListener(View root, EditText editText, int layoutId) { - ImageButton pasteImageButton = root.findViewById(layoutId); - pasteImageButton.setOnClickListener(view1 -> { - Context ctx = getContext(); - if (ctx != null) { - editText.setText(Helper.getClipBoardText(ctx)); - } - }); - } - - public interface AddNodeListener { - void onNodeAdded(); - } -} \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.kt b/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.kt new file mode 100644 index 0000000..9abfbe9 --- /dev/null +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.kt @@ -0,0 +1,133 @@ +package net.mynero.wallet.fragment.dialog + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText +import android.widget.ImageButton +import android.widget.Toast +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import net.mynero.wallet.R +import net.mynero.wallet.data.Node.Companion.fromJson +import net.mynero.wallet.service.PrefService +import net.mynero.wallet.util.Constants +import net.mynero.wallet.util.Helper.getClipBoardText +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +class AddNodeBottomSheetDialog : BottomSheetDialogFragment() { + @JvmField + var listener: AddNodeListener? = null + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.add_node_bottom_sheet_dialog, null) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val addNodeButton = view.findViewById