Skip to content

Commit

Permalink
#155: prepare to fix android10 incompatibility: Made CursorLoaderWith…
Browse files Browse the repository at this point in the history
…Exception swapable
  • Loading branch information
k3b committed Dec 2, 2019
1 parent 91eb4b3 commit 7b33702
Show file tree
Hide file tree
Showing 19 changed files with 781 additions and 227 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/de/k3b/android/androFotoFinder/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public static class Media {
public static boolean initialImageDetailResolutionHigh = false; // false: MediaStore.Images.Thumbnails.MINI_KIND; true: FULL_SCREEN_KIND;
public static boolean mapsForgeEnabled = false;

// #155: fix android10 incompatibility
// Build.VERSION_CODES.??ANDROID10?? = 29
//!!!
public static final boolean useMediaImageDbReplacement = true;
// public static final boolean useMediaImageDbReplacement = (Build.VERSION.SDK_INT >= 29);
/** map with blue selection markers: how much to area to increase */
public static final double mapMultiselectionBoxIncreaseByProcent = 100.0;
/** map with blue selection markers: minimum size of zoom box in degrees */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private void execQuery(QueryParameter query,
this.onProgress(0,0, "Calculate");
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "ZipExecute",
query, null);
query, null, null);

int itemCount = cursor.getCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected IDirectory doInBackground(QueryParameter... queryParameter) {
try {
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "ZipExecute",
queryParameters, null);
queryParameters, null, null);

