Skip to content

Commit

Permalink
#155: prepare to fix android10 incompatibility: refactored replace al…
Browse files Browse the repository at this point in the history
…l static method calls of ContentProviderMediaExecuter(ContentProviderMediaImpl) with dynamic Interface IMediaDBApi calls
  • Loading branch information
k3b committed Nov 27, 2019
1 parent 60afb0f commit 91eb4b3
Show file tree
Hide file tree
Showing 32 changed files with 318 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.ArrayList;

import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.io.FileUtils;
import de.k3b.io.VISIBILITY;
import de.k3b.io.collections.SelectedItems;
import de.k3b.io.FileUtils;
import de.k3b.media.PhotoPropertiesUtil;

/**
Expand All @@ -47,7 +47,7 @@ public AdapterArrayHelper(Activity context, String fullPhotoPath, String debugCo

if (Global.mustRemoveNOMEDIAfromDB && (mRootDir != null) && (mFullPhotoPaths != null)) {
String parentDirString = mRootDir.getAbsolutePath();
FotoSql.execDeleteByPath(debugContext + " AdapterArrayHelper mustRemoveNOMEDIAfromDB ", context, parentDirString, VISIBILITY.PRIVATE_PUBLIC);
FotoSql.execDeleteByPath(debugContext + " AdapterArrayHelper mustRemoveNOMEDIAfromDB ", parentDirString, VISIBILITY.PRIVATE_PUBLIC);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static SelectedFiles querySelectedFiles(Context context, SelectedItems it
List<String> paths = new ArrayList<String>();
List<Date> datesPhotoTaken = new ArrayList<Date>();

if (FotoSql.getFileNames(context, items, ids, paths, datesPhotoTaken) != null) {
if (FotoSql.getFileNames(items, ids, paths, datesPhotoTaken) != null) {
return new SelectedFiles(paths.toArray(new String[paths.size()]), ids.toArray(new Long[ids.size()]), datesPhotoTaken.toArray(new Date[datesPhotoTaken.size()]));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.queries.FotoSqlBase;
import de.k3b.android.androFotoFinder.queries.MediaDBContentprovider;
import de.k3b.android.osmdroid.forge.MapsForgeSupport;
import de.k3b.android.util.LogCat;
import de.k3b.android.widget.ActivityWithCallContext;
Expand Down Expand Up @@ -94,6 +95,9 @@ public static RefWatcher getRefWatcher(Context context) {
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
FotoSqlBase.init();

/// #155: todo: depending on android-api version set IMediaDBApi
FotoSql.setMediaDBApi(new MediaDBContentprovider(this));

super.onCreate();

LibGlobal.appName = getString(R.string.app_name);
Expand Down Expand Up @@ -165,7 +169,7 @@ private File getOutpuFile() {
// #60: configure some of the mapsforge settings first
MapsForgeSupport.createInstance(this);

FotoSql.deleteMediaWithNullPath(this);
FotoSql.deleteMediaWithNullPath();

Log.i(Global.LOG_CONTEXT, getAppId() + " created");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private SelectedFiles getSelectedFiles(String dbgContext, Intent intent, boolean
if (itemCount > 0) {
if ((mustLoadIDs) && (ids == null)) {
ids = new Long[itemCount];
Map<String, Long> idMap = FotoSql.execGetPathIdMap(this, fileNames);
Map<String, Long> idMap = FotoSql.execGetPathIdMap(fileNames);

for (int i = 0; i < itemCount; i++) {
ids[i] = idMap.get(fileNames[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private static SelectedFiles getSelectedFiles(String dbgContext, Context ctx, In
if (itemCount > 0) {
if ((mustLoadIDs) && (ids == null)) {
ids = new Long[itemCount];
Map<String, Long> idMap = FotoSql.execGetPathIdMap(ctx, fileNames);
Map<String, Long> idMap = FotoSql.execGetPathIdMap(fileNames);

for (int i = 0; i < itemCount; i++) {
ids[i] = idMap.get(fileNames[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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 @@ -210,8 +209,8 @@ private void execQuery(QueryParameter query,
Cursor cursor = null;
try {
this.onProgress(0,0, "Calculate");
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "ZipExecute", context,
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "ZipExecute",
query, null);

int itemCount = cursor.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private SelectedFiles getSelectedFiles(String dbgContext, Intent intent, boolean
if (itemCount > 0) {
if ((mustLoadIDs) && (ids == null)) {
ids = new Long[itemCount];
Map<String, Long> idMap = FotoSql.execGetPathIdMap(this, fileNames);
Map<String, Long> idMap = FotoSql.execGetPathIdMap(fileNames);

for (int i = 0; i < itemCount; i++) {
ids[i] = idMap.get(fileNames[i]);
Expand Down Expand Up @@ -702,7 +702,7 @@ private void updateHistory(QueryParameter query) {

paths.add(DCIM_ROOT);

String minFolder = FotoSql.getMinFolder(getApplicationContext(), query, true);
String minFolder = FotoSql.getMinFolder(query, true);
updateHistory(FileUtils.getDir(minFolder), filenames, paths, 1);

String queryFolder = FotoSql.getFilePath(query, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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 +101,8 @@ protected IDirectory doInBackground(QueryParameter... queryParameter) {
}

try {
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "ZipExecute", context,
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "ZipExecute",
queryParameters, null);

int itemCount = cursor.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
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 @@ -545,7 +544,7 @@ private void onDeleteAnswer(File file, IDirectory dir) {
}

// delete from database
if (FotoSql.deleteMedia("delete album", getActivity(),
if (FotoSql.deleteMedia("delete album",
ListUtils.toStringList(file.getAbsolutePath()),false) > 0) {
deleteSuccess = true;
}
Expand Down Expand Up @@ -664,11 +663,11 @@ private boolean fixLinks(IDirectory linkDir) {
if (!canonicalPath.endsWith("/")) canonicalPath+="/";

String sqlWhereLink = FotoSql.SQL_COL_PATH + " like '" + linkPath + "%'";
SelectedFiles linkFiles = FotoSql.getSelectedfiles(context, sqlWhereLink, VISIBILITY.PRIVATE_PUBLIC);
SelectedFiles linkFiles = FotoSql.getSelectedfiles(sqlWhereLink, VISIBILITY.PRIVATE_PUBLIC);

String sqlWhereCanonical = FotoSql.SQL_COL_PATH + " in (" + linkFiles.toString() + ")";
sqlWhereCanonical = sqlWhereCanonical.replace(linkPath,canonicalPath);
SelectedFiles canonicalFiles = FotoSql.getSelectedfiles(context, sqlWhereCanonical, VISIBILITY.PRIVATE_PUBLIC);
SelectedFiles canonicalFiles = FotoSql.getSelectedfiles(sqlWhereCanonical, VISIBILITY.PRIVATE_PUBLIC);
HashMap<String, String> link2canonical = new HashMap<String, String>();
for(String cann : canonicalFiles.getFileNames()) {
link2canonical.put(linkPath + cann.substring(canonicalPath.length()), cann);
Expand All @@ -693,9 +692,9 @@ private boolean fixLinks(IDirectory linkDir) {
if (cann == null) {
// rename linkFile to canonicalFile
updateValues.put(FotoSql.SQL_COL_PATH, canonicalPath + lin.substring(linkPath.length()));
ContentProviderMediaExecuter.execUpdate("fixLinks", context, linkIds[i].intValue(), updateValues);
FotoSql.getMediaDBApi().execUpdate("fixLinks", linkIds[i].intValue(), updateValues);
} else {
ContentProviderMediaExecuter.deleteMedia("DirectoryPickerFragment.fixLinks", context, FotoSql.FILTER_COL_PK, new String[]{linkIds[i].toString()}, true);
FotoSql.getMediaDBApi().deleteMedia("DirectoryPickerFragment.fixLinks", 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 @@ -134,7 +134,7 @@ private long getPickCount(String dbgContext,
QueryParameter query = AndroidAlbumUtils.getAsAlbumOrMergedNewQuery(
dbgContext, mContext, baseQuery, filter);
if (query == null) return 0;
return FotoSql.getCount(mContext, query);
return FotoSql.getCount(query);
}

private boolean showPhoto(String dbgContext, QueryParameter baseQuery) {
Expand Down Expand Up @@ -162,7 +162,7 @@ private boolean showMap(String dbgContext, QueryParameter baseQuery) {
QueryParameter query = AndroidAlbumUtils.getAsAlbumOrMergedNewQuery(
dbgContext, mContext, baseQuery, currentSelectionFilter);
if (query != null) {
IGeoRectangle area = FotoSql.execGetGeoRectangle(null, mContext, query,
IGeoRectangle area = FotoSql.execGetGeoRectangle(null, query,
null, "Calculate visible arean", dbgContext);
MapGeoPickerActivity.showActivity(dbgContext, mContext, null,
query, area, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
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 @@ -1153,7 +1152,7 @@ private Uri getUri(Activity parent, long id) {
Uri resultUri = null;
if (mModePickGeoElsePickImaage) {
// mode pick gep
IGeoPoint initialPoint = FotoSql.execGetPosition(null, parent,
IGeoPoint initialPoint = FotoSql.execGetPosition(null,
null, id, mDebugPrefix, "getSelectedUri");

if (initialPoint != null) {
Expand Down Expand Up @@ -1417,7 +1416,7 @@ private void onDuplicatesFound(SelectedItems selectedItems, StringBuffer debugMe

String sqlWhere = query.toAndroidWhere(); // + " OR " + FotoSql.SQL_COL_PATH + " is null";
try {
delCount = ContentProviderMediaExecuter.deleteMedia(mDebugPrefix + "onDuplicatesFound", activity, sqlWhere, null, true);
delCount = FotoSql.getMediaDBApi().deleteMedia(mDebugPrefix + "onDuplicatesFound", 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
Expand Up @@ -800,7 +800,7 @@ private static int updateIncompleteMediaDatabase(String debugPrefix, Context con
String dbPathSearch = null;
ArrayList<String> missing = new ArrayList<String>();
dbPathSearch = dirToScan.getPath() + "/%";
List<String> known = FotoSql.execGetFotoPaths(context, dbPathSearch);
List<String> known = FotoSql.execGetFotoPaths(dbPathSearch);
File[] existing = dirToScan.listFiles();

if (existing != null) {
Expand Down Expand Up @@ -973,7 +973,7 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {

case R.id.cmd_show_geo_as: {
final long imageId = getCurrentImageId();
IGeoPoint _geo = FotoSql.execGetPosition(null, this,
IGeoPoint _geo = FotoSql.execGetPosition(null,
null, imageId, mDebugPrefix, "on cmd_show_geo_as");
final String currentFilePath = getCurrentFilePath();
GeoPointDto geo = new GeoPointDto(_geo.getLatitude(), _geo.getLongitude(), GeoPointDto.NO_ZOOM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Date;
import java.util.List;

import de.k3b.android.androFotoFinder.queries.ContentProviderMediaExecuter;
import de.k3b.android.androFotoFinder.queries.ContentProviderMediaImpl;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.android.widget.ActivityWithCallContext;
import de.k3b.database.QueryParameter;
Expand Down Expand Up @@ -138,7 +138,7 @@ private static void appendExifInfo(StringBuilder result, Activity context, Strin

if (currentImageId != 0) {

ContentValues dbContent = ContentProviderMediaExecuter.getDbContent(context, currentImageId);
ContentValues dbContent = ContentProviderMediaImpl.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
Expand Up @@ -1120,7 +1120,7 @@ private boolean zoomToFit(IGeoPoint geoCenterPoint, Object... dbgContext) {
QueryParameter baseQuery = getQueryForPositionRectangle(geoCenterPoint);
BoundingBox boundingBox = null;

IGeoRectangle fittingRectangle = FotoSql.execGetGeoRectangle(null, this.getActivity(),
IGeoRectangle fittingRectangle = FotoSql.execGetGeoRectangle(null,
baseQuery, null, mDebugPrefix, "zoomToFit", dbgContext);
double delta = getDelta(fittingRectangle);
if ((geoCenterPoint != null) && (delta < 1e-6)) {
Expand Down Expand Up @@ -1194,7 +1194,7 @@ private double getMarkerDelta() {

private IGeoPoint getGeoPointById(int markerId, IGeoPoint notFoundValue, Object... dbgContext) {
if (markerId != NO_MARKER_ID) {
IGeoPoint pos = FotoSql.execGetPosition(null, this.getActivity(),
IGeoPoint pos = FotoSql.execGetPosition(null,
null, markerId, mDebugPrefix, "getGeoPointById", dbgContext);
if (pos != null) {
return pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void showActivity(String debugContext, Activity context, SelectedF
}

if (AffUtils.putSelectedFiles(intent, selectedItems)) {
IGeoPoint initialPoint = FotoSql.execGetPosition(null, context,
IGeoPoint initialPoint = FotoSql.execGetPosition(null,
null, selectedItems.getId(0), context, mDebugPrefix, "showActivity");
if (initialPoint != null) {
GeoUri PARSER = new GeoUri(GeoUri.OPT_PARSE_INFER_MISSING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

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.ClickableIconOverlay;
import de.k3b.android.osmdroid.IconFactory;
Expand Down Expand Up @@ -96,8 +95,8 @@ protected OverlayManager doInBackground(QueryParameter... queryParameter) {

Cursor cursor = null;
try {
cursor = ContentProviderMediaExecuter.createCursorForQuery(
null, "MakerLoader", mContext,
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "MakerLoader",
queryParameters, null);

int itemCount = cursor.getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void onOk() {

Activity activity = getActivity();
if (mMarkerId != NO_MARKER_ID) {
result = FotoSql.execGetPosition(null, activity, null, mMarkerId,
result = FotoSql.execGetPosition(null, null, mMarkerId,
mDebugPrefix,"onOk");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package de.k3b.android.androFotoFinder.media;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
Expand Down Expand Up @@ -206,7 +206,7 @@ private void updateDB(String dbgContext, String _path, long xmlLastFileModifyDat

TagSql.setFileModifyDate(dbValues, new Date().getTime() / 1000);

mUpdateCount += TagSql.execUpdate(dbgContext, PhotoPropertiesMediaDBCsvImportActivity.this, path, xmlLastFileModifyDate, dbValues, VISIBILITY.PRIVATE_PUBLIC);
mUpdateCount += TagSql.execUpdate(dbgContext, path, xmlLastFileModifyDate, dbValues, VISIBILITY.PRIVATE_PUBLIC);
mItemCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static QueryParameter getQueryFromUriOrNull(

QueryParameter query = QueryParameter.load(context.getContentResolver().openInputStream(uri));
if (query != null) {
Map<String, Long> found = FotoSql.execGetPathIdMap(context, path);
Map<String, Long> found = FotoSql.execGetPathIdMap(path);
if ((found == null) || (found.size() == 0)) {
AndroidAlbumUtils.albumMediaScan(dbgContext + " not found mediadb => ", context, new File(path), 1);
}
Expand Down 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);
ContentProviderMediaExecuter.insertOrUpdateMediaDatabase(dbgContext, context, newAbsolutePath, values, null, 1l);
FotoSql.getMediaDBApi().insertOrUpdateMediaDatabase(dbgContext, newAbsolutePath, values, null, 1l);
}
}

Expand All @@ -381,7 +381,7 @@ public static int albumMediaScan(String dbgContext, Context context, File _root,
int result = 0;
if (root != null) {
List<String> currentFiles = AlbumFile.getFilePaths(null, root, subDirLevels);
List<String> databaseFiles = FotoSql.getAlbumFiles(context, FileUtils.tryGetCanonicalPath(root, null), subDirLevels);
List<String> databaseFiles = FotoSql.getAlbumFiles(FileUtils.tryGetCanonicalPath(root, null), subDirLevels);

List<String> added = new ArrayList<String>();
List<String> removed = new ArrayList<String>();
Expand All @@ -392,7 +392,7 @@ public static int albumMediaScan(String dbgContext, Context context, File _root,
result++;
}

result += FotoSql.deleteMedia(dbgMessage + "delete-obsolete", context, removed, false);
result += FotoSql.deleteMedia(dbgMessage + "delete-obsolete", removed, false);
}
return result;
}
Expand Down
Loading

0 comments on commit 91eb4b3

Please sign in to comment.