Skip to content

Commit

Permalink
#190: AO10-DB-Menue DB-Update und DB-Restore and FixDatabase with toa…
Browse files Browse the repository at this point in the history
…sts when finished
  • Loading branch information
k3b committed Apr 20, 2021
1 parent aa27257 commit 02144ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.Date;

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -1377,6 +1378,7 @@ public boolean run(Long id, Cursor cursor) {
if (selectedItemIds.size() > 0) {
onDuplicatesFound(selectedItemIds, null);
}
return count;
}


Expand Down

0 comments on commit 02144ad

Please sign in to comment.