Skip to content

Commit 7b33702

Browse files
committed
#155: prepare to fix android10 incompatibility: Made CursorLoaderWithException swapable
1 parent 91eb4b3 commit 7b33702

19 files changed

+781
-227
lines changed

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/Global.java

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public static class Media {
124124
public static boolean initialImageDetailResolutionHigh = false; // false: MediaStore.Images.Thumbnails.MINI_KIND; true: FULL_SCREEN_KIND;
125125
public static boolean mapsForgeEnabled = false;
126126

127+
// #155: fix android10 incompatibility
128+
// Build.VERSION_CODES.??ANDROID10?? = 29
129+
//!!!
130+
public static final boolean useMediaImageDbReplacement = true;
131+
// public static final boolean useMediaImageDbReplacement = (Build.VERSION.SDK_INT >= 29);
127132
/** map with blue selection markers: how much to area to increase */
128133
public static final double mapMultiselectionBoxIncreaseByProcent = 100.0;
129134
/** map with blue selection markers: minimum size of zoom box in degrees */

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/backup/Backup2ZipService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void execQuery(QueryParameter query,
211211
this.onProgress(0,0, "Calculate");
212212
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
213213
null, "ZipExecute",
214-
query, null);
214+
query, null, null);
215215

216216
int itemCount = cursor.getCount();
217217

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/directory/DirectoryLoaderTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected IDirectory doInBackground(QueryParameter... queryParameter) {
103103
try {
104104
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
105105
null, "ZipExecute",
106-
queryParameters, null);
106+
queryParameters, null, null);
107107