int itemCount = cursor.getCount();
final int expectedCount = itemCount + itemCount;
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.CursorLoaderWithException;
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 @@ -231,7 +232,7 @@ public void onLoadFinished(Loader<Cursor> _loader, Cursor data) {

final Activity context = getActivity();
if (data == null) {
FotoSql.CursorLoaderWithException loader = (FotoSql.CursorLoaderWithException) _loader;
CursorLoaderWithException loader = (CursorLoaderWithException) _loader;
String title;
String message = context.getString(R.string.global_err_sql_message_format, loader.getException().getMessage(), loader.getQuery().toSqlString());
if (loader.getException() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected OverlayManager doInBackground(QueryParameter... queryParameter) {
try {
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
null, "MakerLoader",
queryParameters, null);
queryParameters, null, null);

int itemCount = cursor.getCount();
final int expectedCount = itemCount + itemCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
import android.os.Build;
import android.os.CancellationSignal;
import android.util.Log;

import java.util.ArrayList;
Expand All @@ -39,35 +41,44 @@
* Static Implementation of Context.getContentResolver()-ContentProvider based media api
*/
public class ContentProviderMediaImpl {
private static final String MODUL_NAME = ContentProviderMediaImpl.class.getName();

public static Cursor createCursorForQuery(
StringBuilder out_debugMessage, String dbgContext, final Context context,
QueryParameter parameters, VISIBILITY visibility) {
QueryParameter parameters, VISIBILITY visibility, CancellationSignal cancellationSignal) {
if (visibility != null) FotoSql.setWhereVisibility(parameters, visibility);
return createCursorForQuery(out_debugMessage, dbgContext, context, parameters.toFrom(),
parameters.toAndroidWhere(),
parameters.toAndroidParameters(), parameters.toOrderBy(),
parameters.toColumns()
cancellationSignal, parameters.toColumns()
);
}

/**
* every cursor query should go through this. adds logging if enabled
*/
static Cursor createCursorForQuery(StringBuilder out_debugMessage, String dbgContext, final Context context, final String from, final String sqlWhereStatement,
final String[] sqlWhereParameters, final String sqlSortOrder,
final String... sqlSelectColums) {
static Cursor createCursorForQuery(
StringBuilder out_debugMessage, String dbgContext, final Context context,
final String from, final String sqlWhereStatement,
final String[] sqlWhereParameters, final String sqlSortOrder,
CancellationSignal cancellationSignal, final String... sqlSelectColums) {
ContentResolver resolver = context.getContentResolver();
Cursor query = null;

Exception excpetion = null;
try {
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder, cancellationSignal);
} else {
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder);
}
} catch (Exception ex) {
excpetion = ex;
} finally {
if ((excpetion != null) || Global.debugEnabledSql || (out_debugMessage != null)) {
StringBuilder message = StringUtils.appendMessage(out_debugMessage, excpetion,
dbgContext, "FotoSql.createCursorForQuery:\n",
dbgContext, MODUL_NAME +
".createCursorForQuery:\n",
QueryParameter.toString(sqlSelectColums, null, from, sqlWhereStatement,
sqlWhereParameters, sqlSortOrder, query.getCount()));
if (out_debugMessage == null) {
Expand All @@ -79,10 +90,6 @@ static Cursor createCursorForQuery(StringBuilder out_debugMessage, String dbgCon
return query;
}

public static int execUpdate(String dbgContext, Context context, long id, ContentValues values) {
return exexUpdateImpl(dbgContext, context, values, FotoSql.FILTER_COL_PK, new String[]{Long.toString(id)});
}

public static int execUpdate(String dbgContext, Context context, String path, ContentValues values, VISIBILITY visibility) {
return exexUpdateImpl(dbgContext, context, values, FotoSql.getFilterExprPathLikeWithVisibility(visibility), new String[]{path});
}
Expand All @@ -101,7 +108,9 @@ public static int exexUpdateImpl(String dbgContext, Context context, ContentValu
excpetion = ex;
} finally {
if ((excpetion != null) || ((dbgContext != null) && (Global.debugEnabledSql || LibGlobal.debugEnabledJpg))) {
Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.exexUpdate " + excpetion + "\n" +
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
MODUL_NAME +
".exexUpdate " + excpetion + "\n" +
QueryParameter.toString(null, values.toString(), FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
sqlWhere, selectionArgs, null, result), excpetion);
}
Expand Down Expand Up @@ -146,7 +155,9 @@ public static Uri execInsert(String dbgContext, Context context, ContentValues v
excpetion = ex;
} finally {
if ((excpetion != null) || Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.execInsert " + excpetion + " " +
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
MODUL_NAME +
".execInsert " + excpetion + " " +
values.toString() + " => " + result + " " + excpetion, excpetion);
}
}
Expand All @@ -166,31 +177,39 @@ public static int deleteMedia(String dbgContext, Context context, String where,
ContentValues values = new ContentValues();
values.put(FotoSql.SQL_COL_PATH, FotoSql.DELETED_FILE_MARKER);
values.put(FotoSql.SQL_COL_EXT_MEDIA_TYPE, 0); // so it will not be shown as image any more
exexUpdateImpl(dbgContext + "-a: FotoSql.deleteMedia: ",
exexUpdateImpl(dbgContext + "-a: " +
MODUL_NAME +
".deleteMedia: ",
context, values, lastUsedWhereClause, lastSelectionArgs);

lastUsedWhereClause = FotoSql.SQL_COL_PATH + " is null";
lastSelectionArgs = null;
delCount = context.getContentResolver()
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + "-b: FotoSql.deleteMedia delete\n" +
Log.i(Global.LOG_CONTEXT, dbgContext + "-b: " +
MODUL_NAME +
".deleteMedia delete\n" +
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
lastUsedWhereClause, lastSelectionArgs, null, delCount));
}
} else {
delCount = context.getContentResolver()
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
Log.i(Global.LOG_CONTEXT, dbgContext + ": FotoSql.deleteMedia\ndelete " +
Log.i(Global.LOG_CONTEXT, dbgContext + ": " +
MODUL_NAME +
".deleteMedia\ndelete " +
QueryParameter.toString(null, null,
FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
lastUsedWhereClause, lastSelectionArgs, null, delCount));
}
}
} catch (Exception ex) {
// null pointer exception when delete matches not items??
final String msg = dbgContext + ": Exception in FotoSql.deleteMedia:\n" +
final String msg = dbgContext + ": Exception in " +
MODUL_NAME +
".deleteMedia:\n" +
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
lastUsedWhereClause, lastSelectionArgs, null, -1)
+ " : " + ex.getMessage();
Expand All @@ -207,7 +226,8 @@ public static int deleteMedia(String dbgContext, Context context, String where,
* @return number of updated items
*/
private static int _del_execRenameFolder_batch_not_working(Context context, String pathOld, String pathNew) {
final String dbgContext = "FotoSql.execRenameFolder('" +
final String dbgContext = MODUL_NAME +
".execRenameFolder('" +
pathOld + "' => '" + pathNew + "')";
// sql update file set path = newBegin + substing(path, begin+len) where path like newBegin+'%'
// public static final String SQL_EXPR_FOLDER = "substr(" + SQL_COL_PATH + ",1,length(" + SQL_COL_PATH + ") - length(" + MediaStore.Images.Media.DISPLAY_NAME + "))";
Expand All @@ -229,7 +249,7 @@ private static int _del_execRenameFolder_batch_not_working(Context context, Stri

Cursor c = null;
try {
c = createCursorForQuery(null, dbgContext, context, queryAffectedFiles, null);
c = createCursorForQuery(null, dbgContext, context, queryAffectedFiles, null, null);
int pkColNo = c.getColumnIndex(FotoSql.SQL_COL_PK);
int pathColNo = c.getColumnIndex(sqlColNewPathAlias);

Expand Down Expand Up @@ -271,7 +291,8 @@ public static ContentValues getDbContent(Context context, final long id) {
return values;
}
} catch (Exception ex) {
Log.e(Global.LOG_CONTEXT, "FotoSql.getDbContent(id=" + id + ") failed", ex);
Log.e(Global.LOG_CONTEXT, MODUL_NAME +
".getDbContent(id=" + id + ") failed", ex);
} finally {
if (c != null) c.close();
}
Expand Down
Loading

0 comments on commit 7b33702

Please sign in to comment.