mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-12-22 13:07:46 +00:00
Send screen redesign (WIP)
This commit is contained in:
parent
064eada022
commit
3f9ceffdde
3 changed files with 436 additions and 0 deletions
|
@ -0,0 +1,115 @@
|
|||
package net.mynero.wallet.fragment.send;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
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.adapter.SubaddressAdapter;
|
||||
import net.mynero.wallet.data.Subaddress;
|
||||
import net.mynero.wallet.util.DayNightMode;
|
||||
import net.mynero.wallet.util.Helper;
|
||||
import net.mynero.wallet.util.NightmodeHelper;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class SendFragment extends Fragment {
|
||||
private TextView addressTextView = null;
|
||||
private TextView addressLabelTextView = null;
|
||||
private ImageView addressImageView = null;
|
||||
private ImageButton copyAddressImageButton = null;
|
||||
private SendViewModel mViewModel;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_send, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(SendViewModel.class);
|
||||
addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
||||
addressTextView = view.findViewById(R.id.address_textview);
|
||||
addressLabelTextView = view.findViewById(R.id.address_label_textview);
|
||||
copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton);
|
||||
bindListeners(view);
|
||||
bindObservers(view);
|
||||
mViewModel.init();
|
||||
}
|
||||
|
||||
private void bindListeners(View view) {
|
||||
ImageButton freshAddressImageView = view.findViewById(R.id.fresh_address_imageview);
|
||||
freshAddressImageView.setOnClickListener(view1 -> {
|
||||
mViewModel.getFreshSubaddress();
|
||||
});
|
||||
}
|
||||
|
||||
private void bindObservers(View view) {
|
||||
SubaddressAdapter adapter = new SubaddressAdapter(mViewModel::selectAddress);
|
||||
RecyclerView recyclerView = view.findViewById(R.id.address_list_recyclerview);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
mViewModel.address.observe(getViewLifecycleOwner(), this::setAddress);
|
||||
mViewModel.addresses.observe(getViewLifecycleOwner(), adapter::submitList);
|
||||
}
|
||||
|
||||
private void setAddress(Subaddress subaddress) {
|
||||
final String label = subaddress.getDisplayLabel();
|
||||
final String address = getContext().getString(R.string.subbaddress_info_subtitle,
|
||||
subaddress.getAddressIndex(), subaddress.getSquashedAddress());
|
||||
addressLabelTextView.setText(label.isEmpty() ? address : label);
|
||||
addressTextView.setText(subaddress.getAddress());
|
||||
addressImageView.setImageBitmap(generate(subaddress.getAddress(), 256, 256));
|
||||
copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", subaddress.getAddress()));
|
||||
}
|
||||
|
||||
private Bitmap generate(String text, int width, int height) {
|
||||
if ((width <= 0) || (height <= 0)) return null;
|
||||
Map<EncodeHintType, Object> hints = new HashMap<>();
|
||||
hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8);
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
|
||||
try {
|
||||
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
|
||||
int[] pixels = new int[width * height];
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
boolean night = NightmodeHelper.getPreferredNightmode() == DayNightMode.NIGHT;
|
||||
if (bitMatrix.get(j, i)) {
|
||||
pixels[i * width + j] = night ? 0xffffffff : 0x00000000;
|
||||
} else {
|
||||
pixels[i * height + j] = getResources().getColor(R.color.oled_colorBackground);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
|
||||
} catch (WriterException ex) {
|
||||
Timber.e(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package net.mynero.wallet.fragment.send;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import net.mynero.wallet.data.Subaddress;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.model.WalletManager;
|
||||
import net.mynero.wallet.service.AddressService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SendViewModel extends ViewModel {
|
||||
private final MutableLiveData<Subaddress> _address = new MutableLiveData<>();
|
||||
public LiveData<Subaddress> address = _address;
|
||||
private final MutableLiveData<List<Subaddress>> _addresses = new MutableLiveData<>();
|
||||
public LiveData<List<Subaddress>> addresses = _addresses;
|
||||
|
||||
public void init() {
|
||||
_address.setValue(AddressService.getInstance().currentSubaddress());
|
||||
_addresses.setValue(getSubaddresses());
|
||||
}
|
||||
|
||||
private List<Subaddress> getSubaddresses() {
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
ArrayList<Subaddress> subaddresses = new ArrayList<>();
|
||||
int addressesSize = AddressService.getInstance().getLatestAddressIndex();
|
||||
for(int i = addressesSize - 1; i >= 0; i--) {
|
||||
subaddresses.add(wallet.getSubaddressObject(i));
|
||||
}
|
||||
return Collections.unmodifiableList(subaddresses);
|
||||
}
|
||||
|
||||
public void getFreshSubaddress() {
|
||||
_address.setValue(AddressService.getInstance().freshSubaddress());
|
||||
_addresses.setValue(getSubaddresses());
|
||||
}
|
||||
|
||||
public void selectAddress(Subaddress subaddress) {
|
||||
_address.setValue(subaddress);
|
||||
}
|
||||
}
|
276
app/src/main/res/layout/fragment_send.xml
Normal file
276
app/src/main/res/layout/fragment_send.xml
Normal file
|
@ -0,0 +1,276 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/oled_dialogBackgroundColor"
|
||||
android:fitsSystemWindows="true">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<!-- CREATE LAYOUT -->
|
||||
<TextView
|
||||
android:id="@+id/send_monero_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/send_monero"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/selected_utxos_value_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<TextView
|
||||
android:id="@+id/selected_utxos_value_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:text="@string/selected_utxos_value"
|
||||
android:textSize="16sp"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toTopOf="@id/address_edittext"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/send_monero_textview" />
|
||||
<EditText
|
||||
android:id="@+id/address_edittext"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:background="@drawable/edittext_bg"
|
||||
android:layout_marginStart="24dp"
|
||||
android:ellipsize="middle"
|
||||
android:hint="@string/address"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/donate_label_textview"
|
||||
app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/selected_utxos_value_textview"
|
||||
tools:visibility="visible" />
|
||||
<TextView
|
||||
android:id="@+id/donate_label_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/donate_label"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/address_edittext"
|
||||
app:layout_constraintBottom_toTopOf="@id/amount_edittext"/>
|
||||
<ImageButton
|
||||
android:id="@+id/paste_address_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="@android:color/transparent"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:src="@drawable/ic_content_paste_24dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/address_edittext"
|
||||
app:layout_constraintEnd_toStartOf="@id/scan_address_imagebutton"
|
||||
app:layout_constraintStart_toEndOf="@id/address_edittext"
|
||||
app:layout_constraintTop_toTopOf="@id/address_edittext"
|
||||
tools:ignore="SpeakableTextPresentCheck"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/scan_address_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:minWidth="48dp"
|
||||
android:minHeight="48dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:src="@drawable/ic_scan"
|
||||
app:layout_constraintBottom_toBottomOf="@id/address_edittext"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/paste_address_imagebutton"
|
||||
app:layout_constraintTop_toTopOf="@id/address_edittext"
|
||||
tools:ignore="SpeakableTextPresentCheck"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/amount_edittext"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:background="@drawable/edittext_bg"
|
||||
android:hint="@string/amount"
|
||||
android:inputType="numberDecimal"
|
||||
app:layout_constraintBottom_toTopOf="@id/tx_fee_radiogroup"
|
||||
app:layout_constraintEnd_toStartOf="@id/send_max_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sending_all_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/sending_all"
|
||||
android:layout_marginStart="24dp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="@id/amount_edittext"
|
||||
app:layout_constraintEnd_toStartOf="@id/send_max_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/amount_edittext"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/send_max_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/send_max"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/amount_edittext"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/amount_edittext"
|
||||
app:layout_constraintTop_toTopOf="@id/amount_edittext"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tx_fee_radiogroup_label_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/fee_priority"
|
||||
android:layout_marginStart="24dp"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/tx_fee_radiogroup"
|
||||
app:layout_constraintTop_toTopOf="@id/tx_fee_radiogroup"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tx_fee_radiogroup"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/tx_fee_radiogroup"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/send_max_button"
|
||||
app:layout_constraintBottom_toTopOf="@id/create_tx_button"
|
||||
app:layout_constraintStart_toEndOf="@id/tx_fee_radiogroup_label_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:text="@string/low"
|
||||
android:id="@+id/low_fee_radiobutton"
|
||||
android:checked="true"
|
||||
android:textSize="16sp" />
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:text="@string/medium"
|
||||
android:id="@+id/med_fee_radiobutton"
|
||||
android:checked="false"
|
||||
android:textSize="16sp"/>
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:text="@string/high"
|
||||
android:id="@+id/high_fee_radiobutton"
|
||||
android:checked="false"
|
||||
android:textSize="16sp"/>
|
||||
</RadioGroup>
|
||||
|
||||
<Button
|
||||
android:id="@+id/create_tx_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/create"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginStart="24dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tx_fee_radiogroup_label_textview"
|
||||
tools:visibility="visible" />
|
||||
|
||||
|
||||
<!-- SEND LAYOUT -->
|
||||
<TextView
|
||||
android:id="@+id/address_pending_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:ellipsize="middle"
|
||||
android:singleLine="true"
|
||||
android:text="@string/tx_address_text"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/amount_pending_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/send_monero_textview"
|
||||
tools:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/amount_pending_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/tx_amount_text"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/fee_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/address_pending_textview"
|
||||
tools:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fee_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/tx_fee_text"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/send_tx_button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/amount_pending_textview"
|
||||
tools:visibility="gone" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/send_tx_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/send"
|
||||
android:visibility="gone"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/fee_textview"
|
||||
tools:visibility="gone" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
Loading…
Reference in a new issue