Skip to content

Commit

Permalink
#155: prepare to fix android10 incompatibility: MediaImageDbReplaceme…
Browse files Browse the repository at this point in the history
…nt(own db-table copy of media db); refactored all context.contentresolver.query/insert/update/delete into seperate ContentProviderMediaExecuter
  • Loading branch information
k3b committed Nov 27, 2019
1 parent c889d58 commit 60afb0f
Show file tree
Hide file tree
Showing 17 changed files with 589 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

package de.k3b.android.androFotoFinder.backup;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;

Expand All @@ -33,6 +31,7 @@
import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.media.PhotoPropertiesMediaDBCursor;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.database.QueryParameter;
Expand Down Expand Up @@ -208,13 +207,12 @@ public static QueryParameter getEffectiveQueryParameter(@NonNull IZipConfig zipC
/** calls consumers for each found query-result-item */
private void execQuery(QueryParameter query,
IItemSaver<IPhotoProperties>... consumers) {
ContentResolver contentResolver = context.getContentResolver();

Cursor cursor = null;
try {
this.onProgress(0,0, "Calculate");
cursor = contentResolver.query(Uri.parse(query.toFrom()), query.toColumns(),
query.toAndroidWhere(), query.toAndroidParameters(), query.toOrderBy());
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "ZipExecute", context,
query, null);

int itemCount = cursor.getCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

import java.util.List;

import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.database.QueryParameter;
import de.k3b.io.Directory;
Expand Down Expand Up @@ -102,8 +102,9 @@ protected IDirectory doInBackground(QueryParameter... queryParameter) {
}

try {
cursor = context.getContentResolver().query(Uri.parse(queryParameters.toFrom()), queryParameters.toColumns(),
queryParameters.toAndroidWhere(), queryParameters.toAndroidParameters(), queryParameters.toOrderBy());
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "ZipExecute", context,
queryParameters, null);

int itemCount = cursor.getCount();
final int expectedCount = itemCount + itemCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import de.k3b.android.androFotoFinder.ThumbNailUtils;
import de.k3b.android.androFotoFinder.backup.BackupActivity;
import de.k3b.android.androFotoFinder.imagedetail.ImageDetailMetaDialogBuilder;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoThumbSql;
import de.k3b.android.androFotoFinder.queries.FotoViewerParameter;
Expand Down Expand Up @@ -692,9 +693,9 @@ private boolean fixLinks(IDirectory linkDir) {
if (cann == null) {
// rename linkFile to canonicalFile
updateValues.put(FotoSql.SQL_COL_PATH, canonicalPath + lin.substring(linkPath.length()));
FotoSql.execUpdate("fixLinks", context, linkIds[i].intValue() ,updateValues);
ContentProviderMediaExecuter.execUpdate("fixLinks", context, linkIds[i].intValue(), updateValues);
} else {
FotoSql.deleteMedia("DirectoryPickerFragment.fixLinks", context, FotoSql.FILTER_COL_PK, new String[] {linkIds[i].toString()}, true);
ContentProviderMediaExecuter.deleteMedia("DirectoryPickerFragment.fixLinks", context, FotoSql.FILTER_COL_PK, new String[]{linkIds[i].toString()}, true);
}
}
PhotoPropertiesMediaFilesScanner.notifyChanges(context, "Fixed link/canonical duplicates");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import de.k3b.android.androFotoFinder.imagedetail.ImageDetailMetaDialogBuilder;
import de.k3b.android.androFotoFinder.locationmap.GeoEditActivity;
import de.k3b.android.androFotoFinder.locationmap.MapGeoPickerActivity;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoViewerParameter;
import de.k3b.android.androFotoFinder.queries.Queryable;
Expand Down Expand Up @@ -1416,7 +1417,7 @@ private void onDuplicatesFound(SelectedItems selectedItems, StringBuffer debugMe

String sqlWhere = query.toAndroidWhere(); // + " OR " + FotoSql.SQL_COL_PATH + " is null";
try {
delCount = FotoSql.deleteMedia(mDebugPrefix + "onDuplicatesFound", activity, sqlWhere, null, true);
delCount = ContentProviderMediaExecuter.deleteMedia(mDebugPrefix + "onDuplicatesFound", activity, sqlWhere, null, true);
} catch (Exception ex) {
Log.w(Global.LOG_CONTEXT, "deleteMedia via update failed for 'where " + sqlWhere +
"'.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2018 by k3b.
* Copyright (c) 2015-2019 by k3b.
*
* This file is part of AndroFotoFinder.
*
Expand Down Expand Up @@ -33,13 +33,14 @@
import java.util.Date;
import java.util.List;

import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.database.QueryParameter;
import de.k3b.io.DateUtil;
import de.k3b.io.FileCommands;
import de.k3b.media.ExifInterfaceEx;
import de.k3b.database.QueryParameter;
import de.k3b.media.PhotoPropertiesImageReader;
import de.k3b.io.FileCommands;
import de.k3b.media.XmpSegment;

/**
Expand Down Expand Up @@ -137,7 +138,7 @@ private static void appendExifInfo(StringBuilder result, Activity context, Strin

if (currentImageId != 0) {

ContentValues dbContent = TagSql.getDbContent(context, currentImageId);
ContentValues dbContent = ContentProviderMediaExecuter.getDbContent(context, currentImageId);
if (dbContent != null) {
result.append(NL).append(line).append(NL);
result.append(NL).append(TagSql.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE).append(NL).append(NL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2018 by k3b.
* Copyright (c) 2015-2019 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017 by k3b.
* Copyright (c) 2015-2019 by k3b.
*
* This file is part of AndroFotoFinder / #APhotoManager.
*
Expand All @@ -22,7 +22,6 @@
import android.app.Activity;
import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

Expand All @@ -34,9 +33,10 @@

import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.osmdroid.IconFactory;
import de.k3b.android.osmdroid.ClickableIconOverlay;
import de.k3b.android.osmdroid.IconFactory;
import de.k3b.android.util.ResourceUtils;
import de.k3b.database.QueryParameter;

Expand Down Expand Up @@ -96,8 +96,9 @@ protected OverlayManager doInBackground(QueryParameter... queryParameter) {

Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(Uri.parse(queryParameters.toFrom()), queryParameters.toColumns(),
queryParameters.toAndroidWhere(), queryParameters.toAndroidParameters(), queryParameters.toOrderBy());
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "MakerLoader", mContext,
queryParameters, null);

int itemCount = cursor.getCount();
final int expectedCount = itemCount + itemCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public static void insertToMediaDB(String dbgContext, @NonNull Context context,
ContentValues values = new ContentValues();
String newAbsolutePath = PhotoPropertiesMediaFilesScanner.setFileFields(values, fileToBeScannedAndInserted);
values.put(FotoSql.SQL_COL_EXT_MEDIA_TYPE, FotoSql.MEDIA_TYPE_ALBUM_FILE);
FotoSql.insertOrUpdateMediaDatabase(dbgContext, context, newAbsolutePath, values, null, 1l);
ContentProviderMediaExecuter.insertOrUpdateMediaDatabase(dbgContext, context, newAbsolutePath, values, null, 1l);
}
}

Expand Down
Loading

0 comments on commit 60afb0f

Please sign in to comment.