X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FMoveToFolderDialog.java;h=9f57519eb545c9a869e0ace5697d7705c8508daf;hb=af807cce079aaae9cbf0430e7da946fcbe0c99c3;hp=2dfda3612f4fbaff245cd1888c1a8b267d9f6be2;hpb=0a5d2eabceeafb49a957598538aa74d4f11dfce0;p=PrivacyBrowserAndroid.git 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 2dfda361..9f57519e 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-2018 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -33,10 +33,6 @@ 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.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -47,6 +43,10 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.NonNull; +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.BookmarksActivity; import com.stoutner.privacybrowser.activities.MainWebViewActivity; @@ -54,28 +54,23 @@ import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; import java.io.ByteArrayOutputStream; -public class MoveToFolderDialog extends AppCompatDialogFragment { - // Instantiate class variables. +public class MoveToFolderDialog extends DialogFragment { + // Instantiate the class variables. + private MoveToFolderListener moveToFolderListener; private BookmarksDatabaseHelper bookmarksDatabaseHelper; private StringBuilder exceptFolders; // The public interface is used to send information back to the parent activity. public interface MoveToFolderListener { - void onMoveToFolder(AppCompatDialogFragment dialogFragment); + void onMoveToFolder(DialogFragment dialogFragment); } - // `moveToFolderListener` is used in `onAttach()` and `onCreateDialog`. - private MoveToFolderListener moveToFolderListener; - public void onAttach(Context context) { + // Run the default commands. super.onAttach(context); - // Get a handle for `MoveToFolderListener` from `parentActivity`. - try { - moveToFolderListener = (MoveToFolderListener) context; - } catch(ClassCastException exception) { - throw new ClassCastException(context.toString() + " must implement EditBookmarkFolderListener."); - } + // Get a handle for `MoveToFolderListener` from the launching context. + moveToFolderListener = (MoveToFolderListener) context; } // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`. @@ -83,7 +78,7 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { @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. @@ -170,13 +165,16 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { } } - // Get a `Cursor` containing the folders to display. - foldersCursor = bookmarksDatabaseHelper.getFoldersCursorExcept(exceptFolders.toString()); + // Get a cursor containing the folders to display. + foldersCursor = bookmarksDatabaseHelper.getFoldersExcept(exceptFolders.toString()); // Setup `foldersCursorAdaptor` with `this` context. `false` disables autoRequery. 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. + assert getActivity() != null; + // Inflate the individual item layout. `false` does not attach it to the root. return getActivity().getLayoutInflater().inflate(R.layout.move_to_folder_item_linearlayout, parent, false); } @@ -238,7 +236,7 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { } // Get a `Cursor` containing the folders to display. - foldersCursor = bookmarksDatabaseHelper.getFoldersCursorExcept(exceptFolders.toString()); + foldersCursor = bookmarksDatabaseHelper.getFoldersExcept(exceptFolders.toString()); // Combine `homeFolderMatrixCursor` and `foldersCursor`. MergeCursor foldersMergeCursor = new MergeCursor(new Cursor[]{homeFolderMatrixCursor, foldersCursor}); @@ -247,6 +245,9 @@ 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. + assert getActivity() != null; + // Inflate the individual item layout. `false` does not attach it to the root. return getActivity().getLayoutInflater().inflate(R.layout.move_to_folder_item_linearlayout, parent, false); } @@ -285,7 +286,7 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { private void addSubfoldersToExceptFolders(String folderName) { // Get a `Cursor` will all the immediate subfolders. - Cursor subfoldersCursor = bookmarksDatabaseHelper.getSubfoldersCursor(folderName); + Cursor subfoldersCursor = bookmarksDatabaseHelper.getSubfolders(folderName); for (int i = 0; i < subfoldersCursor.getCount(); i++) { // Move `subfolderCursor` to the current item. @@ -302,4 +303,4 @@ public class MoveToFolderDialog extends AppCompatDialogFragment { addSubfoldersToExceptFolders(subfolderName); } } -} +} \ No newline at end of file