X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FMoveToFolderDialog.java;h=25701f7792fd4a76ec5fc1734d17b22e2cecd6f2;hp=28d0fa55e24815095c6fa1143aa7f53fe9477329;hb=bc2e180db377eedadbe1ea455d8fb311ead8f9d6;hpb=892e8297ba8d23a37c091fb38325929dcf7d17c9 diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.java index 28d0fa55..25701f77 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2019 Soren Stoutner . + * Copyright © 2016-2020 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,10 +20,10 @@ 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; @@ -33,10 +33,7 @@ import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; -// `AppCompatDialogFragment` must be used instead of `DialogFragment` or an error is produced on API <=22. -import android.support.v7.app.AppCompatDialogFragment; +import android.preference.PreferenceManager; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -47,14 +44,18 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.DialogFragment; + import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.BookmarksActivity; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; import java.io.ByteArrayOutputStream; -public class MoveToFolderDialog extends AppCompatDialogFragment { +public class MoveToFolderDialog extends DialogFragment { // Instantiate the class variables. private MoveToFolderListener moveToFolderListener; private BookmarksDatabaseHelper bookmarksDatabaseHelper; @@ -62,10 +63,10 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { // The public interface is used to send information back to the parent activity. public interface MoveToFolderListener { - void onMoveToFolder(AppCompatDialogFragment dialogFragment); + void onMoveToFolder(DialogFragment dialogFragment); } - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { // Run the default commands. super.onAttach(context); @@ -73,23 +74,16 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { moveToFolderListener = (MoveToFolderListener) context; } - // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. + // `@SuppressLint("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 = new BookmarksDatabaseHelper(getContext(), null, null, 0); // 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.move_to_folder); @@ -114,8 +108,14 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { // Create an alert dialog from the alert dialog builder. final AlertDialog alertDialog = dialogBuilder.create(); + // 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) { // Remove the warning below that `getWindow()` might be null. assert alertDialog.getWindow() != null; @@ -172,7 +172,7 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { foldersCursorAdapter = new CursorAdapter(alertDialog.getContext(), foldersCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - // Remove the incorrect lint warning that `.getLayoutInflator()` might be false. + // Remove the incorrect lint warning that `.getLayoutInflater()` might be false. assert getActivity() != null; // Inflate the individual item layout. `false` does not attach it to the root. @@ -245,7 +245,7 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { foldersCursorAdapter = new CursorAdapter(alertDialog.getContext(), foldersMergeCursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - // Remove the incorrect lint warning that `.getLayoutInflator()` might be false. + // Remove the incorrect lint warning that `.getLayoutInflater()` might be false. assert getActivity() != null; // Inflate the individual item layout. `false` does not attach it to the root. @@ -270,8 +270,13 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { }; } - // Display the ListView + // Get a handle for the folders list view. ListView foldersListView = alertDialog.findViewById(R.id.move_to_folder_listview); + + // Remove the incorrect lint warning below that the view might be null. + assert foldersListView != null; + + // Set the folder list view adapter. foldersListView.setAdapter(foldersCursorAdapter); // Enable the move button when a folder is selected. @@ -303,4 +308,4 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { addSubfoldersToExceptFolders(subfolderName); } } -} +} \ No newline at end of file