X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FEditBookmarkDatabaseViewDialog.java;h=5abda5b9b5b52df98c664e4f94a0eca970564a1e;hp=7328080e44179318ddac7ee671b21388c2ac48ff;hb=47b689dbdaf08b9636021ddd8f72ca9ee7f11998;hpb=572449f6c66adfc1a3d88e761cb87581a7961df3 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 7328080e..5abda5b9 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkDatabaseViewDialog.java @@ -32,6 +32,7 @@ import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.annotation.NonNull; // `AppCompatDialogFragment` is required instead of `DialogFragment` or an error is produced on API <=22. +import android.support.v4.content.ContextCompat; import android.support.v4.widget.ResourceCursorAdapter; import android.support.v7.app.AppCompatDialogFragment; import android.text.Editable; @@ -194,19 +195,19 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Display `currentIconBitmap` in `edit_bookmark_current_icon`. currentIconImageView.setImageBitmap(currentIconBitmap); - // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`. + // Get a bitmap of the favorite icon from `MainWebViewActivity` and display it in `edit_bookmark_web_page_favorite_icon`. newFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIconBitmap); // Populate the bookmark name and URL `EditTexts`. nameEditText.setText(currentBookmarkName); urlEditText.setText(currentUrl); - // Setup a `MatrixCursor` "Home Folder". + // Setup a matrix cursor for "Home Folder". String[] matrixCursorColumnNames = {BookmarksDatabaseHelper._ID, BookmarksDatabaseHelper.BOOKMARK_NAME}; MatrixCursor matrixCursor = new MatrixCursor(matrixCursorColumnNames); matrixCursor.addRow(new Object[]{HOME_FOLDER_DATABASE_ID, getString(R.string.home_folder)}); - // Get a `Cursor` with the list of all the folders. + // Get a cursor with the list of all the folders. Cursor foldersCursor = bookmarksDatabaseHelper.getAllFolders(); // Combine `matrixCursor` and `foldersCursor`. @@ -215,20 +216,36 @@ public class EditBookmarkDatabaseViewDialog extends AppCompatDialogFragment { // Remove the incorrect lint warning below that `getContext()` might be null. assert getContext() != null; - // Create a `ResourceCursorAdapter` for the `Spinner`. `0` specifies no flags.; - ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.spinner_item, foldersMergeCursor, 0) { + // Create a resource cursor adapter for the spinner. + ResourceCursorAdapter foldersCursorAdapter = new ResourceCursorAdapter(getContext(), R.layout.databaseview_spinner_item, foldersMergeCursor, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { - // Get a handle for the `Spinner` item `TextView`. + // Get handles for the spinner views. + ImageView spinnerItemImageView = view.findViewById(R.id.spinner_item_imageview); TextView spinnerItemTextView = view.findViewById(R.id.spinner_item_textview); - // Set the `TextView` to display the folder name. + // Set the folder icon according to the type. + if (foldersMergeCursor.getPosition() == 0) { // Set the `Home Folder` icon. + // Set the gray folder image. `ContextCompat` must be used until the minimum API >= 21. + spinnerItemImageView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.folder_gray)); + } else { // Set a user folder icon. + // Get the folder icon byte array. + byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); + + // Convert the byte array to a bitmap beginning at the first byte and ending at the last. + Bitmap folderIconBitmap = BitmapFactory.decodeByteArray(folderIconByteArray, 0, folderIconByteArray.length); + + // Set the folder icon. + spinnerItemImageView.setImageBitmap(folderIconBitmap); + } + + // Set the text view to display the folder name. spinnerItemTextView.setText(cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME))); } }; // Set the `ResourceCursorAdapter` drop drown view resource. - foldersCursorAdapter.setDropDownViewResource(R.layout.spinner_dropdown_items); + foldersCursorAdapter.setDropDownViewResource(R.layout.databaseview_spinner_dropdown_items); // Set the adapter for the folder `Spinner`. folderSpinner.setAdapter(foldersCursorAdapter);