A little bit of refactoring
This commit is contained in:
parent
04a511d3f4
commit
c46167bfe7
2 changed files with 23 additions and 18 deletions
|
@ -53,10 +53,10 @@ import static org.shadowice.flocke.andotp.Utilities.Settings.AuthMethod;
|
||||||
public class AuthenticateActivity extends ThemedActivity
|
public class AuthenticateActivity extends ThemedActivity
|
||||||
implements EditText.OnEditorActionListener {
|
implements EditText.OnEditorActionListener {
|
||||||
public static final String EXTRA_NAME_PASSWORD_KEY = "password_key";
|
public static final String EXTRA_NAME_PASSWORD_KEY = "password_key";
|
||||||
public static final String EXTRA_NAME_RELOAD_ADAPTER = "reload_adapter";
|
public static final String EXTRA_NAME_SAVE_DATABASE = "save_database";
|
||||||
public static final String EXTRA_NAME_MESSAGE_ID = "message_id";
|
public static final String EXTRA_NAME_MESSAGE = "message";
|
||||||
|
|
||||||
boolean reloadAdapter = false;
|
boolean saveDatabase = false;
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
View v = stub.inflate();
|
View v = stub.inflate();
|
||||||
|
|
||||||
Intent callingIntent = getIntent();
|
Intent callingIntent = getIntent();
|
||||||
reloadAdapter = callingIntent.getBooleanExtra(EXTRA_NAME_RELOAD_ADAPTER, false);
|
saveDatabase = callingIntent.getBooleanExtra(EXTRA_NAME_SAVE_DATABASE, false);
|
||||||
int labelMsg = callingIntent.getIntExtra(EXTRA_NAME_MESSAGE_ID, R.string.auth_msg_authenticate);
|
int labelMsg = callingIntent.getIntExtra(EXTRA_NAME_MESSAGE, R.string.auth_msg_authenticate);
|
||||||
|
|
||||||
TextView passwordLabel = v.findViewById(R.id.passwordLabel);
|
TextView passwordLabel = v.findViewById(R.id.passwordLabel);
|
||||||
TextInputLayout passwordLayout = v.findViewById(R.id.passwordLayout);
|
TextInputLayout passwordLayout = v.findViewById(R.id.passwordLayout);
|
||||||
|
@ -193,7 +193,7 @@ public class AuthenticateActivity extends ThemedActivity
|
||||||
public void finishWithResult(boolean success, byte[] key) {
|
public void finishWithResult(boolean success, byte[] key) {
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
|
|
||||||
data.putExtra(EXTRA_NAME_RELOAD_ADAPTER, reloadAdapter);
|
data.putExtra(EXTRA_NAME_SAVE_DATABASE, saveDatabase);
|
||||||
|
|
||||||
if (key != null)
|
if (key != null)
|
||||||
data.putExtra(EXTRA_NAME_PASSWORD_KEY, key);
|
data.putExtra(EXTRA_NAME_PASSWORD_KEY, key);
|
||||||
|
|
|
@ -74,9 +74,9 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_MESSAGE_ID;
|
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_MESSAGE;
|
||||||
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_PASSWORD_KEY;
|
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_PASSWORD_KEY;
|
||||||
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_RELOAD_ADAPTER;
|
import static org.shadowice.flocke.andotp.Activities.AuthenticateActivity.EXTRA_NAME_SAVE_DATABASE;
|
||||||
import static org.shadowice.flocke.andotp.Activities.BackupActivity.EXTRA_NAME_ENCRYPTION_KEY;
|
import static org.shadowice.flocke.andotp.Activities.BackupActivity.EXTRA_NAME_ENCRYPTION_KEY;
|
||||||
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
|
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public class MainActivity extends BaseActivity
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void authenticate(int messageId, boolean reloadAdapter) {
|
public void authenticate(int messageId, boolean saveDatabase) {
|
||||||
Settings.AuthMethod authMethod = settings.getAuthMethod();
|
Settings.AuthMethod authMethod = settings.getAuthMethod();
|
||||||
|
|
||||||
if (authMethod == Settings.AuthMethod.DEVICE) {
|
if (authMethod == Settings.AuthMethod.DEVICE) {
|
||||||
|
@ -138,8 +138,8 @@ public class MainActivity extends BaseActivity
|
||||||
}
|
}
|
||||||
} else if (authMethod == Settings.AuthMethod.PASSWORD || authMethod == Settings.AuthMethod.PIN) {
|
} else if (authMethod == Settings.AuthMethod.PASSWORD || authMethod == Settings.AuthMethod.PIN) {
|
||||||
Intent authIntent = new Intent(this, AuthenticateActivity.class);
|
Intent authIntent = new Intent(this, AuthenticateActivity.class);
|
||||||
authIntent.putExtra(EXTRA_NAME_RELOAD_ADAPTER, reloadAdapter);
|
authIntent.putExtra(EXTRA_NAME_SAVE_DATABASE, saveDatabase);
|
||||||
authIntent.putExtra(EXTRA_NAME_MESSAGE_ID, messageId);
|
authIntent.putExtra(EXTRA_NAME_MESSAGE, messageId);
|
||||||
startActivityForResult(authIntent, INTENT_INTERNAL_AUTHENTICATE);
|
startActivityForResult(authIntent, INTENT_INTERNAL_AUTHENTICATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ public class MainActivity extends BaseActivity
|
||||||
if (requireAuthentication) {
|
if (requireAuthentication) {
|
||||||
if (settings.getAuthMethod() != Settings.AuthMethod.NONE) {
|
if (settings.getAuthMethod() != Settings.AuthMethod.NONE) {
|
||||||
requireAuthentication = false;
|
requireAuthentication = false;
|
||||||
authenticate(R.string.auth_msg_authenticate, true);
|
authenticate(R.string.auth_msg_authenticate, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (encryptionType == Constants.EncryptionType.KEYSTORE) {
|
if (encryptionType == Constants.EncryptionType.KEYSTORE) {
|
||||||
|
@ -331,7 +331,7 @@ public class MainActivity extends BaseActivity
|
||||||
populateAdapter();
|
populateAdapter();
|
||||||
} else if (encryptionType == Constants.EncryptionType.PASSWORD) {
|
} else if (encryptionType == Constants.EncryptionType.PASSWORD) {
|
||||||
if (adapter.getEncryptionKey() == null) {
|
if (adapter.getEncryptionKey() == null) {
|
||||||
authenticate(R.string.auth_msg_authenticate,true);
|
authenticate(R.string.auth_msg_authenticate,false);
|
||||||
} else {
|
} else {
|
||||||
populateAdapter();
|
populateAdapter();
|
||||||
}
|
}
|
||||||
|
@ -365,8 +365,13 @@ public class MainActivity extends BaseActivity
|
||||||
adapter.saveEntries();
|
adapter.saveEntries();
|
||||||
} else if (settings.getEncryption() == Constants.EncryptionType.PASSWORD) {
|
} else if (settings.getEncryption() == Constants.EncryptionType.PASSWORD) {
|
||||||
encryptionType = Constants.EncryptionType.PASSWORD;
|
encryptionType = Constants.EncryptionType.PASSWORD;
|
||||||
authenticate(R.string.auth_msg_confirm,false);
|
authenticate(R.string.auth_msg_confirm,true);
|
||||||
}
|
}
|
||||||
|
} else if (key.equals(getString(R.string.settings_key_auth)) ||
|
||||||
|
key.equals(getString(R.string.settings_key_auth_password_pbkdf2)) ||
|
||||||
|
key.equals(getString(R.string.settings_key_auth_pin_pbkdf2))) {
|
||||||
|
if (encryptionType == Constants.EncryptionType.PASSWORD)
|
||||||
|
authenticate(R.string.auth_msg_confirm, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,14 +425,14 @@ public class MainActivity extends BaseActivity
|
||||||
encryptionKey = EncryptionHelper.generateSymmetricKey(credentialSeed);
|
encryptionKey = EncryptionHelper.generateSymmetricKey(credentialSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean reloadAdapter = intent.getBooleanExtra(EXTRA_NAME_RELOAD_ADAPTER, false);
|
boolean saveDatabase = intent.getBooleanExtra(EXTRA_NAME_SAVE_DATABASE, false);
|
||||||
|
|
||||||
adapter.setEncryptionKey(encryptionKey);
|
adapter.setEncryptionKey(encryptionKey);
|
||||||
|
|
||||||
if (reloadAdapter)
|
if (saveDatabase)
|
||||||
populateAdapter();
|
|
||||||
else
|
|
||||||
adapter.saveEntries();
|
adapter.saveEntries();
|
||||||
|
|
||||||
|
populateAdapter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue