From 02144adf14920f483f3b9be83998cf8fc4b3ef04 Mon Sep 17 00:00:00 2001 From: k3b <1374583+k3b@users.noreply.github.com> Date: Tue, 20 Apr 2021 19:21:51 +0200 Subject: [PATCH] #190: AO10-DB-Menue DB-Update und DB-Restore and FixDatabase with toasts when finished --- .../androFotoFinder/FotoGalleryActivity.java | 22 ++++++++++++------- .../gallery/cursor/GalleryCursorFragment.java | 16 ++++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java index 7373404d..c3a997f4 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/FotoGalleryActivity.java @@ -30,6 +30,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.widget.Toast; import java.util.Date; @@ -211,12 +212,11 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.cmd_db_recreate: return onDbReloadQuestion(item.getTitle().toString()); case R.id.cmd_db_update: - if (0 != onDbUpdateCommand(item)) - notifyPhotoChanged(); + onDbUpdate(item.getTitle().toString()); return true; case R.id.cmd_db_backup: - onDbBackup(); + onDbBackup(item.getTitle()); return true; case R.id.cmd_more: @@ -233,23 +233,29 @@ public void run() { } - private void onDbBackup() { + private void onDbBackup(CharSequence title) { AndroFotoFinderApp.getMediaContent2DbUpdateService().createBackup(); + Toast.makeText(this, title, Toast.LENGTH_LONG).show(); } - private int onDbUpdateCommand(MenuItem item) { + private void onDbUpdate(String title) { + if (0 != onDbUpdateCommand(title)) { + Toast.makeText(this, title, Toast.LENGTH_LONG).show(); + notifyPhotoChanged(); + } + } + + private int onDbUpdateCommand(String title) { Activity activity = this; int count = AndroFotoFinderApp.getMediaContent2DbUpdateService().update(this, null); - final String message = item.getTitle().toString(); - IProgessListener progessListener = activity instanceof IProgessListener ? ((IProgessListener) activity) : null; IMediaRepositoryApi mediaDBApi = FotoSql.getMediaLocalDatabase(); Date dateLastAdded = Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask.loadDateLastAdded(activity); PhotoPropertiesMediaFilesScanner scanner = PhotoPropertiesMediaFilesScanner.getInstance(activity); Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask newScanner = new Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask( - mediaDBApi, scanner, scanner.mContext, message, + mediaDBApi, scanner, scanner.mContext, title, dateLastAdded, progessListener); AndroidFileCommands cmd = AndroidFileCommands.createFileCommand(this, true) diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java index b534ff28..df92921c 100644 --- a/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java +++ b/app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java @@ -1282,7 +1282,7 @@ private void removeAllFromSelection() { FotoSql.setWhereVisibility(query, VISIBILITY.DEFAULT); boolean multiSelectionActive = isMultiSelectionActive(); - FotoSql.each("removeDuplicates", query, new FotoSql.Runner() { + FotoSql.each("removeAllFromSelection", query, new FotoSql.Runner() { @Override public boolean run(Long id, Cursor cursor) { mSelectedItemIds.remove(id); @@ -1330,19 +1330,19 @@ private void fixMediaDatabase() { if (Global.debugEnabled) { Log.d(Global.LOG_CONTEXT, "Analysing media database for potential problems"); } - repairMissingDisplayNames(); - removeDuplicates(); + int count = repairMissingDisplayNames() + removeDuplicates(); + Toast.makeText(this.getActivity(), getString(R.string.image_success_update_format, count), Toast.LENGTH_LONG).show(); } } /** * image entries may not have DISPLAY_NAME which is essential for calculating the item-s folder. */ - private void repairMissingDisplayNames() { + private int repairMissingDisplayNames() { QueryParameter query = FotoSql.queryGetMissingDisplayNames; FotoSql.setWhereVisibility(query, VISIBILITY.PRIVATE_PUBLIC); - FotoSql.each("repairMissingDisplayNames", query, new FotoSql.Runner() { + int count = FotoSql.each("repairMissingDisplayNames", query, new FotoSql.Runner() { PhotoPropertiesMediaFilesScanner scanner = null; private int colPk; private int colPath; @@ -1359,14 +1359,15 @@ public boolean run(Long id, Cursor cursor) { return true; } }); + return count; } - private void removeDuplicates() { + private int removeDuplicates() { QueryParameter query = FotoSql.queryGetDuplicates; FotoSql.setWhereVisibility(query, VISIBILITY.PRIVATE_PUBLIC); final SelectedItemIds selectedItemIds = new SelectedItemIds(); - FotoSql.each("removeDuplicates", query, new FotoSql.Runner() { + int count = FotoSql.each("removeDuplicates", query, new FotoSql.Runner() { @Override public boolean run(Long id, Cursor cursor) { selectedItemIds.add(id); @@ -1377,6 +1378,7 @@ public boolean run(Long id, Cursor cursor) { if (selectedItemIds.size() > 0) { onDuplicatesFound(selectedItemIds, null); } + return count; }