From cefc546c0ae646c8e65db85f8a0f3330878a9db2 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 28 Apr 2018 11:08:23 +0200 Subject: [PATCH 01/18] Upgrade german translation --- app/src/main/res/values-de/strings.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 58b10d367..b2eb109d9 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 Verlauf Wie richte ich den Fingerabdruckscanner ein ? Speichern sie ihren persönlichen Fingerabruck in From 1d36683128c6ff7c246df02491e033a8369f2411 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 28 Apr 2018 11:11:50 +0200 Subject: [PATCH 02/18] Remove screens in Readme --- ReadMe.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 2594859b5..38ce991ce 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,9 +38,6 @@ 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 [ Date: Sat, 28 Apr 2018 19:49:59 +0200 Subject: [PATCH 03/18] Fix crash by return blank when Resources$NotFoundException --- .../keepass/icons/IconDrawableFactory.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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; } From 5cf5719e8e11d0a5e0cd538f9716035037045104 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 28 Apr 2018 20:08:33 +0200 Subject: [PATCH 04/18] Fix education text color --- .../java/com/kunzisoft/keepass/activities/EntryActivity.java | 2 ++ .../com/kunzisoft/keepass/activities/EntryEditActivity.java | 2 ++ .../java/com/kunzisoft/keepass/activities/GroupActivity.java | 4 ++++ .../com/kunzisoft/keepass/fileselect/FileSelectActivity.java | 4 ++++ .../java/com/kunzisoft/keepass/password/PasswordActivity.java | 3 +++ 5 files changed, 15 insertions(+) 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..8308f853a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -274,6 +274,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 +301,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() { 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..b46f7f092 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java @@ -285,6 +285,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 +314,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 +346,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 +377,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() { 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..dff6d0083 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; @@ -312,6 +313,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 +354,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 +376,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() { 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..9e3887044 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; @@ -337,6 +338,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 +371,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() { From 52e12d7cbd01e90b4e7daec79dc5294d291a54e1 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 28 Apr 2018 22:34:25 +0200 Subject: [PATCH 05/18] Upgrade russian translation --- app/src/main/res/values-ru/strings.xml | 38 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 0a44a2da4..e483d1cef 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 минут Никогда From 5fbb37df824889193e2e3538447cb11ce35f851f Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sun, 29 Apr 2018 14:07:56 +0200 Subject: [PATCH 06/18] Fix german fingerprint error --- app/src/main/res/values-de/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b2eb109d9..5ddb9183d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -218,7 +218,7 @@ Fingerabdruck wird gescannt Verschlüsseltes Passwort wurde gespeichert Ungültiger Schlüssel - Probleme mit dem Fingerabdruck + Probleme mit dem Fingerabdruck : %1$s Verlauf Wie richte ich den Fingerabdruckscanner ein ? Speichern sie ihren persönlichen Fingerabruck in From 42d34d8f0cc7d56fc612ff6b253e904a2f7dc04f Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 16:10:18 +0200 Subject: [PATCH 07/18] Add material icon pack in free version and change texts --- ReadMe.md | 2 ++ app/build.gradle | 2 +- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 38ce991ce..2a88da271 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -40,6 +40,8 @@ You can contribute in different ways to help us on our work. ## 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..fba6450bb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5c0f738c4..6410d674d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -294,7 +294,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> From b796c1687729c93a55bc60135e5efdb1f21547b4 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 16:57:10 +0200 Subject: [PATCH 08/18] Upgrade Italian --- app/src/main/res/values-it/strings.xml | 68 +++++++++++++++++++------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 26fdbc89e..fc4751f56 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,42 @@ 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 +154,25 @@ Ordinamento DB Speciale Titolo/descrizione voce + Risultati ricerca Twofish 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. From 3c66ec82b5b6a8daa9d1e6d290ca0937cb395242 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 17:00:42 +0200 Subject: [PATCH 09/18] Upgrade French --- app/src/main/res/values-fr/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 891acfcb4..c5f210eb1 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> From 4164b5bd37fe53f8dfb5e4f8fafcf3913e5650b8 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 17:47:31 +0200 Subject: [PATCH 10/18] Fix crash by locking activity position --- .../keepass/tests/database/DeleteEntry.java | 4 +- .../keepass/activities/EntryEditActivity.java | 16 +-- .../keepass/activities/GroupActivity.java | 16 +-- .../keepass/activities/ListNodesActivity.java | 6 +- .../database/action/AddEntryRunnable.java | 73 ++++++++++ .../database/action/AddGroupRunnable.java | 79 +++++++++++ .../AfterActionNodeOnFinish.java | 4 +- .../database/action/CreateDBRunnable.java | 63 +++++++++ .../database/action/DeleteEntryRunnable.java | 103 +++++++++++++++ .../DeleteGroupRunnable.java} | 18 +-- .../database/action/FileOnFinishRunnable.java | 44 ++++++ .../database/action/LoadDBRunnable.java | 125 ++++++++++++++++++ .../OnFinishRunnable.java} | 14 +- .../{edit => action}/RunnableOnFinish.java | 6 +- .../database/action/SaveDBRunnable.java | 69 ++++++++++ .../database/action/SetPasswordRunnable.java | 118 +++++++++++++++++ .../database/action/UpdateEntryRunnable.java | 84 ++++++++++++ .../database/action/UpdateGroupRunnable.java | 88 ++++++++++++ .../fileselect/FileSelectActivity.java | 14 +- .../password/AssignPasswordHelper.java | 29 ++-- .../keepass/password/PasswordActivity.java | 8 +- ...riptionPreferenceDialogFragmentCompat.java | 4 +- ...aseNamePreferenceDialogFragmentCompat.java | 4 +- ...aseSavePreferenceDialogFragmentCompat.java | 12 +- .../RoundsPreferenceDialogFragmentCompat.java | 4 +- .../kunzisoft/keepass/tasks/ProgressTask.java | 56 +++++--- 26 files changed, 964 insertions(+), 97 deletions(-) create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java rename app/src/main/java/com/kunzisoft/keepass/database/{edit => action}/AfterActionNodeOnFinish.java (89%) create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java rename app/src/main/java/com/kunzisoft/keepass/database/{edit/DeleteGroup.java => action/DeleteGroupRunnable.java} (79%) create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java rename app/src/main/java/com/kunzisoft/keepass/database/{edit/OnFinish.java => action/OnFinishRunnable.java} (84%) rename app/src/main/java/com/kunzisoft/keepass/database/{edit => action}/RunnableOnFinish.java (90%) create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java 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/EntryEditActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java index 8308f853a..47b325941 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -49,10 +49,10 @@ 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; @@ -249,13 +249,13 @@ public class EntryEditActivity extends LockingHideActivity } mCallbackNewEntry = populateNewEntry(); - OnFinish onFinish = new AfterSave(); + 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(); @@ -554,7 +554,7 @@ public class EntryEditActivity extends LockingHideActivity } } - private final class AfterSave extends OnFinish { + private final class AfterSave extends OnFinishRunnable { AfterSave() { super(new Handler()); 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 b46f7f092..307f3df89 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; @@ -435,7 +435,7 @@ 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(); @@ -444,7 +444,7 @@ public class GroupActivity extends ListNodesActivity 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(); @@ -552,7 +552,7 @@ public class GroupActivity extends ListNodesActivity newGroup.setIcon(iconStandard); new ProgressTask(this, - new AddGroup(this, + new AddGroupRunnable(this, App.getDB(), newGroup, new AfterAddNode(new Handler())), @@ -572,7 +572,7 @@ public class GroupActivity extends ListNodesActivity mAdapter.removeNode(oldGroupToUpdate); // If group update new ProgressTask(this, - new UpdateGroup(this, + new UpdateGroupRunnable(this, App.getDB(), oldGroupToUpdate, updateGroup, 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..b2ef7a8dc 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java @@ -49,8 +49,8 @@ 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; @@ -330,7 +330,7 @@ public abstract class ListNodesActivity extends LockingActivity } } - class AfterDeleteNode extends OnFinish { + class AfterDeleteNode extends OnFinishRunnable { private PwNode pwNode; AfterDeleteNode(Handler handler, PwNode pwNode) { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java new file mode 100644 index 000000000..eba9f108a --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AddEntryRunnable.java @@ -0,0 +1,73 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwEntry; + +public class AddEntryRunnable extends RunnableOnFinish { + + protected Database mDb; + private PwEntry mEntry; + private Context ctx; + private boolean mDontSave; + + public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) { + this(ctx, db, entry, finish, false); + } + + public AddEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + this.mDb = db; + this.mEntry = entry; + this.ctx = ctx; + this.mDontSave = dontSave; + + this.mFinish = new AfterAdd(mFinish); + } + + @Override + public void run() { + mDb.addEntryTo(mEntry, mEntry.getParent()); + + // Commit to disk + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); + save.run(); + } + + private class AfterAdd extends OnFinishRunnable { + + AfterAdd(OnFinishRunnable finish) { + super(finish); + } + + @Override + public void run() { + if ( !mSuccess ) { + mDb.removeEntryFrom(mEntry, mEntry.getParent()); + } + // TODO if add entry callback + super.run(); + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java new file mode 100644 index 000000000..688aa428e --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AddGroupRunnable.java @@ -0,0 +1,79 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwGroup; + +public class AddGroupRunnable extends RunnableOnFinish { + + protected Database mDb; + private PwGroup mNewGroup; + private Context ctx; + private boolean mDontSave; + + public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode) { + this(ctx, db, newGroup, afterAddNode, false); + } + + public AddGroupRunnable(Context ctx, Database db, PwGroup newGroup, AfterActionNodeOnFinish afterAddNode, + boolean dontSave) { + super(afterAddNode); + + this.mDb = db; + this.mNewGroup = newGroup; + this.mDontSave = dontSave; + this.ctx = ctx; + + this.mFinish = new AfterAdd(mFinish); + } + + @Override + public void run() { + mDb.addGroupTo(mNewGroup, mNewGroup.getParent()); + + // Commit to disk + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); + save.run(); + } + + private class AfterAdd extends OnFinishRunnable { + + AfterAdd(OnFinishRunnable finish) { + super(finish); + } + + @Override + public void run() { + if ( !mSuccess ) { + mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent()); + } + + // TODO Better callback + AfterActionNodeOnFinish afterAddNode = + (AfterActionNodeOnFinish) super.mOnFinish; + afterAddNode.mSuccess = mSuccess; + afterAddNode.mMessage = mMessage; + afterAddNode.run(null, mNewGroup); + } + } +} 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/action/CreateDBRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java new file mode 100644 index 000000000..7aa72ecc3 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/CreateDBRunnable.java @@ -0,0 +1,63 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.app.App; +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwDatabase; +import com.kunzisoft.keepass.utils.UriUtil; + +public class CreateDBRunnable extends RunnableOnFinish { + + private String mFilename; + private boolean mDontSave; + private Context ctx; + + public CreateDBRunnable(Context ctx, String filename, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + mFilename = filename; + mDontSave = dontSave; + this.ctx = ctx; + } + + @Override + public void run() { + // Create new database record + Database db = new Database(); + App.setDB(db); + + PwDatabase pm = PwDatabase.getNewDBInstance(mFilename); + pm.initNew(mFilename); + + // Set Database state + db.setPwDatabase(pm); + db.setUri(UriUtil.parseDefaultFile(mFilename)); + db.setLoaded(); + App.clearShutdown(); + + // Commit changes + SaveDBRunnable save = new SaveDBRunnable(ctx, db, mFinish, mDontSave); + mFinish = null; + save.run(); + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java new file mode 100644 index 000000000..0f56322b2 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/DeleteEntryRunnable.java @@ -0,0 +1,103 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwEntry; +import com.kunzisoft.keepass.database.PwGroup; + +/** Task to delete entries + * @author bpellin + * + */ +public class DeleteEntryRunnable extends RunnableOnFinish { + + private Database mDb; + private PwEntry mEntry; + private boolean mDontSave; + private Context ctx; + + public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish) { + this(ctx, db, entry, finish, false); + } + + public DeleteEntryRunnable(Context ctx, Database db, PwEntry entry, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + this.mDb = db; + this.mEntry = entry; + this.mDontSave = dontSave; + this.ctx = ctx; + + } + + @Override + public void run() { + PwGroup parent = mEntry.getParent(); + + // Remove Entry from parent + boolean recycle = mDb.canRecycle(mEntry); + if (recycle) { + mDb.recycle(mEntry); + } + else { + mDb.deleteEntry(mEntry); + } + + // Save + mFinish = new AfterDelete(mFinish, parent, mEntry, recycle); + + // Commit database + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); + save.run(); + } + + private class AfterDelete extends OnFinishRunnable { + + private PwGroup mParent; + private PwEntry mEntry; + private boolean recycled; + + AfterDelete(OnFinishRunnable finish, PwGroup parent, PwEntry entry, boolean r) { + super(finish); + + mParent = parent; + mEntry = entry; + recycled = r; + } + + @Override + public void run() { + if ( !mSuccess ) { + if (recycled) { + mDb.undoRecycle(mEntry, mParent); + } + else { + mDb.undoDeleteEntry(mEntry, mParent); + } + } + // TODO Callback after delete entry + + super.run(); + } + } +} 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/action/FileOnFinishRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java new file mode 100644 index 000000000..49e206ed4 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/FileOnFinishRunnable.java @@ -0,0 +1,44 @@ +/* + * 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.database.action; + +import android.net.Uri; + +import java.io.Serializable; + +public class FileOnFinishRunnable extends OnFinishRunnable implements Serializable { + private Uri mFilename = null; + protected FileOnFinishRunnable mOnFinish; + + public FileOnFinishRunnable(FileOnFinishRunnable finish) { + super(finish); + + mOnFinish = finish; + } + + public void setFilename(Uri filename) { + mFilename = filename; + } + + public Uri getFilename() { + return mFilename; + } + +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java new file mode 100644 index 000000000..289226c81 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/LoadDBRunnable.java @@ -0,0 +1,125 @@ +/* + * 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.database.action; + +import android.content.Context; +import android.content.SharedPreferences; +import android.net.Uri; +import android.preference.PreferenceManager; + +import com.kunzisoft.keepass.R; +import com.kunzisoft.keepass.app.App; +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.exception.ArcFourException; +import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; +import com.kunzisoft.keepass.database.exception.InvalidAlgorithmException; +import com.kunzisoft.keepass.database.exception.InvalidDBException; +import com.kunzisoft.keepass.database.exception.InvalidDBSignatureException; +import com.kunzisoft.keepass.database.exception.InvalidDBVersionException; +import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; +import com.kunzisoft.keepass.database.exception.InvalidPasswordException; +import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; + +import java.io.FileNotFoundException; +import java.io.IOException; + +public class LoadDBRunnable extends RunnableOnFinish { + private Uri mUri; + private String mPass; + private Uri mKey; + private Database mDb; + private Context mCtx; + private boolean mRememberKeyfile; + + public LoadDBRunnable(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinishRunnable finish) { + super(finish); + + mDb = db; + mCtx = ctx; + mUri = uri; + mPass = pass; + mKey = key; + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); + mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default)); + } + + @Override + public void run() { + try { + mDb.loadData(mCtx, mUri, mPass, mKey, mStatus); + + saveFileData(mUri, mKey); + + } catch (ArcFourException e) { + finish(false, mCtx.getString(R.string.error_arc4)); + return; + } catch (InvalidPasswordException e) { + finish(false, mCtx.getString(R.string.InvalidPassword)); + return; + } catch (ContentFileNotFoundException e) { + finish(false, mCtx.getString(R.string.file_not_found_content)); + return; + } catch (FileNotFoundException e) { + finish(false, mCtx.getString(R.string.file_not_found)); + return; + } catch (IOException e) { + finish(false, e.getMessage()); + return; + } catch (KeyFileEmptyException e) { + finish(false, mCtx.getString(R.string.keyfile_is_empty)); + return; + } catch (InvalidAlgorithmException e) { + finish(false, mCtx.getString(R.string.invalid_algorithm)); + return; + } catch (InvalidKeyFileException e) { + finish(false, mCtx.getString(R.string.keyfile_does_not_exist)); + return; + } catch (InvalidDBSignatureException e) { + finish(false, mCtx.getString(R.string.invalid_db_sig)); + return; + } catch (InvalidDBVersionException e) { + finish(false, mCtx.getString(R.string.unsupported_db_version)); + return; + } catch (InvalidDBException e) { + finish(false, mCtx.getString(R.string.error_invalid_db)); + return; + } catch (OutOfMemoryError e) { + finish(false, mCtx.getString(R.string.error_out_of_memory)); + return; + } catch (Exception e) { + finish(false, e.getMessage()); + return; + } + + finish(true); + } + + private void saveFileData(Uri uri, Uri key) { + if ( ! mRememberKeyfile ) { + key = null; + } + + App.getFileHistory().createFile(uri, key); + } + + + +} 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 84% 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..82d34d87c 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; } 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 90% 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..e509122bc 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; public abstract class RunnableOnFinish implements Runnable { - public OnFinish mFinish; + public OnFinishRunnable mFinish; public UpdateStatus mStatus; - public RunnableOnFinish(OnFinish finish) { + public RunnableOnFinish(OnFinishRunnable finish) { mFinish = finish; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java new file mode 100644 index 000000000..29a8bca77 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/SaveDBRunnable.java @@ -0,0 +1,69 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.exception.PwDbOutputException; + +import java.io.IOException; + +public class SaveDBRunnable extends RunnableOnFinish { + private Database mDb; + private boolean mDontSave; + private Context mCtx; + + public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + mDb = db; + mDontSave = dontSave; + mCtx = ctx; + } + + public SaveDBRunnable(Context ctx, Database db, OnFinishRunnable finish) { + super(finish); + + mDb = db; + mDontSave = false; + mCtx = ctx; + } + + @Override + public void run() { + + if ( ! mDontSave ) { + try { + mDb.saveData(mCtx); + } catch (IOException e) { + finish(false, e.getMessage()); + return; + } catch (PwDbOutputException e) { + // TODO: Restore + finish(false, e.getMessage()); + return; + } + } + + finish(true); + } + +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java new file mode 100644 index 000000000..7d76c6303 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java @@ -0,0 +1,118 @@ +/* + * 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.database.action; + +import android.content.Context; +import android.content.DialogInterface; +import android.net.Uri; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwDatabase; +import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; +import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; +import com.kunzisoft.keepass.utils.UriUtil; + +import java.io.IOException; +import java.io.InputStream; + +public class SetPasswordRunnable extends RunnableOnFinish { + + private String mPassword; + private Uri mKeyfile; + private Database mDb; + private boolean mDontSave; + private Context ctx; + + public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) { + this(ctx, db, password, keyfile, finish, false); + + } + + public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + mDb = db; + mPassword = password; + mKeyfile = keyfile; + mDontSave = dontSave; + this.ctx = ctx; + } + + @Override + public void run() { + PwDatabase pm = mDb.getPwDatabase(); + + byte[] backupKey = new byte[pm.getMasterKey().length]; + System.arraycopy(pm.getMasterKey(), 0, backupKey, 0, backupKey.length); + + // Set key + try { + InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile); + pm.setMasterKey(mPassword, is); + } catch (InvalidKeyFileException e) { + erase(backupKey); + finish(false, e.getMessage()); + return; + } catch (IOException e) { + erase(backupKey); + finish(false, e.getMessage()); + return; + } + + // Save Database + mFinish = new AfterSave(backupKey, mFinish); + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); + save.run(); + } + + private class AfterSave extends OnFinishRunnable { + private byte[] mBackup; + + public AfterSave(byte[] backup, OnFinishRunnable finish) { + super(finish); + + mBackup = backup; + } + + @Override + public void run() { + if ( ! mSuccess ) { + // Erase the current master key + erase(mDb.getPwDatabase().getMasterKey()); + mDb.getPwDatabase().setMasterKey(mBackup); + } + + super.run(); + } + + } + + /** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory + * @param array + */ + private void erase(byte[] array) { + if ( array == null ) return; + + for ( int i = 0; i < array.length; i++ ) { + array[i] = 0; + } + } + +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java new file mode 100644 index 000000000..050af574d --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateEntryRunnable.java @@ -0,0 +1,84 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwEntry; + +public class UpdateEntryRunnable extends RunnableOnFinish { + + private Database mDb; + private PwEntry mOldE; + private PwEntry mNewE; + private Context ctx; + private boolean mDontSave; + + public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish) { + this(ctx, db, oldE, newE, finish, false); + } + + public UpdateEntryRunnable(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinishRunnable finish, boolean dontSave) { + super(finish); + + this.mDb = db; + this.mOldE = oldE; + this.mNewE = newE; + this.ctx = ctx; + this.mDontSave = dontSave; + + // Keep backup of original values in case save fails + PwEntry backup; + backup = mOldE.clone(); + + mFinish = new AfterUpdate(backup, finish); + } + + @Override + public void run() { + // Update entry with new values + mDb.updateEntry(mOldE, mNewE); + mOldE.touch(true, true); + + // Commit to disk + SaveDBRunnable save = new SaveDBRunnable(ctx, mDb, mFinish, mDontSave); + save.run(); + } + + private class AfterUpdate extends OnFinishRunnable { + private PwEntry mBackup; + + AfterUpdate(PwEntry backup, OnFinishRunnable finish) { + super(finish); + mBackup = backup; + } + + @Override + public void run() { + if ( !mSuccess ) { + // If we fail to save, back out changes to global structure + mDb.updateEntry(mOldE, mBackup); + } + // TODO Callback for update entry + super.run(); + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java new file mode 100644 index 000000000..d1d52c0f6 --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/UpdateGroupRunnable.java @@ -0,0 +1,88 @@ +/* + * 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.database.action; + +import android.content.Context; + +import com.kunzisoft.keepass.database.Database; +import com.kunzisoft.keepass.database.PwGroup; + +public class UpdateGroupRunnable extends RunnableOnFinish { + + private Database mDb; + private PwGroup mOldGroup; + private PwGroup mNewGroup; + private Context ctx; + private boolean mDontSave; + + public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish) { + this(ctx, db, oldGroup, newGroup, finish, false); + } + + public UpdateGroupRunnable(Context ctx, Database db, PwGroup oldGroup, PwGroup newGroup, AfterActionNodeOnFinish finish, boolean dontSave) { + super(finish); + + this.mDb = db; + this.mOldGroup = oldGroup; + this.mNewGroup = newGroup; + this.ctx = ctx; + this.mDontSave = dontSave; + + // Keep backup of original values in case save fails + PwGroup backup; + backup = mOldGroup.clone(); + + this.mFinish = new AfterUpdate(backup, finish); + } + + @Override + public void run() { + // Update group with new values + mDb.updateGroup(mOldGroup, mNewGroup); + mOldGroup.touch(true, true); + + // Commit to disk + new SaveDBRunnable(ctx, mDb, mFinish, mDontSave).run(); + } + + private class AfterUpdate extends OnFinishRunnable { + private PwGroup mBackup; + + AfterUpdate(PwGroup backup, OnFinishRunnable finish) { + super(finish); + mBackup = backup; + } + + @Override + public void run() { + if ( !mSuccess ) { + // If we fail to save, back out changes to global structure + mDb.updateGroup(mOldGroup, mBackup); + } + + // TODO Better callback + AfterActionNodeOnFinish afterActionNodeOnFinish = + (AfterActionNodeOnFinish) super.mOnFinish; + afterActionNodeOnFinish.mSuccess = mSuccess; + afterActionNodeOnFinish.mMessage = mMessage; + afterActionNodeOnFinish.run(mOldGroup, mNewGroup); + } + } +} 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 dff6d0083..f447c9ead 100644 --- a/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java @@ -51,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; @@ -515,13 +515,13 @@ 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, + CreateDBRunnable create = new CreateDBRunnable(FileSelectActivity.this, databaseFilename, assignPasswordOnFinish, true); ProgressTask createTask = new ProgressTask( @@ -546,9 +546,9 @@ public class FileSelectActivity extends StylishActivity implements } - private class AssignPasswordOnFinish extends FileOnFinish { + private class AssignPasswordOnFinish extends FileOnFinishRunnable { - AssignPasswordOnFinish(FileOnFinish fileOnFinish) { + AssignPasswordOnFinish(FileOnFinishRunnable fileOnFinish) { super(fileOnFinish); } @@ -560,7 +560,7 @@ public class FileSelectActivity extends StylishActivity implements } } - 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/password/AssignPasswordHelper.java b/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java index e405e818a..e4023b0c9 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,28 @@ */ package com.kunzisoft.keepass.password; +import android.app.Activity; import android.content.Context; +import android.content.DialogInterface; import android.net.Uri; import android.os.Handler; import 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.database.action.FileOnFinishRunnable; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.database.action.SetPasswordRunnable; +import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; import com.kunzisoft.keepass.tasks.ProgressTask; public class AssignPasswordHelper { - private Context context; + private Activity context; private String masterPassword = null; private Uri keyfile = null; - public AssignPasswordHelper(Context context, + public AssignPasswordHelper(Activity context, boolean withMasterPassword, String masterPassword, boolean withKeyFile, @@ -49,20 +52,22 @@ public class AssignPasswordHelper { this.keyfile = keyfile; } - public void assignPasswordInDatabase(FileOnFinish fileOnFinish) { - SetPassword sp = new SetPassword(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler())); + public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) { + SetPasswordRunnable sp = new SetPasswordRunnable(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler())); final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database); - boolean valid = sp.validatePassword(context, (dialog, which) -> pt.run()); - if (valid) { + if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) { pt.run(); + } else { + PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); + dialog.show(context, (newDialog, which) -> pt.run(), true); } } - private class AfterSave extends OnFinish { - private FileOnFinish mFinish; + private class AfterSave extends OnFinishRunnable { + private FileOnFinishRunnable mFinish; - public AfterSave(FileOnFinish finish, Handler handler) { + public AfterSave(FileOnFinishRunnable finish, Handler handler) { super(finish, handler); mFinish = finish; } 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 9e3887044..e916bfff6 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -62,8 +62,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; @@ -819,7 +819,7 @@ public class PasswordActivity extends StylishActivity Handler handler = new Handler(); AfterLoad afterLoad = new AfterLoad(handler, db); - LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); + LoadDBRunnable task = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database); pt.run(); } @@ -866,7 +866,7 @@ public class PasswordActivity extends StylishActivity /** * Called after verify and try to opening the database */ - private final class AfterLoad extends OnFinish { + private final class AfterLoad extends OnFinishRunnable { protected Database db; 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 f72d500f8..4ae400e9e 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 @@ -5,7 +5,7 @@ import android.os.Bundle; import android.os.Handler; import android.view.View; -import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -43,7 +43,7 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS super.onDialogClosed(positiveResult); } - private class AfterDescriptionSave extends OnFinish { + private class AfterDescriptionSave extends OnFinishRunnable { private String mNewDescription; private String mOldDescription; 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 59efc8350..9f90a2446 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 @@ -5,7 +5,7 @@ import android.os.Bundle; import android.os.Handler; import android.view.View; -import com.kunzisoft.keepass.database.edit.OnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -43,7 +43,7 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref super.onDialogClosed(positiveResult); } - private class AfterNameSave extends OnFinish { + private class AfterNameSave extends OnFinishRunnable { private String mNewName; private String mOldName; 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 950c2dd9f..be5e3221c 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 @@ -5,15 +5,15 @@ 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.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.database.action.SaveDBRunnable; import com.kunzisoft.keepass.tasks.ProgressTask; public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat { protected Database database; - private OnFinish afterSaveDatabase; + private OnFinishRunnable afterSaveDatabase; @Override protected void onBindDialogView(View view) { @@ -28,14 +28,14 @@ public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputP assert getContext() != null; if (database != null && afterSaveDatabase != null) { - SaveDB save = new SaveDB(getContext(), database, afterSaveDatabase); - ProgressTask pt = new ProgressTask(getContext(), save, R.string.saving_database); + SaveDBRunnable save = new SaveDBRunnable(getContext(), database, afterSaveDatabase); + ProgressTask pt = new ProgressTask(getActivity(), save, R.string.saving_database); pt.run(); } } } - 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 afc861034..a6fe9d6c4 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 @@ -26,7 +26,7 @@ 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; public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -82,7 +82,7 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference super.onDialogClosed(positiveResult); } - private class AfterRoundSave extends OnFinish { + private class AfterRoundSave extends OnFinishRunnable { private long mNewRounds; private long mOldRounds; diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java index 3eae9817d..e16a999b0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java @@ -19,45 +19,47 @@ */ package com.kunzisoft.keepass.tasks; +import android.app.Activity; import android.app.ProgressDialog; -import android.content.Context; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.os.Handler; import com.kunzisoft.keepass.R; -import com.kunzisoft.keepass.database.edit.OnFinish; -import com.kunzisoft.keepass.database.edit.RunnableOnFinish; +import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.database.action.RunnableOnFinish; /** Designed to Pop up a progress dialog, run a thread in the background, * run cleanup in the current thread, close the dialog. Without blocking * the current thread. - * - * @author bpellin - * */ public class ProgressTask implements Runnable { - private Context mCtx; - private Handler mHandler; + + private Activity activity; private RunnableOnFinish mTask; private ProgressDialog mPd; - public ProgressTask(Context ctx, RunnableOnFinish task, int messageId) { - mCtx = ctx; - mTask = task; - mHandler = new Handler(); + public ProgressTask(Activity activity, RunnableOnFinish task, int messageId) { + this.activity = activity; + this.mTask = task; + Handler 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)); + // TODO Move in activity + this.mPd = new ProgressDialog(activity); + this.mPd.setCanceledOnTouchOutside(false); + this.mPd.setTitle(activity.getText(R.string.progress_title)); + this.mPd.setMessage(activity.getText(messageId)); // Set code to run when this is finished - mTask.setStatus(new UpdateStatus(ctx, mHandler, mPd)); - mTask.mFinish = new AfterTask(task.mFinish, mHandler); + this.mTask.setStatus(new UpdateStatus(activity, mHandler, mPd)); + this.mTask.mFinish = new AfterTask(task.mFinish, mHandler); } public void run() { + lockScreenOrientation(); + // Show process dialog mPd.show(); @@ -66,9 +68,9 @@ public class ProgressTask implements Runnable { t.start(); } - private class AfterTask extends OnFinish { + private class AfterTask extends OnFinishRunnable { - public AfterTask(OnFinish finish, Handler handler) { + AfterTask(OnFinishRunnable finish, Handler handler) { super(finish, handler); } @@ -86,7 +88,21 @@ public class ProgressTask implements Runnable { if (mPd != null && mPd.isShowing()) { mPd.dismiss(); } + unlockScreenOrientation(); } } + + private void lockScreenOrientation() { + int currentOrientation = activity.getResources().getConfiguration().orientation; + if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } + + private void unlockScreenOrientation() { + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } } From e8d71039d7145bb371c12566d020323da0fcf658 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 18:18:13 +0200 Subject: [PATCH 11/18] refactor --- .../keepass/database/edit/AddEntry.java | 73 ---------- .../keepass/database/edit/AddGroup.java | 79 ----------- .../keepass/database/edit/CreateDB.java | 63 --------- .../keepass/database/edit/DeleteEntry.java | 103 -------------- .../keepass/database/edit/FileOnFinish.java | 44 ------ .../keepass/database/edit/LoadDB.java | 125 ----------------- .../keepass/database/edit/SaveDB.java | 69 ---------- .../keepass/database/edit/SetPassword.java | 128 ------------------ .../keepass/database/edit/UpdateEntry.java | 84 ------------ .../keepass/database/edit/UpdateGroup.java | 88 ------------ 10 files changed, 856 deletions(-) delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteEntry.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java deleted file mode 100644 index 4bc3b74b7..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddEntry.java +++ /dev/null @@ -1,73 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwEntry; - -public class AddEntry extends RunnableOnFinish { - - protected Database mDb; - private PwEntry mEntry; - private Context ctx; - private boolean mDontSave; - - public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { - this(ctx, db, entry, finish, false); - } - - public AddEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { - super(finish); - - this.mDb = db; - this.mEntry = entry; - this.ctx = ctx; - this.mDontSave = dontSave; - - this.mFinish = new AfterAdd(mFinish); - } - - @Override - public void run() { - mDb.addEntryTo(mEntry, mEntry.getParent()); - - // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); - save.run(); - } - - private class AfterAdd extends OnFinish { - - AfterAdd(OnFinish finish) { - super(finish); - } - - @Override - public void run() { - if ( !mSuccess ) { - mDb.removeEntryFrom(mEntry, mEntry.getParent()); - } - // TODO if add entry callback - super.run(); - } - } -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java deleted file mode 100644 index 21691613a..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/AddGroup.java +++ /dev/null @@ -1,79 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwGroup; - -public class AddGroup extends RunnableOnFinish { - - protected Database mDb; - private PwGroup mNewGroup; - private Context ctx; - private boolean mDontSave; - - public AddGroup(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) { - super(afterAddNode); - - this.mDb = db; - this.mNewGroup = newGroup; - this.mDontSave = dontSave; - this.ctx = ctx; - - this.mFinish = new AfterAdd(mFinish); - } - - @Override - public void run() { - mDb.addGroupTo(mNewGroup, mNewGroup.getParent()); - - // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); - save.run(); - } - - private class AfterAdd extends OnFinish { - - AfterAdd(OnFinish finish) { - super(finish); - } - - @Override - public void run() { - if ( !mSuccess ) { - mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent()); - } - - // TODO Better callback - AfterActionNodeOnFinish afterAddNode = - (AfterActionNodeOnFinish) super.mOnFinish; - afterAddNode.mSuccess = mSuccess; - afterAddNode.mMessage = mMessage; - afterAddNode.run(null, mNewGroup); - } - } -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java deleted file mode 100644 index 8c9328f70..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/CreateDB.java +++ /dev/null @@ -1,63 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.app.App; -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwDatabase; -import com.kunzisoft.keepass.utils.UriUtil; - -public class CreateDB extends RunnableOnFinish { - - private String mFilename; - private boolean mDontSave; - private Context ctx; - - public CreateDB(Context ctx, String filename, OnFinish finish, boolean dontSave) { - super(finish); - - mFilename = filename; - mDontSave = dontSave; - this.ctx = ctx; - } - - @Override - public void run() { - // Create new database record - Database db = new Database(); - App.setDB(db); - - PwDatabase pm = PwDatabase.getNewDBInstance(mFilename); - pm.initNew(mFilename); - - // Set Database state - db.setPwDatabase(pm); - db.setUri(UriUtil.parseDefaultFile(mFilename)); - db.setLoaded(); - App.clearShutdown(); - - // Commit changes - SaveDB save = new SaveDB(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/edit/DeleteEntry.java deleted file mode 100644 index 832da0b2d..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/DeleteEntry.java +++ /dev/null @@ -1,103 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwEntry; -import com.kunzisoft.keepass.database.PwGroup; - -/** Task to delete entries - * @author bpellin - * - */ -public class DeleteEntry extends RunnableOnFinish { - - private Database mDb; - private PwEntry mEntry; - private boolean mDontSave; - private Context ctx; - - public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish) { - this(ctx, db, entry, finish, false); - } - - public DeleteEntry(Context ctx, Database db, PwEntry entry, OnFinish finish, boolean dontSave) { - super(finish); - - this.mDb = db; - this.mEntry = entry; - this.mDontSave = dontSave; - this.ctx = ctx; - - } - - @Override - public void run() { - PwGroup parent = mEntry.getParent(); - - // Remove Entry from parent - boolean recycle = mDb.canRecycle(mEntry); - if (recycle) { - mDb.recycle(mEntry); - } - else { - mDb.deleteEntry(mEntry); - } - - // Save - mFinish = new AfterDelete(mFinish, parent, mEntry, recycle); - - // Commit database - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); - save.run(); - } - - private class AfterDelete extends OnFinish { - - private PwGroup mParent; - private PwEntry mEntry; - private boolean recycled; - - AfterDelete(OnFinish finish, PwGroup parent, PwEntry entry, boolean r) { - super(finish); - - mParent = parent; - mEntry = entry; - recycled = r; - } - - @Override - public void run() { - if ( !mSuccess ) { - if (recycled) { - mDb.undoRecycle(mEntry, mParent); - } - else { - mDb.undoDeleteEntry(mEntry, mParent); - } - } - // TODO Callback after delete entry - - super.run(); - } - } -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java deleted file mode 100644 index beca8c727..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/FileOnFinish.java +++ /dev/null @@ -1,44 +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.database.edit; - -import android.net.Uri; - -import java.io.Serializable; - -public class FileOnFinish extends OnFinish implements Serializable { - private Uri mFilename = null; - protected FileOnFinish mOnFinish; - - public FileOnFinish(FileOnFinish finish) { - super(finish); - - mOnFinish = finish; - } - - public void setFilename(Uri filename) { - mFilename = filename; - } - - public Uri getFilename() { - return mFilename; - } - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java deleted file mode 100644 index f9d42fb6d..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/LoadDB.java +++ /dev/null @@ -1,125 +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.database.edit; - -import android.content.Context; -import android.content.SharedPreferences; -import android.net.Uri; -import android.preference.PreferenceManager; - -import com.kunzisoft.keepass.R; -import com.kunzisoft.keepass.app.App; -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.exception.ArcFourException; -import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException; -import com.kunzisoft.keepass.database.exception.InvalidAlgorithmException; -import com.kunzisoft.keepass.database.exception.InvalidDBException; -import com.kunzisoft.keepass.database.exception.InvalidDBSignatureException; -import com.kunzisoft.keepass.database.exception.InvalidDBVersionException; -import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; -import com.kunzisoft.keepass.database.exception.InvalidPasswordException; -import com.kunzisoft.keepass.database.exception.KeyFileEmptyException; - -import java.io.FileNotFoundException; -import java.io.IOException; - -public class LoadDB extends RunnableOnFinish { - private Uri mUri; - private String mPass; - private Uri mKey; - private Database mDb; - private Context mCtx; - private boolean mRememberKeyfile; - - public LoadDB(Database db, Context ctx, Uri uri, String pass, Uri key, OnFinish finish) { - super(finish); - - mDb = db; - mCtx = ctx; - mUri = uri; - mPass = pass; - mKey = key; - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); - mRememberKeyfile = prefs.getBoolean(ctx.getString(R.string.keyfile_key), ctx.getResources().getBoolean(R.bool.keyfile_default)); - } - - @Override - public void run() { - try { - mDb.loadData(mCtx, mUri, mPass, mKey, mStatus); - - saveFileData(mUri, mKey); - - } catch (ArcFourException e) { - finish(false, mCtx.getString(R.string.error_arc4)); - return; - } catch (InvalidPasswordException e) { - finish(false, mCtx.getString(R.string.InvalidPassword)); - return; - } catch (ContentFileNotFoundException e) { - finish(false, mCtx.getString(R.string.file_not_found_content)); - return; - } catch (FileNotFoundException e) { - finish(false, mCtx.getString(R.string.file_not_found)); - return; - } catch (IOException e) { - finish(false, e.getMessage()); - return; - } catch (KeyFileEmptyException e) { - finish(false, mCtx.getString(R.string.keyfile_is_empty)); - return; - } catch (InvalidAlgorithmException e) { - finish(false, mCtx.getString(R.string.invalid_algorithm)); - return; - } catch (InvalidKeyFileException e) { - finish(false, mCtx.getString(R.string.keyfile_does_not_exist)); - return; - } catch (InvalidDBSignatureException e) { - finish(false, mCtx.getString(R.string.invalid_db_sig)); - return; - } catch (InvalidDBVersionException e) { - finish(false, mCtx.getString(R.string.unsupported_db_version)); - return; - } catch (InvalidDBException e) { - finish(false, mCtx.getString(R.string.error_invalid_db)); - return; - } catch (OutOfMemoryError e) { - finish(false, mCtx.getString(R.string.error_out_of_memory)); - return; - } catch (Exception e) { - finish(false, e.getMessage()); - return; - } - - finish(true); - } - - private void saveFileData(Uri uri, Uri key) { - if ( ! mRememberKeyfile ) { - key = null; - } - - App.getFileHistory().createFile(uri, key); - } - - - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java deleted file mode 100644 index 8933bf724..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/SaveDB.java +++ /dev/null @@ -1,69 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.exception.PwDbOutputException; - -import java.io.IOException; - -public class SaveDB extends RunnableOnFinish { - private Database mDb; - private boolean mDontSave; - private Context mCtx; - - public SaveDB(Context ctx, Database db, OnFinish finish, boolean dontSave) { - super(finish); - - mDb = db; - mDontSave = dontSave; - mCtx = ctx; - } - - public SaveDB(Context ctx, Database db, OnFinish finish) { - super(finish); - - mDb = db; - mDontSave = false; - mCtx = ctx; - } - - @Override - public void run() { - - if ( ! mDontSave ) { - try { - mDb.saveData(mCtx); - } catch (IOException e) { - finish(false, e.getMessage()); - return; - } catch (PwDbOutputException e) { - // TODO: Restore - finish(false, e.getMessage()); - return; - } - } - - finish(true); - } - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java deleted file mode 100644 index 9f2cf70f8..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/SetPassword.java +++ /dev/null @@ -1,128 +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.database.edit; - -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 { - - private String mPassword; - private Uri mKeyfile; - private Database mDb; - private boolean mDontSave; - private Context ctx; - - public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish) { - this(ctx, db, password, keyfile, finish, false); - - } - - public SetPassword(Context ctx, Database db, String password, Uri keyfile, OnFinish finish, boolean dontSave) { - super(finish); - - mDb = db; - mPassword = password; - mKeyfile = keyfile; - mDontSave = dontSave; - 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(); - - byte[] backupKey = new byte[pm.getMasterKey().length]; - System.arraycopy(pm.getMasterKey(), 0, backupKey, 0, backupKey.length); - - // Set key - try { - InputStream is = UriUtil.getUriInputStream(ctx, mKeyfile); - pm.setMasterKey(mPassword, is); - } catch (InvalidKeyFileException e) { - erase(backupKey); - finish(false, e.getMessage()); - return; - } catch (IOException e) { - erase(backupKey); - finish(false, e.getMessage()); - return; - } - - // Save Database - mFinish = new AfterSave(backupKey, mFinish); - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); - save.run(); - } - - private class AfterSave extends OnFinish { - private byte[] mBackup; - - public AfterSave(byte[] backup, OnFinish finish) { - super(finish); - - mBackup = backup; - } - - @Override - public void run() { - if ( ! mSuccess ) { - // Erase the current master key - erase(mDb.getPwDatabase().getMasterKey()); - mDb.getPwDatabase().setMasterKey(mBackup); - } - - super.run(); - } - - } - - /** Overwrite the array as soon as we don't need it to avoid keeping the extra data in memory - * @param array - */ - private void erase(byte[] array) { - if ( array == null ) return; - - for ( int i = 0; i < array.length; i++ ) { - array[i] = 0; - } - } - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java deleted file mode 100644 index 75525f184..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateEntry.java +++ /dev/null @@ -1,84 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwEntry; - -public class UpdateEntry extends RunnableOnFinish { - - private Database mDb; - private PwEntry mOldE; - private PwEntry mNewE; - private Context ctx; - private boolean mDontSave; - - public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish) { - this(ctx, db, oldE, newE, finish, false); - } - - public UpdateEntry(Context ctx, Database db, PwEntry oldE, PwEntry newE, OnFinish finish, boolean dontSave) { - super(finish); - - this.mDb = db; - this.mOldE = oldE; - this.mNewE = newE; - this.ctx = ctx; - this.mDontSave = dontSave; - - // Keep backup of original values in case save fails - PwEntry backup; - backup = mOldE.clone(); - - mFinish = new AfterUpdate(backup, finish); - } - - @Override - public void run() { - // Update entry with new values - mDb.updateEntry(mOldE, mNewE); - mOldE.touch(true, true); - - // Commit to disk - SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave); - save.run(); - } - - private class AfterUpdate extends OnFinish { - private PwEntry mBackup; - - AfterUpdate(PwEntry backup, OnFinish finish) { - super(finish); - mBackup = backup; - } - - @Override - public void run() { - if ( !mSuccess ) { - // If we fail to save, back out changes to global structure - mDb.updateEntry(mOldE, mBackup); - } - // TODO Callback for update entry - super.run(); - } - } -} diff --git a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java b/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java deleted file mode 100644 index c9fdcf70e..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/database/edit/UpdateGroup.java +++ /dev/null @@ -1,88 +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.database.edit; - -import android.content.Context; - -import com.kunzisoft.keepass.database.Database; -import com.kunzisoft.keepass.database.PwGroup; - -public class UpdateGroup extends RunnableOnFinish { - - private Database mDb; - private PwGroup mOldGroup; - private PwGroup mNewGroup; - private Context ctx; - private boolean mDontSave; - - public UpdateGroup(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) { - super(finish); - - this.mDb = db; - this.mOldGroup = oldGroup; - this.mNewGroup = newGroup; - this.ctx = ctx; - this.mDontSave = dontSave; - - // Keep backup of original values in case save fails - PwGroup backup; - backup = mOldGroup.clone(); - - this.mFinish = new AfterUpdate(backup, finish); - } - - @Override - public void run() { - // Update group with new values - mDb.updateGroup(mOldGroup, mNewGroup); - mOldGroup.touch(true, true); - - // Commit to disk - new SaveDB(ctx, mDb, mFinish, mDontSave).run(); - } - - private class AfterUpdate extends OnFinish { - private PwGroup mBackup; - - AfterUpdate(PwGroup backup, OnFinish finish) { - super(finish); - mBackup = backup; - } - - @Override - public void run() { - if ( !mSuccess ) { - // If we fail to save, back out changes to global structure - mDb.updateGroup(mOldGroup, mBackup); - } - - // TODO Better callback - AfterActionNodeOnFinish afterActionNodeOnFinish = - (AfterActionNodeOnFinish) super.mOnFinish; - afterActionNodeOnFinish.mSuccess = mSuccess; - afterActionNodeOnFinish.mMessage = mMessage; - afterActionNodeOnFinish.run(mOldGroup, mNewGroup); - } - } -} From 77614d0c4a7eafafcd461586f3da9acb17501164 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Mon, 30 Apr 2018 19:54:50 +0200 Subject: [PATCH 12/18] Upgrade changelogs and version --- CHANGELOG | 6 ++++++ app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/10.txt | 4 ++++ fastlane/metadata/android/fr-FR/changelogs/10.txt | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/10.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/10.txt 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/app/build.gradle b/app/build.gradle index fba6450bb..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" 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 From cf026e8eaae30d00d30d8d71564f1da85e249d23 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Tue, 1 May 2018 20:03:43 +0200 Subject: [PATCH 13/18] Update progress bar and message progress --- .../kunzisoft/keepass/database/Database.java | 60 ++++---- .../database/action/OnFinishRunnable.java | 3 +- .../database/action/RunnableOnFinish.java | 6 +- .../keepass/database/load/Importer.java | 5 +- .../keepass/database/load/ImporterV3.java | 20 +-- .../database/load/ImporterV3Debug.java | 4 +- .../keepass/database/load/ImporterV4.java | 12 +- .../keepass/password/PasswordActivity.java | 121 ++++++++-------- .../tasks/ProgressTaskDialogFragment.java | 129 ++++++++++++++++++ .../keepass/tasks/ProgressTaskUpdater.java | 24 ++++ .../tasks/UpdateProgressTaskStatus.java | 54 ++++++++ .../kunzisoft/keepass/tasks/UpdateStatus.java | 10 +- app/src/main/res/layout/password.xml | 11 ++ app/src/main/res/layout/progress_dialog.xml | 21 +++ 14 files changed, 365 insertions(+), 115 deletions(-) create mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskUpdater.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java create mode 100644 app/src/main/res/layout/progress_dialog.xml 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 433a973c4..db27121a0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/Database.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/Database.java @@ -36,7 +36,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; @@ -99,19 +99,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")) { @@ -138,7 +130,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); @@ -157,14 +149,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() ) { @@ -178,7 +166,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()) { @@ -222,19 +210,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); - //BufferedOutputStream bos = new BufferedOutputStream(fos); - //PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar()); - PwDbOutput pmo = PwDbOutput.getInstance(pm, fos); - pmo.output(); - //bos.flush(); - //bos.close(); - 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 { @@ -250,16 +242,18 @@ public class Database { } } else { - OutputStream os; + OutputStream os = null; try { os = ctx.getContentResolver().openOutputStream(uri); + PwDbOutput pmo = PwDbOutput.getInstance(pm, os); + if (pmo != null) + pmo.output(); } catch (Exception e) { throw new IOException("Failed to store database."); + } finally { + if (os != null) + os.close(); } - - PwDbOutput pmo = PwDbOutput.getInstance(pm, os); - pmo.output(); - os.close(); } mUri = uri; } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java index 82d34d87c..6db343ecf 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/OnFinishRunnable.java @@ -75,7 +75,8 @@ public class OnFinishRunnable 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/action/RunnableOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java index e509122bc..7fa909f3f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java @@ -19,13 +19,13 @@ */ 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 OnFinishRunnable mFinish; - public UpdateStatus mStatus; + public ProgressTaskUpdater mStatus; public RunnableOnFinish(OnFinishRunnable finish) { mFinish = finish; @@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable { } } - public void setStatus(UpdateStatus status) { + public void setStatus(ProgressTaskUpdater status) { mStatus = status; } 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 ee15c2df2..f56f11b49 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.setMasterKey(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 5d98c2a46..0d35e1be6 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.setMasterKey(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/password/PasswordActivity.java b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java index e916bfff6..cc2554fa4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -71,7 +71,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; @@ -122,6 +123,8 @@ public class PasswordActivity extends StylishActivity private CompoundButton checkboxKeyfileView; private CompoundButton checkboxDefaultDatabaseView; + private ProgressTaskDialogFragment loadingDatabaseDialog; + private DefaultCheckChange defaultCheckChange; private ValidateButtonViewClickListener validateButtonViewClickListener; @@ -812,16 +815,74 @@ public class PasswordActivity extends StylishActivity // Clear before we load Database db = App.getDB(); db.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, db); + LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); + databaseLoadingTask.setStatus( + new UpdateProgressTaskStatus(this, + handler, + ProgressTaskDialogFragment.start(getSupportFragmentManager(), R.string.loading_database) + )); + Thread t = new Thread(databaseLoadingTask); + t.start(); + } - LoadDBRunnable task = new LoadDBRunnable(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(getSupportFragmentManager()); + }); + } + } + + 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 @@ -863,54 +924,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 OnFinishRunnable { - - 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/tasks/ProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java new file mode 100644 index 000000000..75098d38d --- /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.content.pm.ActivityInfo; +import android.content.res.Configuration; +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.view.LayoutInflater; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.kunzisoft.keepass.R; + +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 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.setTitle(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); + if (title != UNDEFINED) + builder.setTitle(title); + + messageView = root.findViewById(R.id.progress_dialog_message); + progressView = root.findViewById(R.id.progress_dialog_bar); + + if (message != UNDEFINED) + messageView.setText(message); + + setCancelable(false); + lockScreenOrientation(); + + return builder.create(); + } + + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + unlockScreenOrientation(); + } + + public static void stop(FragmentManager fragmentManager) { + Fragment fragmentTask = fragmentManager.findFragmentByTag(PROGRESS_TASK_DIALOG_TAG); + if (fragmentTask != null) { + ProgressTaskDialogFragment loadingDatabaseDialog = (ProgressTaskDialogFragment) fragmentTask; + loadingDatabaseDialog.dismissAllowingStateLoss(); + } + } + + private void lockScreenOrientation() { + if (getActivity() != null) { + int currentOrientation = getResources().getConfiguration().orientation; + if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + } + } + } + + private void unlockScreenOrientation() { + if (getActivity() != null) + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); + } + + public void setTitle(@StringRes int titleId) { + this.title = titleId; + } + + @Override + public void updateMessage(int resId) { + this.message = resId; + if (messageView != null) + this.messageView.setText(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/UpdateProgressTaskStatus.java b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java new file mode 100644 index 000000000..64430cb6c --- /dev/null +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java @@ -0,0 +1,54 @@ +/* + * 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.content.Context; +import android.os.Handler; + +public class UpdateProgressTaskStatus implements ProgressTaskUpdater { + private Context mContext; + private ProgressTaskUpdater mProgressTaskUpdater; + private Handler mHandler; + + public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) { + this.mContext = context; + this.mProgressTaskUpdater = progressTaskUpdater; + this.mHandler = handler; + } + + @Override + public void updateMessage(int resId) { + if ( mContext != null && mProgressTaskUpdater != null && mHandler != null ) { + mHandler.post(new UpdateMessage(resId)); + } + } + + private class UpdateMessage implements Runnable { + private int mResId; + + UpdateMessage(int resId) { + mResId = resId; + } + + public void run() { + mProgressTaskUpdater.updateMessage(mResId); + } + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java index 43488a9ed..4461d495f 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java @@ -23,16 +23,12 @@ import android.app.ProgressDialog; import android.content.Context; import android.os.Handler; -public class UpdateStatus { +public class UpdateStatus implements ProgressTaskUpdater { private ProgressDialog mPD; private Context mCtx; private Handler mHandler; - public UpdateStatus() { - - } - - public UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) { + UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) { mCtx = ctx; mPD = pd; mHandler = handler; @@ -47,7 +43,7 @@ public class UpdateStatus { private class UpdateMessage implements Runnable { private int mResId; - public UpdateMessage(int resId) { + UpdateMessage(int resId) { mResId = resId; } diff --git a/app/src/main/res/layout/password.xml b/app/src/main/res/layout/password.xml index e00840e8a..641525cab 100644 --- a/app/src/main/res/layout/password.xml +++ b/app/src/main/res/layout/password.xml @@ -190,6 +190,17 @@ + + + + + + + + + \ No newline at end of file From a50aa0fb95c343e95cb115140a137e4019d899ea Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 2 May 2018 07:16:55 +0200 Subject: [PATCH 14/18] Fix null pointer for KeyDerivationName --- .../java/com/kunzisoft/keepass/database/PwDatabaseV4.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 0175e2a0e..504165f36 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java @@ -332,7 +332,10 @@ public class PwDatabaseV4 extends PwDatabase { @Override public String getKeyDerivationName() { - return kdfEngine.getName(); + if (kdfEngine!=null) + return kdfEngine.getName(); + else + return ""; } @Override From ec08f3430d9be967474fbbb800c90dbd73fef58c Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 2 May 2018 09:54:55 +0200 Subject: [PATCH 15/18] Add progress bar for all, create database in a single progress dialog --- .../keepass/activities/EntryEditActivity.java | 26 +++-- .../keepass/activities/GroupActivity.java | 63 ++++++---- .../keepass/activities/ListNodesActivity.java | 75 +++++++----- ...e.java => AssignPasswordInDBRunnable.java} | 8 +- .../database/action/RunnableOnFinish.java | 2 +- .../fileselect/FileSelectActivity.java | 29 +++-- .../password/AssignPasswordHelper.java | 70 ++++++++---- .../keepass/password/PasswordActivity.java | 22 ++-- ...riptionPreferenceDialogFragmentCompat.java | 21 ++-- ...aseNamePreferenceDialogFragmentCompat.java | 22 ++-- ...aseSavePreferenceDialogFragmentCompat.java | 16 ++- .../RoundsPreferenceDialogFragmentCompat.java | 21 ++-- .../kunzisoft/keepass/tasks/ProgressTask.java | 108 ------------------ .../tasks/ProgressTaskDialogFragment.java | 13 ++- ...aveDatabaseProgressTaskDialogFragment.java | 16 +++ .../tasks/UpdateProgressTaskStatus.java | 4 + .../kunzisoft/keepass/tasks/UpdateStatus.java | 55 --------- 17 files changed, 273 insertions(+), 298 deletions(-) rename app/src/main/java/com/kunzisoft/keepass/database/action/{SetPasswordRunnable.java => AssignPasswordInDBRunnable.java} (87%) delete mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java create mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java delete mode 100644 app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java 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 47b325941..0c2938a2d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -58,7 +58,8 @@ import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment; import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment; import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.settings.PreferencesUtil; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Util; @@ -249,6 +250,7 @@ public class EntryEditActivity extends LockingHideActivity } mCallbackNewEntry = populateNewEntry(); + // Open a progress dialog and save entry OnFinishRunnable onFinish = new AfterSave(); EntryEditActivity act = EntryEditActivity.this; RunnableOnFinish task; @@ -257,8 +259,12 @@ public class EntryEditActivity extends LockingHideActivity } else { task = new UpdateEntryRunnable(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); } - ProgressTask pt = new ProgressTask(act, task, R.string.saving_database); - pt.run(); + task.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + SaveDatabaseProgressTaskDialogFragment.start( + getSupportFragmentManager()) + )); + new Thread(task).start(); } /** @@ -562,11 +568,15 @@ public class EntryEditActivity extends LockingHideActivity @Override public void run() { - if ( mSuccess ) { - finish(); - } else { - displayMessage(EntryEditActivity.this); - } + runOnUiThread(() -> { + if ( mSuccess ) { + finish(); + } else { + displayMessage(EntryEditActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + }); } } 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 307f3df89..bc5fa6ec4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java @@ -68,7 +68,8 @@ import com.kunzisoft.keepass.dialogs.ReadOnlyDialog; import com.kunzisoft.keepass.icons.IconPackChooser; import com.kunzisoft.keepass.search.SearchResultsActivity; import com.kunzisoft.keepass.settings.PreferencesUtil; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; import com.kunzisoft.keepass.view.AddNodeButtonView; public class GroupActivity extends ListNodesActivity @@ -437,8 +438,12 @@ public class GroupActivity extends ListNodesActivity Handler handler = new Handler(); DeleteEntryRunnable task = new DeleteEntryRunnable(this, App.getDB(), entry, new AfterDeleteNode(handler, entry)); - ProgressTask pt = new ProgressTask(this, task, R.string.saving_database); - pt.run(); + task.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + SaveDatabaseProgressTaskDialogFragment.start( + getSupportFragmentManager()) + )); + new Thread(task).start(); } private void deleteGroup(PwGroup group) { @@ -446,8 +451,12 @@ public class GroupActivity extends ListNodesActivity Handler handler = new Handler(); DeleteGroupRunnable task = new DeleteGroupRunnable(this, App.getDB(), group, new AfterDeleteNode(handler, group)); - ProgressTask pt = new ProgressTask(this, task, R.string.saving_database); - pt.run(); + task.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + SaveDatabaseProgressTaskDialogFragment.start( + getSupportFragmentManager()) + )); + new Thread(task).start(); } @Override @@ -548,16 +557,21 @@ public class GroupActivity extends ListNodesActivity newGroup.setName(name); try { iconStandard = (PwIconStandard) icon; - } catch (Exception e) {} // TODO custom icon + } catch (Exception ignored) {} // TODO custom icon newGroup.setIcon(iconStandard); - new ProgressTask(this, - new AddGroupRunnable(this, - 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 @@ -566,20 +580,23 @@ public class GroupActivity extends ListNodesActivity updateGroup.setName(name); try { iconStandard = (PwIconStandard) icon; - } catch (Exception e) {} // TODO custom icon + } catch (Exception ignored) {} // TODO custom icon updateGroup.setIcon(iconStandard); mAdapter.removeNode(oldGroupToUpdate); - // If group update - new ProgressTask(this, - new UpdateGroupRunnable(this, - 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 b2ef7a8dc..04f42752c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java @@ -55,6 +55,7 @@ import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment; import com.kunzisoft.keepass.dialogs.SortDialogFragment; import com.kunzisoft.keepass.password.AssignPasswordHelper; import com.kunzisoft.keepass.settings.PreferencesUtil; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; import com.kunzisoft.keepass.tasks.UIToastTask; import com.kunzisoft.keepass.utils.MenuUtil; @@ -307,11 +308,16 @@ public abstract class ListNodesActivity extends LockingActivity public void run(PwNode oldNode, PwNode newNode) { super.run(); - if (mSuccess) { - mAdapter.addNode(newNode); - } else { - displayMessage(ListNodesActivity.this); - } + + runOnUiThread(() -> { + if (mSuccess) { + mAdapter.addNode(newNode); + } else { + displayMessage(ListNodesActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + }); } } @@ -322,11 +328,16 @@ public abstract class ListNodesActivity extends LockingActivity public void run(PwNode oldNode, PwNode newNode) { super.run(); - if (mSuccess) { - mAdapter.updateNode(oldNode, newNode); - } else { - displayMessage(ListNodesActivity.this); - } + + runOnUiThread(() -> { + if (mSuccess) { + mAdapter.updateNode(oldNode, newNode); + } else { + displayMessage(ListNodesActivity.this); + } + + SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + }); } } @@ -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(getSupportFragmentManager()); + }); } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java similarity index 87% rename from app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java rename to app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java index 7d76c6303..d30667309 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/SetPasswordRunnable.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/AssignPasswordInDBRunnable.java @@ -20,19 +20,17 @@ package com.kunzisoft.keepass.database.action; import android.content.Context; -import android.content.DialogInterface; import android.net.Uri; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.PwDatabase; import com.kunzisoft.keepass.database.exception.InvalidKeyFileException; -import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; import com.kunzisoft.keepass.utils.UriUtil; import java.io.IOException; import java.io.InputStream; -public class SetPasswordRunnable extends RunnableOnFinish { +public class AssignPasswordInDBRunnable extends RunnableOnFinish { private String mPassword; private Uri mKeyfile; @@ -40,12 +38,12 @@ public class SetPasswordRunnable extends RunnableOnFinish { private boolean mDontSave; private Context ctx; - public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) { + public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish) { this(ctx, db, password, keyfile, finish, false); } - public SetPasswordRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) { + public AssignPasswordInDBRunnable(Context ctx, Database db, String password, Uri keyfile, OnFinishRunnable finish, boolean dontSave) { super(finish); mDb = db; diff --git a/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java index 7fa909f3f..aa1f32304 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/action/RunnableOnFinish.java @@ -45,7 +45,7 @@ public abstract class RunnableOnFinish implements Runnable { } } - public void setStatus(ProgressTaskUpdater status) { + public void setUpdateProgressTaskStatus(ProgressTaskUpdater status) { mStatus = status; } 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 f447c9ead..7afbdfb4c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/fileselect/FileSelectActivity.java @@ -60,7 +60,8 @@ import com.kunzisoft.keepass.password.AssignPasswordHelper; import com.kunzisoft.keepass.password.PasswordActivity; import com.kunzisoft.keepass.settings.PreferencesUtil; import com.kunzisoft.keepass.stylish.StylishActivity; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; import com.kunzisoft.keepass.utils.EmptyUtils; import com.kunzisoft.keepass.utils.MenuUtil; import com.kunzisoft.keepass.utils.UriUtil; @@ -520,17 +521,21 @@ public class FileSelectActivity extends StylishActivity implements AssignPasswordOnFinish assignPasswordOnFinish = new AssignPasswordOnFinish(launchActivityOnFinish); - // Create the new database - CreateDBRunnable create = new CreateDBRunnable(FileSelectActivity.this, - databaseFilename, assignPasswordOnFinish, true); - - ProgressTask createTask = new ProgressTask( - FileSelectActivity.this, create, - R.string.progress_create); - createTask.run(); - + // Initialize the password helper assigner to set the password after the database creation assignPasswordHelper = new AssignPasswordHelper(this, masterPasswordChecked, masterPassword, keyFileChecked, keyFile); + assignPasswordHelper.setCreateProgressDialog(false); + + // Create the new database + CreateDBRunnable createDBTask = new CreateDBRunnable(FileSelectActivity.this, + databaseFilename, assignPasswordOnFinish, true); + createDBTask.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(this, + ProgressTaskDialogFragment.start( + getSupportFragmentManager(), + R.string.progress_create) + )); + new Thread(createDBTask).start(); } catch (Exception e) { String error = "Unable to create database with this password and key file"; @@ -555,7 +560,9 @@ public class FileSelectActivity extends StylishActivity implements @Override public void run() { if (mSuccess) { - assignPasswordHelper.assignPasswordInDatabase(mOnFinish); + // Dont use ProgressTaskDialogFragment.stop(getSupportFragmentManager()); + // assignPasswordHelper do it + runOnUiThread(() -> assignPasswordHelper.assignPasswordInDatabase(mOnFinish)); } } } 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 e4023b0c9..0b211c6d7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java @@ -19,28 +19,30 @@ */ package com.kunzisoft.keepass.password; -import android.app.Activity; -import android.content.Context; -import android.content.DialogInterface; import android.net.Uri; import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.widget.Toast; -import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.app.App; +import com.kunzisoft.keepass.database.action.AssignPasswordInDBRunnable; import com.kunzisoft.keepass.database.action.FileOnFinishRunnable; import com.kunzisoft.keepass.database.action.OnFinishRunnable; -import com.kunzisoft.keepass.database.action.SetPasswordRunnable; import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.tasks.ProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; public class AssignPasswordHelper { - private Activity context; + private AppCompatActivity context; private String masterPassword = null; private Uri keyfile = null; - public AssignPasswordHelper(Activity context, + private boolean createProgressDialog; + + public AssignPasswordHelper(AppCompatActivity context, boolean withMasterPassword, String masterPassword, boolean withKeyFile, @@ -50,38 +52,66 @@ public class AssignPasswordHelper { this.masterPassword = masterPassword; if (withKeyFile) this.keyfile = keyfile; + + createProgressDialog = true; + } + + public void setCreateProgressDialog(boolean createProgressDialog) { + this.createProgressDialog = createProgressDialog; } public void assignPasswordInDatabase(FileOnFinishRunnable fileOnFinish) { - SetPasswordRunnable sp = new SetPasswordRunnable(context, App.getDB(), masterPassword, keyfile, new AfterSave(fileOnFinish, new Handler())); - final ProgressTask pt = new ProgressTask(context, sp, R.string.saving_database); + AssignPasswordInDBRunnable assignPasswordInDBRunnable = new AssignPasswordInDBRunnable( + context, + App.getDB(), + masterPassword, + keyfile, + new AfterSave(fileOnFinish, new Handler()) + ); + if (createProgressDialog) { + assignPasswordInDBRunnable.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(context, + SaveDatabaseProgressTaskDialogFragment.start( + context.getSupportFragmentManager()) + )); + } + Thread taskThread = new Thread(assignPasswordInDBRunnable); + // Show the progress dialog now or after dialog confirmation if (App.getDB().getPwDatabase().validatePasswordEncoding(masterPassword)) { - pt.run(); + taskThread.start(); } else { PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper(); - dialog.show(context, (newDialog, which) -> pt.run(), true); + dialog.show(context, (newDialog, which) -> taskThread.start(), true); } } private class AfterSave extends OnFinishRunnable { private FileOnFinishRunnable mFinish; - public AfterSave(FileOnFinishRunnable finish, Handler handler) { + AfterSave(FileOnFinishRunnable finish, Handler handler) { super(finish, handler); mFinish = finish; } @Override public void run() { - 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.getSupportFragmentManager()); + }); } } } 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 cc2554fa4..fc0e9fe8c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -811,21 +811,29 @@ public class PasswordActivity extends StylishActivity loadDatabase(password, keyUri); } - private void loadDatabase(String pass, Uri keyfile) { + private void loadDatabase(String password, Uri keyfile) { // Clear before we load - Database db = App.getDB(); - db.clear(); + Database database = App.getDB(); + database.clear(); // Clear the shutdown flag App.clearShutdown(); // Show the progress dialog Handler handler = new Handler(); - AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, db); - LoadDBRunnable databaseLoadingTask = new LoadDBRunnable(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad); - databaseLoadingTask.setStatus( + AfterLoadingDatabase afterLoad = new AfterLoadingDatabase(handler, database); + LoadDBRunnable databaseLoadingTask = new LoadDBRunnable( + database, + PasswordActivity.this, + mDbUri, + password, + keyfile, + afterLoad); + databaseLoadingTask.setUpdateProgressTaskStatus( new UpdateProgressTaskStatus(this, handler, - ProgressTaskDialogFragment.start(getSupportFragmentManager(), R.string.loading_database) + ProgressTaskDialogFragment.start( + getSupportFragmentManager(), + R.string.loading_database) )); Thread t = new Thread(databaseLoadingTask); t.start(); 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 4ae400e9e..0b0debf9a 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 @@ -1,11 +1,12 @@ package com.kunzisoft.keepass.settings.preferenceDialogFragment; -import android.content.Context; import android.os.Bundle; import android.os.Handler; +import android.support.v7.app.AppCompatActivity; import android.view.View; import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -37,7 +38,7 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS database.assignDescription(dbDescription); Handler handler = new Handler(); - setAfterSaveDatabase(new AfterDescriptionSave(getContext(), handler, dbDescription, oldDescription)); + setAfterSaveDatabase(new AfterDescriptionSave((AppCompatActivity) getActivity(), handler, dbDescription, oldDescription)); } super.onDialogClosed(positiveResult); @@ -45,14 +46,14 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS private class AfterDescriptionSave extends OnFinishRunnable { + private AppCompatActivity mActivity; private String mNewDescription; private String mOldDescription; - private Context mCtx; - AfterDescriptionSave(Context ctx, Handler handler, String newDescription, String oldDescription) { + AfterDescriptionSave(AppCompatActivity ctx, Handler handler, String newDescription, String oldDescription) { super(handler); - mCtx = ctx; + mActivity = ctx; mNewDescription = newDescription; mOldDescription = oldDescription; } @@ -62,12 +63,18 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS String descriptionToShow = mNewDescription; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.assignDescription(mOldDescription); database.assignDescription(mOldDescription); } - getPreference().setSummary(descriptionToShow); + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(descriptionToShow); + SaveDatabaseProgressTaskDialogFragment.stop( + mActivity.getSupportFragmentManager()); + }); + } 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 9f90a2446..2cf492061 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 @@ -1,11 +1,12 @@ package com.kunzisoft.keepass.settings.preferenceDialogFragment; -import android.content.Context; import android.os.Bundle; import android.os.Handler; +import android.support.v7.app.AppCompatActivity; import android.view.View; import com.kunzisoft.keepass.database.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -37,7 +38,7 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref database.assignName(dbName); Handler handler = new Handler(); - setAfterSaveDatabase(new AfterNameSave(getContext(), handler, dbName, oldName)); + setAfterSaveDatabase(new AfterNameSave((AppCompatActivity) getActivity(), handler, dbName, oldName)); } super.onDialogClosed(positiveResult); @@ -47,12 +48,12 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref private String mNewName; private String mOldName; - private Context mCtx; + private AppCompatActivity mActivity; - AfterNameSave(Context ctx, Handler handler, String newName, String oldName) { + AfterNameSave(AppCompatActivity ctx, Handler handler, String newName, String oldName) { super(handler); - mCtx = ctx; + mActivity = ctx; mNewName = newName; mOldName = oldName; } @@ -62,11 +63,18 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref String nameToShow = mNewName; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.assignName(mOldName); } - getPreference().setSummary(nameToShow); + + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(nameToShow); + SaveDatabaseProgressTaskDialogFragment.stop( + mActivity.getSupportFragmentManager()); + }); + } 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 be5e3221c..09dd66d82 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 @@ -2,12 +2,12 @@ package com.kunzisoft.keepass.settings.preferenceDialogFragment; import android.view.View; -import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.database.Database; import com.kunzisoft.keepass.database.action.OnFinishRunnable; import com.kunzisoft.keepass.database.action.SaveDBRunnable; -import com.kunzisoft.keepass.tasks.ProgressTask; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; +import com.kunzisoft.keepass.tasks.UpdateProgressTaskStatus; public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputPreferenceDialogFragmentCompat { @@ -25,12 +25,16 @@ public abstract class DatabaseSavePreferenceDialogFragmentCompat extends InputP @Override public void onDialogClosed(boolean positiveResult) { if ( positiveResult ) { - assert getContext() != null; + assert getActivity() != null; if (database != null && afterSaveDatabase != null) { - SaveDBRunnable save = new SaveDBRunnable(getContext(), database, afterSaveDatabase); - ProgressTask pt = new ProgressTask(getActivity(), save, R.string.saving_database); - pt.run(); + SaveDBRunnable saveDBRunnable = new SaveDBRunnable(getContext(), database, afterSaveDatabase); + saveDBRunnable.setUpdateProgressTaskStatus( + new UpdateProgressTaskStatus(getContext(), + SaveDatabaseProgressTaskDialogFragment.start( + getActivity().getSupportFragmentManager()) + )); + new Thread(saveDBRunnable).start(); } } } 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 a6fe9d6c4..84c2e0cbe 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.action.OnFinishRunnable; +import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment; public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreferenceDialogFragmentCompat { @@ -76,7 +77,7 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference } Handler handler = new Handler(); - setAfterSaveDatabase(new AfterRoundSave(getContext(), handler, rounds, oldRounds)); + setAfterSaveDatabase(new AfterRoundSave((AppCompatActivity) getActivity(), handler, rounds, oldRounds)); } super.onDialogClosed(positiveResult); @@ -86,12 +87,12 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference private long mNewRounds; private long mOldRounds; - private Context mCtx; + private AppCompatActivity mActivity; - AfterRoundSave(Context ctx, Handler handler, long newRounds, long oldRounds) { + AfterRoundSave(AppCompatActivity ctx, Handler handler, long newRounds, long oldRounds) { super(handler); - mCtx = ctx; + mActivity = ctx; mNewRounds = newRounds; mOldRounds = oldRounds; } @@ -101,11 +102,17 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference long roundsToShow = mNewRounds; if (!mSuccess) { - displayMessage(mCtx); + displayMessage(mActivity); database.setNumberKeyEncryptionRounds(mOldRounds); } - getPreference().setSummary(String.valueOf(roundsToShow)); + if (mActivity != null) { + mActivity.runOnUiThread(() -> { + getPreference().setSummary(String.valueOf(roundsToShow)); + SaveDatabaseProgressTaskDialogFragment.stop( + mActivity.getSupportFragmentManager()); + }); + } 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 e16a999b0..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTask.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft. - * - * This file is part of KeePass DX. - * - * KeePass DX is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KeePass DX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with KeePass DX. If not, see . - * - */ -package com.kunzisoft.keepass.tasks; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.pm.ActivityInfo; -import android.content.res.Configuration; -import android.os.Handler; - -import com.kunzisoft.keepass.R; -import com.kunzisoft.keepass.database.action.OnFinishRunnable; -import com.kunzisoft.keepass.database.action.RunnableOnFinish; - -/** Designed to Pop up a progress dialog, run a thread in the background, - * run cleanup in the current thread, close the dialog. Without blocking - * the current thread. - */ -public class ProgressTask implements Runnable { - - private Activity activity; - private RunnableOnFinish mTask; - private ProgressDialog mPd; - - public ProgressTask(Activity activity, RunnableOnFinish task, int messageId) { - this.activity = activity; - this.mTask = task; - Handler mHandler = new Handler(); - - // Show process dialog - // TODO Move in activity - this.mPd = new ProgressDialog(activity); - this.mPd.setCanceledOnTouchOutside(false); - this.mPd.setTitle(activity.getText(R.string.progress_title)); - this.mPd.setMessage(activity.getText(messageId)); - - // Set code to run when this is finished - this.mTask.setStatus(new UpdateStatus(activity, mHandler, mPd)); - this.mTask.mFinish = new AfterTask(task.mFinish, mHandler); - - } - - public void run() { - lockScreenOrientation(); - - // Show process dialog - mPd.show(); - - // Start Thread to Run task - Thread t = new Thread(mTask); - t.start(); - } - - private class AfterTask extends OnFinishRunnable { - - AfterTask(OnFinishRunnable finish, Handler handler) { - super(finish, handler); - } - - @Override - public void run() { - super.run(); - // Remove the progress dialog - mHandler.post(new CloseProcessDialog()); - } - - } - - private class CloseProcessDialog implements Runnable { - public void run() { - if (mPd != null && mPd.isShowing()) { - mPd.dismiss(); - } - unlockScreenOrientation(); - } - } - - private void lockScreenOrientation() { - int currentOrientation = activity.getResources().getConfiguration().orientation; - if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } else { - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - } - } - - private void unlockScreenOrientation() { - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); - } - -} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java index 75098d38d..379dd01ba 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java @@ -77,8 +77,7 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre messageView = root.findViewById(R.id.progress_dialog_message); progressView = root.findViewById(R.id.progress_dialog_bar); - if (message != UNDEFINED) - messageView.setText(message); + updateMessage(message); setCancelable(false); lockScreenOrientation(); @@ -123,7 +122,13 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre @Override public void updateMessage(int resId) { this.message = resId; - if (messageView != null) - this.messageView.setText(message); + if (messageView != null) { + if (message == UNDEFINED) { + messageView.setVisibility(View.GONE); + } else { + messageView.setText(message); + messageView.setVisibility(View.VISIBLE); + } + } } } 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..a514f688f --- /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.setTitle(R.string.saving_database); + dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); + return dialog; + } +} diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java index 64430cb6c..2e2ed1eed 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateProgressTaskStatus.java @@ -27,6 +27,10 @@ public class UpdateProgressTaskStatus implements ProgressTaskUpdater { private ProgressTaskUpdater mProgressTaskUpdater; private Handler mHandler; + public UpdateProgressTaskStatus(Context context, ProgressTaskUpdater progressTaskUpdater) { + this(context, new Handler(), progressTaskUpdater); + } + public UpdateProgressTaskStatus(Context context, Handler handler, ProgressTaskUpdater progressTaskUpdater) { this.mContext = context; this.mProgressTaskUpdater = progressTaskUpdater; diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java b/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java deleted file mode 100644 index 4461d495f..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/UpdateStatus.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft. - * - * This file is part of KeePass DX. - * - * KeePass DX is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KeePass DX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with KeePass DX. If not, see . - * - */ -package com.kunzisoft.keepass.tasks; - -import android.app.ProgressDialog; -import android.content.Context; -import android.os.Handler; - -public class UpdateStatus implements ProgressTaskUpdater { - private ProgressDialog mPD; - private Context mCtx; - private Handler mHandler; - - UpdateStatus(Context ctx, Handler handler, ProgressDialog pd) { - mCtx = ctx; - mPD = pd; - mHandler = handler; - } - - public void updateMessage(int resId) { - if ( mCtx != null && mPD != null && mHandler != null ) { - mHandler.post(new UpdateMessage(resId)); - } - } - - private class UpdateMessage implements Runnable { - private int mResId; - - UpdateMessage(int resId) { - mResId = resId; - } - - public void run() { - mPD.setMessage(mCtx.getString(mResId)); - } - - } -} From 60e2d786dd635d94bb87d0a55bed998e2dc5a291 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 2 May 2018 13:49:03 +0200 Subject: [PATCH 16/18] Change progress dialog title, and remove code --- .../keepass/database/PwDatabase.java | 19 ----------- .../keepass/database/PwDatabaseV3.java | 23 +++++++++++++ .../keepass/database/PwDatabaseV4.java | 22 ------------- .../tasks/ProgressTaskDialogFragment.java | 32 ++++++++++++------- ...aveDatabaseProgressTaskDialogFragment.java | 2 +- app/src/main/res/layout/progress_dialog.xml | 19 ++++++++++- 6 files changed, 63 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java index d3f87537d..7433612ea 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabase.java @@ -100,25 +100,6 @@ public abstract class PwDatabase { } } + public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException { + + // Write checksum Checksum + MessageDigest md; + try { + md = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + throw new IOException("SHA-256 not implemented here."); + } + NullOutputStream nos = new NullOutputStream(); + DigestOutputStream dos = new DigestOutputStream(nos, md); + + byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds); + dos.write(masterSeed); + dos.write(transformedMasterKey); + + finalKey = md.digest(); + } + @Override protected String getPasswordEncoding() { return "ISO-8859-1"; 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 0175e2a0e..ff418f891 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java +++ b/app/src/main/java/com/kunzisoft/keepass/database/PwDatabaseV4.java @@ -359,28 +359,6 @@ public class PwDatabaseV4 extends PwDatabase { return md.digest(fKey); } - @Override - public void makeFinalKey(byte[] masterSeed, byte[] masterSeed2, long numRounds) throws IOException { - - byte[] transformedMasterKey = transformMasterKey(masterSeed2, masterKey, numRounds); - - - byte[] cmpKey = new byte[65]; - System.arraycopy(masterSeed, 0, cmpKey, 0, 32); - System.arraycopy(transformedMasterKey, 0, cmpKey, 32, 32); - finalKey = CryptoUtil.resizeKey(cmpKey, 0, 64, dataEngine.keyLength()); - - MessageDigest md; - try { - md = MessageDigest.getInstance("SHA-512"); - cmpKey[64] = 1; - hmacKey = md.digest(cmpKey); - } catch (NoSuchAlgorithmException e) { - throw new IOException("No SHA-512 implementation"); - } finally { - Arrays.fill(cmpKey, (byte)0); - } - } public void makeFinalKey(byte[] masterSeed, KdfParameters kdfP) throws IOException { makeFinalKey(masterSeed, kdfP, 0); } diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java index 379dd01ba..baa9723d2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java @@ -47,13 +47,14 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre 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.setTitle(titleId); + dialog.updateTitle(titleId); dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); return dialog; } @@ -71,12 +72,12 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre @SuppressLint("InflateParams") View root = inflater.inflate(R.layout.progress_dialog, null); builder.setView(root); - if (title != UNDEFINED) - builder.setTitle(title); + 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); @@ -119,16 +120,25 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre this.title = titleId; } - @Override - public void updateMessage(int resId) { - this.message = resId; - if (messageView != null) { - if (message == UNDEFINED) { - messageView.setVisibility(View.GONE); + private void updateView(TextView textView, @StringRes int resId) { + if (textView != null) { + if (resId == UNDEFINED) { + textView.setVisibility(View.GONE); } else { - messageView.setText(message); - messageView.setVisibility(View.VISIBLE); + 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/SaveDatabaseProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java index a514f688f..105223b84 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/SaveDatabaseProgressTaskDialogFragment.java @@ -9,7 +9,7 @@ public class SaveDatabaseProgressTaskDialogFragment extends ProgressTaskDialogFr public static SaveDatabaseProgressTaskDialogFragment start(FragmentManager fragmentManager) { // Create an instance of the dialog fragment and show it SaveDatabaseProgressTaskDialogFragment dialog = new SaveDatabaseProgressTaskDialogFragment(); - dialog.setTitle(R.string.saving_database); + dialog.updateTitle(R.string.saving_database); dialog.show(fragmentManager, PROGRESS_TASK_DIALOG_TAG); return dialog; } diff --git a/app/src/main/res/layout/progress_dialog.xml b/app/src/main/res/layout/progress_dialog.xml index 9f427e09a..4eae38997 100644 --- a/app/src/main/res/layout/progress_dialog.xml +++ b/app/src/main/res/layout/progress_dialog.xml @@ -3,11 +3,27 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> + + From 64e9b9fb6de01f0db1edcebf196e7d4a9b3ca648 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 2 May 2018 14:02:10 +0200 Subject: [PATCH 17/18] Fix lock orientation change --- .../keepass/activities/EntryEditActivity.java | 2 +- .../keepass/activities/ListNodesActivity.java | 6 ++-- .../password/AssignPasswordHelper.java | 2 +- .../keepass/password/PasswordActivity.java | 3 +- ...riptionPreferenceDialogFragmentCompat.java | 3 +- ...aseNamePreferenceDialogFragmentCompat.java | 3 +- .../RoundsPreferenceDialogFragmentCompat.java | 3 +- .../tasks/ProgressTaskDialogFragment.java | 29 +++++-------------- .../com/kunzisoft/keepass/utils/Util.java | 19 ++++++++++++ 9 files changed, 36 insertions(+), 34 deletions(-) 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 0c2938a2d..ed0658ffc 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -575,7 +575,7 @@ public class EntryEditActivity extends LockingHideActivity displayMessage(EntryEditActivity.this); } - SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(EntryEditActivity.this); }); } } 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 04f42752c..ff0153dc2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/ListNodesActivity.java @@ -316,7 +316,7 @@ public abstract class ListNodesActivity extends LockingActivity displayMessage(ListNodesActivity.this); } - SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); }); } } @@ -336,7 +336,7 @@ public abstract class ListNodesActivity extends LockingActivity displayMessage(ListNodesActivity.this); } - SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); }); } } @@ -376,7 +376,7 @@ public abstract class ListNodesActivity extends LockingActivity finish(); } - SaveDatabaseProgressTaskDialogFragment.stop(getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(ListNodesActivity.this); }); } } 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 0b211c6d7..fd3eaa194 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/AssignPasswordHelper.java @@ -110,7 +110,7 @@ public class AssignPasswordHelper { } // To remove progress task - ProgressTaskDialogFragment.stop(context.getSupportFragmentManager()); + 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 fc0e9fe8c..ab0e5e1c9 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -55,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; @@ -875,7 +876,7 @@ public class PasswordActivity extends StylishActivity } // To remove progress task - ProgressTaskDialogFragment.stop(getSupportFragmentManager()); + ProgressTaskDialogFragment.stop(PasswordActivity.this); }); } } 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 0b0debf9a..86b17a78a 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 @@ -71,8 +71,7 @@ public class DatabaseDescriptionPreferenceDialogFragmentCompat extends DatabaseS if (mActivity != null) { mActivity.runOnUiThread(() -> { getPreference().setSummary(descriptionToShow); - SaveDatabaseProgressTaskDialogFragment.stop( - mActivity.getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); }); } 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 2cf492061..889718683 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 @@ -71,8 +71,7 @@ public class DatabaseNamePreferenceDialogFragmentCompat extends DatabaseSavePref if (mActivity != null) { mActivity.runOnUiThread(() -> { getPreference().setSummary(nameToShow); - SaveDatabaseProgressTaskDialogFragment.stop( - mActivity.getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); }); } 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 84c2e0cbe..ae3fe991b 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 @@ -109,8 +109,7 @@ public class RoundsPreferenceDialogFragmentCompat extends DatabaseSavePreference if (mActivity != null) { mActivity.runOnUiThread(() -> { getPreference().setSummary(String.valueOf(roundsToShow)); - SaveDatabaseProgressTaskDialogFragment.stop( - mActivity.getSupportFragmentManager()); + SaveDatabaseProgressTaskDialogFragment.stop(mActivity); }); } diff --git a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java index baa9723d2..86b5fa4b2 100644 --- a/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java +++ b/app/src/main/java/com/kunzisoft/keepass/tasks/ProgressTaskDialogFragment.java @@ -22,8 +22,6 @@ package com.kunzisoft.keepass.tasks; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.DialogInterface; -import android.content.pm.ActivityInfo; -import android.content.res.Configuration; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.StringRes; @@ -31,12 +29,14 @@ 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{ @@ -81,7 +81,7 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre updateMessage(message); setCancelable(false); - lockScreenOrientation(); + Util.lockScreenOrientation(getActivity()); return builder.create(); } @@ -89,33 +89,18 @@ public class ProgressTaskDialogFragment extends DialogFragment implements Progre @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); - unlockScreenOrientation(); + Util.unlockScreenOrientation(getActivity()); } - public static void stop(FragmentManager fragmentManager) { - Fragment fragmentTask = fragmentManager.findFragmentByTag(PROGRESS_TASK_DIALOG_TAG); + 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); } } - private void lockScreenOrientation() { - if (getActivity() != null) { - int currentOrientation = getResources().getConfiguration().orientation; - if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { - getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } else { - getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - } - } - } - - private void unlockScreenOrientation() { - if (getActivity() != null) - getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); - } - public void setTitle(@StringRes int titleId) { this.title = titleId; } 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); + } } From a932156e85a1af6f8dedf83628da687e5b4b1567 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 2 May 2018 15:26:24 +0200 Subject: [PATCH 18/18] Remove unused progressbar --- app/src/main/res/layout/password.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/src/main/res/layout/password.xml b/app/src/main/res/layout/password.xml index 641525cab..e00840e8a 100644 --- a/app/src/main/res/layout/password.xml +++ b/app/src/main/res/layout/password.xml @@ -190,17 +190,6 @@ - -