mirror of https://github.com/m2049r/xmrwallet.git
lock in background (#936)
This commit is contained in:
parent
451371cd92
commit
48577e46aa
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class LockFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
Timber.d("onCreateView");
|
||||
final FrameLayout frame = new FrameLayout(requireContext());
|
||||
frame.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
return frame;
|
||||
}
|
||||
}
|
|
@ -76,6 +76,7 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.Getter;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class LoginActivity extends BaseActivity
|
||||
|
|
|
@ -45,6 +45,7 @@ import androidx.core.view.GravityCompat;
|
|||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
@ -70,6 +71,7 @@ import com.m2049r.xmrwallet.widget.Toolbar;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class WalletActivity extends BaseActivity implements WalletFragment.Listener,
|
||||
|
@ -200,12 +202,6 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
|||
return getWallet().getSubaddress(major, minor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Timber.d("onStart()");
|
||||
}
|
||||
|
||||
private void startWalletService() {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
|
@ -239,12 +235,6 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Timber.d("onStop()");
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Timber.d("onDestroy()");
|
||||
|
@ -498,12 +488,16 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
|||
@Override
|
||||
protected void onPause() {
|
||||
Timber.d("onPause()");
|
||||
lock();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (locked) {
|
||||
unlock();
|
||||
}
|
||||
Timber.d("onResume()");
|
||||
}
|
||||
|
||||
|
@ -1216,4 +1210,31 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
|||
getWallet().setPocketChangeSetting(Wallet.PocketChangeSetting.from(settings));
|
||||
}
|
||||
|
||||
@Getter
|
||||
private boolean locked = false;
|
||||
|
||||
private void unlock() {
|
||||
Helper.promptPassword(WalletActivity.this, getWalletName(), false, new Helper.PasswordAction() {
|
||||
@Override
|
||||
public void act(String walletName, String password, boolean fingerprintUsed) {
|
||||
popFragmentStack(null);
|
||||
locked = false;
|
||||
Timber.d("locked: %b", isLocked());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String walletName) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void lock() {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getBoolean(getString(R.string.preferred_lock), false)) {
|
||||
replaceFragment(new LockFragment(), null, null);
|
||||
locked = true;
|
||||
}
|
||||
Timber.d("locked %b", isLocked());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -478,7 +478,6 @@ public class Helper {
|
|||
.setPositiveButton(context.getString(R.string.label_ok), null)
|
||||
.setNegativeButton(context.getString(R.string.label_cancel),
|
||||
(dialog, id) -> {
|
||||
action.fail(wallet);
|
||||
Helper.hideKeyboardAlways((Activity) context);
|
||||
cancelSignal.cancel();
|
||||
if (passwordTask != null) {
|
||||
|
@ -487,6 +486,7 @@ public class Helper {
|
|||
}
|
||||
dialog.cancel();
|
||||
openDialog = null;
|
||||
action.fail(wallet);
|
||||
});
|
||||
openDialog = alertDialogBuilder.create();
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ import android.Manifest;
|
|||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.m2049r.xmrwallet.BuildConfig;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
|
|
|
@ -19,7 +19,8 @@ package com.m2049r.xmrwallet.util;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ package com.m2049r.xmrwallet.util;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
package com.m2049r.xmrwallet.util;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
import com.m2049r.xmrwallet.model.NetworkType;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import com.m2049r.xmrwallet.service.exchange.api.ExchangeApi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class ServiceHelper {
|
||||
|
|
|
@ -19,7 +19,9 @@ package com.m2049r.xmrwallet.util;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
|
|
@ -445,4 +445,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -446,4 +446,6 @@
|
|||
<string name="pocketchange_create_title">Erstelle schnellen Wechsel</string>
|
||||
|
||||
<string name="label_apply">ANWENDEN</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -447,4 +447,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -445,4 +445,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -438,9 +438,10 @@
|
|||
<string name="tx_locked">Monto trabado hasta el bloque %1$d (faltan %2$d bloques ≈ %3$,.2f días)</string>
|
||||
|
||||
<string name="label_streetmode">Modo calle activado\nSólo se ºmostrarán transacciones nuevas</string>
|
||||
<string name="pocketchange_info">Para reducir el tiempo entre pagos, Monerujo puede crear cambio de más al enviar a costo de comisiones más altas. Va a crear e intentar mantener 10 monedas del monto seleccionado.</string>
|
||||
<string name="pocketchange_create_title">Crear cambio</string>
|
||||
<string name="pocketchange_info">Para reducir el tiempo entre pagos, Monerujo puede crear cambio de más al enviar a costo de comisiones más altas. Va a crear e intentar mantener 10 monedas del monto seleccionado.</string>
|
||||
<string name="pocketchange_create_title">Crear cambio</string>
|
||||
|
||||
<string name="label_apply">APLICAR</string>
|
||||
|
||||
<string name="label_apply">APLICAR</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -445,4 +445,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -685,4 +685,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -458,4 +458,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -436,4 +436,15 @@
|
|||
</string-array>
|
||||
|
||||
<string name="message_qr_failed">לא הצליח ליצור QR לשיתוף!</string>
|
||||
|
||||
<string name="tx_locked">Transaction amount locked until block %1$d (in %2$d blocks ≈ %3$,.2f days)</string>
|
||||
|
||||
<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>
|
||||
|
||||
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
|
||||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -449,4 +449,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -450,4 +450,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -450,4 +450,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -447,4 +447,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -447,4 +447,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -440,4 +440,6 @@ aqui.</string>
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -451,4 +451,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -447,4 +447,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -451,4 +451,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -448,4 +448,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -446,4 +446,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -439,4 +439,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -445,4 +445,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -451,4 +451,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -372,4 +372,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -446,4 +446,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -469,6 +469,7 @@
|
|||
<string name="preferred_theme" translatable="false">preferred_theme</string>
|
||||
<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="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>
|
||||
|
@ -498,4 +499,6 @@
|
|||
<string name="pocketchange_create_title">Create Change</string>
|
||||
|
||||
<string name="label_apply">APPLY</string>
|
||||
|
||||
<string name="setting_lock">Lock Wallet in Background</string>
|
||||
</resources>
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
app:key="@string/preferred_theme"
|
||||
app:title="@string/setting_theme"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/preferred_lock"
|
||||
android:title="@string/setting_lock" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory app:title="@string/title_info">
|
||||
<Preference
|
||||
|
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.3.0'
|
||||
classpath 'com.android.tools.build:gradle:8.3.1'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue