mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-23 07:19:13 +00:00
Use AtomicReference instead of an array where needed
This commit is contained in:
parent
80b1967693
commit
9dc1b954d4
2 changed files with 17 additions and 13 deletions
|
@ -21,6 +21,7 @@ import java.io.InputStream;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
|
@ -363,13 +364,13 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
|
||||
// TODO: create a custom layout to show a message AND a checkbox
|
||||
final boolean[] checked = {true};
|
||||
final AtomicReference<Boolean> checked = new AtomicReference<>(true);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Export the database")
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
String filename;
|
||||
try {
|
||||
filename = _db.export(checked[0]);
|
||||
filename = _db.export(checked.get());
|
||||
} catch (DatabaseManagerException e) {
|
||||
Toast.makeText(getActivity(), getString(R.string.exporting_database_error), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
@ -387,7 +388,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int index, boolean isChecked) {
|
||||
checked[0] = isChecked;
|
||||
checked.set(isChecked);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,8 @@ import android.widget.TextView;
|
|||
|
||||
import com.mattprecious.swirl.SwirlView;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
|
@ -64,13 +66,14 @@ public class Dialogs {
|
|||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
|
||||
final Button[] buttonOK = new Button[1];
|
||||
final AtomicReference<Button> buttonOK = new AtomicReference<>();
|
||||
alert.setOnShowListener(dialog -> {
|
||||
buttonOK[0] = alert.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
buttonOK[0].setEnabled(false);
|
||||
Button button = alert.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setEnabled(false);
|
||||
buttonOK.set(button);
|
||||
|
||||
// replace the default listener
|
||||
buttonOK[0].setOnClickListener(v -> {
|
||||
button.setOnClickListener(v -> {
|
||||
if (!EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm)) {
|
||||
return;
|
||||
}
|
||||
|
@ -96,7 +99,7 @@ public class Dialogs {
|
|||
TextWatcher watcher = new TextWatcher() {
|
||||
public void onTextChanged(CharSequence c, int start, int before, int count) {
|
||||
boolean equal = EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm);
|
||||
buttonOK[0].setEnabled(equal);
|
||||
buttonOK.get().setEnabled(equal);
|
||||
}
|
||||
public void beforeTextChanged(CharSequence c, int start, int count, int after) { }
|
||||
public void afterTextChanged(Editable c) { }
|
||||
|
@ -114,7 +117,7 @@ public class Dialogs {
|
|||
|
||||
Cipher cipher;
|
||||
FingerprintSlot slot;
|
||||
final FingerprintUiHelper[] helper = new FingerprintUiHelper[1];
|
||||
final AtomicReference<FingerprintUiHelper> helper = new AtomicReference<>();
|
||||
FingerprintManager manager = FingerprintHelper.getManager(activity);
|
||||
|
||||
try {
|
||||
|
@ -130,11 +133,11 @@ public class Dialogs {
|
|||
.setView(view)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setOnDismissListener(d -> {
|
||||
helper[0].stopListening();
|
||||
helper.get().stopListening();
|
||||
})
|
||||
.show();
|
||||
|
||||
helper[0] = new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, new FingerprintUiHelper.Callback() {
|
||||
helper.set(new FingerprintUiHelper(manager, imgFingerprint, textFingerprint, new FingerprintUiHelper.Callback() {
|
||||
@Override
|
||||
public void onAuthenticated() {
|
||||
listener.onSlotResult(slot, cipher);
|
||||
|
@ -145,9 +148,9 @@ public class Dialogs {
|
|||
public void onError() {
|
||||
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
helper[0].startListening(new FingerprintManager.CryptoObject(cipher));
|
||||
helper.get().startListening(new FingerprintManager.CryptoObject(cipher));
|
||||
}
|
||||
|
||||
public interface SlotListener {
|
||||
|
|
Loading…
Add table
Reference in a new issue