From ce5985bb47653b95663017356dd6facb14476587 Mon Sep 17 00:00:00 2001 From: pokkst Date: Wed, 7 Sep 2022 16:36:18 -0500 Subject: [PATCH] Move receive/send to new bottom sheet dialogs, change theme stuff. NOTE: This commit still logs seed phrases for development purposes --- app/src/main/AndroidManifest.xml | 2 +- .../dialog/ReceiveBottomSheetDialog.java | 73 +++++++++++++++++++ .../dialog/SendBottomSheetDialog.java | 51 +++++++++++++ .../xmrwallet/fragment/home/HomeFragment.java | 40 +++------- .../fragment/home/HomeViewModel.java | 24 +----- .../m2049r/xmrwallet/util/ThemeHelper.java | 9 +-- app/src/main/res/layout/fragment_home.xml | 64 ++++------------ .../res/layout/send_bottom_sheet_dialog.xml | 47 ++++++++++++ app/src/main/res/values-land/dimens.xml | 3 - app/src/main/res/values-night-v23/styles.xml | 11 --- app/src/main/res/values-night-v27/styles.xml | 12 --- app/src/main/res/values-v23/styles.xml | 11 --- app/src/main/res/values-v27/styles.xml | 12 --- app/src/main/res/values-w1240dp/dimens.xml | 3 - app/src/main/res/values-w600dp/dimens.xml | 3 - app/src/main/res/values/styles.xml | 52 ++++++------- app/src/main/res/values/themes.xml | 5 -- 17 files changed, 224 insertions(+), 198 deletions(-) create mode 100644 app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/ReceiveBottomSheetDialog.java create mode 100644 app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java create mode 100644 app/src/main/res/layout/send_bottom_sheet_dialog.xml delete mode 100644 app/src/main/res/values-land/dimens.xml delete mode 100644 app/src/main/res/values-night-v23/styles.xml delete mode 100644 app/src/main/res/values-night-v27/styles.xml delete mode 100644 app/src/main/res/values-v23/styles.xml delete mode 100644 app/src/main/res/values-v27/styles.xml delete mode 100644 app/src/main/res/values-w1240dp/dimens.xml delete mode 100644 app/src/main/res/values-w600dp/dimens.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a43e517..250d604 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ android:label="@string/app_name" android:preserveLegacyExternalStorage="true" android:supportsRtl="true" - android:theme="@style/MyMaterialThemeClassic" + android:theme="@style/MyMaterialThemeOled" android:usesCleartextTraffic="true"> { + if (!addr.isEmpty()) { + addressTextView.setText(addr); + addressImageView.setImageBitmap(generate(addr, 256, 256)); + } + }); + } + + public Bitmap generate(String text, int width, int height) { + if ((width <= 0) || (height <= 0)) return null; + Map hints = new HashMap<>(); + hints.put(EncodeHintType.CHARACTER_SET, "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++) { + if (bitMatrix.get(j, i)) { + pixels[i * width + j] = 0x00000000; + } else { + pixels[i * height + j] = 0xffffffff; + } + } + } + return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565); + } catch (WriterException ex) { + Timber.e(ex); + } + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java new file mode 100644 index 0000000..b5c1466 --- /dev/null +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java @@ -0,0 +1,51 @@ +package com.m2049r.xmrwallet.fragment.dialog; + +import android.os.Bundle; +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.m2049r.xmrwallet.R; +import com.m2049r.xmrwallet.model.Wallet; +import com.m2049r.xmrwallet.service.TxService; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class SendBottomSheetDialog extends BottomSheetDialogFragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.send_bottom_sheet_dialog, null); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + EditText addressEditText = view.findViewById(R.id.address_edittext); + EditText amountEditText = view.findViewById(R.id.amount_edittext); + Button sendButton = view.findViewById(R.id.send_button); + + TxService.getInstance().clearSendEvent.observe(getViewLifecycleOwner(), o -> { + dismiss(); + }); + + sendButton.setOnClickListener(view1 -> { + String address = addressEditText.getText().toString().trim(); + String amount = amountEditText.getText().toString().trim(); + boolean validAddress = Wallet.isAddressValid(address); + if (validAddress && !amount.isEmpty()) { + sendButton.setEnabled(false); + TxService.getInstance().sendTx(address, amount); + } else if (!validAddress) { + Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); + } else if (amount.isEmpty()) { + Toast.makeText(getActivity(), getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java index 579ec9c..906d1fc 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java @@ -7,6 +7,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -18,8 +19,11 @@ import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; import androidx.navigation.fragment.NavHostFragment; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.m2049r.xmrwallet.MainActivity; import com.m2049r.xmrwallet.R; +import com.m2049r.xmrwallet.fragment.dialog.ReceiveBottomSheetDialog; +import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog; import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.service.AddressService; import com.m2049r.xmrwallet.service.BalanceService; @@ -41,46 +45,26 @@ public class HomeFragment extends Fragment { mViewModel = new ViewModelProvider(this).get(HomeViewModel.class); ImageView settingsImageView = view.findViewById(R.id.settings_imageview); - ImageView addressImageView = view.findViewById(R.id.monero_qr_imageview); - TextView addressTextView = view.findViewById(R.id.address_textview); TextView balanceTextView = view.findViewById(R.id.balance_textview); - EditText addressEditText = view.findViewById(R.id.address_edittext); - EditText amountEditText = view.findViewById(R.id.amount_edittext); Button sendButton = view.findViewById(R.id.send_button); - - AddressService.getInstance().address.observe(getViewLifecycleOwner(), addr -> { - if (!addr.isEmpty()) { - addressTextView.setText(addr); - addressImageView.setImageBitmap(mViewModel.generate(addr, 256, 256)); - } - }); + Button receiveButton = view.findViewById(R.id.receive_button); BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> { balanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance))); }); - TxService.getInstance().clearSendEvent.observe(getViewLifecycleOwner(), o -> { - addressEditText.setText(null); - amountEditText.setText(null); - sendButton.setEnabled(true); - }); - settingsImageView.setOnClickListener(view12 -> { navigate(R.id.settings_fragment); }); sendButton.setOnClickListener(view1 -> { - String address = addressEditText.getText().toString().trim(); - String amount = amountEditText.getText().toString().trim(); - boolean validAddress = Wallet.isAddressValid(address); - if (validAddress && !amount.isEmpty()) { - sendButton.setEnabled(false); - TxService.getInstance().sendTx(address, amount); - } else if (!validAddress) { - Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); - } else if (amount.isEmpty()) { - Toast.makeText(getActivity(), getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show(); - } + SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); + sendDialog.show(getActivity().getSupportFragmentManager(), null); + }); + + receiveButton.setOnClickListener(view1 -> { + ReceiveBottomSheetDialog receiveDialog = new ReceiveBottomSheetDialog(); + receiveDialog.show(getActivity().getSupportFragmentManager(), null); }); } diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeViewModel.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeViewModel.java index 09e1c00..4af425c 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeViewModel.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeViewModel.java @@ -17,27 +17,5 @@ import java.util.Map; import timber.log.Timber; public class HomeViewModel extends ViewModel { - public Bitmap generate(String text, int width, int height) { - if ((width <= 0) || (height <= 0)) return null; - Map hints = new HashMap<>(); - hints.put(EncodeHintType.CHARACTER_SET, "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++) { - if (bitMatrix.get(j, i)) { - pixels[i * width + j] = 0x00000000; - } else { - pixels[i * height + j] = 0xffffffff; - } - } - } - return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565); - } catch (WriterException ex) { - Timber.e(ex); - } - return null; - } + } \ No newline at end of file diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/ThemeHelper.java b/app/src/main/java/com/m2049r/xmrwallet/util/ThemeHelper.java index 21ff733..abd7553 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/ThemeHelper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/ThemeHelper.java @@ -46,14 +46,7 @@ public class ThemeHelper { } public static void setTheme(@NonNull Activity activity, @NonNull String theme) { - switch (theme) { - case "Classic": - activity.setTheme(R.style.MyMaterialThemeClassic); - break; - case "Oled": - activity.setTheme(R.style.MyMaterialThemeOled); - break; - } + activity.setTheme(R.style.MyMaterialThemeOled); } public static void setPreferred(Activity activity) { diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index e815152..6f9bd09 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -16,76 +16,40 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"/> - - - - - - + app:layout_constraintTop_toTopOf="@id/settings_imageview" + app:layout_constraintBottom_toBottomOf="@id/settings_imageview"/> - - + android:layout_marginBottom="16dp" + android:text="Receive" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toStartOf="@id/send_button" + app:layout_constraintBottom_toBottomOf="parent"/> +