diff --git a/CHANGELOG b/CHANGELOG index 2786d9182..5e6f2b8b8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +KeepassDX (2.5.0.0beta10) + * Upgrade translations + * Fix classic dark theme + * Add Material Icon Pack to the Free version + * Fix bugs + KeepassDX (2.5.0.0beta9) * Education Screens to learn how to use the app * New designs diff --git a/ReadMe.md b/ReadMe.md index 2594859b5..2a88da271 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -17,9 +17,6 @@ Keepass DX is opensource and ad-free. - - - ## What is KeePass DX? Today you need to remember many passwords. You need a password for your e-mail account, your website's FTP password, online passwords (like website member account), etc. etc. etc. The list is endless. Also, you should use different passwords for each account. Because if you use only one password everywhere and someone gets this password you have a problem... A serious problem. The thief would have access to your e-mail account, website, etc. Unimaginable. @@ -41,11 +38,10 @@ You can contribute in different ways to help us on our work. * **[Donate](https://www.kunzisoft.com/donation)** 人◕ ‿‿ ◕人Y for a better service and a quick development of your features. * Buy the **[Pro version](https://play.google.com/store/apps/details?id=com.kunzisoft.keepass.pro)** of KeePass DX - - - ## Download +*We recommend the installation from [F-Droid](https://f-droid.org/en/packages/com.kunzisoft.keepass.libre/) which verifies that all libraries and application code are open source.* + [Get it on F-Droid](https://f-droid.org/en/packages/com.kunzisoft.keepass.libre/) diff --git a/app/build.gradle b/app/build.gradle index 8f2297e09..b1e069938 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.kunzisoft.keepass" minSdkVersion 14 targetSdkVersion 27 - versionCode = 9 - versionName = "2.5.0.0beta9" + versionCode = 10 + versionName = "2.5.0.0beta10" multiDexEnabled true testApplicationId = "com.kunzisoft.keepass.tests" @@ -65,7 +65,7 @@ android { buildConfigField "boolean", "FULL_VERSION", "false" buildConfigField "boolean", "CLOSED_STORE", "true" buildConfigField "String[]", "STYLES_DISABLED", "{\"KeepassDXStyle_Dark\",\"KeepassDXStyle_Blue\",\"KeepassDXStyle_Purple\"}" - buildConfigField "String[]", "ICON_PACKS_DISABLED", "{\"material\"}" + buildConfigField "String[]", "ICON_PACKS_DISABLED", "{}" } } diff --git a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/DeleteEntry.java b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/DeleteEntry.java index b2748636a..92ce85b87 100644 --- a/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/DeleteEntry.java +++ b/app/src/androidTest/java/com/kunzisoft/keepass/tests/database/DeleteEntry.java @@ -30,7 +30,7 @@ import com.kunzisoft.keepass.database.PwDatabaseV3; import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntryV3; import com.kunzisoft.keepass.database.PwGroup; -import com.kunzisoft.keepass.database.edit.DeleteGroup; +import com.kunzisoft.keepass.database.action.DeleteGroupRunnable; import com.kunzisoft.keepass.search.SearchDbHelper; public class DeleteEntry extends AndroidTestCase { @@ -60,7 +60,7 @@ public class DeleteEntry extends AndroidTestCase { assertNotNull("Could not find group1", group1); // Delete the group - DeleteGroup task = new DeleteGroup(null, db, group1, null, true); + DeleteGroupRunnable task = new DeleteGroupRunnable(null, db, group1, null, true); task.run(); // Verify the entries were deleted diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java index a2f0fcdec..d59a7e06b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java @@ -222,6 +222,7 @@ public class EntryActivity extends LockingHideActivity { TapTarget.forView(findViewById(R.id.entry_user_name_action_image), getString(R.string.education_field_copy_title), getString(R.string.education_field_copy_summary)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -250,6 +251,7 @@ public class EntryActivity extends LockingHideActivity { TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit, getString(R.string.education_entry_edit_title), getString(R.string.education_entry_edit_summary)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java index 332f58636..ed0658ffc 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -49,16 +49,17 @@ import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwGroupId; import com.kunzisoft.keepass.database.PwIconStandard; -import com.kunzisoft.keepass.database.edit.AddEntry; -import com.kunzisoft.keepass.database.edit.OnFinish; -import com.kunzisoft.keepass.database.edit.RunnableOnFinish; -import com.kunzisoft.keepass.database.edit.UpdateEntry; +import com.kunzisoft.keepass.database.action.AddEntryRunnable; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.database.action.RunnableOnFinish; +import com.kunzisoft.keepass.database.action.UpdateEntryRunnable; import com.kunzisoft.keepass.database.security.ProtectedString; 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,16 +250,21 @@ public class EntryEditActivity extends LockingHideActivity } mCallbackNewEntry = populateNewEntry(); - OnFinish onFinish = new AfterSave(); + // Open a progress dialog and save entry + OnFinishRunnable onFinish = new AfterSave(); EntryEditActivity act = EntryEditActivity.this; RunnableOnFinish task; if ( mIsNew ) { - task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish); + task = new AddEntryRunnable(act, App.getDB(), mCallbackNewEntry, onFinish); } else { - task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); + 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(); } /** @@ -274,6 +280,7 @@ public class EntryEditActivity extends LockingHideActivity TapTarget.forView(generatePasswordView, getString(R.string.education_generate_password_title), getString(R.string.education_generate_password_summary)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -300,6 +307,7 @@ public class EntryEditActivity extends LockingHideActivity TapTarget.forView(addNewFieldView, getString(R.string.education_entry_new_field_title), getString(R.string.education_entry_new_field_summary)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -552,7 +560,7 @@ public class EntryEditActivity extends LockingHideActivity } } - private final class AfterSave extends OnFinish { + private final class AfterSave extends OnFinishRunnable { AfterSave() { super(new Handler()); @@ -560,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity @Override public void run() { - if ( mSuccess ) { - finish(); - } else { - displayMessage(EntryEditActivity.this); - } + runOnUiThread(() -> { + if ( mSuccess ) { + finish(); + } else { + displayMessage(EntryEditActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this); + }); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java index 8befbeb31..bc5fa6ec4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java @@ -57,10 +57,10 @@ import com.kunzisoft.keepass.database.PwIcon; import com.kunzisoft.keepass.database.PwIconStandard; import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.SortNodeEnum; -import com.kunzisoft.keepass.database.edit.AddGroup; -import com.kunzisoft.keepass.database.edit.DeleteEntry; -import com.kunzisoft.keepass.database.edit.DeleteGroup; -import com.kunzisoft.keepass.database.edit.UpdateGroup; +import com.kunzisoft.keepass.database.action.AddGroupRunnable; +import com.kunzisoft.keepass.database.action.DeleteEntryRunnable; +import com.kunzisoft.keepass.database.action.DeleteGroupRunnable; +import com.kunzisoft.keepass.database.action.UpdateGroupRunnable; import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; @@ -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 @@ -285,6 +286,7 @@ public class GroupActivity extends ListNodesActivity TapTarget.forView(findViewById(R.id.add_button), getString(R.string.education_new_node_title), getString(R.string.education_new_node_summary)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -313,6 +315,7 @@ public class GroupActivity extends ListNodesActivity TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search, getString(R.string.education_search_title), getString(R.string.education_search_summary)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -344,6 +347,7 @@ public class GroupActivity extends ListNodesActivity TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort, getString(R.string.education_sort_title), getString(R.string.education_sort_summary)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -374,6 +378,7 @@ public class GroupActivity extends ListNodesActivity TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock, getString(R.string.education_lock_title), getString(R.string.education_lock_summary)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -431,19 +436,27 @@ public class GroupActivity extends ListNodesActivity private void deleteEntry(PwEntry entry) { Handler handler = new Handler(); - DeleteEntry task = new DeleteEntry(this, App.getDB(), entry, + 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) { //TODO Verify trash recycle bin Handler handler = new Handler(); - DeleteGroup task = new DeleteGroup(this, App.getDB(), group, + 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 @@ -544,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 AddGroup(this, - App.getDB(), - newGroup, - new AfterAddNode(new Handler())), - R.string.saving_database) - .run(); + // If group created save it in the database + AddGroupRunnable addGroupRunnable = new AddGroupRunnable(this, + App.getDB(), + newGroup, + new AfterAddNode(new Handler())); + addGroupRunnable.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + SaveDatabaseProgressTaskDialogFragment.start( + getSupportFragmentManager()) + )); + new Thread(addGroupRunnable).start(); + break; case UPDATE: // If update add new elements @@ -562,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 UpdateGroup(this, - App.getDB(), - oldGroupToUpdate, - updateGroup, - new AfterUpdateNode(new Handler())), - R.string.saving_database) - .run(); + // If group updated save it in the database + UpdateGroupRunnable updateGroupRunnable = new UpdateGroupRunnable(this, + App.getDB(), + oldGroupToUpdate, + updateGroup, + new AfterUpdateNode(new Handler())); + updateGroupRunnable.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + SaveDatabaseProgressTaskDialogFragment.start( + getSupportFragmentManager()) + )); + new Thread(updateGroupRunnable).start(); } break; diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java index 94af4bdac..ff0153dc2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java @@ -49,12 +49,13 @@ import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwGroup; import com.kunzisoft.keepass.database.PwNode; import com.kunzisoft.keepass.database.SortNodeEnum; -import com.kunzisoft.keepass.database.edit.AfterActionNodeOnFinish; -import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.database.action.AfterActionNodeOnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; 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(); - if (mSuccess) { - mAdapter.addNode(newNode); - } else { - displayMessage(ListNodesActivity.this); - } + + runOnUiThread(() -> { + if (mSuccess) { + mAdapter.addNode(newNode); + } else { + displayMessage(ListNodesActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); + }); } } @@ -322,15 +328,20 @@ public abstract class ListNodesActivity extends LockingActivity public void run(PwNode oldNode, PwNode newNode) { super.run(); - if (mSuccess) { - mAdapter.updateNode(oldNode, newNode); - } else { - displayMessage(ListNodesActivity.this); - } + + runOnUiThread(() -> { + if (mSuccess) { + mAdapter.updateNode(oldNode, newNode); + } else { + displayMessage(ListNodesActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); + }); } } - class AfterDeleteNode extends OnFinish { + class AfterDeleteNode extends OnFinishRunnable { private PwNode pwNode; AfterDeleteNode(Handler handler, PwNode pwNode) { @@ -340,27 +351,33 @@ public abstract class ListNodesActivity extends LockingActivity @Override public void run() { - if ( mSuccess) { - mAdapter.removeNode(pwNode); - PwGroup parent = pwNode.getParent(); - Database db = App.getDB(); - PwDatabase database = db.getPwDatabase(); - if (db.isRecycleBinAvailable() && - db.isRecycleBinEnabled()) { - PwGroup recycleBin = database.getRecycleBin(); - // Add trash if it doesn't exists - if (parent.equals(recycleBin) - && mCurrentGroup != null - && mCurrentGroup.getParent() == null - && !mCurrentGroup.equals(recycleBin)) { - mAdapter.addNode(parent); + super.run(); + + runOnUiThread(() -> { + if ( mSuccess) { + mAdapter.removeNode(pwNode); + PwGroup parent = pwNode.getParent(); + Database db = App.getDB(); + PwDatabase database = db.getPwDatabase(); + if (db.isRecycleBinAvailable() && + db.isRecycleBinEnabled()) { + PwGroup recycleBin = database.getRecycleBin(); + // Add trash if it doesn't exists + if (parent.equals(recycleBin) + && mCurrentGroup != null + && mCurrentGroup.getParent() == null + && !mCurrentGroup.equals(recycleBin)) { + mAdapter.addNode(parent); + } } + } else { + mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage)); + App.setShutdown(); + finish(); } - } else { - mHandler.post(new UIToastTask(ListNodesActivity.this, "Unrecoverable error: " + mMessage)); - App.setShutdown(); - finish(); - } + + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); + }); } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/Database.java b/app/src/main/java/com/kunzisoft/keepass/database/Database.java index 7a52c111d..c88d442ab 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/Database.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/Database.java @@ -37,7 +37,7 @@ import com.kunzisoft.keepass.database.load.ImporterFactory; import com.kunzisoft.keepass.database.save.PwDbOutput; import com.kunzisoft.keepass.icons.IconDrawableFactory; import com.kunzisoft.keepass.search.SearchDbHelper; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import com.kunzisoft.keepass.utils.UriUtil; import java.io.BufferedInputStream; @@ -102,19 +102,11 @@ public class Database { loaded = true; } - public void loadData(Context ctx, InputStream is, String password, InputStream keyInputStream) throws IOException, InvalidDBException { - loadData(ctx, is, password, keyInputStream, new UpdateStatus(), !Importer.DEBUG); - } - - public void loadData(Context ctx, Uri uri, String password, Uri keyfile) throws IOException, FileNotFoundException, InvalidDBException { - loadData(ctx, uri, password, keyfile, new UpdateStatus(), !Importer.DEBUG); - } - - public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status) throws IOException, FileNotFoundException, InvalidDBException { + public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status) throws IOException, FileNotFoundException, InvalidDBException { loadData(ctx, uri, password, keyfile, status, !Importer.DEBUG); } - public void loadData(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException { + public void loadData(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug) throws IOException, FileNotFoundException, InvalidDBException { mUri = uri; readOnly = false; if (uri.getScheme().equals("file")) { @@ -141,7 +133,7 @@ public class Database { } - private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, UpdateStatus status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException { + private void passUrisAsInputStreams(Context ctx, Uri uri, String password, Uri keyfile, ProgressTaskUpdater status, boolean debug, long roundsFix) throws IOException, FileNotFoundException, InvalidDBException { InputStream is, kfIs; try { is = UriUtil.getUriInputStream(ctx, uri); @@ -160,14 +152,10 @@ public class Database { } public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, boolean debug) throws IOException, InvalidDBException { - loadData(ctx, is, password, kfIs, new UpdateStatus(), debug); + loadData(ctx, is, password, kfIs, null, debug, 0); } - public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug) throws IOException, InvalidDBException { - loadData(ctx, is, password, kfIs, status, debug, 0); - } - - public void loadData(Context ctx, InputStream is, String password, InputStream kfIs, UpdateStatus status, boolean debug, long roundsFix) throws IOException, InvalidDBException { + private void loadData(Context ctx, InputStream is, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, boolean debug, long roundsFix) throws IOException, InvalidDBException { BufferedInputStream bis = new BufferedInputStream(is); if ( ! bis.markSupported() ) { @@ -181,7 +169,7 @@ public class Database { bis.reset(); // Return to the start - pm = imp.openDatabase(bis, password, kfIs, status, roundsFix); + pm = imp.openDatabase(bis, password, kfIs, progressTaskUpdater, roundsFix); if ( pm != null ) { try { switch (pm.getVersion()) { @@ -225,17 +213,23 @@ public class Database { saveData(ctx, mUri); } - public void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException { - + private void saveData(Context ctx, Uri uri) throws IOException, PwDbOutputException { if (uri.getScheme().equals("file")) { String filename = uri.getPath(); File tempFile = new File(filename + ".tmp"); - FileOutputStream fos = new FileOutputStream(tempFile); - PwDbOutput pmo = PwDbOutput.getInstance(pm, fos); - if (pmo != null) - pmo.output(); - fos.close(); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(tempFile); + PwDbOutput pmo = PwDbOutput.getInstance(pm, fos); + if (pmo != null) + pmo.output(); + } catch (Exception e) { + throw new IOException("Failed to store database."); + } finally { + if (fos != null) + fos.close(); + } // Force data to disk before continuing try { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java index 12fa585be..0da15022b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java @@ -162,7 +162,10 @@ public class PwDatabaseV4 extends PwDatabase { @Override public String getKeyDerivationName(Resources resources) { - return kdfEngine.getName(resources); + if (kdfEngine!=null) + return kdfEngine.getName(resources); + else + return ""; } @Override diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java similarity index 76% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java index 4bc3b74b7..eba9f108a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java @@ -17,25 +17,25 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwEntry; -public class AddEntry extends RunnableOnFinish { +public class AddEntryRunnable extends RunnableOnFinish { protected Database mDb; private PwEntry mEntry; private Context ctx; private boolean mDontSave; - public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { + public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) { this(ctx, db, entry, finish, false); } - public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { + public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) { super(finish); this.mDb = db; @@ -51,13 +51,13 @@ public class AddEntry extends RunnableOnFinish { mDb.addEntryTo(mEntry, mEntry.getParent()); // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); save.run(); } - private class AfterAdd extends OnFinish { + private class AfterAdd extends OnFinishRunnable { - AfterAdd(OnFinish finish) { + AfterAdd(OnFinishRunnable finish) { super(finish); } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java similarity index 78% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java index 21691613a..688aa428e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java @@ -17,26 +17,26 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwGroup; -public class AddGroup extends RunnableOnFinish { +public class AddGroupRunnable extends RunnableOnFinish { protected Database mDb; private PwGroup mNewGroup; private Context ctx; private boolean mDontSave; - public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) { + public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) { this(ctx, db, newGroup, afterAddNode, false); } - public AddGroup(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, - boolean dontSave) { + public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, + boolean dontSave) { super(afterAddNode); this.mDb = db; @@ -52,13 +52,13 @@ public class AddGroup extends RunnableOnFinish { mDb.addGroupTo(mNewGroup, mNewGroup.getParent()); // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); save.run(); } - private class AfterAdd extends OnFinish { + private class AfterAdd extends OnFinishRunnable { - AfterAdd(OnFinish finish) { + AfterAdd(OnFinishRunnable finish) { super(finish); } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/AfterActionNodeOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AfterActionNodeOnFinish.java similarity index 89% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/AfterActionNodeOnFinish.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/AfterActionNodeOnFinish.java index 6e4eb7493..93424790d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/AfterActionNodeOnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AfterActionNodeOnFinish.java @@ -17,13 +17,13 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.os.Handler; import com.kunzisoft.keepass.database.PwNode; -public abstract class AfterActionNodeOnFinish extends OnFinish { +public abstract class AfterActionNodeOnFinish extends OnFinishRunnable { public AfterActionNodeOnFinish(Handler handler) { super(handler); } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java similarity index 74% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java index 850cb91b7..cdd8cb608 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java @@ -17,22 +17,20 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +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 SetPassword extends RunnableOnFinish { +public class AssignPasswordInDBRunnable extends RunnableOnFinish { private String mPassword; private Uri mKeyfile; @@ -40,12 +38,12 @@ public class SetPassword extends RunnableOnFinish { private boolean mDontSave; private Context ctx; - public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish) { + public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) { this(ctx, db, password, keyfile, finish, false); } - public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish, boolean dontSave) { + public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) { super(finish); mDb = db; @@ -55,16 +53,6 @@ public class SetPassword extends RunnableOnFinish { this.ctx = ctx; } - public boolean validatePassword(Context ctx, DialogInterface.OnClickListener onclick) { - if (!mDb.getPwDatabase().validatePasswordEncoding(mPassword)) { - PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); - dialog.show(ctx, onclick, true); - return false; - } - - return true; - } - @Override public void run() { PwDatabase pm = mDb.getPwDatabase(); @@ -88,14 +76,14 @@ public class SetPassword extends RunnableOnFinish { // Save Database mFinish = new AfterSave(backupKey, mFinish); - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); save.run(); } - private class AfterSave extends OnFinish { + private class AfterSave extends OnFinishRunnable { private byte[] mBackup; - public AfterSave(byte[] backup, OnFinish finish) { + public AfterSave(byte[] backup, OnFinishRunnable finish) { super(finish); mBackup = backup; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java similarity index 84% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java index 8c9328f70..7aa72ecc3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; @@ -26,13 +26,13 @@ import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.utils.UriUtil; -public class CreateDB extends RunnableOnFinish { +public class CreateDBRunnable extends RunnableOnFinish { private String mFilename; private boolean mDontSave; private Context ctx; - public CreateDB(Context ctx, String filename, OnFinish finish, boolean dontSave) { + public CreateDBRunnable(Context ctx, String filename, OnFinishRunnable finish, boolean dontSave) { super(finish); mFilename = filename; @@ -56,7 +56,7 @@ public class CreateDB extends RunnableOnFinish { App.clearShutdown(); // Commit changes - SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, db, mFinish, mDontSave); mFinish = null; save.run(); } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteEntry.java b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java similarity index 79% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteEntry.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java index 832da0b2d..0f56322b2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteEntry.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; @@ -29,18 +29,18 @@ import com.kunzisoft.keepass.database.PwGroup; * @author bpellin * */ -public class DeleteEntry extends RunnableOnFinish { +public class DeleteEntryRunnable extends RunnableOnFinish { private Database mDb; private PwEntry mEntry; private boolean mDontSave; private Context ctx; - public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { + public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) { this(ctx, db, entry, finish, false); } - public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { + public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) { super(finish); this.mDb = db; @@ -67,17 +67,17 @@ public class DeleteEntry extends RunnableOnFinish { mFinish = new AfterDelete(mFinish, parent, mEntry, recycle); // Commit database - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); save.run(); } - private class AfterDelete extends OnFinish { + private class AfterDelete extends OnFinishRunnable { private PwGroup mParent; private PwEntry mEntry; private boolean recycled; - AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) { + AfterDelete(OnFinishRunnable finish, PwGroup parent, PwEntry entry, boolean r) { super(finish); mParent = parent; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteGroup.java b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteGroupRunnable.java similarity index 79% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteGroup.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/DeleteGroupRunnable.java index 6fc74c6d5..7a66f21f7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteGroup.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteGroupRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; @@ -29,19 +29,19 @@ import com.kunzisoft.keepass.database.PwGroup; import java.util.ArrayList; import java.util.List; -public class DeleteGroup extends RunnableOnFinish { +public class DeleteGroupRunnable extends RunnableOnFinish { private Context mContext; private Database mDb; private PwGroup mGroup; private boolean mDontSave; - public DeleteGroup(Context ctx, Database db, PwGroup group, OnFinish finish) { + public DeleteGroupRunnable(Context ctx, Database db, PwGroup group, OnFinishRunnable finish) { super(finish); setMembers(ctx, db, group, false); } - public DeleteGroup(Context ctx, Database db, PwGroup group, OnFinish finish, boolean dontSave) { + public DeleteGroupRunnable(Context ctx, Database db, PwGroup group, OnFinishRunnable finish, boolean dontSave) { super(finish); setMembers(ctx, db, group, dontSave); } @@ -67,14 +67,14 @@ public class DeleteGroup extends RunnableOnFinish { // Remove child entries List childEnt = new ArrayList<>(mGroup.getChildEntries()); // TODO new Methods for ( int i = 0; i < childEnt.size(); i++ ) { - DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true); + DeleteEntryRunnable task = new DeleteEntryRunnable(mContext, mDb, childEnt.get(i), null, true); task.run(); } // Remove child groups List childGrp = new ArrayList<>(mGroup.getChildGroups()); for ( int i = 0; i < childGrp.size(); i++ ) { - DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true); + DeleteGroupRunnable task = new DeleteGroupRunnable(mContext, mDb, childGrp.get(i), null, true); task.run(); } mDb.deleteGroup(mGroup); @@ -88,17 +88,17 @@ public class DeleteGroup extends RunnableOnFinish { mFinish = new AfterDelete(mFinish, parent, mGroup, recycle); // Commit Database - SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(mContext, mDb, mFinish, mDontSave); save.run(); } - private class AfterDelete extends OnFinish { + private class AfterDelete extends OnFinishRunnable { private PwGroup mParent; private PwGroup mGroup; private boolean recycled; - AfterDelete(OnFinish finish, PwGroup parent, PwGroup mGroup, boolean recycle) { + AfterDelete(OnFinishRunnable finish, PwGroup parent, PwGroup mGroup, boolean recycle) { super(finish); this.mParent = parent; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java similarity index 81% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java index beca8c727..49e206ed4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java @@ -17,17 +17,17 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.net.Uri; import java.io.Serializable; -public class FileOnFinish extends OnFinish implements Serializable { +public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable { private Uri mFilename = null; - protected FileOnFinish mOnFinish; + protected FileOnFinishRunnable mOnFinish; - public FileOnFinish(FileOnFinish finish) { + public FileOnFinishRunnable(FileOnFinishRunnable finish) { super(finish); mOnFinish = finish; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java b/app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java similarity index 95% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java index f9d42fb6d..289226c81 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import android.content.SharedPreferences; @@ -40,7 +40,7 @@ import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; import java.io.FileNotFoundException; import java.io.IOException; -public class LoadDB extends RunnableOnFinish { +public class LoadDBRunnable extends RunnableOnFinish { private Uri mUri; private String mPass; private Uri mKey; @@ -48,7 +48,7 @@ public class LoadDB extends RunnableOnFinish { private Context mCtx; private boolean mRememberKeyfile; - public LoadDB(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinish finish) { + public LoadDBRunnable(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinishRunnable finish) { super(finish); mDb = db; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/OnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java similarity index 83% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/OnFinish.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java index 030820063..6db343ecf 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/OnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import android.os.Handler; @@ -29,27 +29,27 @@ import android.widget.Toast; * @author bpellin * */ -public class OnFinish implements Runnable { +public class OnFinishRunnable implements Runnable { protected boolean mSuccess; protected String mMessage; - protected OnFinish mOnFinish; + protected OnFinishRunnable mOnFinish; protected Handler mHandler; - public OnFinish() { + public OnFinishRunnable() { } - public OnFinish(Handler handler) { + public OnFinishRunnable(Handler handler) { mOnFinish = null; mHandler = handler; } - public OnFinish(OnFinish finish, Handler handler) { + public OnFinishRunnable(OnFinishRunnable finish, Handler handler) { mOnFinish = finish; mHandler = handler; } - public OnFinish(OnFinish finish) { + public OnFinishRunnable(OnFinishRunnable finish) { mOnFinish = finish; mHandler = null; } @@ -75,7 +75,8 @@ public class OnFinish implements Runnable { } } } - + + // TODO Move protected void displayMessage(Context ctx) { if ( mMessage != null && mMessage.length() > 0 ) { Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/RunnableOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java similarity index 80% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/RunnableOnFinish.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java index d2802279f..aa1f32304 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/RunnableOnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java @@ -17,17 +17,17 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; public abstract class RunnableOnFinish implements Runnable { - public OnFinish mFinish; - public UpdateStatus mStatus; + public OnFinishRunnable mFinish; + public ProgressTaskUpdater mStatus; - public RunnableOnFinish(OnFinish finish) { + public RunnableOnFinish(OnFinishRunnable finish) { mFinish = finish; } @@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable { } } - public void setStatus(UpdateStatus status) { + public void setUpdateProgressTaskStatus(ProgressTaskUpdater status) { mStatus = status; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java similarity index 84% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java index 8933bf724..29a8bca77 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java @@ -17,7 +17,7 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; @@ -26,12 +26,12 @@ import com.kunzisoft.keepass.database.exception.PwDbOutputException; import java.io.IOException; -public class SaveDB extends RunnableOnFinish { +public class SaveDBRunnable extends RunnableOnFinish { private Database mDb; private boolean mDontSave; private Context mCtx; - public SaveDB(Context ctx, Database db, OnFinish finish, boolean dontSave) { + public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish, boolean dontSave) { super(finish); mDb = db; @@ -39,7 +39,7 @@ public class SaveDB extends RunnableOnFinish { mCtx = ctx; } - public SaveDB(Context ctx, Database db, OnFinish finish) { + public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish) { super(finish); mDb = db; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java similarity index 77% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java index 75525f184..050af574d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java @@ -17,14 +17,14 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwEntry; -public class UpdateEntry extends RunnableOnFinish { +public class UpdateEntryRunnable extends RunnableOnFinish { private Database mDb; private PwEntry mOldE; @@ -32,11 +32,11 @@ public class UpdateEntry extends RunnableOnFinish { private Context ctx; private boolean mDontSave; - public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish) { + public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish) { this(ctx, db, oldE, newE, finish, false); } - public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish, boolean dontSave) { + public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish, boolean dontSave) { super(finish); this.mDb = db; @@ -59,14 +59,14 @@ public class UpdateEntry extends RunnableOnFinish { mOldE.touch(true, true); // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); save.run(); } - private class AfterUpdate extends OnFinish { + private class AfterUpdate extends OnFinishRunnable { private PwEntry mBackup; - AfterUpdate(PwEntry backup, OnFinish finish) { + AfterUpdate(PwEntry backup, OnFinishRunnable finish) { super(finish); mBackup = backup; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java similarity index 79% rename from app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java index c9fdcf70e..d1d52c0f6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java @@ -17,14 +17,14 @@ * along with KeePass DX. If not, see . * */ -package com.kunzisoft.keepass.database.edit; +package com.kunzisoft.keepass.database.action; import android.content.Context; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwGroup; -public class UpdateGroup extends RunnableOnFinish { +public class UpdateGroupRunnable extends RunnableOnFinish { private Database mDb; private PwGroup mOldGroup; @@ -32,11 +32,11 @@ public class UpdateGroup extends RunnableOnFinish { private Context ctx; private boolean mDontSave; - public UpdateGroup(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) { + public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) { this(ctx, db, oldGroup, newGroup, finish, false); } - public UpdateGroup(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) { + public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) { super(finish); this.mDb = db; @@ -59,13 +59,13 @@ public class UpdateGroup extends RunnableOnFinish { mOldGroup.touch(true, true); // Commit to disk - new SaveDB(ctx, mDb, mFinish, mDontSave).run(); + new SaveDBRunnable(ctx, mDb, mFinish, mDontSave).run(); } - private class AfterUpdate extends OnFinish { + private class AfterUpdate extends OnFinishRunnable { private PwGroup mBackup; - AfterUpdate(PwGroup backup, OnFinish finish) { + AfterUpdate(PwGroup backup, OnFinishRunnable finish) { super(finish); mBackup = backup; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java b/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java index 2fe04613c..2c56f2122 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/load/Importer.java @@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load; import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.exception.InvalidDBException; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import java.io.IOException; import java.io.InputStream; @@ -33,8 +33,7 @@ public abstract class Importer { public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream) throws IOException, InvalidDBException; - public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, UpdateStatus status, long roundsFix) + public abstract PwDatabase openDatabase(InputStream inStream, String password, InputStream keyInputStream, ProgressTaskUpdater updater, long roundsFix) throws IOException, InvalidDBException; - } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java index 900c9505c..ef02959cc 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3.java @@ -65,7 +65,7 @@ import com.kunzisoft.keepass.database.exception.InvalidPasswordException; import com.kunzisoft.keepass.stream.LEDataInputStream; import com.kunzisoft.keepass.stream.LEDataOutputStream; import com.kunzisoft.keepass.stream.NullOutputStream; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import com.kunzisoft.keepass.utils.Types; import java.io.IOException; @@ -124,15 +124,15 @@ public class ImporterV3 extends Importer { * @throws InvalidAlgorithmParameterException if error decrypting main file body. * @throws ShortBufferException if error decrypting main file body. */ + @Override public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs) - throws IOException, InvalidDBException - { - return openDatabase(inStream, password, kfIs, new UpdateStatus(), 0); + throws IOException, InvalidDBException { + return openDatabase(inStream, password, kfIs, null, 0); } - public PwDatabaseV3 openDatabase( InputStream inStream, String password, InputStream kfIs, UpdateStatus status, long roundsFix) - throws IOException, InvalidDBException - { + @Override + public PwDatabaseV3 openDatabase(InputStream inStream, String password, InputStream kfIs, ProgressTaskUpdater progressTaskUpdater, long roundsFix) + throws IOException, InvalidDBException { PwDatabaseV3 newManager; @@ -156,7 +156,8 @@ public class ImporterV3 extends Importer { throw new InvalidDBVersionException(); } - status.updateMessage(R.string.creating_db_key); + if (progressTaskUpdater != null) + progressTaskUpdater.updateMessage(R.string.creating_db_key); newManager = createDB(); newManager.retrieveMasterKey(password, kfIs); @@ -177,7 +178,8 @@ public class ImporterV3 extends Importer { // Generate transformedMasterKey from masterKey newManager.makeFinalKey(hdr.masterSeed, hdr.transformSeed, newManager.getNumberKeyEncryptionRounds()); - status.updateMessage(R.string.decrypting_db); + if (progressTaskUpdater != null) + progressTaskUpdater.updateMessage(R.string.decrypting_db); // Initialize Rijndael algorithm Cipher cipher; try { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java index df7a4609b..2ad980ed3 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV3Debug.java @@ -21,7 +21,7 @@ package com.kunzisoft.keepass.database.load; import com.kunzisoft.keepass.database.PwDatabaseV3Debug; import com.kunzisoft.keepass.database.exception.InvalidDBException; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import java.io.IOException; import java.io.InputStream; @@ -35,7 +35,7 @@ public class ImporterV3Debug extends ImporterV3 { @Override public PwDatabaseV3Debug openDatabase(InputStream inStream, String password, - InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException, + InputStream keyInputStream, ProgressTaskUpdater status, long roundsFix) throws IOException, InvalidDBException { return (PwDatabaseV3Debug) super.openDatabase(inStream, password, keyInputStream, status, roundsFix); diff --git a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java index 204cf28f7..018e80a42 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/load/ImporterV4.java @@ -19,6 +19,7 @@ */ package com.kunzisoft.keepass.database.load; +import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.crypto.CipherFactory; import com.kunzisoft.keepass.crypto.PwStreamCipherFactory; import com.kunzisoft.keepass.crypto.engine.CipherEngine; @@ -42,7 +43,7 @@ import com.kunzisoft.keepass.stream.BetterCipherInputStream; import com.kunzisoft.keepass.stream.HashedBlockInputStream; import com.kunzisoft.keepass.stream.HmacBlockInputStream; import com.kunzisoft.keepass.stream.LEDataInputStream; -import com.kunzisoft.keepass.tasks.UpdateStatus; +import com.kunzisoft.keepass.tasks.ProgressTaskUpdater; import com.kunzisoft.keepass.utils.DateUtil; import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.MemUtil; @@ -97,13 +98,16 @@ public class ImporterV4 extends Importer { public PwDatabaseV4 openDatabase(InputStream inStream, String password, InputStream keyInputStream) throws IOException, InvalidDBException { - return openDatabase(inStream, password, keyInputStream, new UpdateStatus(), 0); + return openDatabase(inStream, password, keyInputStream, null, 0); } @Override public PwDatabaseV4 openDatabase(InputStream inStream, String password, - InputStream keyInputStream, UpdateStatus status, long roundsFix) throws IOException, + InputStream keyInputStream, ProgressTaskUpdater progressTaskUpdater, long roundsFix) throws IOException, InvalidDBException { + + if (progressTaskUpdater != null) + progressTaskUpdater.updateMessage(R.string.creating_db_key); db = createDB(); PwDbHeaderV4 header = new PwDbHeaderV4(db); @@ -118,6 +122,8 @@ public class ImporterV4 extends Importer { db.retrieveMasterKey(password, keyInputStream); db.makeFinalKey(header.masterSeed, db.getKdfParameters(), roundsFix); + if (progressTaskUpdater != null) + progressTaskUpdater.updateMessage(R.string.decrypting_db); CipherEngine engine; Cipher cipher; try { diff --git a/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java b/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java index 9575c0585..7afbdfb4c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java @@ -24,6 +24,7 @@ import android.app.Activity; import android.app.assist.AssistStructure; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -50,8 +51,8 @@ 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.edit.CreateDB; -import com.kunzisoft.keepass.database.edit.FileOnFinish; +import com.kunzisoft.keepass.database.action.CreateDBRunnable; +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; @@ -59,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; @@ -312,6 +314,7 @@ public class FileSelectActivity extends StylishActivity implements getString(R.string.education_create_database_title), getString(R.string.education_create_database_summary)) .icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -352,6 +355,7 @@ public class FileSelectActivity extends StylishActivity implements getString(R.string.education_select_database_title), getString(R.string.education_select_database_summary)) .icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -373,6 +377,7 @@ public class FileSelectActivity extends StylishActivity implements getString(R.string.education_open_link_database_title), getString(R.string.education_open_link_database_summary)) .icon(ContextCompat.getDrawable(FileSelectActivity.this, R.drawable.ic_link_white_24dp)) + .textColorInt(Color.WHITE) .tintTarget(true) .cancelable(true), new TapTargetView.Listener() { @@ -511,22 +516,26 @@ public class FileSelectActivity extends StylishActivity implements // Prep an object to collect a password once the database has // been created - FileOnFinish launchActivityOnFinish = new FileOnFinish( + FileOnFinishRunnable launchActivityOnFinish = new FileOnFinishRunnable( new LaunchGroupActivity(databaseFilename)); AssignPasswordOnFinish assignPasswordOnFinish = new AssignPasswordOnFinish(launchActivityOnFinish); - // Create the new database - CreateDB create = new CreateDB(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"; @@ -542,21 +551,23 @@ public class FileSelectActivity extends StylishActivity implements } - private class AssignPasswordOnFinish extends FileOnFinish { + private class AssignPasswordOnFinish extends FileOnFinishRunnable { - AssignPasswordOnFinish(FileOnFinish fileOnFinish) { + AssignPasswordOnFinish(FileOnFinishRunnable fileOnFinish) { super(fileOnFinish); } @Override public void run() { if (mSuccess) { - assignPasswordHelper.assignPasswordInDatabase(mOnFinish); + // Dont use ProgressTaskDialogFragment.stop(getSupportFragmentManager()); + // assignPasswordHelper do it + runOnUiThread(() -> assignPasswordHelper.assignPasswordInDatabase(mOnFinish)); } } } - private class LaunchGroupActivity extends FileOnFinish { + private class LaunchGroupActivity extends FileOnFinishRunnable { private Uri mUri; LaunchGroupActivity(String filename) { diff --git a/app/src/main/java/com/kunzisoft/keepass/icons/IconDrawableFactory.java b/app/src/main/java/com/kunzisoft/keepass/icons/IconDrawableFactory.java index a8f9ede20..379524434 100644 --- a/app/src/main/java/com/kunzisoft/keepass/icons/IconDrawableFactory.java +++ b/app/src/main/java/com/kunzisoft/keepass/icons/IconDrawableFactory.java @@ -29,6 +29,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v4.widget.ImageViewCompat; +import android.util.Log; import android.widget.ImageView; import com.kunzisoft.keepass.R; @@ -44,6 +45,9 @@ import org.apache.commons.collections.map.ReferenceMap; * Factory class who build database icons dynamically, can assign an icon of IconPack, or a custom icon to an ImageView with a tint */ public class IconDrawableFactory { + + private static final String TAG = IconDrawableFactory.class.getName(); + private static Drawable blank = null; private static int blankWidth = -1; private static int blankHeight = -1; @@ -236,12 +240,22 @@ public class IconDrawableFactory { Drawable draw = (Drawable) standardIconMap.get(newCacheKey); if (draw == null) { - draw = ContextCompat.getDrawable(context, iconId); + try { + draw = ContextCompat.getDrawable(context, iconId); + } catch (Exception e) { + Log.e(TAG, "Can't get icon", e); + } if (draw != null) { standardIconMap.put(newCacheKey, draw); } } + if (draw == null) { + if (blank == null) + initBlank(context.getResources()); + draw = blank; + } + return draw; } diff --git a/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java b/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java index e405e818a..fd3eaa194 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java @@ -19,25 +19,30 @@ */ package com.kunzisoft.keepass.password; -import android.content.Context; 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.edit.FileOnFinish; -import com.kunzisoft.keepass.database.edit.OnFinish; -import com.kunzisoft.keepass.database.edit.SetPassword; -import com.kunzisoft.keepass.tasks.ProgressTask; +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.dialogs.PasswordEncodingDialogHelper; +import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; public class AssignPasswordHelper { - private Context context; + private AppCompatActivity context; private String masterPassword = null; private Uri keyfile = null; - public AssignPasswordHelper(Context context, + private boolean createProgressDialog; + + public AssignPasswordHelper(AppCompatActivity context, boolean withMasterPassword, String masterPassword, boolean withKeyFile, @@ -47,36 +52,66 @@ public class AssignPasswordHelper { this.masterPassword = masterPassword; if (withKeyFile) this.keyfile = keyfile; + + createProgressDialog = true; } - public void assignPasswordInDatabase(FileOnFinish fileOnFinish) { - SetPassword sp = new SetPassword(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler())); - final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database); - boolean valid = sp.validatePassword(context, (dialog, which) -> pt.run()); + public void setCreateProgressDialog(boolean createProgressDialog) { + this.createProgressDialog = createProgressDialog; + } - if (valid) { - pt.run(); + public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) { + 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)) { + taskThread.start(); + } else { + PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); + dialog.show(context, (newDialog, which) -> taskThread.start(), true); } } - private class AfterSave extends OnFinish { - private FileOnFinish mFinish; + private class AfterSave extends OnFinishRunnable { + private FileOnFinishRunnable mFinish; - public AfterSave(FileOnFinish finish, Handler handler) { + AfterSave(FileOnFinishRunnable finish, Handler handler) { super(finish, handler); mFinish = finish; } @Override public void run() { - if ( mSuccess ) { - if ( mFinish != null ) { - mFinish.setFilename(keyfile); - } - } else { - displayMessage(context); - } super.run(); + + context.runOnUiThread(() -> { + if ( mSuccess ) { + if ( mFinish != null ) { + mFinish.setFilename(keyfile); + } + } else { + if ( mMessage != null && mMessage.length() > 0 ) { + Toast.makeText(context, mMessage, Toast.LENGTH_LONG).show(); + } + } + + // To remove progress task + ProgressTaskDialogFragment.stop(context); + }); } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java index 04e730ab6..ab0e5e1c9 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -24,6 +24,7 @@ import android.app.Activity; import android.app.assist.AssistStructure; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -54,6 +55,7 @@ import com.getkeepsafe.taptargetview.TapTarget; import com.getkeepsafe.taptargetview.TapTargetView; import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.activities.GroupActivity; +import com.kunzisoft.keepass.activities.ListNodesActivity; import com.kunzisoft.keepass.activities.LockingActivity; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.autofill.AutofillHelper; @@ -61,8 +63,8 @@ import com.kunzisoft.keepass.compat.BackupManagerCompat; import com.kunzisoft.keepass.compat.ClipDataCompat; import com.kunzisoft.keepass.compat.EditorCompat; import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.edit.LoadDB; -import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.database.action.LoadDBRunnable; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; import com.kunzisoft.keepass.fileselect.KeyFileHelper; import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector; @@ -70,7 +72,8 @@ import com.kunzisoft.keepass.fingerprint.FingerPrintDialog; import com.kunzisoft.keepass.fingerprint.FingerPrintHelper; 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; @@ -121,6 +124,8 @@ public class PasswordActivity extends StylishActivity private CompoundButton checkboxKeyfileView; private CompoundButton checkboxDefaultDatabaseView; + private ProgressTaskDialogFragment loadingDatabaseDialog; + private DefaultCheckChange defaultCheckChange; private ValidateButtonViewClickListener validateButtonViewClickListener; @@ -337,6 +342,7 @@ public class PasswordActivity extends StylishActivity getString(R.string.education_unlock_summary)) .dimColor(R.color.green) .icon(ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -369,6 +375,7 @@ public class PasswordActivity extends StylishActivity TapTarget.forView(fingerprintImageView, getString(R.string.education_fingerprint_title), getString(R.string.education_fingerprint_summary)) + .textColorInt(Color.WHITE) .tintTarget(false) .cancelable(true), new TapTargetView.Listener() { @@ -805,20 +812,86 @@ 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(); - AfterLoad afterLoad = new AfterLoad(handler, db); + 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) + )); + Thread t = new Thread(databaseLoadingTask); + t.start(); + } - LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); - ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database); - pt.run(); + /** + * Called after verify and try to opening the database + */ + private final class AfterLoadingDatabase extends OnFinishRunnable { + + protected Database db; + + AfterLoadingDatabase( + Handler handler, + Database db) { + super(handler); + + this.db = db; + } + + @Override + public void run() { + runOnUiThread(() -> { + // Recheck fingerprint if error + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // Stay with the same mode + reInitWithFingerprintMode(); + } + + if (db.isPasswordEncodingError()) { + PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); + dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity()); + } else if (mSuccess) { + launchGroupActivity(); + } else { + if ( mMessage != null && mMessage.length() > 0 ) { + Toast.makeText(PasswordActivity.this, mMessage, Toast.LENGTH_LONG).show(); + } + } + + // To remove progress task + ProgressTaskDialogFragment.stop(PasswordActivity.this); + }); + } + } + + private void launchGroupActivity() { + AssistStructure assistStructure = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + assistStructure = autofillHelper.getAssistStructure(); + if (assistStructure != null) { + GroupActivity.launch(PasswordActivity.this, assistStructure); + } + } + if (assistStructure == null) { + GroupActivity.launch(PasswordActivity.this); + } } @Override @@ -860,54 +933,6 @@ public class PasswordActivity extends StylishActivity PasswordActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults); } - /** - * Called after verify and try to opening the database - */ - private final class AfterLoad extends OnFinish { - - protected Database db; - - AfterLoad( - Handler handler, - Database db) { - super(handler); - - this.db = db; - } - - @Override - public void run() { - - // Recheck fingerprint if error - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - // Stay with the same mode - reInitWithFingerprintMode(); - } - - if (db.isPasswordEncodingError()) { - PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); - dialog.show(PasswordActivity.this, (dialog1, which) -> launchGroupActivity()); - } else if (mSuccess) { - launchGroupActivity(); - } else { - displayMessage(PasswordActivity.this); - } - } - } - - private void launchGroupActivity() { - AssistStructure assistStructure = null; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - assistStructure = autofillHelper.getAssistStructure(); - if (assistStructure != null) { - GroupActivity.launch(PasswordActivity.this, assistStructure); - } - } - if (assistStructure == null) { - GroupActivity.launch(PasswordActivity.this); - } - } - private static class UriIntentInitTask extends AsyncTask { static final String KEY_FILENAME = "fileName"; diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java index 983879c61..8dd1e3c48 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseDescriptionPreferenceDialogFragmentCompat.java @@ -19,12 +19,13 @@ */ 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.edit.OnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class DatabaseDescriptionPreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat { @@ -56,22 +57,22 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends InputData database.assignDescription(newDescription); Handler handler = new Handler(); - setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, newDescription, oldDescription)); + setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, newDescription, oldDescription)); } super.onDialogClosed(positiveResult); } - private class AfterDescriptionSave extends OnFinish { + 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; } @@ -81,11 +82,16 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends InputData String descriptionToShow = mNewDescription; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.assignDescription(mOldDescription); } - getPreference().setSummary(descriptionToShow); + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(descriptionToShow); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); + }); + } super.run(); } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java index 5241de323..3c603b373 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseNamePreferenceDialogFragmentCompat.java @@ -19,12 +19,13 @@ */ 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.edit.OnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class DatabaseNamePreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat { @@ -56,22 +57,22 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends InputDatabaseSav database.assignName(newName); Handler handler = new Handler(); - setAfterSaveDatabase(new AfterNameSave(getContext(), handler, newName, oldName)); + setAfterSaveDatabase(new AfterNameSave((AppCompatActivity) getActivity(), handler, newName, oldName)); } super.onDialogClosed(positiveResult); } - private class AfterNameSave extends OnFinish { + private class AfterNameSave extends OnFinishRunnable { 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; } @@ -81,11 +82,17 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends InputDatabaseSav String nameToShow = mNewName; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.assignName(mOldName); } - getPreference().setSummary(nameToShow); + + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(nameToShow); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); + }); + } super.run(); } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java index c85b4f56a..f25695379 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/DatabaseSavePreferenceDialogFragmentCompat.java @@ -21,18 +21,18 @@ 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.edit.OnFinish; -import com.kunzisoft.keepass.database.edit.SaveDB; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.database.action.SaveDBRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat { protected Database database; - private OnFinish afterSaveDatabase; + private OnFinishRunnable afterSaveDatabase; @Override protected void onBindDialogView(View view) { @@ -44,17 +44,21 @@ 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) { - SaveDB save = new SaveDB(getContext(), database, afterSaveDatabase); - ProgressTask pt = new ProgressTask(getContext(), 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(); } } } - public void setAfterSaveDatabase(OnFinish afterSaveDatabase) { + public void setAfterSaveDatabase(OnFinishRunnable afterSaveDatabase) { this.afterSaveDatabase = afterSaveDatabase; } } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/RoundsPreferenceDialogFragmentCompat.java b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/RoundsPreferenceDialogFragmentCompat.java index 5640d77ef..c8b0c95f7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/RoundsPreferenceDialogFragmentCompat.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/preferenceDialogFragment/RoundsPreferenceDialogFragmentCompat.java @@ -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.edit.OnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class RoundsPreferenceDialogFragmentCompat extends InputDatabaseSavePreferenceDialogFragmentCompat { @@ -76,22 +77,22 @@ public class RoundsPreferenceDialogFragmentCompat extends InputDatabaseSavePrefe } Handler handler = new Handler(); - setAfterSaveDatabase(new AfterRoundSave(getContext(), handler, rounds, oldRounds)); + setAfterSaveDatabase(new AfterRoundSave((AppCompatActivity) getActivity(), handler, rounds, oldRounds)); } super.onDialogClosed(positiveResult); } - private class AfterRoundSave extends OnFinish { + private class AfterRoundSave extends OnFinishRunnable { 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,16 @@ public class RoundsPreferenceDialogFragmentCompat extends InputDatabaseSavePrefe long roundsToShow = mNewRounds; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.setNumberKeyEncryptionRounds(mOldRounds); } - getPreference().setSummary(String.valueOf(roundsToShow)); + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(String.valueOf(roundsToShow)); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); + }); + } super.run(); } diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java deleted file mode 100644 index 3eae9817d..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java +++ /dev/null @@ -1,92 +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 . - * - */ -package com.kunzisoft.keepass.tasks; - -import android.app.ProgressDialog; -import android.content.Context; -import android.os.Handler; - -import com.kunzisoft.keepass.R; -import com.kunzisoft.keepass.database.edit.OnFinish; -import com.kunzisoft.keepass.database.edit.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. - * - * @author bpellin - * - */ -public class ProgressTask implements Runnable { - private Context mCtx; - private Handler mHandler; - private RunnableOnFinish mTask; - private ProgressDialog mPd; - - public ProgressTask(Context ctx, RunnableOnFinish task, int messageId) { - mCtx = ctx; - mTask = task; - mHandler = new Handler(); - - // Show process dialog - mPd = new ProgressDialog(mCtx); - mPd.setCanceledOnTouchOutside(false); - mPd.setTitle(ctx.getText(R.string.progress_title)); - mPd.setMessage(ctx.getText(messageId)); - - // Set code to run when this is finished - mTask.setStatus(new UpdateStatus(ctx, mHandler, mPd)); - mTask.mFinish = new AfterTask(task.mFinish, mHandler); - - } - - public void run() { - // Show process dialog - mPd.show(); - - // Start Thread to Run task - Thread t = new Thread(mTask); - t.start(); - } - - private class AfterTask extends OnFinish { - - public AfterTask(OnFinish 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(); - } - } - } - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java new file mode 100644 index 000000000..86b5fa4b2 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java @@ -0,0 +1,129 @@ +/* + * Copyright 2018 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 . + * + */ +package com.kunzisoft.keepass.tasks; + +import android.annotation.SuppressLint; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.utils.Util; + +public class ProgressTaskDialogFragment extends DialogFragment implements ProgressTaskUpdater{ + + public static final String PROGRESS_TASK_DIALOG_TAG = "progressDialogFragment"; + + private static final int UNDEFINED = -1; + + private @StringRes int title = UNDEFINED; + private @StringRes int message = UNDEFINED; + + private TextView titleView; + private TextView messageView; + private ProgressBar progressView; + + public static ProgressTaskDialogFragment start(FragmentManager fragmentManager, @StringRes int titleId) { + // Create an instance of the dialog fragment and show it + ProgressTaskDialogFragment dialog = new ProgressTaskDialogFragment(); + dialog.updateTitle(titleId); + dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); + return dialog; + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + assert getActivity() != null; + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + // Get the layout inflater + LayoutInflater inflater = getActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + @SuppressLint("InflateParams") + View root = inflater.inflate(R.layout.progress_dialog, null); + builder.setView(root); + + titleView = root.findViewById(R.id.progress_dialog_title); + messageView = root.findViewById(R.id.progress_dialog_message); + progressView = root.findViewById(R.id.progress_dialog_bar); + + updateTitle(title); + updateMessage(message); + + setCancelable(false); + Util.lockScreenOrientation(getActivity()); + + return builder.create(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + Util.unlockScreenOrientation(getActivity()); + } + + public static void stop(AppCompatActivity activity) { + Fragment fragmentTask = activity.getSupportFragmentManager().findFragmentByTag(PROGRESS_TASK_DIALOG_TAG); + if (fragmentTask != null) { + ProgressTaskDialogFragment loadingDatabaseDialog = (ProgressTaskDialogFragment) fragmentTask; + loadingDatabaseDialog.dismissAllowingStateLoss(); + Util.unlockScreenOrientation(activity); + } + } + + public void setTitle(@StringRes int titleId) { + this.title = titleId; + } + + private void updateView(TextView textView, @StringRes int resId) { + if (textView != null) { + if (resId == UNDEFINED) { + textView.setVisibility(View.GONE); + } else { + textView.setText(resId); + textView.setVisibility(View.VISIBLE); + } + } + } + + public void updateTitle(int resId) { + this.title = resId; + updateView(titleView, title); + } + + @Override + public void updateMessage(int resId) { + this.message = resId; + updateView(messageView, message); + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskUpdater.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskUpdater.java new file mode 100644 index 000000000..23188c78b --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskUpdater.java @@ -0,0 +1,24 @@ +/* + * Copyright 2018 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 . + * + */ +package com.kunzisoft.keepass.tasks; + +public interface ProgressTaskUpdater { + void updateMessage(int resId); +} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java new file mode 100644 index 000000000..105223b84 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java @@ -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.updateTitle(R.string.saving_database); + dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); + return dialog; + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java similarity index 61% rename from app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java rename to app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java index 43488a9ed..2e2ed1eed 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java @@ -19,27 +19,27 @@ */ package com.kunzisoft.keepass.tasks; -import android.app.ProgressDialog; import android.content.Context; import android.os.Handler; -public class UpdateStatus { - private ProgressDialog mPD; - private Context mCtx; +public class UpdateProgressTaskStatus implements ProgressTaskUpdater { + private Context mContext; + private ProgressTaskUpdater mProgressTaskUpdater; private Handler mHandler; - - public UpdateStatus() { - + + public UpdateProgressTaskStatus(Context context, ProgressTaskUpdater progressTaskUpdater) { + this(context, new Handler(), progressTaskUpdater); } - - public UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) { - mCtx = ctx; - mPD = pd; - mHandler = handler; + + public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) { + this.mContext = context; + this.mProgressTaskUpdater = progressTaskUpdater; + this.mHandler = handler; } - + + @Override public void updateMessage(int resId) { - if ( mCtx != null && mPD != null && mHandler != null ) { + if ( mContext != null && mProgressTaskUpdater != null && mHandler != null ) { mHandler.post(new UpdateMessage(resId)); } } @@ -47,13 +47,12 @@ public class UpdateStatus { private class UpdateMessage implements Runnable { private int mResId; - public UpdateMessage(int resId) { + UpdateMessage(int resId) { mResId = resId; } public void run() { - mPD.setMessage(mCtx.getString(mResId)); + mProgressTaskUpdater.updateMessage(mResId); } - } } diff --git a/app/src/main/java/com/kunzisoft/keepass/utils/Util.java b/app/src/main/java/com/kunzisoft/keepass/utils/Util.java index cae34f1c2..bfdc1cec5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/utils/Util.java +++ b/app/src/main/java/com/kunzisoft/keepass/utils/Util.java @@ -19,9 +19,12 @@ */ package com.kunzisoft.keepass.utils; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.graphics.Typeface; import android.net.Uri; import android.widget.EditText; @@ -70,4 +73,20 @@ public class Util { public static void applyFontVisibilityTo(final Context context, final EditText editText) { applyFontVisibilityTo(context, (TextView) editText); } + + public static void lockScreenOrientation(Activity activity) { + if (activity != null) { + int currentOrientation = activity.getResources().getConfiguration().orientation; + if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } + } + + public static void unlockScreenOrientation(Activity activity) { + if (activity != null) + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } } diff --git a/app/src/main/res/layout/progress_dialog.xml b/app/src/main/res/layout/progress_dialog.xml new file mode 100644 index 000000000..4eae38997 --- /dev/null +++ b/app/src/main/res/layout/progress_dialog.xml @@ -0,0 +1,38 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d84417c27..10d7fa3af 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -166,7 +166,7 @@ Storage Access Framework als Dateimanager verwenden (Android KitKat und später) Storage Access Framework Warnung - Das .kdb Format unterstützt nur den Latin1 Zeichensatz. Ihr Passwort enthällt andere Zeichen. Diese Zeichen werden umgewandelt. Dies reduziert die Sicherheit des Passwortes. Es wird empfohen ihr Passwort zu ändern. + Das .kdb Format unterstützt nur den Latin1 Zeichensatz. Ihr Passwort enthält andere Zeichen. Diese Zeichen werden umgewandelt. Dies reduziert die Sicherheit des Passwortes. Es wird empfohlen ihr Passwort zu ändern. Die SD-Karte ist schreibgeschützt. Etwaige Änderungen in den Datensätzen können daher nicht in der Datenbank gespeichert werden. Keine SD-Karte vorhanden oder derzeit nicht im Gerät eingebunden. Daher kann weder eine Datenbank geöffnet, noch erstellt werden. Version: @@ -217,6 +217,8 @@ Fingerabruck unterstützt, jedoch nicht für dieses Gerät konfiguriert Fingerabdruck wird gescannt Verschlüsseltes Passwort wurde gespeichert + Ungültiger Schlüssel + Probleme mit dem Fingerabdruck : %1$s Verlauf Wie richte ich den Fingerabdruckscanner ein ? Speichern sie ihren persönlichen Fingerabruck in diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 1652bba15..677de4ba3 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -290,7 +290,7 @@ Participer pour augmenter la stabilité, la sécurité et ajouter plus de fonctionnalités. Contrairement à d\'autres applications de gestion de mots de passe, cette application est <strong>sans publicité</strong>, <strong>open source</strong> et ne récupère pas de données personnelles sur ses serveurs, même dans sa version gratuite. - En achetant la version pro, vous accéderez à cette <strong>fonctionnalité</strong> <i>(et bien d\'autres)</i> et vous aiderez en particulier à <strong>la réalisation de projets communautaires.</strong> + En achetant la version pro, vous accéderez à cette <strong>fonctionnalité visuelle</strong> et vous aiderez en particulier à <strong>la réalisation de projets communautaires.</strong> Cette <strong>fonctionnalité</strong> <i>(et bien d\'autres)</i> sont disponibles grâce à votre générosité. Afin de garder notre liberté et d\'être toujours actif, nous comptons sur votre <strong>contribution.</strong> diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 02df6a4a4..42ca383c5 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -17,25 +17,29 @@ You should have received a copy of the GNU General Public License along with KeePass DX. If not, see . - Italian translation by Diego Pierotto + Italian translation by Diego Pierotto. Updated by anthologist on April 2018. --> Commenti: Pagina web: - KeePass DX è un\'implementazione del gestore password KeePass. + KeePass DX è un\'implementazione Android del gestore password KeePass. Accetto Aggiungi voce Aggiungi gruppo + Aggiungi stringa Algoritmo Scadenza applicazione Tempo prima che venga bloccato il database quando l\'applicazione è inattiva. Applicazione - Impostazioni Applicazione + Impostazioni applicazione Parentesi Sfogliare i file richiede l\'applicazione Gestore File di Open Intents, clicca sotto per installarlo. A causa di alcune stranezze nel gestore file, la prima volta la navigazione potrebbe non funzionare correttamente. Annulla Appunti eliminati. + Errore negli appunti + Alcuni telefoni Android di Samsung hanno un bug nell\'implementazione degli appunti che causa errori nella copia degli appunti da applicazioni. Per maggiori dettagli: + Eliminazione degli appunti fallita Scadenza appunti Tempo prima di eliminare gli appunti dopo la copia del nome file o password Copia %1$s negli appunti @@ -44,7 +48,7 @@ Decodifica contenuto database… Usa come database predefinito Cifre - KeePass DX \u00A9 %1$d Kunzisoft viene distribuito ASSOLUTAMENTE con NESSUNA GARANZIA; Si tratta di software libero, e sei invitato a distribuirlo sotto le condizioni della licenza GPL versione 3 o superiore. + KeePass DX \u00A9 %1$d Kunzisoft viene distribuito ASSOLUTAMENTE con NESSUNA GARANZIA; Si tratta di software libero e sei invitato a distribuirlo sotto le condizioni della licenza GPL versione 3 o superiore. Inserisci il nome file del database Ultimo accesso Annulla @@ -54,6 +58,7 @@ Scade File chiave Modificato + Dati non trovati. Password Salva Nome @@ -64,20 +69,24 @@ Impossibile creare la directory principale. File già esistente. Impossibile aprire il collegamento. - E\' necessario un nome file. + È necessario un nome file. Impossibile creare il file: Database non valido. Percorso non valido. - E\' necessario un nome. - E\' necessaria una password o un file chiave. + È necessario un nome. + È necessaria una password o un file chiave. Il telefono ha esaurito la memoria durante l\'elaborazione del database. Potrebbe essere troppo grande per il tuo telefono. - Almeno un tipo di generazione password deve essere selezionato + Deve essere selezionato almeno un tipo di generazione password Le password non corrispondono. Il livello deve essere un numero. Livello troppo grande. Impostato a 2147483648. - E\' necessario un titolo. - Inserisci un valore positivo nella lunghezza campo + È richiesto un nome per ogni stringa. + È necessario un titolo. + Inserisci un valore positivo nel campo lunghezza + Nome campo + Valore campo File non trovato. + File non trovato. Prova a riaprire dal tuo fornitore di contenuti. Sfoglia file Genera password conferma password @@ -90,7 +99,10 @@ Installa dal Play Store Installa dal F-Droid Password o file chiave non validi. + Algoritmo non valido. Formato database non riconosciuto. + Il file chiave non esiste. + Il file chiave è vuoto. Lunghezza Dimensione elenco gruppo Dimensione del testo nell\'elenco del gruppo @@ -99,34 +111,41 @@ Maschera password Nascondi le password in modo predefinito Info - Modifica chiave Principale + Modifica chiave principale Impostazioni - Impostazioni Database + Impostazioni database Elimina Dona Modifica - Nascondi Password - Blocca Database + Nascondi password + Blocca database Apri Cerca - Mostra Password + Mostra password Vai all\'URL Meno Mai Nessun risultato di ricerca Nessun gestore per questo URL. Apri un database recente : - Non cercare voci di backup e nel Cestino - Ometti i gruppi \'Backup\' e Cestino dai risultati di ricerca + Non cercare voci di backup + Ometti il gruppo \'Backup\' dai risultati di ricerca (si applica solo ai .kdb) Creazione nuovo database… In corso… + Protezione + Sola lettura + KeePassDroid non ha i permessi di scrittura nel percorso del database, quindi il database verrà aperto in sola lettura. + A partire da Android KitKat, alcuni dispositivi non permettono più alle applicazioni di scrivere nella scheda SD. + Cronologia file recenti + Ricorda i file usati recentemente Ricorda la posizione dei file chiave Salva il file chiave Elimina - Rijndael (AES) - Principale + Root Livello cifratura Un livello di cifratura elevato fornisce una protezione maggiore contro attacchi di tipo "forza brutta", ma può veramente rallentare il caricamento e il salvataggio. + Livello di cifratura prima della malformazione + Se il database si è rovinato, inserisci il numero di livello usato precedentemente e il database potrà essere aperto. livello Salvataggio database… Spazio @@ -134,13 +153,24 @@ Ordinamento DB Speciale Titolo/descrizione voce - Twofish + Risultati ricerca Sottolinea Versione database non supportata. Maiuscolo + Usa l\'Android Storage Access Framework per sfogliare i file (KitKat e successivi) + Storage Access Framework + Attenzione + Il formato .kdb supporta solo il set di caratteri Latin1. La tua password potrebbe contenere caratteri fuori da questo set. Tutti i caratteri non Latin1 vengono convertiti nello stesso carattere, il che riduce la sicurezza della password. Si consiglia di modificare la password. Attualmente la scheda SD è in sola lettura. Non sei in grado di salvare le modifiche nel database. Attualmente la scheda SD non è montata nel dispositivo. Non sarai in grado di caricare o creare un nuovo database. Versione: + Impronte supportate ma non configurate nel dispositivo + In attesa di impronte + Password criptata salvata + Problema chiave non valida + Problema impronta : %1$s + Usa l\'impronta per salvare questa password + Nessuna password salvata per questo database Inserisci una password e/o file chiave per sbloccare il database. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 1d88ab132..5b80757f8 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -24,6 +24,7 @@ Принять Новая запись Новая группа + Новая строка Алгоритм Блокировка базы Задержка блокировки при бездействии @@ -45,7 +46,7 @@ Расшифровка базы… По умолчанию Цифры 0…9 - KeePass DX \u00A9 %1$d Kunzisoft Программа предоставляется БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ. Распространяется свободно по лицензии GPL v3 или новее + KeePass DX \u00A9 %1$d Kunzisoft Программа предоставляется БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ. Распространяется свободно по лицензии GPL v3 или новее. Путь к базе KeePass Доступ Отмена @@ -83,6 +84,7 @@ Имя поля Значение поля Файл не найден + Файл не найден. Попробуйте повторно открыть через встроенный поставщик содержимого. Обзор файлов Создать пароль подтверждение @@ -129,7 +131,8 @@ Создание базы… Обработка Защита - KeePass DX не имеет разрешений на запись по указанному пути. База будет открыта только для чтения + Только чтение + KeePass DX не имеет разрешений на запись по указанному пути. База будет открыта только для чтения. Начиная с Android KitKat, на некоторых устройствах приложениям запрещена запись на SD-карту Недавно открытые Хранить имена открытых файлов @@ -154,25 +157,32 @@ _Подчёркивание_ Неподдерживаемая версия базы ЗАГЛАВНЫЕ - Storage Access Framework для обзора файлов (KK+) + Storage Access Framework для обзора файлов (KitKat+) Обзор через SAF Внимание - Пароль содержит символы вне кодировки Latin1, поддерживаемой форматом .kdb! ВСЕ не-Latin1 символы будут преобразованы в одинаковый символ. Рекомендуется изменить пароль - Запись на карту памяти невозможна. Изменения не будут сохранены - Карта памяти не подключена. Работа с базой невозможна + Пароль содержит символы вне кодировки Latin1, поддерживаемой форматом .kdb! ВСЕ не-Latin1 символы будут преобразованы в одинаковый символ. Рекомендуется изменить пароль. + Запись на карту памяти невозможна. Изменения не будут сохранены. + Карта памяти не подключена. Работа с базой невозможна. Версия: + Отпечатки пальцев поддерживаются, но не настроены на устройстве + Ожидание отпечатка пальца + Зашифрованный пароль сохранён + Проблема из-за неверного ключа + Проблема с отпечатком пальца : %1$s + Используйте отпечаток пальца, чтобы сохранить пароль + Для этой базы пароль ещё не сохранён Введите пароль или путь к файлу-ключу. - 5 сек. - 10 сек. - 20 сек. - 30 сек. - 1 мин. - 5 мин. - 15 мин. - 30 мин. + 5 секунд + 10 секунд + 20 секунд + 30 секунд + 1 минута + 5 минут + 15 минут + 30 минут Никогда diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b61df37e4..965becbb9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -291,7 +291,7 @@ Participate to increase the stability, the security and to add more features. Unlike many password management applications, this app is <strong>ad-free</strong>, <strong>open source</strong> and does not recover personal data on its servers, even in its free version. - By buying the pro version, you will have access to this <strong>feature</strong> <i>(and many more)</i> and you will help especially to <strong>the realization of community projects.</strong> + By buying the pro version, you will have access to this <strong>visual feature</strong> and you will help especially to <strong>the realization of community projects.</strong> This <strong>feature</strong> <i>(and many more)</i> are available thanks to your generosity. In order to keep our freedom and to be always active, we count on your <strong>contribution.</strong> diff --git a/fastlane/metadata/android/en-US/changelogs/10.txt b/fastlane/metadata/android/en-US/changelogs/10.txt new file mode 100644 index 000000000..d37af4810 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/10.txt @@ -0,0 +1,4 @@ + * Upgrade translations + * Fix classic dark theme + * Add Material Icon Pack to the Free version + * Fix bugs \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/10.txt b/fastlane/metadata/android/fr-FR/changelogs/10.txt new file mode 100644 index 000000000..1e7a183b7 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/10.txt @@ -0,0 +1,4 @@ + * Mise à jour des traductions + * Correction du thème sombre classic + * Ajout du Pack d'Icones Material à la version gratuite + * Corrections de bugs \ No newline at end of file