X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksActivity.java;h=bd274ec2213985cbd02be090ee19b0016f360ad9;hp=360f858d4c0d4de543033fd1fe4721b637bfedb0;hb=231b7c038227e36f96ed28e9c2ff8bde793133ec;hpb=fbb7aef30a9417c42661a0f76b5836dcf6a40242 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java index 360f858d..bd274ec2 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -24,14 +24,11 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.database.Cursor; -import android.database.CursorWindow; -import android.database.sqlite.SQLiteCursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Bundle; import android.util.SparseBooleanArray; import android.view.ActionMode; @@ -82,6 +79,10 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `restartFromBookmarksDatabaseViewActivity` is public static so it can be accessed from `BookmarksDatabaseViewActivity`. It is also used in `onRestart()`. public static boolean restartFromBookmarksDatabaseViewActivity; + // The current WebView strings are public static so they can be updated from `MainWebViewActivity`. They are use in `onCreate()`. + public static String currentWebViewUrl; + public static String currentWebViewTitle; + // `bookmarksDatabaseHelper` is used in `onCreate()`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, // `onMoveToFolder()`, `deleteBookmarkFolderContents()`, `loadFolder()`, and `onDestroy()`. @@ -93,8 +94,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `bookmarksCursor` is used in `onCreate()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, `deleteBookmarkFolderContents()`, // `loadFolder()`, and `onDestroy()`. - // TODO This should be switched back to a `Cursor` after the release of 2.17.1. - private SQLiteCursor bookmarksCursor; + private Cursor bookmarksCursor; // `bookmarksCursorAdapter` is used in `onCreate(), `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, and `onLoadFolder()`. private CursorAdapter bookmarksCursorAdapter; @@ -338,8 +338,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Update the bookmarks cursor with the current contents of the bookmarks database. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -385,8 +384,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Update the bookmarks cursor with the current contents of the bookmarks database. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -447,8 +445,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone(); // Update the bookmarks cursor with the current contents of the bookmarks database except for the specified database IDs. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolder); // Update the list view. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -467,8 +464,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // The user pushed the `Undo` button. case Snackbar.Callback.DISMISS_EVENT_ACTION: // Update the bookmarks cursor with the current contents of the bookmarks database, including the "deleted" bookmarks. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the list view. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -561,8 +557,10 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Set the create new bookmark FAB to display the `AlertDialog`. createBookmarkFab.setOnClickListener(view -> { - // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`. - DialogFragment createBookmarkDialog = new CreateBookmarkDialog(); + // Instantiate the create bookmark dialog. + DialogFragment createBookmarkDialog = CreateBookmarkDialog.createBookmark(currentWebViewUrl, currentWebViewTitle, MainWebViewActivity.favoriteIconBitmap); + + // Display the create bookmark dialog. createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark)); }); } @@ -681,8 +679,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, currentFolder, newBookmarkDisplayOrder, favoriteIconByteArray); // Update the bookmarks cursor with the current contents of this folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -743,8 +740,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksDatabaseHelper.createFolder(folderNameString, currentFolder, folderIconByteArray); // Update the bookmarks cursor with the current contents of this folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -793,8 +789,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma contextualActionMode.finish(); // Update the bookmarks cursor with the contents of the current folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -888,8 +883,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Update the bookmarks cursor with the current contents of this folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -934,8 +928,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } // Update the bookmarks cursor with the current contents of this folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Update the `ListView`. bookmarksCursorAdapter.changeCursor(bookmarksCursor); @@ -1039,16 +1032,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma private void loadFolder() { // Update bookmarks cursor with the contents of the bookmarks database for the current folder. - // TODO Change this back to a `Cursor` after 2.17.1 is released. - bookmarksCursor = (SQLiteCursor) bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); - - // TODO Remove after the release of 2.17.1. - if (Build.VERSION.SDK_INT >= 28) { - // Create a big cursor window. - CursorWindow bigCursorWindow = new CursorWindow("Big Cursor Window", 4194304); - - bookmarksCursor.setWindow(bigCursorWindow); - } + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); // Setup a `CursorAdapter`. `this` specifies the `Context`. `false` disables `autoRequery`. bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {