mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 00:53:26 +02:00
Singleton handler
This commit is contained in:
@@ -40,9 +40,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcel;
|
||||
import android.os.PowerManager;
|
||||
import android.os.StatFs;
|
||||
@@ -1258,8 +1256,6 @@ public class Helper {
|
||||
static void authenticate(final FragmentActivity activity, final LifecycleOwner owner,
|
||||
Boolean enabled, final
|
||||
Runnable authenticated, final Runnable cancelled) {
|
||||
final Handler handler = new Handler();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
String pin = prefs.getString("pin", null);
|
||||
|
||||
@@ -1289,7 +1285,7 @@ public class Helper {
|
||||
if (errorCode != BiometricPrompt.ERROR_NEGATIVE_BUTTON &&
|
||||
errorCode != BiometricPrompt.ERROR_CANCELED &&
|
||||
errorCode != BiometricPrompt.ERROR_USER_CANCELED)
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ToastEx.makeText(activity,
|
||||
@@ -1298,20 +1294,20 @@ public class Helper {
|
||||
}
|
||||
});
|
||||
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
||||
Log.i("Biometric succeeded");
|
||||
setAuthenticated(activity);
|
||||
handler.post(authenticated);
|
||||
ApplicationEx.getMainHandler().post(authenticated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAuthenticationFailed() {
|
||||
Log.w("Biometric failed");
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1328,12 +1324,12 @@ public class Helper {
|
||||
}
|
||||
};
|
||||
|
||||
handler.postDelayed(cancelPrompt, 60 * 1000L);
|
||||
ApplicationEx.getMainHandler().postDelayed(cancelPrompt, 60 * 1000L);
|
||||
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroy() {
|
||||
handler.post(cancelPrompt);
|
||||
ApplicationEx.getMainHandler().post(cancelPrompt);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1352,21 +1348,21 @@ public class Helper {
|
||||
|
||||
if (pin.equals(entered)) {
|
||||
setAuthenticated(activity);
|
||||
handler.post(authenticated);
|
||||
ApplicationEx.getMainHandler().post(authenticated);
|
||||
} else
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
handler.post(cancelled);
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
.create();
|
||||
@@ -1390,7 +1386,7 @@ public class Helper {
|
||||
}
|
||||
});
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
etPin.requestFocus();
|
||||
@@ -1413,8 +1409,6 @@ public class Helper {
|
||||
|
||||
static void selectKeyAlias(final Activity activity, final LifecycleOwner owner, final String alias, final IKeyAlias intf) {
|
||||
final Context context = activity.getApplicationContext();
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -1431,7 +1425,7 @@ public class Helper {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
KeyChain.choosePrivateKeyAlias(activity, new KeyChainAliasCallback() {
|
||||
@@ -1447,7 +1441,7 @@ public class Helper {
|
||||
}
|
||||
|
||||
private void deliver(final String selected) {
|
||||
handler.post(new Runnable() {
|
||||
ApplicationEx.getMainHandler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
||||
|
||||
Reference in New Issue
Block a user