From f4c1af1bb8c5397f40b5a7061e0b07a4c69bece3 Mon Sep 17 00:00:00 2001 From: m2049r Date: Sat, 17 Apr 2021 21:03:32 +0200 Subject: [PATCH] Some refactoring (#742) * configure enabling of shift & exchange * refactor qr logo code * fix rename wallet --- app/build.gradle | 4 +- .../com/m2049r/xmrwallet/LoginActivity.java | 6 +- .../com/m2049r/xmrwallet/ReceiveFragment.java | 20 +++---- .../com/m2049r/xmrwallet/WalletFragment.java | 3 +- .../send/SendAddressWizardFragment.java | 55 +++++++++++-------- .../com/m2049r/xmrwallet/util/Helper.java | 6 +- .../com/m2049r/xmrwallet/util/Notice.java | 18 +++--- .../xmrwallet/widget/ExchangeEditText.java | 3 +- .../m2049r/xmrwallet/widget/ExchangeView.java | 7 +-- .../main/res/layout/fragment_send_address.xml | 1 + external-libs/Makefile | 8 +-- external-libs/VERSION | 2 +- 12 files changed, 70 insertions(+), 63 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 400d9ef..63d0e89 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.m2049r.xmrwallet" minSdkVersion 21 targetSdkVersion 30 - versionCode 900 - versionName "1.19.0.2 'XXX'" + versionCode 1000 + versionName "2.0.0.0 'Puginarug'" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java index 4e8895e..b5d1de2 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java @@ -985,16 +985,16 @@ public class LoginActivity extends BaseActivity File dstDir = dstWallet.getParentFile(); String dstName = dstWallet.getName(); try { - try { + copyFile(new File(srcDir, srcName + ".keys"), new File(dstDir, dstName + ".keys")); + try { // cache & address.txt are optional files copyFile(new File(srcDir, srcName), new File(dstDir, dstName)); + copyFile(new File(srcDir, srcName + ".address.txt"), new File(dstDir, dstName + ".address.txt")); } catch (IOException ex) { Timber.d("CACHE %s", ignoreCacheError); if (!ignoreCacheError) { // ignore cache backup error if backing up (can be resynced) throw ex; } } - copyFile(new File(srcDir, srcName + ".keys"), new File(dstDir, dstName + ".keys")); - copyFile(new File(srcDir, srcName + ".address.txt"), new File(dstDir, dstName + ".address.txt")); success = true; } catch (IOException ex) { Timber.e("wallet copy failed: %s", ex.getMessage()); diff --git a/app/src/main/java/com/m2049r/xmrwallet/ReceiveFragment.java b/app/src/main/java/com/m2049r/xmrwallet/ReceiveFragment.java index df3788b..48af052 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/ReceiveFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/ReceiveFragment.java @@ -385,24 +385,18 @@ public class ReceiveFragment extends Fragment { } private Bitmap addLogo(Bitmap qrBitmap) { + // addume logo & qrcode are both square Bitmap logo = getMoneroLogo(); - int qrWidth = qrBitmap.getWidth(); - int qrHeight = qrBitmap.getHeight(); - int logoWidth = logo.getWidth(); - int logoHeight = logo.getHeight(); + final int qrSize = qrBitmap.getWidth(); + final int logoSize = logo.getWidth(); - Bitmap logoBitmap = Bitmap.createBitmap(qrWidth, qrHeight, Bitmap.Config.ARGB_8888); + Bitmap logoBitmap = Bitmap.createBitmap(qrSize, qrSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(logoBitmap); canvas.drawBitmap(qrBitmap, 0, 0, null); canvas.save(); - // figure out how to scale the logo - float scaleSize = 1.0f; - while ((logoWidth / scaleSize) > (qrWidth / 5.) || (logoHeight / scaleSize) > (qrHeight / 5.)) { - scaleSize *= 2; - } - float sx = 1.0f / scaleSize; - canvas.scale(sx, sx, qrWidth / 2f, qrHeight / 2f); - canvas.drawBitmap(logo, (qrWidth - logoWidth) / 2f, (qrHeight - logoHeight) / 2f, null); + final float sx = 0.2f * qrSize / logoSize; + canvas.scale(sx, sx, qrSize / 2f, qrSize / 2f); + canvas.drawBitmap(logo, (qrSize - logoSize) / 2f, (qrSize - logoSize) / 2f, null); canvas.restore(); return logoBitmap; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java index 0052448..3bd60ec 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java @@ -126,7 +126,8 @@ public class WalletFragment extends Fragment sCurrency = view.findViewById(R.id.sCurrency); List currencies = new ArrayList<>(); currencies.add(Helper.BASE_CRYPTO); - currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); + if (Helper.SHOW_EXCHANGERATES) + currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); ArrayAdapter spinnerAdapter = new ArrayAdapter<>(Objects.requireNonNull(getContext()), R.layout.item_spinner_balance, currencies); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sCurrency.setAdapter(spinnerAdapter); diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java index 5114b41..190e956 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java @@ -117,32 +117,34 @@ public class SendAddressWizardFragment extends SendWizardFragment { View view = inflater.inflate(R.layout.fragment_send_address, container, false); - tvXmrTo = view.findViewById(R.id.tvXmrTo); - - ibCrypto = new HashMap<>(); - for (Crypto crypto : Crypto.values()) { - final ImageButton button = view.findViewById(crypto.getButtonId()); - ibCrypto.put(crypto, button); - button.setOnClickListener(v -> { - if (possibleCryptos.contains(crypto)) { - selectedCrypto = crypto; - updateCryptoButtons(false); - } else { - // show help what to do: - if (button.getId() != R.id.ibXMR) { - final String name = getResources().getStringArray(R.array.cryptos)[crypto.ordinal()]; - final String symbol = getCryptoForButton(button).getSymbol(); - tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help, name, symbol))); - tvXmrTo.setVisibility(View.VISIBLE); + if (Helper.ALLOW_SHIFT) { + tvXmrTo = view.findViewById(R.id.tvXmrTo); + ibCrypto = new HashMap<>(); + for (Crypto crypto : Crypto.values()) { + final ImageButton button = view.findViewById(crypto.getButtonId()); + ibCrypto.put(crypto, button); + button.setOnClickListener(v -> { + if (possibleCryptos.contains(crypto)) { + selectedCrypto = crypto; + updateCryptoButtons(false); } else { - tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help_xmr))); - tvXmrTo.setVisibility(View.VISIBLE); + // show help what to do: + if (button.getId() != R.id.ibXMR) { + final String name = getResources().getStringArray(R.array.cryptos)[crypto.ordinal()]; + final String symbol = getCryptoForButton(button).getSymbol(); + tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help, name, symbol))); + tvXmrTo.setVisibility(View.VISIBLE); + } else { + tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help_xmr))); + tvXmrTo.setVisibility(View.VISIBLE); + } } - } - }); + }); + } + updateCryptoButtons(true); + } else { + view.findViewById(R.id.llExchange).setVisibility(View.GONE); } - updateCryptoButtons(true); - etAddress = view.findViewById(R.id.etAddress); etAddress.getEditText().setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); etAddress.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() { @@ -285,6 +287,7 @@ public class SendAddressWizardFragment extends SendWizardFragment { } private void updateCryptoButtons(boolean noAddress) { + if (!Helper.ALLOW_SHIFT) return; for (Crypto crypto : Crypto.values()) { if (crypto == selectedCrypto) { selectedCrypto(crypto); @@ -447,7 +450,11 @@ public class SendAddressWizardFragment extends SendWizardFragment { BarcodeData barcodeData = sendListener.getBarcodeData(); if (barcodeData != null) { Timber.d("GOT DATA"); - + if (!Helper.ALLOW_SHIFT && (barcodeData.asset != Crypto.XMR)) { + Timber.d("BUT ONLY XMR SUPPORTED"); + barcodeData = null; + sendListener.setBarcodeData(barcodeData); + } if (barcodeData.address != null) { etAddress.getEditText().setText(barcodeData.address); possibleCryptos.clear(); diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java index e500e8c..e093573 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java @@ -57,6 +57,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.textfield.TextInputLayout; import com.m2049r.xmrwallet.BuildConfig; import com.m2049r.xmrwallet.R; +import com.m2049r.xmrwallet.data.Crypto; import com.m2049r.xmrwallet.model.WalletManager; import java.io.File; @@ -78,7 +79,10 @@ import timber.log.Timber; public class Helper { static public final String NOCRAZYPASS_FLAGFILE = ".nocrazypass"; - static public final String BASE_CRYPTO = "XMR"; + static public final String BASE_CRYPTO = Crypto.XMR.getSymbol(); + + static public final boolean SHOW_EXCHANGERATES = true; + static public final boolean ALLOW_SHIFT = true; static private final String WALLET_DIR = "wallets"; static private final String MONERO_DIR = "monero"; diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java index 5608270..8e5c4df 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java @@ -18,8 +18,6 @@ package com.m2049r.xmrwallet.util; import android.content.Context; import android.content.SharedPreferences; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -27,6 +25,9 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.dialog.HelpFragment; @@ -44,12 +45,13 @@ public class Notice { synchronized (Notice.class) { if (notices != null) return; notices = new ArrayList<>(); - notices.add( - new Notice(NOTICE_SHOW_XMRTO_ENABLED_SEND, - R.string.info_xmrto_enabled, - R.string.help_xmrto, - 1) - ); + if (Helper.ALLOW_SHIFT) + notices.add( + new Notice(NOTICE_SHOW_XMRTO_ENABLED_SEND, + R.string.info_xmrto_enabled, + R.string.help_xmrto, + 1) + ); notices.add( new Notice(NOTICE_SHOW_LEDGER, R.string.info_ledger_enabled, diff --git a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeEditText.java b/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeEditText.java index 6602cb7..0a04c84 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeEditText.java +++ b/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeEditText.java @@ -172,7 +172,8 @@ public class ExchangeEditText extends LinearLayout { } protected void setCurrencyAdapter(Spinner spinner, List currencies) { - currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); + if (Helper.SHOW_EXCHANGERATES) + currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); ArrayAdapter spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, currencies); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); diff --git a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeView.java b/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeView.java index f2a301c..aacce64 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeView.java +++ b/app/src/main/java/com/m2049r/xmrwallet/widget/ExchangeView.java @@ -155,7 +155,8 @@ public class ExchangeView extends LinearLayout { void setCurrencyAdapter(Spinner spinner) { List currencies = new ArrayList<>(); currencies.add(Helper.BASE_CRYPTO); - currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); + if (Helper.SHOW_EXCHANGERATES) + currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); ArrayAdapter spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, currencies); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); @@ -167,11 +168,7 @@ public class ExchangeView extends LinearLayout { etAmount = findViewById(R.id.etAmount); tvAmountB = findViewById(R.id.tvAmountB); sCurrencyA = findViewById(R.id.sCurrencyA); - ArrayAdapter adapter = ArrayAdapter.createFromResource(getContext(), R.array.currency, R.layout.item_spinner); - adapter.setDropDownViewResource(R.layout.item_spinner_dropdown_item); - sCurrencyA.setAdapter(adapter); sCurrencyB = findViewById(R.id.sCurrencyB); - sCurrencyB.setAdapter(adapter); evExchange = findViewById(R.id.evExchange); pbExchange = findViewById(R.id.pbExchange); diff --git a/app/src/main/res/layout/fragment_send_address.xml b/app/src/main/res/layout/fragment_send_address.xml index 29dcfcb..5e83958 100644 --- a/app/src/main/res/layout/fragment_send_address.xml +++ b/app/src/main/res/layout/fragment_send_address.xml @@ -60,6 +60,7 @@ diff --git a/external-libs/Makefile b/external-libs/Makefile index 96dc5f0..4bb56f3 100644 --- a/external-libs/Makefile +++ b/external-libs/Makefile @@ -45,10 +45,6 @@ VERSION: echo MONERUJO `git -C . branch | grep "^\*" | sed 's/^..//'` with MONERO `git -C monero branch | grep "^\*" | sed 's/^..//'` > VERSION clean: - -docker container rm monero-android-arm64 -f - -docker container rm monero-android-arm32 -f - -docker container rm monero-android-x86_64 -f - -docker container rm monero-android-x86 -f -rm -rf arm64-v8a -rm -rf armeabi-v7a -rm -rf x86_64 @@ -57,6 +53,10 @@ clean: -rm -f VERSION distclean: clean + -docker container rm monero-android-arm64 -f + -docker container rm monero-android-arm32 -f + -docker container rm monero-android-x86_64 -f + -docker container rm monero-android-x86 -f -docker image rm monero-android-arm64 -f -docker image rm monero-android-arm32 -f -docker image rm monero-android-x86_64 -f diff --git a/external-libs/VERSION b/external-libs/VERSION index 38fd6d9..ccf9458 100644 --- a/external-libs/VERSION +++ b/external-libs/VERSION @@ -1 +1 @@ -MONERUJO feature_dockerbuild with MONERO release-v0.17.1.9-monerujo +MONERUJO feature_refactor_some with MONERO feature_noaddress