Skip to content

Commit

Permalink
#169: ao10 menu "Database..." with subitems for database and media sc…
Browse files Browse the repository at this point in the history
…anner
  • Loading branch information
k3b committed Mar 12, 2021
1 parent 6a62ba3 commit c478c46
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,29 @@
import android.view.MenuInflater;
import android.view.MenuItem;

import java.util.Date;

import de.k3b.LibGlobal;
import de.k3b.android.androFotoFinder.directory.DirectoryGui;
import de.k3b.android.androFotoFinder.gallery.cursor.GalleryCursorFragment;
import de.k3b.android.androFotoFinder.imagedetail.ImageDetailActivityViewPager;
import de.k3b.android.androFotoFinder.locationmap.GeoEditActivity;
import de.k3b.android.androFotoFinder.queries.AndroidAlbumUtils;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoViewerParameter;
import de.k3b.android.androFotoFinder.queries.IMediaRepositoryApi;
import de.k3b.android.androFotoFinder.queries.Queryable;
import de.k3b.android.io.AndroidFileCommands;
import de.k3b.android.util.Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask;
import de.k3b.android.util.GarbageCollector;
import de.k3b.android.util.IntentUtil;
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.widget.AboutDialogPreference;
import de.k3b.android.widget.BaseQueryActivity;
import de.k3b.android.widget.Dialogs;
import de.k3b.database.QueryParameter;
import de.k3b.io.IDirectory;
import de.k3b.io.IProgessListener;
import de.k3b.io.collections.SelectedItemIds;

/**
Expand Down Expand Up @@ -167,15 +175,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
inflater.inflate(R.menu.menu_gallery_non_selected_only, menu);
inflater.inflate(R.menu.menu_gallery_non_multiselect, menu);

if (Global.useAo10MediaImageDbReplacement) {
inflater.inflate(R.menu.menu_ao10, menu);
}
inflater.inflate(Global.useAo10MediaImageDbReplacement ? R.menu.menu_gallery_ao10 : R.menu.menu_gallery_ao9, menu);

/*
getActionBar().setListNavigationCallbacks();
MenuItem sorter = menu.getItem(R.id.cmd_sort);
sorter.getSubMenu().
*/
Global.fixMenu(this, menu);
}

Expand Down Expand Up @@ -206,10 +207,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.cmd_about:
AboutDialogPreference.createAboutDialog(this).show();
return true;
case R.id.cmd_db_reload:
case R.id.cmd_db_recreate:
return onDbReloadQuestion(item.getTitle().toString());
case R.id.cmd_db_update:
if (0 != AndroFotoFinderApp.getMediaContent2DbUpdateService().update(this, null))
if (0 != onDbUpdateCommand(item))
notifyPhotoChanged();
return true;
case R.id.cmd_more:
Expand All @@ -226,6 +227,29 @@ public void run() {

}

private int onDbUpdateCommand(MenuItem item) {
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,
dateLastAdded, progessListener);

AndroidFileCommands cmd = AndroidFileCommands.createFileCommand(this, true)
.setContext(this);

cmd.runScanner(activity, null, newScanner);

return count;
}

private boolean onDbReloadQuestion(String title) {
Dialogs dlg = new Dialogs() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public static void fixMenu(Context context, Menu menu) {
R.id.cmd_selection_add_all,
R.id.cmd_selection_remove_all,
R.id.cmd_about,
R.id.cmd_scan,
R.id.cmd_more,
R.id.cmd_show_geo,
R.id.cmd_gallery,
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/de/k3b/android/io/AndroidFileCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2020 by k3b.
* Copyright (c) 2015-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down Expand Up @@ -407,15 +407,19 @@ private void onMediaScannerAnswer(Activity activity, IFile scanRootDir,
ScannerTaskFactory.createScannerTask(message, mScanner,
fullScan, rescanNeverScannedByAPM, scanForDeleted, progessListener);

synchronized (this) {
if (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner == null) {
RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner = scanner;
scanner.execute(new IFile[]{scanRootDir});
} // else scanner is already running
}
runScanner(activity, scanRootDir, scanner);
}
}

showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner, activity);
public void runScanner(Activity activity, IFile scanRootDir, RecursivePhotoPropertiesMediaFilesScannerAsyncTask scanner) {
synchronized (this) {
if (RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner == null) {
RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner = scanner;
scanner.execute(new IFile[]{scanRootDir});
} // else scanner is already running
}

showMediaScannerStatus(RecursivePhotoPropertiesMediaFilesScannerAsyncTask.sScanner, activity);
}

