X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FEditBookmarkDatabaseViewDialog.java;h=7328080e44179318ddac7ee671b21388c2ac48ff;hb=572449f6c66adfc1a3d88e761cb87581a7961df3;hp=028db1b79c7c538cd4bc3b16ce88cfc170fe2f7b;hpb=0a5d2eabceeafb49a957598538aa74d4f11dfce0;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java index 028db1b7..7328080e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2018 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -58,7 +58,6 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Instantiate the class variables. private EditBookmarkDatabaseViewListener editBookmarkDatabaseViewListener; - private int bookmarkDatabaseId; private String currentBookmarkName; private String currentUrl; private int currentFolderDatabaseId; @@ -80,12 +79,9 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Run the default commands. super.onAttach(context); - // Get a handle for `EditBookmarkDatabaseViewListener` from `context`. - try { - editBookmarkDatabaseViewListener = (EditBookmarkDatabaseViewListener) context; - } catch(ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement EditBookmarkDatabaseViewListener."); - } + // Get a handle for `EditBookmarkDatabaseViewListener` from the launching context. + + editBookmarkDatabaseViewListener = (EditBookmarkDatabaseViewListener) context; } // Store the database ID in the arguments bundle. @@ -104,28 +100,22 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { return editBookmarkDatabaseViewDialog; } + // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. + @SuppressLint("InflateParams") @Override - public void onCreate(Bundle savedInstanceState) { - // Run the default commands. - super.onCreate(savedInstanceState); - + @NonNull + public Dialog onCreateDialog(Bundle savedInstanceState) { // Remove the incorrect lint warning below that `getInt()` might be null. assert getArguments() != null; - // Store the bookmark database ID in the class variable. - bookmarkDatabaseId = getArguments().getInt("Database ID"); - } + // Get the bookmark database ID from the bundle. + int bookmarkDatabaseId = getArguments().getInt("Database ID"); - // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. - @SuppressLint("InflateParams") - @Override - @NonNull - public Dialog onCreateDialog(Bundle savedInstanceState) { - // Initialize the database helper. The two `nulls` do not specify the database name or a `CursorFactory`. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`. + // Initialize the database helper. The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`. BookmarksDatabaseHelper bookmarksDatabaseHelper = new BookmarksDatabaseHelper(getContext(), null, null, 0); // Get a cursor with the selected bookmark and move it to the first position. - Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(bookmarkDatabaseId); + Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmark(bookmarkDatabaseId); bookmarkCursor.moveToFirst(); // Use an alert dialog builder to create the alert dialog. @@ -217,7 +207,7 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { matrixCursor.addRow(new Object[]{HOME_FOLDER_DATABASE_ID, getString(R.string.home_folder)}); // Get a `Cursor` with the list of all the folders. - Cursor foldersCursor = bookmarksDatabaseHelper.getAllFoldersCursor(); + Cursor foldersCursor = bookmarksDatabaseHelper.getAllFolders(); // Combine `matrixCursor` and `foldersCursor`. MergeCursor foldersMergeCursor = new MergeCursor(new Cursor[]{matrixCursor, foldersCursor}); @@ -226,7 +216,7 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { assert getContext() != null; // Create a `ResourceCursorAdapter` for the `Spinner`. `0` specifies no flags.; - ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.edit_bookmark_databaseview_spinner_item, foldersMergeCursor, 0) { + ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.spinner_item, foldersMergeCursor, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { // Get a handle for the `Spinner` item `TextView`. @@ -238,7 +228,7 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { }; // Set the `ResourceCursorAdapter` drop drown view resource. - foldersCursorAdapter.setDropDownViewResource(R.layout.edit_bookmark_databaseview_spinner_dropdown_item); + foldersCursorAdapter.setDropDownViewResource(R.layout.spinner_dropdown_items); // Set the adapter for the folder `Spinner`. folderSpinner.setAdapter(foldersCursorAdapter);