1
mirror of https://github.com/m2049r/xmrwallet synced 2025-09-04 00:53:36 +02:00

Compare commits

..

4 Commits

Author SHA1 Message Date
m2049r
989d52b33d Option to remember and reuse selected fiat (#967) 2024-11-08 12:01:35 +01:00
m2049r
a3c0ca7ebe bump version 2024-11-05 08:46:32 +01:00
m2049r
c9132d7d97 more permission checks 2024-11-05 08:42:14 +01:00
m2049r
758b042680 fix some crashing if bluetooth pemissions are not given (#965)
* show error instead of crashing

* ignore if fragement is no longer

* bump version
2024-11-03 16:19:35 +01:00
9 changed files with 99 additions and 20 deletions

View File

@@ -8,8 +8,8 @@ android {
compileSdk 35
minSdkVersion 21
targetSdkVersion 35
versionCode 4102
versionName "4.1.2 'Exolix'"
versionCode 4105
versionName "4.1.5 'Exolix'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {

View File

@@ -1411,7 +1411,7 @@ public class LoginActivity extends BaseActivity
Timber.d("onDeviceConnected: %s", connectedDeviceName);
try {
SidekickConnectFragment f = (SidekickConnectFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_container);
assert f != null;
if (f == null) return;
f.allowClick();
} catch (ClassCastException ex) {
// ignore it

View File

@@ -27,6 +27,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -75,12 +76,13 @@ public class SidekickConnectFragment extends Fragment
@Override
public void onPause() {
Timber.d("onPause()");
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED)
throw new IllegalStateException("Bluetooth permission not granted");
if (bluetoothAdapter.isDiscovering()) {
bluetoothAdapter.cancelDiscovery();
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show();
} else {
if (bluetoothAdapter.isDiscovering()) {
bluetoothAdapter.cancelDiscovery();
}
}
// the the activity we are connected? why? it can ask the bluetoothservice...
super.onPause();
}
@@ -116,8 +118,10 @@ public class SidekickConnectFragment extends Fragment
private void populateList() {
List<BluetoothInfo> items = new ArrayList<>();
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED)
throw new IllegalStateException("Bluetooth permission not granted");
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show();
return;
}
for (BluetoothDevice device : bluetoothAdapter.getBondedDevices()) {
final int deviceCLass = device.getBluetoothClass().getDeviceClass();
switch (deviceCLass) {
@@ -158,8 +162,10 @@ public class SidekickConnectFragment extends Fragment
// Make sure we're not doing discovery anymore
if (bluetoothAdapter != null) {
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED)
throw new IllegalStateException("Bluetooth permission not granted");
if (ActivityCompat.checkSelfPermission(requireContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(requireContext(), "Bluetooth permission not granted", Toast.LENGTH_LONG).show();
return;
}
bluetoothAdapter.cancelDiscovery();
}
}

View File

@@ -51,6 +51,7 @@ import com.m2049r.xmrwallet.service.exchange.api.ExchangeCallback;
import com.m2049r.xmrwallet.service.exchange.api.ExchangeRate;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.ServiceHelper;
import com.m2049r.xmrwallet.util.StickyFiatHelper;
import com.m2049r.xmrwallet.util.ThemeHelper;
import com.m2049r.xmrwallet.widget.Toolbar;
@@ -131,6 +132,7 @@ public class WalletFragment extends Fragment
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(requireContext(), R.layout.item_spinner_balance, currencies);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sCurrency.setAdapter(spinnerAdapter);
StickyFiatHelper.setPreferredCurrencyPosition(sCurrency);
bSend = view.findViewById(R.id.bSend);
bReceive = view.findViewById(R.id.bReceive);
@@ -182,6 +184,7 @@ public class WalletFragment extends Fragment
sCurrency.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
StickyFiatHelper.setPreferredFiatSymbol(requireContext(), (String) sCurrency.getSelectedItem());
refreshBalance();
}
@@ -315,13 +318,7 @@ public class WalletFragment extends Fragment
balanceCurrency = Helper.BASE_CRYPTO;
balanceRate = 1.0;
} else {
int spinnerPosition = ((ArrayAdapter) sCurrency.getAdapter()).getPosition(exchangeRate.getQuoteCurrency());
if (spinnerPosition < 0) { // requested currency not in list
Timber.e("Requested currency not in list %s", exchangeRate.getQuoteCurrency());
sCurrency.setSelection(0, true);
} else {
sCurrency.setSelection(spinnerPosition, true);
}
StickyFiatHelper.setCurrencyPosition(sCurrency, exchangeRate.getQuoteCurrency());
balanceCurrency = exchangeRate.getQuoteCurrency();
balanceRate = exchangeRate.getRate();
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 m2049r
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.m2049r.xmrwallet.util;
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import androidx.preference.PreferenceManager;
import com.m2049r.xmrwallet.R;
public class StickyFiatHelper {
public static String getPreferredFiatSymbol(Context ctx) {
if (PreferenceManager.getDefaultSharedPreferences(ctx)
.getBoolean(ctx.getString(R.string.preferred_stickyfiat), false)) {
return PreferenceManager.getDefaultSharedPreferences(ctx)
.getString(ctx.getString(R.string.preferred_stickyfiat_pref), Helper.BASE_CRYPTO);
}
return null;
}
public static void setPreferredFiatSymbol(Context ctx, String symbol) {
if (PreferenceManager.getDefaultSharedPreferences(ctx)
.getBoolean(ctx.getString(R.string.preferred_stickyfiat), false)) {
PreferenceManager.getDefaultSharedPreferences(ctx).edit()
.putString(ctx.getString(R.string.preferred_stickyfiat_pref), symbol).apply();
}
}
public static void setPreferredCurrencyPosition(Spinner spinner) {
String stickyFiat = StickyFiatHelper.getPreferredFiatSymbol(spinner.getContext());
if (stickyFiat != null) {
StickyFiatHelper.setCurrencyPosition(spinner, stickyFiat);
}
}
public static void setCurrencyPosition(Spinner spinner, String symbol) {
int spinnerPosition = ((ArrayAdapter) spinner.getAdapter()).getPosition(symbol);
if (spinnerPosition < 0) { // requested currency not in list
spinner.setSelection(0, true);
} else {
spinner.setSelection(spinnerPosition, true);
}
}
}

View File

@@ -41,6 +41,7 @@ import com.m2049r.xmrwallet.service.exchange.api.ExchangeCallback;
import com.m2049r.xmrwallet.service.exchange.api.ExchangeRate;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.ServiceHelper;
import com.m2049r.xmrwallet.util.StickyFiatHelper;
import com.m2049r.xmrwallet.util.ThemeHelper;
import java.util.ArrayList;
@@ -181,7 +182,8 @@ public class ExchangeEditText extends LinearLayout {
}
void setInitialSpinnerSelections(Spinner baseSpinner, Spinner quoteSpinner) {
baseSpinner.setSelection(0, true);
//baseSpinner.setSelection(0, true);
StickyFiatHelper.setPreferredCurrencyPosition(baseSpinner);
quoteSpinner.setSelection(0, true);
}

View File

@@ -44,6 +44,7 @@ import com.m2049r.xmrwallet.service.exchange.api.ExchangeCallback;
import com.m2049r.xmrwallet.service.exchange.api.ExchangeRate;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.ServiceHelper;
import com.m2049r.xmrwallet.util.StickyFiatHelper;
import com.m2049r.xmrwallet.util.ThemeHelper;
import java.util.ArrayList;
@@ -174,6 +175,7 @@ public class ExchangeView extends LinearLayout {
pbExchange = findViewById(R.id.pbExchange);
setCurrencyAdapter(sCurrencyA);
StickyFiatHelper.setPreferredCurrencyPosition(sCurrencyA);
setCurrencyAdapter(sCurrencyB);
// make progress circle gray

View File

@@ -461,6 +461,7 @@
<string name="preferred_nightmode" translatable="false">preferred_nightmode</string>
<string name="preferred_locale" translatable="false">preferred_locale</string>
<string name="preferred_lock" translatable="false">preferred_lock</string>
<string name="preferred_stickyfiat" translatable="false">preferred_stickyfiat</string>
<string name="about_info" translatable="false">about_info</string>
<string name="privacy_info" translatable="false">privacy_info</string>
<string name="credits_info" translatable="false">credits_info</string>
@@ -510,4 +511,8 @@
<string name="open_wallet_sidekick_missing">Please connect Sidekick device</string>
<string name="fab_restore_sidekick">Restore from Sidekick</string>
<string name="sidekick_connected">Sidekick Connected</string>
<string name="setting_stickyfiat">Sticky Fiat</string>
<string name="setting_stickyfiat_summary">Remember last used fiat currency</string>
<string name="preferred_stickyfiat_pref" translatable="false">preferred_stickyfiat_pref</string>
</resources>

View File

@@ -24,6 +24,11 @@
android:defaultValue="false"
android:key="@string/preferred_lock"
android:title="@string/setting_lock" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/preferred_stickyfiat"
android:summary="@string/setting_stickyfiat_summary"
android:title="@string/setting_stickyfiat" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/title_info">
<Preference