]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/EditBookmarkFolderDatabaseViewDialog.java
Fix importing of settings from prior to 3.3. https://redmine.stoutner.com/issues/608
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / EditBookmarkFolderDatabaseViewDialog.java
index 5033ece87bcb22c59b7f234e91727f3979a8ed1e..7960c68a73620f1e56e811ab268777833572d999 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
 package com.stoutner.privacybrowser.dialogs;
 
 import android.annotation.SuppressLint;
-import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.database.DatabaseUtils;
 import android.database.MatrixCursor;
@@ -31,6 +31,7 @@ import android.database.MergeCursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.util.Log;
@@ -48,19 +49,17 @@ import android.widget.Spinner;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
 import androidx.core.content.ContextCompat;
 import androidx.fragment.app.DialogFragment;  // The AndroidX dialog fragment must be used or an error is produced on API <=22.
 
 import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.activities.MainWebViewActivity;
+import com.stoutner.privacybrowser.activities.BookmarksDatabaseViewActivity;
 import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
 
 import java.io.ByteArrayOutputStream;
 
 public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
-    // Define the home folder database ID constant.
-    public static final int HOME_FOLDER_DATABASE_ID = -1;
-
     // Define the edit bookmark folder database view listener.
     private EditBookmarkFolderDatabaseViewListener editBookmarkFolderDatabaseViewListener;
 
@@ -70,7 +69,7 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId, Bitmap favoriteIconBitmap);
     }
 
-    public void onAttach(Context context) {
+    public void onAttach(@NonNull Context context) {
         // Run the default commands.
         super.onAttach(context);
 
@@ -137,14 +136,7 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         folderCursor.moveToFirst();
 
         // Use an alert dialog builder to create the alert dialog.
-        AlertDialog.Builder dialogBuilder;
-
-        // Set the style according to the theme.
-        if (MainWebViewActivity.darkTheme) {
-            dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
-        } else {
-            dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
-        }
+        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog);
 
         // Set the title.
         dialogBuilder.setTitle(R.string.edit_folder);
@@ -172,8 +164,14 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         // Remove the warning below that `getWindow()` might be null.
         assert alertDialog.getWindow() != null;
 
+        // Get a handle for the shared preferences.
+        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
+
+        // Get the screenshot preference.
+        boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
+
         // Disable screenshots if not allowed.
-        if (!MainWebViewActivity.allowScreenshots) {
+        if (!allowScreenshots) {
             alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
         }
 
@@ -190,6 +188,15 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         EditText displayOrderEditText = alertDialog.findViewById(R.id.edit_folder_display_order_edittext);
         Button editButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
 
+        // Remove the incorrect lint warnings below that the views might be null.
+        assert databaseIdTextView != null;
+        assert iconRadioGroup != null;
+        assert currentIconImageView != null;
+        assert newFavoriteIconImageView != null;
+        assert nameEditText != null;
+        assert folderSpinner != null;
+        assert displayOrderEditText != null;
+
         // Store the current folder values.
         String currentFolderName = folderCursor.getString(folderCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
         int currentDisplayOrder = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER));
@@ -216,7 +223,7 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         // 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)});
+        matrixCursor.addRow(new Object[]{BookmarksDatabaseViewActivity.HOME_FOLDER_DATABASE_ID, getString(R.string.home_folder)});
 
         // Add all subfolders of the current folder to the list of folders not to display.
         String exceptFolders = getStringOfSubfolders(currentFolderName, bookmarksDatabaseHelper);
@@ -404,6 +411,12 @@ public class EditBookmarkFolderDatabaseViewDialog extends DialogFragment {
         RadioButton currentIconRadioButton = alertDialog.findViewById(R.id.edit_folder_current_icon_radiobutton);
         Button editButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
 
+        // Remove the incorrect lint warning below that the views might be null.
+        assert nameEditText != null;
+        assert folderSpinner != null;
+        assert displayOrderEditText != null;
+        assert currentIconRadioButton != null;
+
         // Get the values from the dialog.
         String newFolderName = nameEditText.getText().toString();
         int newParentFolderDatabaseId = (int) folderSpinner.getSelectedItemId();