mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix database creation workflow
This commit is contained in:
@@ -4,16 +4,16 @@ import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
|
||||
public abstract class ActionDatabaseRunnable extends RunnableOnFinish {
|
||||
public abstract class ActionWithSaveDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
protected Database mDb;
|
||||
protected Context mContext;
|
||||
protected boolean mDontSave;
|
||||
protected Database mDatabase;
|
||||
|
||||
public ActionDatabaseRunnable(Context context, Database db, OnFinishRunnable finish, boolean dontSave) {
|
||||
public ActionWithSaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mDatabase = database;
|
||||
this.mContext = context;
|
||||
this.mDontSave = dontSave;
|
||||
this.mFinish = new AfterActionRunnable(finish);
|
||||
@@ -22,10 +22,14 @@ public abstract class ActionDatabaseRunnable extends RunnableOnFinish {
|
||||
@Override
|
||||
public void run() {
|
||||
// Commit to disk
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, mDb, mFinish, mDontSave);
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, mDatabase, mFinish, mDontSave);
|
||||
save.run();
|
||||
}
|
||||
|
||||
public void runWithoutSaveDatabase() {
|
||||
mFinish.run();
|
||||
}
|
||||
|
||||
abstract protected void onFinish(boolean success, String message);
|
||||
|
||||
private class AfterActionRunnable extends OnFinishRunnable {
|
||||
@@ -37,6 +41,7 @@ public abstract class ActionDatabaseRunnable extends RunnableOnFinish {
|
||||
@Override
|
||||
public void run() {
|
||||
onFinish(mSuccess, mMessage);
|
||||
super.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,17 +30,17 @@ import com.kunzisoft.keepass.utils.UriUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssignPasswordInDBRunnable extends ActionDatabaseRunnable {
|
||||
public class AssignPasswordInDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||
|
||||
private String mPassword;
|
||||
private Uri mKeyfile;
|
||||
private byte[] mBackupKey;
|
||||
|
||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||
this(ctx, db, password, keyfile, finish, false);
|
||||
}
|
||||
|
||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||
public AssignPasswordInDatabaseRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(ctx, db, finish, dontSave);
|
||||
|
||||
this.mPassword = password;
|
||||
@@ -49,7 +49,7 @@ public class AssignPasswordInDBRunnable extends ActionDatabaseRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PwDatabase pm = mDb.getPwDatabase();
|
||||
PwDatabase pm = mDatabase.getPwDatabase();
|
||||
|
||||
mBackupKey = new byte[pm.getMasterKey().length];
|
||||
System.arraycopy(pm.getMasterKey(), 0, mBackupKey, 0, mBackupKey.length);
|
||||
@@ -58,31 +58,27 @@ public class AssignPasswordInDBRunnable extends ActionDatabaseRunnable {
|
||||
try {
|
||||
InputStream is = UriUtil.getUriInputStream(mContext, mKeyfile);
|
||||
pm.retrieveMasterKey(mPassword, is);
|
||||
} catch (InvalidKeyFileException e) {
|
||||
// Save Database
|
||||
super.run();
|
||||
} catch (InvalidKeyFileException|IOException e) {
|
||||
erase(mBackupKey);
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
erase(mBackupKey);
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
super.runWithoutSaveDatabase();
|
||||
}
|
||||
|
||||
// Save Database
|
||||
super.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if (!success) {
|
||||
// Erase the current master key
|
||||
erase(mDb.getPwDatabase().getMasterKey());
|
||||
mDb.getPwDatabase().setMasterKey(mBackupKey);
|
||||
erase(mDatabase.getPwDatabase().getMasterKey());
|
||||
mDatabase.getPwDatabase().setMasterKey(mBackupKey);
|
||||
}
|
||||
}
|
||||
|
||||
/** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
||||
* @param array
|
||||
/**
|
||||
* Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory
|
||||
*/
|
||||
private void erase(byte[] array) {
|
||||
if ( array == null ) return;
|
||||
@@ -26,18 +26,18 @@ import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.utils.UriUtil;
|
||||
|
||||
public class CreateDBRunnable extends RunnableOnFinish {
|
||||
public class CreateDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
private Context mContext;
|
||||
private boolean mDontSave;
|
||||
private String mFilename;
|
||||
private boolean mDontSave;
|
||||
private Context ctx;
|
||||
|
||||
public CreateDBRunnable(Context ctx, String filename, OnFinishRunnable finish, boolean dontSave) {
|
||||
public CreateDatabaseRunnable(Context mContext, String filename, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
mFilename = filename;
|
||||
mDontSave = dontSave;
|
||||
this.ctx = ctx;
|
||||
this.mContext = mContext;
|
||||
this.mDontSave = dontSave;
|
||||
this.mFilename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,8 +56,9 @@ public class CreateDBRunnable extends RunnableOnFinish {
|
||||
App.clearShutdown();
|
||||
|
||||
// Commit changes
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(ctx, db, mFinish, mDontSave);
|
||||
SaveDatabaseRunnable save = new SaveDatabaseRunnable(mContext, db, mFinish, mDontSave);
|
||||
mFinish = null;
|
||||
|
||||
save.run();
|
||||
}
|
||||
}
|
||||
@@ -42,33 +42,33 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LoadDBRunnable extends RunnableOnFinish {
|
||||
private static final String TAG = LoadDBRunnable.class.getName();
|
||||
public class LoadDatabaseRunnable extends RunnableOnFinish {
|
||||
private static final String TAG = LoadDatabaseRunnable.class.getName();
|
||||
|
||||
private Context mContext;
|
||||
private Database mDatabase;
|
||||
private Uri mUri;
|
||||
private String mPass;
|
||||
private Uri mKey;
|
||||
private Database mDb;
|
||||
private Context mCtx;
|
||||
private boolean mRememberKeyfile;
|
||||
|
||||
public LoadDBRunnable(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
|
||||
public LoadDatabaseRunnable(Context context, Database database, Uri uri, String pass, Uri key, OnFinishRunnable finish) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
mCtx = ctx;
|
||||
mUri = uri;
|
||||
mPass = pass;
|
||||
mKey = key;
|
||||
this.mContext = context;
|
||||
this.mDatabase = database;
|
||||
this.mUri = uri;
|
||||
this.mPass = pass;
|
||||
this.mKey = key;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default));
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
this.mRememberKeyfile = prefs.getBoolean(context.getString(R.string.keyfile_key), context.getResources().getBoolean(R.bool.keyfile_default));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mDb.loadData(mCtx, mUri, mPass, mKey, mStatus);
|
||||
mDatabase.loadData(mContext, mUri, mPass, mKey, mStatus);
|
||||
|
||||
saveFileData(mUri, mKey);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
||||
catchError(e, R.string.error_invalid_db);
|
||||
return;
|
||||
} catch (OutOfMemoryError e) {
|
||||
String errorMessage = mCtx.getString(R.string.error_out_of_memory);
|
||||
String errorMessage = mContext.getString(R.string.error_out_of_memory);
|
||||
Log.e(TAG, errorMessage, e);
|
||||
finish(false, errorMessage);
|
||||
return;
|
||||
@@ -121,7 +121,7 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
||||
}
|
||||
|
||||
private void catchError(Exception e, @StringRes int messageId) {
|
||||
String errorMessage = mCtx.getString(messageId);
|
||||
String errorMessage = mContext.getString(messageId);
|
||||
Log.e(TAG, errorMessage, e);
|
||||
finish(false, errorMessage);
|
||||
}
|
||||
@@ -134,6 +134,4 @@ public class LoadDBRunnable extends RunnableOnFinish {
|
||||
App.getFileHistory().createFile(uri, key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -28,16 +28,16 @@ import java.io.IOException;
|
||||
|
||||
public class SaveDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
private Context mCtx;
|
||||
private Database mDb;
|
||||
private Context mContext;
|
||||
private Database mDatabase;
|
||||
private boolean mDontSave;
|
||||
|
||||
public SaveDatabaseRunnable(Context ctx, Database db, OnFinishRunnable finish, boolean dontSave) {
|
||||
public SaveDatabaseRunnable(Context context, Database database, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
this.mDb = db;
|
||||
this.mContext = context;
|
||||
this.mDatabase = database;
|
||||
this.mDontSave = dontSave;
|
||||
this.mCtx = ctx;
|
||||
}
|
||||
|
||||
public SaveDatabaseRunnable(Context ctx, Database db, OnFinishRunnable finish) {
|
||||
@@ -49,7 +49,7 @@ public class SaveDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
if ( ! mDontSave ) {
|
||||
try {
|
||||
mDb.saveData(mCtx);
|
||||
mDatabase.saveData(mContext);
|
||||
} catch (IOException e) {
|
||||
finish(false, e.getMessage());
|
||||
return;
|
||||
|
||||
@@ -4,9 +4,9 @@ import android.content.Context;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwNode;
|
||||
import com.kunzisoft.keepass.database.action.ActionDatabaseRunnable;
|
||||
import com.kunzisoft.keepass.database.action.ActionWithSaveDatabaseRunnable;
|
||||
|
||||
abstract class ActionNodeDatabaseRunnable extends ActionDatabaseRunnable {
|
||||
abstract class ActionNodeDatabaseRunnable extends ActionWithSaveDatabaseRunnable {
|
||||
|
||||
private AfterActionNodeOnFinish callbackRunnable;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class AddEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mDb.addEntryTo(mNewEntry, mNewEntry.getParent());
|
||||
mDatabase.addEntryTo(mNewEntry, mNewEntry.getParent());
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
@@ -49,7 +49,7 @@ public class AddEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDb.removeEntryFrom(mNewEntry, mNewEntry.getParent());
|
||||
mDatabase.removeEntryFrom(mNewEntry, mNewEntry.getParent());
|
||||
}
|
||||
callbackNodeAction(success, message, null, mNewEntry);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mDb.addGroupTo(mNewGroup, mNewGroup.getParent());
|
||||
mDatabase.addGroupTo(mNewGroup, mNewGroup.getParent());
|
||||
|
||||
// Commit to disk
|
||||
super.run();
|
||||
@@ -49,7 +49,7 @@ public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
@Override
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||
mDatabase.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||
}
|
||||
callbackNodeAction(success, message, null, mNewGroup);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mEntryCopied = mDb.copyEntry(mEntryToCopy, mNewParent);
|
||||
mEntryCopied = mDatabase.copyEntry(mEntryToCopy, mNewParent);
|
||||
|
||||
if (mEntryCopied != null) {
|
||||
mEntryCopied.touch(true, true);
|
||||
@@ -65,7 +65,7 @@ public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to delete the copy
|
||||
try {
|
||||
mDb.deleteEntry(mEntryCopied);
|
||||
mDatabase.deleteEntry(mEntryCopied);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to delete the copied entry");
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
mParent = mEntryToDelete.getParent();
|
||||
|
||||
// Remove Entry from parent
|
||||
mRecycle = mDb.canRecycle(mEntryToDelete);
|
||||
mRecycle = mDatabase.canRecycle(mEntryToDelete);
|
||||
if (mRecycle) {
|
||||
mDb.recycle(mEntryToDelete);
|
||||
mDatabase.recycle(mEntryToDelete);
|
||||
}
|
||||
else {
|
||||
mDb.deleteEntry(mEntryToDelete);
|
||||
mDatabase.deleteEntry(mEntryToDelete);
|
||||
}
|
||||
|
||||
// Commit database
|
||||
@@ -62,10 +62,10 @@ public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDb.undoRecycle(mEntryToDelete, mParent);
|
||||
mDatabase.undoRecycle(mEntryToDelete, mParent);
|
||||
}
|
||||
else {
|
||||
mDb.undoDeleteEntry(mEntryToDelete, mParent);
|
||||
mDatabase.undoDeleteEntry(mEntryToDelete, mParent);
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, message, mEntryToDelete, null);
|
||||
|
||||
@@ -49,30 +49,30 @@ public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
mParent = mGroupToDelete.getParent();
|
||||
|
||||
// Remove Group from parent
|
||||
mRecycle = mDb.canRecycle(mGroupToDelete);
|
||||
mRecycle = mDatabase.canRecycle(mGroupToDelete);
|
||||
if (mRecycle) {
|
||||
mDb.recycle(mGroupToDelete);
|
||||
mDatabase.recycle(mGroupToDelete);
|
||||
}
|
||||
else {
|
||||
// TODO tests
|
||||
// Remove child entries
|
||||
List<PwEntry> childEnt = new ArrayList<>(mGroupToDelete.getChildEntries()); // TODO new Methods
|
||||
for ( int i = 0; i < childEnt.size(); i++ ) {
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDb, childEnt.get(i), null, true);
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDatabase, childEnt.get(i), null, true);
|
||||
task.run();
|
||||
}
|
||||
|
||||
// Remove child groups
|
||||
List<PwGroup> childGrp = new ArrayList<>(mGroupToDelete.getChildGroups());
|
||||
for ( int i = 0; i < childGrp.size(); i++ ) {
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDb, childGrp.get(i), null, true);
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDatabase, childGrp.get(i), null, true);
|
||||
task.run();
|
||||
}
|
||||
mDb.deleteGroup(mGroupToDelete);
|
||||
mDatabase.deleteGroup(mGroupToDelete);
|
||||
|
||||
// Remove from PwDatabaseV3
|
||||
// TODO ENcapsulate
|
||||
mDb.getPwDatabase().getGroups().remove(mGroupToDelete);
|
||||
mDatabase.getPwDatabase().getGroups().remove(mGroupToDelete);
|
||||
}
|
||||
|
||||
// Commit Database
|
||||
@@ -83,7 +83,7 @@ public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDb.undoRecycle(mGroupToDelete, mParent);
|
||||
mDatabase.undoRecycle(mGroupToDelete, mParent);
|
||||
}
|
||||
else {
|
||||
// Let's not bother recovering from a failure to save a deleted tree. It is too much work.
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
// Move entry in new parent
|
||||
|
||||
mOldParent = mEntryToMove.getParent();
|
||||
mDb.moveEntry(mEntryToMove, mNewParent);
|
||||
mDatabase.moveEntry(mEntryToMove, mNewParent);
|
||||
|
||||
if (mEntryToMove != null) {
|
||||
mEntryToMove.touch(true, true);
|
||||
@@ -67,7 +67,7 @@ public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to remove in the first place
|
||||
try {
|
||||
mDb.moveEntry(mEntryToMove, mOldParent);
|
||||
mDatabase.moveEntry(mEntryToMove, mOldParent);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to replace the entry");
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
// Move group in new parent if not in the current group
|
||||
if (!mGroupToMove.equals(mNewParent)
|
||||
&& !mNewParent.isContainedIn(mGroupToMove)) {
|
||||
mDb.moveGroup(mGroupToMove, mNewParent);
|
||||
mDatabase.moveGroup(mGroupToMove, mNewParent);
|
||||
|
||||
if (mGroupToMove != null) {
|
||||
mGroupToMove.touch(true, true);
|
||||
@@ -76,7 +76,7 @@ public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to move in the first place
|
||||
try {
|
||||
mDb.moveGroup(mGroupToMove, mOldParent);
|
||||
mDatabase.moveGroup(mGroupToMove, mOldParent);
|
||||
} catch (Exception e) {
|
||||
Log.i(TAG, "Unable to replace the group");
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Update entry with new values
|
||||
mDb.updateEntry(mOldEntry, mNewEntry);
|
||||
mDatabase.updateEntry(mOldEntry, mNewEntry);
|
||||
mOldEntry.touch(true, true);
|
||||
|
||||
super.run();
|
||||
@@ -56,7 +56,7 @@ public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateEntry(mOldEntry, mBackupEntry);
|
||||
mDatabase.updateEntry(mOldEntry, mBackupEntry);
|
||||
}
|
||||
callbackNodeAction(success, message, mOldEntry, mNewEntry);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Update group with new values
|
||||
mDb.updateGroup(mOldGroup, mNewGroup);
|
||||
mDatabase.updateGroup(mOldGroup, mNewGroup);
|
||||
mOldGroup.touch(true, true);
|
||||
|
||||
// Commit to disk
|
||||
@@ -57,7 +57,7 @@ public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateGroup(mOldGroup, mBackupGroup);
|
||||
mDatabase.updateGroup(mOldGroup, mBackupGroup);
|
||||
}
|
||||
callbackNodeAction(success, message, mOldGroup, mNewGroup);
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.activities.GroupActivity;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||
import com.kunzisoft.keepass.database.action.CreateDBRunnable;
|
||||
import com.kunzisoft.keepass.database.action.CreateDatabaseRunnable;
|
||||
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
|
||||
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
|
||||
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||
import com.kunzisoft.keepass.password.PasswordActivity;
|
||||
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.stylish.StylishActivity;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
||||
@@ -538,7 +538,7 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
assignPasswordHelper.setCreateProgressDialog(false);
|
||||
|
||||
// Create the new database
|
||||
CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this,
|
||||
CreateDatabaseRunnable createDBTask = new CreateDatabaseRunnable(FileSelectActivity.this,
|
||||
databaseFilename, assignPasswordOnFinish, true);
|
||||
createDBTask.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
@@ -589,11 +589,13 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
@Override
|
||||
public void run() {
|
||||
if (mSuccess) {
|
||||
// Add to recent files
|
||||
fileHistory.createFile(mUri, getFilename());
|
||||
mAdapter.notifyDataSetChanged();
|
||||
updateTitleFileListView();
|
||||
GroupActivity.launch(FileSelectActivity.this);
|
||||
runOnUiThread(() -> {
|
||||
// Add to recent files
|
||||
fileHistory.createFile(mUri, getFilename());
|
||||
mAdapter.notifyDataSetChanged();
|
||||
updateTitleFileListView();
|
||||
GroupActivity.launch(FileSelectActivity.this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
package com.kunzisoft.keepass.password;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable;
|
||||
import com.kunzisoft.keepass.database.action.AssignPasswordInDatabaseRunnable;
|
||||
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||
@@ -61,21 +60,21 @@ public class AssignPasswordHelper {
|
||||
}
|
||||
|
||||
public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
|
||||
AssignPasswordInDBRunnable assignPasswordInDBRunnable = new AssignPasswordInDBRunnable(
|
||||
AssignPasswordInDatabaseRunnable assignPasswordInDatabaseRunnable = new AssignPasswordInDatabaseRunnable(
|
||||
context,
|
||||
App.getDB(),
|
||||
masterPassword,
|
||||
keyfile,
|
||||
new AfterSave(fileOnFinish, new Handler())
|
||||
new AfterSave(fileOnFinish)
|
||||
);
|
||||
if (createProgressDialog) {
|
||||
assignPasswordInDBRunnable.setUpdateProgressTaskStatus(
|
||||
assignPasswordInDatabaseRunnable.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(context,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
context.getSupportFragmentManager())
|
||||
));
|
||||
}
|
||||
Thread taskThread = new Thread(assignPasswordInDBRunnable);
|
||||
Thread taskThread = new Thread(assignPasswordInDatabaseRunnable);
|
||||
|
||||
// Show the progress dialog now or after dialog confirmation
|
||||
if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) {
|
||||
@@ -89,8 +88,8 @@ public class AssignPasswordHelper {
|
||||
private class AfterSave extends OnFinishRunnable {
|
||||
private FileOnFinishRunnable mFinish;
|
||||
|
||||
AfterSave(FileOnFinishRunnable finish, Handler handler) {
|
||||
super(finish, handler);
|
||||
AfterSave(FileOnFinishRunnable finish) {
|
||||
super(finish);
|
||||
mFinish = finish;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
@@ -63,7 +62,7 @@ import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.autofill.AutofillHelper;
|
||||
import com.kunzisoft.keepass.compat.ClipDataCompat;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.action.LoadDBRunnable;
|
||||
import com.kunzisoft.keepass.database.action.LoadDatabaseRunnable;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||
import com.kunzisoft.keepass.fileselect.KeyFileHelper;
|
||||
@@ -891,9 +890,9 @@ public class PasswordActivity extends StylishActivity
|
||||
// Show the progress dialog
|
||||
Handler handler = new Handler();
|
||||
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database);
|
||||
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(
|
||||
database,
|
||||
LoadDatabaseRunnable databaseLoadingTask = new LoadDatabaseRunnable(
|
||||
PasswordActivity.this,
|
||||
database,
|
||||
mDbUri,
|
||||
password,
|
||||
keyfile,
|
||||
@@ -905,8 +904,7 @@ public class PasswordActivity extends StylishActivity
|
||||
getSupportFragmentManager(),
|
||||
R.string.loading_database)
|
||||
));
|
||||
Thread t = new Thread(databaseLoadingTask);
|
||||
t.start();
|
||||
new Thread(databaseLoadingTask).start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user