public boolean cmdMediaScannerWithQuestion(Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static RecursivePhotoPropertiesMediaFilesScannerAsyncTask createScannerTa
boolean fullScan, boolean rescanNeverScannedByAPM, boolean scanForDeleted,
IProgessListener progessListener) {
RecursivePhotoPropertiesMediaFilesScannerAsyncTask newScanner;
if (rescanNeverScannedByAPM && Global.useAo10MediaImageDbReplacement && FotoSql.getMediaLocalDatabase() != null) {
if (false && rescanNeverScannedByAPM && Global.useAo10MediaImageDbReplacement && FotoSql.getMediaLocalDatabase() != null) {
IMediaRepositoryApi mediaDBApi = FotoSql.getMediaLocalDatabase();
Date dateLastAdded = Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask.loadDateLastAdded(scanner.mContext);
newScanner = new Ao10DbUpdateOnlyPhotoPropertiesMediaFilesScannerAsyncTask(
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/res/menu/menu_ao10.xml

This file was deleted.

55 changes: 55 additions & 0 deletions app/src/main/res/menu/menu_gallery_ao10.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?><!--
/*
* Copyright (c) 2020-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
* This program 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.
*
* This program 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
* this program. If not, see <http://www.gnu.org/licenses/>
*/
Gallery menu-items addon for android 10 and later (with android-10 specific menue items)
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/cmd_database"
android:orderInCategory="110"
android:showAsAction="never"
android:title="@string/database_menu_title"
android:visible="true">
<menu>
<item
android:id="@+id/cmd_scan"
android:orderInCategory="110"
android:showAsAction="never"
android:title="@string/scanner_menu_title"
android:visible="true" />

<item
android:id="@+id/cmd_db_recreate"
android:orderInCategory="9900"
android:showAsAction="never"
android:title="@string/load_db_menu_title"
android:visible="true" />

<item
android:id="@+id/cmd_db_update"
android:orderInCategory="9900"
android:showAsAction="never"
android:title="@string/update_db_menu_title"
android:visible="true" />

</menu>
</item>
</menu>
30 changes: 30 additions & 0 deletions app/src/main/res/menu/menu_gallery_ao9.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?><!--
/*
* Copyright (c) 2020-2021 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
* This program 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.
*
* This program 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
* this program. If not, see <http://www.gnu.org/licenses/>
*/
Gallery menu-items addon for android 4-9 (non-android-10 specific menue item)
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/cmd_scan"
android:orderInCategory="110"
android:showAsAction="never"
android:title="@string/scanner_menu_title"
android:visible="true" />
</menu>
2 changes: 0 additions & 2 deletions app/src/main/res/menu/menu_gallery_non_multiselect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ Note menu_gallery_non_multiselect-seachbar and menu_gallery_non_multiselect are
android:orderInCategory="1000"
android:showAsAction="ifRoom" />

<item android:id="@+id/cmd_scan" android:title="@string/scanner_menu_title" android:orderInCategory="110"
android:showAsAction="never" android:visible="true"/>

<item android:id="@+id/cmd_app_pin"
android:title="@string/menu_title_app_pinnend"
Expand Down
29 changes: 19 additions & 10 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@
<string name="overwrite_question_title">Überschreiben?</string>
<string name="rename_menu_title">Umbenennen</string>
<string name="rename_result_format">%1$d/%2$d Dateien umbenannt</string>
<string name="scanner_dir_question">Ab wo scannen?</string>
<string name="scanner_err_busy">Fotodateien können nicht bearbeitet werden, solange der Android Media Scanner aktiv ist. Versuchen Sie es später erneut.</string>
<string name="scanner_menu_title">Media-Scanner</string>
<string name="scanner_update_result_format">%1$d Elemente in Mediendatenbank aktualisiert</string>
<string name="selection_status_format">%1$d ausgewählt</string>
<string name="selection_none_hint">Wählen Sie den Ordner, aus dem Bilder geladen werden sollen, und drücken Sie OK</string>
<string name="selected_only_menu_title">Nur ausgewählte</string>
Expand Down Expand Up @@ -150,7 +146,7 @@ Wollen Sie alle Medien-Dateien (Foto, Video, Audio) unterhalb von

unsichtbar machen für Medien-Datenbank, Gallery-Apps und den Media-Scanner?

Verstecken kann über das \'Media-Scanner\' Gallery-Menü rückgängig gemacht werden."</string>
Verstecken kann über das \'Mediendatenbank.../Media-Scanner\' Gallery-Menü rückgängig gemacht werden."</string>
<string name="filter_path_hint">Teil von Ordner oder Dateiname. %=Wildcard</string>
<string name="lbl_any">Suche</string>
<string name="filter_any_hint">in Tags, Title, Beschreibung oder Pfad</string>
Expand Down Expand Up @@ -207,6 +203,8 @@ Verstecken kann über das \'Media-Scanner\' Gallery-Menü rückgängig gemacht w
<string name="menu_title_app_unpinnend">App ungeschützt/nicht fixiert</string>
<!-- #100: private images get the extension ".jpg-p" which hides them from other gallery-apps and image pickers. -->
<string name="settings_rename_private_jpg_title">Private *.jpg wird zu *.jpg-p </string>
<string name="settings_rename_private_jpg_summary">... um sie vor anderen Fotoanzeigen zu verstecken</string>

<string name="clear_menu_title">Leeren</string>
<string name="show_in_filemanager_menu_title">In Dateimanager öffnen</string>
<!-- #1113: Searchbar -->
Expand Down Expand Up @@ -240,9 +238,7 @@ Verstecken kann über das \'Media-Scanner\' Gallery-Menü rückgängig gemacht w
<string name="settings_category_appearance_title">Aussehen</string>
<string name="light_theme_title">Hell</string>
<string name="dark_theme_title">Dunkel</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">Mediendatenbank (neu) laden</string>
<string name="update_db_menu_title">Mediendatenbank aktualisieren</string>

<!-- #169: sd-card-saf-write-permission support -->
<string name="permission_error">Fehlende Berechtigung</string>
<string name="select_folder_root_rationale"><![CDATA["<h2>Benötigt Verzeichnisberechtigungen.</h2>
Expand All @@ -251,9 +247,22 @@ Verstecken kann über das \'Media-Scanner\' Gallery-Menü rückgängig gemacht w
der SD-Karte oder des USB-Sticks aus.</p>
"]]></string>
<string name="settings_debug_log_saf">Logcat SAF File Handling</string>
<!-- #100: private images get the extension ".jpg-p" which hides them from other gallery-apps and image pickers. -->
<string name="settings_rename_private_jpg_summary">... um sie vor anderen Fotoanzeigen zu verstecken</string>

<!-- #155: android10 -->
<string name="database_menu_title">Mediendatenbank ...</string>
<string name="load_db_menu_title">Mediendatenbank (neu) laden</string>

<string name="update_db_menu_title">Mediendatenbank aktualisieren</string>

<!-- #173: incremental media scanner -->
<string name="scanner_menu_title">Media-Scanner</string>

<string name="scanner_dir_question">Ab wo scannen?</string>

<string name="lbl_media_scanner_full">Vollständiger Scan</string>
<string name="lbl_media_scanner_non_apm_only">Alle Neueinlesen</string>
<string name="lbl_media_scanner_deleted">Suche nach gelöschten</string>

<string name="scanner_err_busy">Fotodateien können nicht bearbeitet werden, solange der Android Media Scanner aktiv ist. Versuchen Sie es später erneut.</string>
<string name="scanner_update_result_format">%1$d Elemente in Mediendatenbank aktualisiert</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-eu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,5 @@ Ezkutaketa desegin dezakezu multimedia eskanerra galeriaren menutik deituz."</st
<string name="dark_theme_title">Iluna</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">(Bir)kargatu multimedia datu-basea</string>
<string name="database_menu_title">Multimedia datu-basea ...</string>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,4 @@ You can undo hiding by calling the mediascanner from gallery-menu."</string>
<string name="light_theme_title">Valo</string>
<string name="dark_theme_title">Tumma</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">(Re)Load Media Database</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,5 @@ onzichtbaar voor de mediadatabase, de galerij apps en de mediascanner. De bestan
<string name="dark_theme_title">Donker</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">(Her)Laad Mediadatabase</string>
<string name="database_menu_title">Mediadatabase ...</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Você pode desfazer a ocultação chamando o leitor mediascanner do menu da gale
<string name="dark_theme_title">Escuro</string>
<!-- #155: android10 -->
<string name="load_db_menu_title">(Re)Carregar Banco de Dados de Mídia</string>
<string name="database_menu_title">Dados de Mídia ...</string>
</resources>
Loading

0 comments on commit c478c46

Please sign in to comment.