mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-22 22:02:25 +00:00
Nav to receive fragment
This commit is contained in:
parent
19f032699e
commit
afc7bb730b
6 changed files with 106 additions and 122 deletions
|
@ -1,103 +0,0 @@
|
|||
package net.mynero.wallet.fragment.dialog;
|
||||
|
||||
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 android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
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.data.Subaddress;
|
||||
import net.mynero.wallet.model.TransactionInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.model.WalletManager;
|
||||
import net.mynero.wallet.service.AddressService;
|
||||
import net.mynero.wallet.service.HistoryService;
|
||||
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 ReceiveBottomSheetDialog extends BottomSheetDialogFragment {
|
||||
private TextView addressTextView = null;
|
||||
private ImageView addressImageView = null;
|
||||
private ImageButton copyAddressImageButton = null;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.receive_bottom_sheet_dialog, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
||||
addressTextView = view.findViewById(R.id.address_textview);
|
||||
copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton);
|
||||
ImageView freshAddressImageView = view.findViewById(R.id.fresh_address_imageview);
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
AddressService addressService = AddressService.getInstance();
|
||||
|
||||
Subaddress addr = addressService.currentSubaddress();
|
||||
setAddress(addr);
|
||||
freshAddressImageView.setOnClickListener(view1 -> {
|
||||
final int maxSubaddresses = addressService.getLastUsedSubaddress() + wallet.getDeviceType().getSubaddressLookahead();
|
||||
if(wallet.getNumSubaddresses() < maxSubaddresses) {
|
||||
setAddress(AddressService.getInstance().freshSubaddress());
|
||||
} else {
|
||||
Toast.makeText(getContext(), getResources().getString(R.string.max_subaddresses_warning), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setAddress(Subaddress subaddress) {
|
||||
addressTextView.setText(subaddress.getAddress());
|
||||
addressImageView.setImageBitmap(generate(subaddress.getAddress(), 256, 256));
|
||||
copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", subaddress.getAddress()));
|
||||
}
|
||||
|
||||
public 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_dialogBackgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
|
||||
} catch (WriterException ex) {
|
||||
Timber.e(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import net.mynero.wallet.MainActivity;
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.adapter.TransactionInfoAdapter;
|
||||
import net.mynero.wallet.fragment.dialog.ReceiveBottomSheetDialog;
|
||||
import net.mynero.wallet.fragment.dialog.SendBottomSheetDialog;
|
||||
import net.mynero.wallet.model.TransactionInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
|
@ -76,8 +75,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
|
|||
});
|
||||
|
||||
receiveButton.setOnClickListener(view1 -> {
|
||||
ReceiveBottomSheetDialog receiveDialog = new ReceiveBottomSheetDialog();
|
||||
receiveDialog.show(getActivity().getSupportFragmentManager(), null);
|
||||
navigate(HomeFragmentDirections.navToReceive());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,52 +1,101 @@
|
|||
package net.mynero.wallet.fragment.receive;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
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.CoinsInfoAdapter;
|
||||
import net.mynero.wallet.fragment.dialog.SendBottomSheetDialog;
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.service.AddressService;
|
||||
import net.mynero.wallet.service.UTXOService;
|
||||
import net.mynero.wallet.util.UriData;
|
||||
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.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class ReceiveFragment extends Fragment {
|
||||
|
||||
private TextView addressTextView = null;
|
||||
private ImageView addressImageView = null;
|
||||
private ImageButton copyAddressImageButton = null;
|
||||
private ReceiveViewModel mViewModel;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.receive_bottom_sheet_dialog, container, false);
|
||||
return inflater.inflate(R.layout.fragment_receive, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(ReceiveViewModel.class);
|
||||
addressImageView = view.findViewById(R.id.monero_qr_imageview);
|
||||
addressTextView = view.findViewById(R.id.address_textview);
|
||||
copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton);
|
||||
mViewModel.init();
|
||||
bindListeners(view);
|
||||
bindObservers(view);
|
||||
}
|
||||
|
||||
private void bindListeners(View view) {
|
||||
|
||||
ImageView freshAddressImageView = view.findViewById(R.id.fresh_address_imageview);
|
||||
freshAddressImageView.setOnClickListener(view1 -> {
|
||||
mViewModel.getFreshSubaddress();
|
||||
});
|
||||
}
|
||||
|
||||
private void bindObservers(View view) {
|
||||
mViewModel.address.observe(getViewLifecycleOwner(), this::setAddress);
|
||||
}
|
||||
|
||||
private void setAddress(Subaddress subaddress) {
|
||||
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_dialogBackgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
|
||||
} catch (WriterException ex) {
|
||||
Timber.e(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,25 @@
|
|||
package net.mynero.wallet.fragment.receive;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class ReceiveViewModel extends ViewModel {
|
||||
import net.mynero.wallet.data.Subaddress;
|
||||
import net.mynero.wallet.service.AddressService;
|
||||
|
||||
public class ReceiveViewModel extends ViewModel {
|
||||
private MutableLiveData<Subaddress> _address = new MutableLiveData<>();
|
||||
public LiveData<Subaddress> address = _address;
|
||||
|
||||
public void init() {
|
||||
_address.setValue(AddressService.getInstance().currentSubaddress());
|
||||
}
|
||||
|
||||
public void getFreshSubaddress() {
|
||||
_address.setValue(AddressService.getInstance().freshSubaddress());
|
||||
}
|
||||
|
||||
public void selectAddress(Subaddress subaddress) {
|
||||
_address.setValue(subaddress);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="@color/oled_dialogBackgroundColor"
|
||||
android:padding="24dp">
|
||||
|
||||
|
||||
|
@ -84,6 +83,19 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/address_textview"
|
||||
app:layout_constraintTop_toTopOf="@id/address_textview" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/address_list_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="128dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/copy_address_imagebutton"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -13,6 +13,10 @@
|
|||
android:id="@+id/nav_to_settings"
|
||||
app:destination="@id/settings_fragment">
|
||||
</action>
|
||||
<action
|
||||
android:id="@+id/nav_to_receive"
|
||||
app:destination="@id/receive_fragment">
|
||||
</action>
|
||||
<action
|
||||
android:id="@+id/nav_to_onboarding"
|
||||
app:destination="@id/onboarding_fragment">
|
||||
|
@ -36,6 +40,12 @@
|
|||
app:destination="@id/utxos_fragment">
|
||||
</action>
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/receive_fragment"
|
||||
android:name="net.mynero.wallet.fragment.receive.ReceiveFragment"
|
||||
android:label="fragment_send_amount"
|
||||
tools:layout="@layout/fragment_receive">
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/utxos_fragment"
|
||||
android:name="net.mynero.wallet.fragment.utxos.UtxosFragment"
|
||||
|
|
Loading…
Reference in a new issue