Skip to content

Commit

Permalink
lock in background (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2049r authored Apr 5, 2024
1 parent 451371c commit 48577e4
Show file tree
Hide file tree
Showing 37 changed files with 150 additions and 29 deletions.
37 changes: 37 additions & 0 deletions app/src/main/java/com/m2049r/xmrwallet/LockFragment.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/m2049r/xmrwallet/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.Map;
import java.util.Set;

import lombok.Getter;
import timber.log.Timber;

public class LoginActivity extends BaseActivity
Expand Down
45 changes: 33 additions & 12 deletions app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand All @@ -70,6 +71,7 @@
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import timber.log.Timber;

public class WalletActivity extends BaseActivity implements WalletFragment.Listener,
Expand Down Expand Up @@ -200,12 +202,6 @@ public String getTxAddress(int major, int minor) {
return getWallet().getSubaddress(major, minor);
}

@Override
protected void onStart() {
super.onStart();
Timber.d("onStart()");
}

private void startWalletService() {
Bundle extras = getIntent().getExtras();
if (extras != null) {
Expand Down Expand Up @@ -239,12 +235,6 @@ private void onWalletRescan() {
}
}

@Override
protected void onStop() {
Timber.d("onStop()");
super.onStop();
}

@Override
protected void onDestroy() {
Timber.d("onDestroy()");
Expand Down Expand Up @@ -498,12 +488,16 @@ void disconnectWalletService() {
@Override
protected void onPause() {
Timber.d("onPause()");
lock();
super.onPause();
}

@Override
protected void onResume() {
super.onResume();
if (locked) {
unlock();
}
Timber.d("onResume()");
}

Expand Down Expand Up @@ -1216,4 +1210,31 @@ public void loadPocketChangeSettings() {
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());
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/m2049r/xmrwallet/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ public void onTextChanged(CharSequence s, int start,
.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) {
Expand All @@ -487,6 +486,7 @@ public void onTextChanged(CharSequence s, int start,
}
dialog.cancel();
openDialog = null;
action.fail(wallet);
});
openDialog = alertDialogBuilder.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/m2049r/xmrwallet/util/ThemeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
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;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-cat/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
9 changes: 5 additions & 4 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
11 changes: 11 additions & 0 deletions app/src/main/res/values-he/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-sr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ta/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Loading

0 comments on commit 48577e4

Please sign in to comment.