From 29b9c0dbaf0cf85a1d2cc3210f519de9f266b744 Mon Sep 17 00:00:00 2001 From: Tadeuszk Kowalski Date: Tue, 15 Feb 2022 18:57:02 +0100 Subject: [PATCH] Add option to delete notebook if linked file gets deleted --- .../main/java/com/orgzly/android/prefs/AppPreferences.java | 6 ++++++ app/src/main/java/com/orgzly/android/sync/SyncService.kt | 7 +++++++ app/src/main/res/values-cs-rCZ/strings.xml | 2 ++ app/src/main/res/values-de-rDE/strings.xml | 2 ++ app/src/main/res/values-es-rES/strings.xml | 2 ++ app/src/main/res/values-fr-rFR/strings.xml | 2 ++ app/src/main/res/values-hu-rHU/strings.xml | 2 ++ app/src/main/res/values-in-rID/strings.xml | 2 ++ app/src/main/res/values-it-rIT/strings.xml | 2 ++ app/src/main/res/values-ja-rJP/strings.xml | 2 ++ app/src/main/res/values-ko-rKR/strings.xml | 2 ++ app/src/main/res/values-nl-rNL/strings.xml | 2 ++ app/src/main/res/values-pl-rPL/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-pt-rPT/strings.xml | 2 ++ app/src/main/res/values-ru-rRU/strings.xml | 2 ++ app/src/main/res/values-sv-rSE/strings.xml | 2 ++ app/src/main/res/values-tr-rTR/strings.xml | 2 ++ app/src/main/res/values-uk-rUA/strings.xml | 2 ++ app/src/main/res/values-zh-rCN/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values/prefs_keys.xml | 3 +++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/prefs_screen_sync.xml | 5 +++++ 24 files changed, 61 insertions(+) diff --git a/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java b/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java index e3024e6c5..e53522659 100644 --- a/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java +++ b/app/src/main/java/com/orgzly/android/prefs/AppPreferences.java @@ -975,6 +975,12 @@ public static boolean syncOnResume(Context context) { context.getResources().getBoolean(R.bool.pref_default_auto_sync_on_resume)); } + public static boolean syncDeletion(Context context) { + return getDefaultSharedPreferences(context).getBoolean( + context.getResources().getString(R.string.pref_key_sync_deletion), + context.getResources().getBoolean(R.bool.pref_default_sync_deletion)); + } + /* * Notes clipboard */ diff --git a/app/src/main/java/com/orgzly/android/sync/SyncService.kt b/app/src/main/java/com/orgzly/android/sync/SyncService.kt index 138ce8952..1274907a0 100644 --- a/app/src/main/java/com/orgzly/android/sync/SyncService.kt +++ b/app/src/main/java/com/orgzly/android/sync/SyncService.kt @@ -307,10 +307,17 @@ class SyncService : Service() { namesake.book.book.id, BookAction.forNow(BookAction.Type.INFO, getString(R.string.canceled))) + } else if (AppPreferences.syncDeletion(context) && + namesake.status == BookSyncStatus.ONLY_BOOK_WITH_LINK && + namesake.rooks.isEmpty()) { + /* Delete book if file backing it does not exist */ + dataRepository.deleteBook(namesake.book, false); } else { syncStatus.set(SyncStatus.Type.BOOK_STARTED, namesake.name, curr, namesakes.size) announceActiveSyncStatus() + + try { val action = syncNamesake(dataRepository, namesake) dataRepository.setBookLastActionAndSyncStatus( diff --git a/app/src/main/res/values-cs-rCZ/strings.xml b/app/src/main/res/values-cs-rCZ/strings.xml index 1ddb827b7..ff449a50a 100644 --- a/app/src/main/res/values-cs-rCZ/strings.xml +++ b/app/src/main/res/values-cs-rCZ/strings.xml @@ -590,4 +590,6 @@ Možnosti pro vývojáře Typ Git repozitáře Ve vývoji + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 0ff1e4957..520c3e3a9 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -568,4 +568,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 5145ecf25..e025ff0b3 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -568,4 +568,6 @@ Opciones de desarrollador Tipo de repositorio Git En desarrollo + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index 787d795c7..37f942c91 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -568,4 +568,6 @@ Options développeur Type de dépôt Git En développement + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-hu-rHU/strings.xml b/app/src/main/res/values-hu-rHU/strings.xml index 2693bd957..49378caad 100644 --- a/app/src/main/res/values-hu-rHU/strings.xml +++ b/app/src/main/res/values-hu-rHU/strings.xml @@ -568,4 +568,6 @@ Fejlesztői beállítások Git adattároló típusa Fejlesztés alatt + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-in-rID/strings.xml b/app/src/main/res/values-in-rID/strings.xml index cc50c8e69..61652fb73 100644 --- a/app/src/main/res/values-in-rID/strings.xml +++ b/app/src/main/res/values-in-rID/strings.xml @@ -557,4 +557,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-it-rIT/strings.xml b/app/src/main/res/values-it-rIT/strings.xml index 9b332f38f..08745f84c 100644 --- a/app/src/main/res/values-it-rIT/strings.xml +++ b/app/src/main/res/values-it-rIT/strings.xml @@ -568,4 +568,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 93389b4d4..839932875 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -557,4 +557,6 @@ 開発者オプション リポジトリの種類 開発中 + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index 8159601a1..b58d06dd8 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -558,4 +558,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-nl-rNL/strings.xml b/app/src/main/res/values-nl-rNL/strings.xml index 90234d143..550d461cc 100644 --- a/app/src/main/res/values-nl-rNL/strings.xml +++ b/app/src/main/res/values-nl-rNL/strings.xml @@ -568,4 +568,6 @@ Ontwikkelaarsopties Git repository type In ontwikkeling + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml index 6e9ae6ffd..f8dae98fa 100644 --- a/app/src/main/res/values-pl-rPL/strings.xml +++ b/app/src/main/res/values-pl-rPL/strings.xml @@ -590,4 +590,6 @@ Developer options Typ repozytorium Git In development + Synchronizuj usunięcie + Usuń notatnik po usunięciu powiązanego pliku diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7a1248650..f1cb4f8a2 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -568,4 +568,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 7f1a19709..2f74444b0 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -568,4 +568,6 @@ Opções de programador Tipo de repositório Git Em desenvolvimento + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index b27dd9153..dfb284c1f 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -590,4 +590,6 @@ Для разработчиков Тип git-репозитория В разработке + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-sv-rSE/strings.xml b/app/src/main/res/values-sv-rSE/strings.xml index df07e0b67..b917409d1 100644 --- a/app/src/main/res/values-sv-rSE/strings.xml +++ b/app/src/main/res/values-sv-rSE/strings.xml @@ -568,4 +568,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index 2acc509b9..35d341629 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -568,4 +568,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-uk-rUA/strings.xml b/app/src/main/res/values-uk-rUA/strings.xml index aeea44549..ad95883bd 100644 --- a/app/src/main/res/values-uk-rUA/strings.xml +++ b/app/src/main/res/values-uk-rUA/strings.xml @@ -590,4 +590,6 @@ Параметри розробника Тип git-репозиторію У розробці + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e8c9fac44..b4805a0b3 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -557,4 +557,6 @@ 开发者选项 Git 仓库类型 开发中 + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index fbcf70384..f7913c173 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -557,4 +557,6 @@ 開發人員選項 Git 儲存庫型式 開發中 + Sync deletion + Delete notebook if its deleted from repo diff --git a/app/src/main/res/values/prefs_keys.xml b/app/src/main/res/values/prefs_keys.xml index 00a2b3b50..421264a24 100644 --- a/app/src/main/res/values/prefs_keys.xml +++ b/app/src/main/res/values/prefs_keys.xml @@ -254,6 +254,9 @@ pref_key_auto_sync_on_resume false + pref_key_sync_deletion + false + pref_key_auto_sync_on_repo_change false diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 735b29910..0e3e0d3f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -704,4 +704,6 @@ Developer options Git repository type In development + Sync deletion + Delete notebook if linked file is deleted from repo diff --git a/app/src/main/res/xml/prefs_screen_sync.xml b/app/src/main/res/xml/prefs_screen_sync.xml index 3d6205ebe..f9fd596b6 100644 --- a/app/src/main/res/xml/prefs_screen_sync.xml +++ b/app/src/main/res/xml/prefs_screen_sync.xml @@ -42,5 +42,10 @@ android:title="@string/org_file_format" android:summary="@string/org_file_format_summary"> +