From f37d8f0d098363c3ae3e78460a82291964655661 Mon Sep 17 00:00:00 2001 From: Campello Manuel <9112949+CampelloManuel@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:44:29 +0200 Subject: [PATCH] Cast dblist as INTEGER to fix #525 --- .../notepad/database/MyContentProvider.java | 20 +++++++++++++++++-- .../notepad/fragments/TaskListFragment.java | 7 ++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java b/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java index 3a980707..7ced1cb6 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java +++ b/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java @@ -442,6 +442,8 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s result.setNotificationUri(getContext().getContentResolver(), uri); break; case Task.SECTIONEDDATEQUERYCODE: + // this branch runs when the user sorts notes by due date + // Add list null because that's what the headers will have final String listId; if (selectionArgs == null || selectionArgs.length == 0) { @@ -450,10 +452,20 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s } else { listId = selectionArgs[0]; } + // Create view if not exists - DatabaseHandler.getInstance(getContext()).getWritableDatabase() - .execSQL(Task.CREATE_SECTIONED_DATE_VIEW(listId)); + // TODO as explained in issue #525, on older OS versions (API 34 emulator, ...) + // this function returns a query to make a view with a column "dblist" of type + // INTEGER, as expected. On the Google Pixel 8a with android 14, and on API 35 + // emulators, the column "dblist" is of type BLOB, which is not correct + String NNN_DATE_VIEW_QUERY = Task.CREATE_SECTIONED_DATE_VIEW(listId); + DatabaseHandler + .getInstance(getContext()) + .getWritableDatabase() + .execSQL(NNN_DATE_VIEW_QUERY); + // this cursor contains the real notes (read from the database) + // and some "artificial" records used as headers for the groups of notes result = DatabaseHandler .getInstance(getContext()) .getReadableDatabase() @@ -466,6 +478,10 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s Task.SECRET_TYPEID + "," + Task.Columns.DUE + "," + Task.SECRET_TYPEID2); + // You can see that the cursor contains both fake records like "today+1" + // and real notes taken from the database + // String DBG_READABLE_CURSOR_DUMP = DatabaseUtils.dumpCursorToString(result); + result.setNotificationUri(getContext().getContentResolver(), Task.URI); break; diff --git a/app/src/main/java/com/nononsenseapps/notepad/fragments/TaskListFragment.java b/app/src/main/java/com/nononsenseapps/notepad/fragments/TaskListFragment.java index eed23999..eb87aae6 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/fragments/TaskListFragment.java +++ b/app/src/main/java/com/nononsenseapps/notepad/fragments/TaskListFragment.java @@ -353,7 +353,12 @@ public Loader onCreateLoader(int id, Bundle arg1) { String[] whereArgs; if (mListId > 0) { - where = Task.Columns.DBLIST + " IS ?"; + // Fix for issue #525 which is caused by some android versions (API 35 + // emulator, Google Pixel 8a on Android 14, ...) incorrectly generating + // the dblist column (=Task.Columns.DBLIST) as BLOB instead of INTEGER. + // So we cast its value to INTEGER to restore the (expected) behavior + // of older android versions + where = "CAST(" + Task.Columns.DBLIST + " AS INTEGER) IS ?"; whereArgs = new String[] { Long.toString(mListId) }; } else { targetUri = Task.URI;