mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add progress bar for all, create database in a single progress dialog
This commit is contained in:
@@ -58,7 +58,8 @@ import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||
import com.kunzisoft.keepass.utils.Types;
|
||||
import com.kunzisoft.keepass.utils.Util;
|
||||
@@ -249,6 +250,7 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
}
|
||||
mCallbackNewEntry = populateNewEntry();
|
||||
|
||||
// Open a progress dialog and save entry
|
||||
OnFinishRunnable onFinish = new AfterSave();
|
||||
EntryEditActivity act = EntryEditActivity.this;
|
||||
RunnableOnFinish task;
|
||||
@@ -257,8 +259,12 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
} else {
|
||||
task = new UpdateEntryRunnable(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
|
||||
}
|
||||
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
||||
pt.run();
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(() -> {
|
||||
if ( mSuccess ) {
|
||||
finish();
|
||||
} else {
|
||||
displayMessage(EntryEditActivity.this);
|
||||
}
|
||||
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,8 @@ import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
|
||||
import com.kunzisoft.keepass.icons.IconPackChooser;
|
||||
import com.kunzisoft.keepass.search.SearchResultsActivity;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
import com.kunzisoft.keepass.view.AddNodeButtonView;
|
||||
|
||||
public class GroupActivity extends ListNodesActivity
|
||||
@@ -437,8 +438,12 @@ public class GroupActivity extends ListNodesActivity
|
||||
Handler handler = new Handler();
|
||||
DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry,
|
||||
new AfterDeleteNode(handler, entry));
|
||||
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
|
||||
pt.run();
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
private void deleteGroup(PwGroup group) {
|
||||
@@ -446,8 +451,12 @@ public class GroupActivity extends ListNodesActivity
|
||||
Handler handler = new Handler();
|
||||
DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group,
|
||||
new AfterDeleteNode(handler, group));
|
||||
ProgressTask pt = new ProgressTask(this, task, R.string.saving_database);
|
||||
pt.run();
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(task).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -548,16 +557,21 @@ public class GroupActivity extends ListNodesActivity
|
||||
newGroup.setName(name);
|
||||
try {
|
||||
iconStandard = (PwIconStandard) icon;
|
||||
} catch (Exception e) {} // TODO custom icon
|
||||
} catch (Exception ignored) {} // TODO custom icon
|
||||
newGroup.setIcon(iconStandard);
|
||||
|
||||
new ProgressTask(this,
|
||||
new AddGroupRunnable(this,
|
||||
// If group created save it in the database
|
||||
AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this,
|
||||
App.getDB(),
|
||||
newGroup,
|
||||
new AfterAddNode(new Handler())),
|
||||
R.string.saving_database)
|
||||
.run();
|
||||
new AfterAddNode(new Handler()));
|
||||
addGroupRunnable.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(addGroupRunnable).start();
|
||||
|
||||
break;
|
||||
case UPDATE:
|
||||
// If update add new elements
|
||||
@@ -566,20 +580,23 @@ public class GroupActivity extends ListNodesActivity
|
||||
updateGroup.setName(name);
|
||||
try {
|
||||
iconStandard = (PwIconStandard) icon;
|
||||
} catch (Exception e) {} // TODO custom icon
|
||||
} catch (Exception ignored) {} // TODO custom icon
|
||||
updateGroup.setIcon(iconStandard);
|
||||
|
||||
mAdapter.removeNode(oldGroupToUpdate);
|
||||
// If group update
|
||||
new ProgressTask(this,
|
||||
new UpdateGroupRunnable(this,
|
||||
|
||||
// If group updated save it in the database
|
||||
UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this,
|
||||
App.getDB(),
|
||||
oldGroupToUpdate,
|
||||
updateGroup,
|
||||
new AfterUpdateNode(new Handler())),
|
||||
R.string.saving_database)
|
||||
.run();
|
||||
|
||||
new AfterUpdateNode(new Handler()));
|
||||
updateGroupRunnable.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager())
|
||||
));
|
||||
new Thread(updateGroupRunnable).start();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
|
||||
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
|
||||
import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UIToastTask;
|
||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||
|
||||
@@ -307,11 +308,16 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
public void run(PwNode oldNode, PwNode newNode) {
|
||||
super.run();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
if (mSuccess) {
|
||||
mAdapter.addNode(newNode);
|
||||
} else {
|
||||
displayMessage(ListNodesActivity.this);
|
||||
}
|
||||
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,11 +328,16 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
public void run(PwNode oldNode, PwNode newNode) {
|
||||
super.run();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
if (mSuccess) {
|
||||
mAdapter.updateNode(oldNode, newNode);
|
||||
} else {
|
||||
displayMessage(ListNodesActivity.this);
|
||||
}
|
||||
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +351,9 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
if ( mSuccess) {
|
||||
mAdapter.removeNode(pwNode);
|
||||
PwGroup parent = pwNode.getParent();
|
||||
@@ -361,6 +375,9 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
App.setShutdown();
|
||||
finish();
|
||||
}
|
||||
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +20,17 @@
|
||||
package com.kunzisoft.keepass.database.action;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwDatabase;
|
||||
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException;
|
||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||
import com.kunzisoft.keepass.utils.UriUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SetPasswordRunnable extends RunnableOnFinish {
|
||||
public class AssignPasswordInDBRunnable extends RunnableOnFinish {
|
||||
|
||||
private String mPassword;
|
||||
private Uri mKeyfile;
|
||||
@@ -40,12 +38,12 @@ public class SetPasswordRunnable extends RunnableOnFinish {
|
||||
private boolean mDontSave;
|
||||
private Context ctx;
|
||||
|
||||
public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) {
|
||||
this(ctx, db, password, keyfile, finish, false);
|
||||
|
||||
}
|
||||
|
||||
public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||
public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) {
|
||||
super(finish);
|
||||
|
||||
mDb = db;
|
||||
@@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatus(ProgressTaskUpdater status) {
|
||||
public void setUpdateProgressTaskStatus(ProgressTaskUpdater status) {
|
||||
mStatus = status;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ import com.kunzisoft.keepass.password.AssignPasswordHelper;
|
||||
import com.kunzisoft.keepass.password.PasswordActivity;
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil;
|
||||
import com.kunzisoft.keepass.stylish.StylishActivity;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
import com.kunzisoft.keepass.utils.EmptyUtils;
|
||||
import com.kunzisoft.keepass.utils.MenuUtil;
|
||||
import com.kunzisoft.keepass.utils.UriUtil;
|
||||
@@ -520,17 +521,21 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
AssignPasswordOnFinish assignPasswordOnFinish =
|
||||
new AssignPasswordOnFinish(launchActivityOnFinish);
|
||||
|
||||
// Create the new database
|
||||
CreateDBRunnable create = new CreateDBRunnable(FileSelectActivity.this,
|
||||
databaseFilename, assignPasswordOnFinish, true);
|
||||
|
||||
ProgressTask createTask = new ProgressTask(
|
||||
FileSelectActivity.this, create,
|
||||
R.string.progress_create);
|
||||
createTask.run();
|
||||
|
||||
// Initialize the password helper assigner to set the password after the database creation
|
||||
assignPasswordHelper = new AssignPasswordHelper(this,
|
||||
masterPasswordChecked, masterPassword, keyFileChecked, keyFile);
|
||||
assignPasswordHelper.setCreateProgressDialog(false);
|
||||
|
||||
// Create the new database
|
||||
CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this,
|
||||
databaseFilename, assignPasswordOnFinish, true);
|
||||
createDBTask.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
ProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager(),
|
||||
R.string.progress_create)
|
||||
));
|
||||
new Thread(createDBTask).start();
|
||||
|
||||
} catch (Exception e) {
|
||||
String error = "Unable to create database with this password and key file";
|
||||
@@ -555,7 +560,9 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
@Override
|
||||
public void run() {
|
||||
if (mSuccess) {
|
||||
assignPasswordHelper.assignPasswordInDatabase(mOnFinish);
|
||||
// Dont use ProgressTaskDialogFragment.stop(getSupportFragmentManager());
|
||||
// assignPasswordHelper do it
|
||||
runOnUiThread(() -> assignPasswordHelper.assignPasswordInDatabase(mOnFinish));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,28 +19,30 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.password;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable;
|
||||
import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.action.SetPasswordRunnable;
|
||||
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
|
||||
public class AssignPasswordHelper {
|
||||
|
||||
private Activity context;
|
||||
private AppCompatActivity context;
|
||||
|
||||
private String masterPassword = null;
|
||||
private Uri keyfile = null;
|
||||
|
||||
public AssignPasswordHelper(Activity context,
|
||||
private boolean createProgressDialog;
|
||||
|
||||
public AssignPasswordHelper(AppCompatActivity context,
|
||||
boolean withMasterPassword,
|
||||
String masterPassword,
|
||||
boolean withKeyFile,
|
||||
@@ -50,38 +52,66 @@ public class AssignPasswordHelper {
|
||||
this.masterPassword = masterPassword;
|
||||
if (withKeyFile)
|
||||
this.keyfile = keyfile;
|
||||
|
||||
createProgressDialog = true;
|
||||
}
|
||||
|
||||
public void setCreateProgressDialog(boolean createProgressDialog) {
|
||||
this.createProgressDialog = createProgressDialog;
|
||||
}
|
||||
|
||||
public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) {
|
||||
SetPasswordRunnable sp = new SetPasswordRunnable(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler()));
|
||||
final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database);
|
||||
AssignPasswordInDBRunnable assignPasswordInDBRunnable = new AssignPasswordInDBRunnable(
|
||||
context,
|
||||
App.getDB(),
|
||||
masterPassword,
|
||||
keyfile,
|
||||
new AfterSave(fileOnFinish, new Handler())
|
||||
);
|
||||
if (createProgressDialog) {
|
||||
assignPasswordInDBRunnable.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(context,
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
context.getSupportFragmentManager())
|
||||
));
|
||||
}
|
||||
Thread taskThread = new Thread(assignPasswordInDBRunnable);
|
||||
|
||||
// Show the progress dialog now or after dialog confirmation
|
||||
if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) {
|
||||
pt.run();
|
||||
taskThread.start();
|
||||
} else {
|
||||
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
|
||||
dialog.show(context, (newDialog, which) -> pt.run(), true);
|
||||
dialog.show(context, (newDialog, which) -> taskThread.start(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private class AfterSave extends OnFinishRunnable {
|
||||
private FileOnFinishRunnable mFinish;
|
||||
|
||||
public AfterSave(FileOnFinishRunnable finish, Handler handler) {
|
||||
AfterSave(FileOnFinishRunnable finish, Handler handler) {
|
||||
super(finish, handler);
|
||||
mFinish = finish;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
|
||||
context.runOnUiThread(() -> {
|
||||
if ( mSuccess ) {
|
||||
if ( mFinish != null ) {
|
||||
mFinish.setFilename(keyfile);
|
||||
}
|
||||
} else {
|
||||
displayMessage(context);
|
||||
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||
Toast.makeText(context, mMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
|
||||
// To remove progress task
|
||||
ProgressTaskDialogFragment.stop(context.getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,21 +811,29 @@ public class PasswordActivity extends StylishActivity
|
||||
loadDatabase(password, keyUri);
|
||||
}
|
||||
|
||||
private void loadDatabase(String pass, Uri keyfile) {
|
||||
private void loadDatabase(String password, Uri keyfile) {
|
||||
// Clear before we load
|
||||
Database db = App.getDB();
|
||||
db.clear();
|
||||
Database database = App.getDB();
|
||||
database.clear();
|
||||
// Clear the shutdown flag
|
||||
App.clearShutdown();
|
||||
|
||||
// Show the progress dialog
|
||||
Handler handler = new Handler();
|
||||
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, db);
|
||||
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad);
|
||||
databaseLoadingTask.setStatus(
|
||||
AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database);
|
||||
LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(
|
||||
database,
|
||||
PasswordActivity.this,
|
||||
mDbUri,
|
||||
password,
|
||||
keyfile,
|
||||
afterLoad);
|
||||
databaseLoadingTask.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
handler,
|
||||
ProgressTaskDialogFragment.start(getSupportFragmentManager(), R.string.loading_database)
|
||||
ProgressTaskDialogFragment.start(
|
||||
getSupportFragmentManager(),
|
||||
R.string.loading_database)
|
||||
));
|
||||
Thread t = new Thread(databaseLoadingTask);
|
||||
t.start();
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
|
||||
public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat {
|
||||
|
||||
@@ -37,7 +38,7 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
|
||||
database.assignDescription(dbDescription);
|
||||
|
||||
Handler handler = new Handler();
|
||||
setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, dbDescription, oldDescription));
|
||||
setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, dbDescription, oldDescription));
|
||||
}
|
||||
|
||||
super.onDialogClosed(positiveResult);
|
||||
@@ -45,14 +46,14 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
|
||||
|
||||
private class AfterDescriptionSave extends OnFinishRunnable {
|
||||
|
||||
private AppCompatActivity mActivity;
|
||||
private String mNewDescription;
|
||||
private String mOldDescription;
|
||||
private Context mCtx;
|
||||
|
||||
AfterDescriptionSave(Context ctx, Handler handler, String newDescription, String oldDescription) {
|
||||
AfterDescriptionSave(AppCompatActivity ctx, Handler handler, String newDescription, String oldDescription) {
|
||||
super(handler);
|
||||
|
||||
mCtx = ctx;
|
||||
mActivity = ctx;
|
||||
mNewDescription = newDescription;
|
||||
mOldDescription = oldDescription;
|
||||
}
|
||||
@@ -62,12 +63,18 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS
|
||||
String descriptionToShow = mNewDescription;
|
||||
|
||||
if (!mSuccess) {
|
||||
displayMessage(mCtx);
|
||||
displayMessage(mActivity);
|
||||
database.assignDescription(mOldDescription);
|
||||
database.assignDescription(mOldDescription);
|
||||
}
|
||||
|
||||
if (mActivity != null) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
getPreference().setSummary(descriptionToShow);
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(
|
||||
mActivity.getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
|
||||
public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat {
|
||||
|
||||
@@ -37,7 +38,7 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
|
||||
database.assignName(dbName);
|
||||
|
||||
Handler handler = new Handler();
|
||||
setAfterSaveDatabase(new AfterNameSave(getContext(), handler, dbName, oldName));
|
||||
setAfterSaveDatabase(new AfterNameSave((AppCompatActivity) getActivity(), handler, dbName, oldName));
|
||||
}
|
||||
|
||||
super.onDialogClosed(positiveResult);
|
||||
@@ -47,12 +48,12 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
|
||||
|
||||
private String mNewName;
|
||||
private String mOldName;
|
||||
private Context mCtx;
|
||||
private AppCompatActivity mActivity;
|
||||
|
||||
AfterNameSave(Context ctx, Handler handler, String newName, String oldName) {
|
||||
AfterNameSave(AppCompatActivity ctx, Handler handler, String newName, String oldName) {
|
||||
super(handler);
|
||||
|
||||
mCtx = ctx;
|
||||
mActivity = ctx;
|
||||
mNewName = newName;
|
||||
mOldName = oldName;
|
||||
}
|
||||
@@ -62,11 +63,18 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref
|
||||
String nameToShow = mNewName;
|
||||
|
||||
if (!mSuccess) {
|
||||
displayMessage(mCtx);
|
||||
displayMessage(mActivity);
|
||||
database.assignName(mOldName);
|
||||
}
|
||||
|
||||
|
||||
if (mActivity != null) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
getPreference().setSummary(nameToShow);
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(
|
||||
mActivity.getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package com.kunzisoft.keepass.settings.preferenceDialogFragment;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.app.App;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.action.SaveDBRunnable;
|
||||
import com.kunzisoft.keepass.tasks.ProgressTask;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus;
|
||||
|
||||
public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat {
|
||||
|
||||
@@ -25,12 +25,16 @@ public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputP
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
if ( positiveResult ) {
|
||||
assert getContext() != null;
|
||||
assert getActivity() != null;
|
||||
|
||||
if (database != null && afterSaveDatabase != null) {
|
||||
SaveDBRunnable save = new SaveDBRunnable(getContext(), database, afterSaveDatabase);
|
||||
ProgressTask pt = new ProgressTask(getActivity(), save, R.string.saving_database);
|
||||
pt.run();
|
||||
SaveDBRunnable saveDBRunnable = new SaveDBRunnable(getContext(), database, afterSaveDatabase);
|
||||
saveDBRunnable.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(getContext(),
|
||||
SaveDatabaseProgressTaskDialogFragment.start(
|
||||
getActivity().getSupportFragmentManager())
|
||||
));
|
||||
new Thread(saveDBRunnable).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.settings.preferenceDialogFragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
|
||||
|
||||
public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat {
|
||||
|
||||
@@ -76,7 +77,7 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
|
||||
}
|
||||
|
||||
Handler handler = new Handler();
|
||||
setAfterSaveDatabase(new AfterRoundSave(getContext(), handler, rounds, oldRounds));
|
||||
setAfterSaveDatabase(new AfterRoundSave((AppCompatActivity) getActivity(), handler, rounds, oldRounds));
|
||||
}
|
||||
|
||||
super.onDialogClosed(positiveResult);
|
||||
@@ -86,12 +87,12 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
|
||||
|
||||
private long mNewRounds;
|
||||
private long mOldRounds;
|
||||
private Context mCtx;
|
||||
private AppCompatActivity mActivity;
|
||||
|
||||
AfterRoundSave(Context ctx, Handler handler, long newRounds, long oldRounds) {
|
||||
AfterRoundSave(AppCompatActivity ctx, Handler handler, long newRounds, long oldRounds) {
|
||||
super(handler);
|
||||
|
||||
mCtx = ctx;
|
||||
mActivity = ctx;
|
||||
mNewRounds = newRounds;
|
||||
mOldRounds = oldRounds;
|
||||
}
|
||||
@@ -101,11 +102,17 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference
|
||||
long roundsToShow = mNewRounds;
|
||||
|
||||
if (!mSuccess) {
|
||||
displayMessage(mCtx);
|
||||
displayMessage(mActivity);
|
||||
database.setNumberKeyEncryptionRounds(mOldRounds);
|
||||
}
|
||||
|
||||
if (mActivity != null) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
getPreference().setSummary(String.valueOf(roundsToShow));
|
||||
SaveDatabaseProgressTaskDialogFragment.stop(
|
||||
mActivity.getSupportFragmentManager());
|
||||
});
|
||||
}
|
||||
|
||||
super.run();
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tasks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.action.OnFinishRunnable;
|
||||
import com.kunzisoft.keepass.database.action.RunnableOnFinish;
|
||||
|
||||
/** Designed to Pop up a progress dialog, run a thread in the background,
|
||||
* run cleanup in the current thread, close the dialog. Without blocking
|
||||
* the current thread.
|
||||
*/
|
||||
public class ProgressTask implements Runnable {
|
||||
|
||||
private Activity activity;
|
||||
private RunnableOnFinish mTask;
|
||||
private ProgressDialog mPd;
|
||||
|
||||
public ProgressTask(Activity activity, RunnableOnFinish task, int messageId) {
|
||||
this.activity = activity;
|
||||
this.mTask = task;
|
||||
Handler mHandler = new Handler();
|
||||
|
||||
// Show process dialog
|
||||
// TODO Move in activity
|
||||
this.mPd = new ProgressDialog(activity);
|
||||
this.mPd.setCanceledOnTouchOutside(false);
|
||||
this.mPd.setTitle(activity.getText(R.string.progress_title));
|
||||
this.mPd.setMessage(activity.getText(messageId));
|
||||
|
||||
// Set code to run when this is finished
|
||||
this.mTask.setStatus(new UpdateStatus(activity, mHandler, mPd));
|
||||
this.mTask.mFinish = new AfterTask(task.mFinish, mHandler);
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
lockScreenOrientation();
|
||||
|
||||
// Show process dialog
|
||||
mPd.show();
|
||||
|
||||
// Start Thread to Run task
|
||||
Thread t = new Thread(mTask);
|
||||
t.start();
|
||||
}
|
||||
|
||||
private class AfterTask extends OnFinishRunnable {
|
||||
|
||||
AfterTask(OnFinishRunnable finish, Handler handler) {
|
||||
super(finish, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
// Remove the progress dialog
|
||||
mHandler.post(new CloseProcessDialog());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class CloseProcessDialog implements Runnable {
|
||||
public void run() {
|
||||
if (mPd != null && mPd.isShowing()) {
|
||||
mPd.dismiss();
|
||||
}
|
||||
unlockScreenOrientation();
|
||||
}
|
||||
}
|
||||
|
||||
private void lockScreenOrientation() {
|
||||
int currentOrientation = activity.getResources().getConfiguration().orientation;
|
||||
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
} else {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
}
|
||||
|
||||
private void unlockScreenOrientation() {
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,8 +77,7 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
|
||||
messageView = root.findViewById(R.id.progress_dialog_message);
|
||||
progressView = root.findViewById(R.id.progress_dialog_bar);
|
||||
|
||||
if (message != UNDEFINED)
|
||||
messageView.setText(message);
|
||||
updateMessage(message);
|
||||
|
||||
setCancelable(false);
|
||||
lockScreenOrientation();
|
||||
@@ -123,7 +122,13 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre
|
||||
@Override
|
||||
public void updateMessage(int resId) {
|
||||
this.message = resId;
|
||||
if (messageView != null)
|
||||
this.messageView.setText(message);
|
||||
if (messageView != null) {
|
||||
if (message == UNDEFINED) {
|
||||
messageView.setVisibility(View.GONE);
|
||||
} else {
|
||||
messageView.setText(message);
|
||||
messageView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.kunzisoft.keepass.tasks;
|
||||
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class SaveDatabaseProgressTaskDialogFragment extends ProgressTaskDialogFragment {
|
||||
|
||||
public static SaveDatabaseProgressTaskDialogFragment start(FragmentManager fragmentManager) {
|
||||
// Create an instance of the dialog fragment and show it
|
||||
SaveDatabaseProgressTaskDialogFragment dialog = new SaveDatabaseProgressTaskDialogFragment();
|
||||
dialog.setTitle(R.string.saving_database);
|
||||
dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG);
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,10 @@ public class UpdateProgressTaskStatus implements ProgressTaskUpdater {
|
||||
private ProgressTaskUpdater mProgressTaskUpdater;
|
||||
private Handler mHandler;
|
||||
|
||||
public UpdateProgressTaskStatus(Context context, ProgressTaskUpdater progressTaskUpdater) {
|
||||
this(context, new Handler(), progressTaskUpdater);
|
||||
}
|
||||
|
||||
public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) {
|
||||
this.mContext = context;
|
||||
this.mProgressTaskUpdater = progressTaskUpdater;
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tasks;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
|
||||
public class UpdateStatus implements ProgressTaskUpdater {
|
||||
private ProgressDialog mPD;
|
||||
private Context mCtx;
|
||||
private Handler mHandler;
|
||||
|
||||
UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) {
|
||||
mCtx = ctx;
|
||||
mPD = pd;
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
public void updateMessage(int resId) {
|
||||
if ( mCtx != null && mPD != null && mHandler != null ) {
|
||||
mHandler.post(new UpdateMessage(resId));
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateMessage implements Runnable {
|
||||
private int mResId;
|
||||
|
||||
UpdateMessage(int resId) {
|
||||
mResId = resId;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
mPD.setMessage(mCtx.getString(mResId));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user