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