Add address label editing

This commit is contained in:
pokkst 2023-12-02 13:28:49 -06:00
parent 59755fd6cb
commit 9551961025
No known key found for this signature in database
GPG key ID: EC4FAAA66859FAA4
5 changed files with 180 additions and 1 deletions

View file

@ -78,6 +78,8 @@ public class SubaddressAdapter extends RecyclerView.Adapter<SubaddressAdapter.Vi
public interface SubaddressAdapterListener { public interface SubaddressAdapterListener {
void onSubaddressSelected(Subaddress subaddress); void onSubaddressSelected(Subaddress subaddress);
void onSubaddressEditLabel(Subaddress subaddress);
} }
/** /**
@ -119,6 +121,10 @@ public class SubaddressAdapter extends RecyclerView.Adapter<SubaddressAdapter.Vi
addressAmountTextView.setText(""); addressAmountTextView.setText("");
itemView.setOnClickListener(view -> listener.onSubaddressSelected(subaddress)); itemView.setOnClickListener(view -> listener.onSubaddressSelected(subaddress));
itemView.setOnLongClickListener(v -> {
listener.onSubaddressEditLabel(subaddress);
return true;
});
} }
} }
} }

View file

@ -0,0 +1,71 @@
package net.mynero.wallet.fragment.dialog;
import android.os.Bundle;
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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import net.mynero.wallet.R;
import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.service.AddressService;
import net.mynero.wallet.util.Helper;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class EditAddressLabelBottomSheetDialog extends BottomSheetDialogFragment {
public LabelListener listener = null;
public int addressIndex = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.bottom_sheet_dialog_edit_address_label, null);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Wallet wallet = WalletManager.getInstance().getWallet();
AddressService addressService = AddressService.getInstance();
ImageButton pasteButton = view.findViewById(R.id.paste_password_imagebutton);
EditText labelEditText = view.findViewById(R.id.wallet_password_edittext);
Button saveLabelButton = view.findViewById(R.id.unlock_wallet_button);
boolean isDate = false;
try {
new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss", Locale.US).parse(wallet.getSubaddressLabel(addressIndex));
isDate = true;
} catch (ParseException ignored) { }
labelEditText.setText(isDate ? null : wallet.getSubaddressLabel(addressIndex));
pasteButton.setOnClickListener(view1 -> labelEditText.setText(Helper.getClipBoardText(view.getContext())));
saveLabelButton.setOnClickListener(view1 -> {
String label = labelEditText.getText().toString();
if(addressService.getLatestAddressIndex() == addressIndex) {
addressService.freshSubaddress();
}
wallet.setSubaddressLabel(addressIndex, label);
wallet.store();
if(listener != null) {
listener.onDismiss();
}
dismiss();
});
}
public interface LabelListener {
void onDismiss();
}
}

View file

@ -26,6 +26,7 @@ import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import net.mynero.wallet.R; import net.mynero.wallet.R;
import net.mynero.wallet.adapter.SubaddressAdapter; import net.mynero.wallet.adapter.SubaddressAdapter;
import net.mynero.wallet.data.Subaddress; import net.mynero.wallet.data.Subaddress;
import net.mynero.wallet.fragment.dialog.EditAddressLabelBottomSheetDialog;
import net.mynero.wallet.util.DayNightMode; import net.mynero.wallet.util.DayNightMode;
import net.mynero.wallet.util.Helper; import net.mynero.wallet.util.Helper;
import net.mynero.wallet.util.NightmodeHelper; import net.mynero.wallet.util.NightmodeHelper;
@ -70,7 +71,17 @@ public class ReceiveFragment extends Fragment {
} }
private void bindObservers(View view) { private void bindObservers(View view) {
SubaddressAdapter adapter = new SubaddressAdapter(mViewModel::selectAddress); SubaddressAdapter adapter = new SubaddressAdapter(new SubaddressAdapter.SubaddressAdapterListener() {
@Override
public void onSubaddressSelected(Subaddress subaddress) {
mViewModel.selectAddress(subaddress);
}
@Override
public void onSubaddressEditLabel(Subaddress subaddress) {
editAddressLabel(subaddress);
}
});
RecyclerView recyclerView = view.findViewById(R.id.address_list_recyclerview); RecyclerView recyclerView = view.findViewById(R.id.address_list_recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
@ -78,6 +89,13 @@ public class ReceiveFragment extends Fragment {
mViewModel.addresses.observe(getViewLifecycleOwner(), adapter::submitList); mViewModel.addresses.observe(getViewLifecycleOwner(), adapter::submitList);
} }
private void editAddressLabel(Subaddress subaddress) {
EditAddressLabelBottomSheetDialog dialog = new EditAddressLabelBottomSheetDialog();
dialog.addressIndex = subaddress.getAddressIndex();
dialog.listener = () -> mViewModel.init();
dialog.show(getParentFragmentManager(), "edit_address_dialog");
}
private void setAddress(Subaddress subaddress) { private void setAddress(Subaddress subaddress) {
final String label = subaddress.getDisplayLabel(); final String label = subaddress.getDisplayLabel();
final String address = getContext().getString(R.string.subbaddress_info_subtitle, final String address = getContext().getString(R.string.subbaddress_info_subtitle,
@ -86,6 +104,14 @@ public class ReceiveFragment extends Fragment {
addressTextView.setText(subaddress.getAddress()); addressTextView.setText(subaddress.getAddress());
addressImageView.setImageBitmap(generate(subaddress.getAddress(), 256, 256)); addressImageView.setImageBitmap(generate(subaddress.getAddress(), 256, 256));
copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", subaddress.getAddress())); copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", subaddress.getAddress()));
addressLabelTextView.setOnLongClickListener(v -> {
editAddressLabel(subaddress);
return true;
});
addressTextView.setOnLongClickListener(v -> {
editAddressLabel(subaddress);
return true;
});
} }
private Bitmap generate(String text, int width, int height) { private Bitmap generate(String text, int width, int height) {

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/oled_dialogBackgroundColor">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/enter_password_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:text="@string/edit_address_label"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="24dp"
android:textSize="32sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/wallet_password_edittext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/wallet_password_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:background="@drawable/edittext_bg"
android:layout_marginStart="24dp"
android:hint="@string/label"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@id/unlock_wallet_button"
app:layout_constraintEnd_toStartOf="@id/paste_password_imagebutton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/enter_password_textview" />
<ImageButton
android:id="@+id/paste_password_imagebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="24dp"
android:background="@android:color/transparent"
android:minWidth="48dp"
android:minHeight="48dp"
android:src="@drawable/ic_content_paste_24dp"
app:layout_constraintBottom_toBottomOf="@id/wallet_password_edittext"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/wallet_password_edittext"
app:layout_constraintTop_toTopOf="@id/wallet_password_edittext" />
<Button
android:id="@+id/unlock_wallet_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
android:text="@string/save"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/wallet_password_edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View file

@ -52,8 +52,11 @@
<string name="password_optional">Password (optional)</string> <string name="password_optional">Password (optional)</string>
<string name="password_confirm">Confirm password</string> <string name="password_confirm">Confirm password</string>
<string name="password">Password</string> <string name="password">Password</string>
<string name="label">Label</string>
<string name="unlock">Unlock</string> <string name="unlock">Unlock</string>
<string name="save">Save</string>
<string name="enter_password">Enter password</string> <string name="enter_password">Enter password</string>
<string name="edit_address_label">Set address label</string>
<string name="tx_address_text">Address: %1$s</string> <string name="tx_address_text">Address: %1$s</string>
<string name="tx_amount_text">Amount: %1$s XMR</string> <string name="tx_amount_text">Amount: %1$s XMR</string>
<string name="tx_fee_text">Fee: %1$s XMR</string> <string name="tx_fee_text">Fee: %1$s XMR</string>