108108
int itemCount = cursor.getCount();
109109
final int expectedCount = itemCount + itemCount;

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/gallery/cursor/GalleryCursorFragment.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import de.k3b.android.androFotoFinder.imagedetail.ImageDetailMetaDialogBuilder;
7272
import de.k3b.android.androFotoFinder.locationmap.GeoEditActivity;
7373
import de.k3b.android.androFotoFinder.locationmap.MapGeoPickerActivity;
74+
import de.k3b.android.androFotoFinder.queries.CursorLoaderWithException;
7475
import de.k3b.android.androFotoFinder.queries.FotoSql;
7576
import de.k3b.android.androFotoFinder.queries.FotoViewerParameter;
7677
import de.k3b.android.androFotoFinder.queries.Queryable;
@@ -231,7 +232,7 @@ public void onLoadFinished(Loader<Cursor> _loader, Cursor data) {
231232

232233
final Activity context = getActivity();
233234
if (data == null) {
234-
FotoSql.CursorLoaderWithException loader = (FotoSql.CursorLoaderWithException) _loader;
235+
CursorLoaderWithException loader = (CursorLoaderWithException) _loader;
235236
String title;
236237
String message = context.getString(R.string.global_err_sql_message_format, loader.getException().getMessage(), loader.getQuery().toSqlString());
237238
if (loader.getException() != null) {

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/locationmap/MarkerLoaderTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected OverlayManager doInBackground(QueryParameter... queryParameter) {
9797
try {
9898
cursor = FotoSql.getMediaDBApi().createCursorForQuery(
9999
null, "MakerLoader",
100-
queryParameters, null);
100+
queryParameters, null, null);
101101

102102
int itemCount = cursor.getCount();
103103
final int expectedCount = itemCount + itemCount;

Diff for: app/src/main/java/de/k3b/android/androFotoFinder/queries/ContentProviderMediaImpl.java

+41-20
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.database.Cursor;
2626
import android.database.DatabaseUtils;
2727
import android.net.Uri;
28+
import android.os.Build;
29+
import android.os.CancellationSignal;
2830
import android.util.Log;
2931

3032
import java.util.ArrayList;
@@ -39,35 +41,44 @@
3941
* Static Implementation of Context.getContentResolver()-ContentProvider based media api
4042
*/
4143
public class ContentProviderMediaImpl {
44+
private static final String MODUL_NAME = ContentProviderMediaImpl.class.getName();
45+
4246
public static Cursor createCursorForQuery(
4347
StringBuilder out_debugMessage, String dbgContext, final Context context,
44-
QueryParameter parameters, VISIBILITY visibility) {
48+
QueryParameter parameters, VISIBILITY visibility, CancellationSignal cancellationSignal) {
4549
if (visibility != null) FotoSql.setWhereVisibility(parameters, visibility);
4650
return createCursorForQuery(out_debugMessage, dbgContext, context, parameters.toFrom(),
4751
parameters.toAndroidWhere(),
4852
parameters.toAndroidParameters(), parameters.toOrderBy(),
49-
parameters.toColumns()
53+
cancellationSignal, parameters.toColumns()
5054
);
5155
}
5256

5357
/**
5458
* every cursor query should go through this. adds logging if enabled
5559
*/
56-
static Cursor createCursorForQuery(StringBuilder out_debugMessage, String dbgContext, final Context context, final String from, final String sqlWhereStatement,
57-
final String[] sqlWhereParameters, final String sqlSortOrder,
58-
final String... sqlSelectColums) {
60+
static Cursor createCursorForQuery(
61+
StringBuilder out_debugMessage, String dbgContext, final Context context,
62+
final String from, final String sqlWhereStatement,
63+
final String[] sqlWhereParameters, final String sqlSortOrder,
64+
CancellationSignal cancellationSignal, final String... sqlSelectColums) {
5965
ContentResolver resolver = context.getContentResolver();
6066
Cursor query = null;
6167

6268
Exception excpetion = null;
6369
try {
64-
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder);
70+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
71+
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder, cancellationSignal);
72+
} else {
73+
query = resolver.query(Uri.parse(from), sqlSelectColums, sqlWhereStatement, sqlWhereParameters, sqlSortOrder);
74+
}
6575
} catch (Exception ex) {
6676
excpetion = ex;
6777
} finally {
6878
if ((excpetion != null) || Global.debugEnabledSql || (out_debugMessage != null)) {
6979
StringBuilder message = StringUtils.appendMessage(out_debugMessage, excpetion,
70-
dbgContext, "FotoSql.createCursorForQuery:\n",
80+
dbgContext, MODUL_NAME +
81+
".createCursorForQuery:\n",
7182
QueryParameter.toString(sqlSelectColums, null, from, sqlWhereStatement,
7283
sqlWhereParameters, sqlSortOrder, query.getCount()));
7384
if (out_debugMessage == null) {
@@ -79,10 +90,6 @@ static Cursor createCursorForQuery(StringBuilder out_debugMessage, String dbgCon
7990
return query;
8091
}
8192

82-
public static int execUpdate(String dbgContext, Context context, long id, ContentValues values) {
83-
return exexUpdateImpl(dbgContext, context, values, FotoSql.FILTER_COL_PK, new String[]{Long.toString(id)});
84-
}
85-
8693
public static int execUpdate(String dbgContext, Context context, String path, ContentValues values, VISIBILITY visibility) {
8794
return exexUpdateImpl(dbgContext, context, values, FotoSql.getFilterExprPathLikeWithVisibility(visibility), new String[]{path});
8895
}
@@ -101,7 +108,9 @@ public static int exexUpdateImpl(String dbgContext, Context context, ContentValu
101108
excpetion = ex;
102109
} finally {
103110
if ((excpetion != null) || ((dbgContext != null) && (Global.debugEnabledSql || LibGlobal.debugEnabledJpg))) {
104-
Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.exexUpdate " + excpetion + "\n" +
111+
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
112+
MODUL_NAME +
113+
".exexUpdate " + excpetion + "\n" +
105114
QueryParameter.toString(null, values.toString(), FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
106115
sqlWhere, selectionArgs, null, result), excpetion);
107116
}
@@ -146,7 +155,9 @@ public static Uri execInsert(String dbgContext, Context context, ContentValues v
146155
excpetion = ex;
147156
} finally {
148157
if ((excpetion != null) || Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
149-
Log.i(Global.LOG_CONTEXT, dbgContext + ":FotoSql.execInsert " + excpetion + " " +
158+
Log.i(Global.LOG_CONTEXT, dbgContext + ":" +
159+
MODUL_NAME +
160+
".execInsert " + excpetion + " " +
150161
values.toString() + " => " + result + " " + excpetion, excpetion);
151162
}
152163
}
@@ -166,31 +177,39 @@ public static int deleteMedia(String dbgContext, Context context, String where,
166177
ContentValues values = new ContentValues();
167178
values.put(FotoSql.SQL_COL_PATH, FotoSql.DELETED_FILE_MARKER);
168179
values.put(FotoSql.SQL_COL_EXT_MEDIA_TYPE, 0); // so it will not be shown as image any more
169-
exexUpdateImpl(dbgContext + "-a: FotoSql.deleteMedia: ",
180+
exexUpdateImpl(dbgContext + "-a: " +
181+
MODUL_NAME +
182+
".deleteMedia: ",
170183
context, values, lastUsedWhereClause, lastSelectionArgs);
171184

172185
lastUsedWhereClause = FotoSql.SQL_COL_PATH + " is null";
173186
lastSelectionArgs = null;
174187
delCount = context.getContentResolver()
175188
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
176189
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
177-
Log.i(Global.LOG_CONTEXT, dbgContext + "-b: FotoSql.deleteMedia delete\n" +
190+
Log.i(Global.LOG_CONTEXT, dbgContext + "-b: " +
191+
MODUL_NAME +
192+
".deleteMedia delete\n" +
178193
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
179194
lastUsedWhereClause, lastSelectionArgs, null, delCount));
180195
}
181196
} else {
182197
delCount = context.getContentResolver()
183198
.delete(FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE, lastUsedWhereClause, lastSelectionArgs);
184199
if (Global.debugEnabledSql || LibGlobal.debugEnabledJpg) {
185-
Log.i(Global.LOG_CONTEXT, dbgContext + ": FotoSql.deleteMedia\ndelete " +
200+
Log.i(Global.LOG_CONTEXT, dbgContext + ": " +
201+
MODUL_NAME +
202+
".deleteMedia\ndelete " +
186203
QueryParameter.toString(null, null,
187204
FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
188205
lastUsedWhereClause, lastSelectionArgs, null, delCount));
189206
}
190207
}
191208
} catch (Exception ex) {
192209
// null pointer exception when delete matches not items??
193-
final String msg = dbgContext + ": Exception in FotoSql.deleteMedia:\n" +
210+
final String msg = dbgContext + ": Exception in " +
211+
MODUL_NAME +
212+
".deleteMedia:\n" +
194213
QueryParameter.toString(null, null, FotoSqlBase.SQL_TABLE_EXTERNAL_CONTENT_URI_FILE_NAME,
195214
lastUsedWhereClause, lastSelectionArgs, null, -1)
196215
+ " : " + ex.getMessage();
@@ -207,7 +226,8 @@ public static int deleteMedia(String dbgContext, Context context, String where,
207226
* @return number of updated items
208227
*/
209228
private static int _del_execRenameFolder_batch_not_working(Context context, String pathOld, String pathNew) {
210-
final String dbgContext = "FotoSql.execRenameFolder('" +
229+
final String dbgContext = MODUL_NAME +
230+
".execRenameFolder('" +
211231
pathOld + "' => '" + pathNew + "')";
212232
// sql update file set path = newBegin + substing(path, begin+len) where path like newBegin+'%'
213233
// public static final String SQL_EXPR_FOLDER = "substr(" + SQL_COL_PATH + ",1,length(" + SQL_COL_PATH + ") - length(" + MediaStore.Images.Media.DISPLAY_NAME + "))";
@@ -229,7 +249,7 @@ private static int _del_execRenameFolder_batch_not_working(Context context, Stri
229249

230250
Cursor c = null;
231251
try {
232-
c = createCursorForQuery(null, dbgContext, context, queryAffectedFiles, null);
252+
c = createCursorForQuery(null, dbgContext, context, queryAffectedFiles, null, null);
233253
int pkColNo = c.getColumnIndex(FotoSql.SQL_COL_PK);
234254
int pathColNo = c.getColumnIndex(sqlColNewPathAlias);
235255

@@ -271,7 +291,8 @@ public static ContentValues getDbContent(Context context, final long id) {
271291
return values;
272292
}
273293
} catch (Exception ex) {
274-
Log.e(Global.LOG_CONTEXT, "FotoSql.getDbContent(id=" + id + ") failed", ex);
294+
Log.e(Global.LOG_CONTEXT, MODUL_NAME +
295+
".getDbContent(id=" + id + ") failed", ex);
275296
} finally {
276297
if (c != null) c.close();
277298
}

0 commit comments

Comments
 (0)