From: Soren Stoutner
è stata derivata da elementi di ic_folder e di ic_exit_to_app, che fanno parte dell'Android Material icon set + e sono state rilasciate sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. + L'immagine risultante è rilasciata sotto Licenza GPLv3+.
+è stata derivata da elementi di ic_bookmark e di ic_create_new_folder, che fanno parte dell'Android Material icon set + e sono state rilasciate sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. + L'immagine risultante è rilasciata sotto Licenza GPLv3+.
è stata derivata da ic_create_new_folder, che fa parte dell'Android Material icon set ed è stata rilasciata sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. L'immagine risultante è rilasciata sotto Licenza GPLv3+.
diff --git a/app/src/main/assets/it/about_licenses_light.html b/app/src/main/assets/it/about_licenses_light.html index da4c7083..f93e858d 100644 --- a/app/src/main/assets/it/about_licenses_light.html +++ b/app/src/main/assets/it/about_licenses_light.html @@ -44,6 +44,12 @@ sono state derivate da ic_security e ic_language, che fanno parte dell'Android Material icon set e sono state rilasciate sotto Licenza Apache 2.0. Il testo completo della Licenza è riportato di seguito. Copyright delle modifiche © 2016 Soren Stoutner. Le immagini risultanti sono rilasciate sotto Licenza GPLv3+. +è stata derivata da elementi di ic_folder e di ic_exit_to_app, che fanno parte dell'Android Material icon set + e sono state rilasciate sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. + L'immagine risultante è rilasciata sotto Licenza GPLv3+.
+è stata derivata da elementi di ic_bookmark e di ic_create_new_folder, che fanno parte dell'Android Material icon set + e sono state rilasciate sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. + L'immagine risultante è rilasciata sotto Licenza GPLv3+.
è stata derivata da ic_create_new_folder, che fa parte dell'Android Material icon set ed è stata rilasciata sotto Licenza Apache 2.0. Copyright delle modifiche © 2017 Soren Stoutner. L'immagine risultante è rilasciata sotto Licenza GPLv3+.
diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java index e4aa9258..8a69e2be 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -61,40 +61,47 @@ import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper; import java.io.ByteArrayOutputStream; -public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener, EditBookmarkFolderDialog.EditBookmarkFolderListener, - MoveToFolderDialog.MoveToFolderListener { +public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener, + EditBookmarkFolderDialog.EditBookmarkFolderListener, MoveToFolderDialog.MoveToFolderListener { - // `bookmarksDatabaseHelper` is public static so it can be accessed from `CreateBookmarkFolderDialog`, `EditBookmarkDialog`, `EditBookmarkFolderDialog` and `MoveToFolderDialog`. It is also used in `onCreate()`, - // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. + // `bookmarksDatabaseHelper` is public static so it can be accessed from `CreateBookmarkFolderDialog`, `EditBookmarkDialog`, `EditBookmarkFolderDialog` and `MoveToFolderDialog`. It is also used in `onCreate()`, `onOptionsItemSelected()`, + // `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, `deleteBookmarkFolderContents()`, and `loadFolder(). public static BookmarksDatabaseHelper bookmarksDatabaseHelper; // `currentFolder` is public static so it can be accessed from `MoveToFolderDialog`. - // It is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`. + // It is used in `onCreate`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, and `loadFolder()`. public static String currentFolder; // `checkedItemIds` is public static so it can be accessed from `EditBookmarkDialog`, `EditBookmarkFolderDialog`, and `MoveToFolderDialog`. - // It is also used in `onActionItemClicked`. + // It is also used in `onCreate()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, and `updateMoveIcons()`. public static long[] checkedItemIds; - // `bookmarksListView` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. + // `bookmarksListView` is used in `onCreate()`, `onOptionsItemSelected()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, `updateMoveIcons()`, `scrollBookmarks()`, + // and `loadFolder()`. private ListView bookmarksListView; - // `contextualActionMode` is used in `onCreate()` and `onEditBookmarkSave()`. - private ActionMode contextualActionMode; + // `bookmarksCursor` is used in `onCreate()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, `deleteBookmarkFolderContents()`, and `loadFolder()`. + private Cursor bookmarksCursor; - // `bookmarkListViewPosition` is used in `onCreate()`, `onSaveEditBookmark()`, and `onSaveEditBookmarkFolder()`. - private int bookmarksListViewPosition; + // `bookmarksCursorAdapter` is used in `onCreate(), `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()`, `onMoveToFolder()`, and `onLoadFolder()`. + private CursorAdapter bookmarksCursorAdapter; - // `appBar` is used in `onCreate()` and `updateBookmarksListView()`. - private ActionBar appBar; + // `contextualActionMode` is used in `onCreate()`, `onSaveEditBookmark()`, `onSaveEditBookmarkFolder()` and `onMoveToFolder()`. + private ActionMode contextualActionMode; - // `bookmarksCursor` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`. - private Cursor bookmarksCursor; + // `appBar` is used in `onCreate()` and `loadFolder()`. + private ActionBar appBar; - // `oldFolderName` is used in `onCreate()` and `onEditBookmarkFolderSave()`. + // `oldFolderName` is used in `onCreate()` and `onSaveEditBookmarkFolder()`. private String oldFolderNameString; + // `moveBookmarkUpMenuItem` is used in `onCreate()` and `updateMoveIcons`. + private MenuItem moveBookmarkUpMenuItem; + + // `moveBookmarkDownMenuItem` is used in `onCreate()` and `updateMoveIcons`. + private MenuItem moveBookmarkDownMenuItem; + @Override protected void onCreate(Bundle savedInstanceState) { // Set the activity theme. @@ -114,25 +121,28 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma final Toolbar bookmarksAppBar = (Toolbar) findViewById(R.id.bookmarks_toolbar); setSupportActionBar(bookmarksAppBar); - // Display the home arrow on `SupportActionBar`. + // Get a handle for the activity, the app bar, and the `ListView`. + final Activity bookmarksActivity = this; appBar = getSupportActionBar(); - assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null. - appBar.setDisplayHomeAsUpEnabled(true); + bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview); + + // This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null. + assert appBar != null; + // Display the home arrow on `SupportActionBar`. + appBar.setDisplayHomeAsUpEnabled(true); // Initialize the database helper and the `ListView`. `this` specifies the context. 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`. bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0); - bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview); // Set currentFolder to the home folder, which is `""` in the database. currentFolder = ""; - // Display the bookmarks in the ListView. - updateBookmarksListView(currentFolder); + // Load the home folder. + loadFolder(); - // Set a listener so that tapping a list item loads the URL. We need to store the activity in a variable so that we can return to the parent activity after loading the URL. - final Activity bookmarksActivity = this; + // Set a listener so that tapping a list item loads the URL or folder. bookmarksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> parent, View view, int position, long id) { @@ -143,17 +153,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID); bookmarkCursor.moveToFirst(); - // If the bookmark is a folder load its contents into the ListView. - if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { + // Act upon the bookmark according to the type. + if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { // The selected bookmark is a folder. // Update `currentFolder`. currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); - // Reload the ListView with `currentFolder`. - updateBookmarksListView(currentFolder); - } else { // Load the URL into `mainWebView`. - // Get the bookmark URL and assign it to formattedUrlString. `mainWebView` will automatically reload when `BookmarksActivity` closes. + // Load the new folder. + loadFolder(); + } else { // The selected bookmark is not a folder. + // Get the bookmark URL and assign it to `formattedUrlString`. `mainWebView` will automatically reload when `BookmarksActivity` closes. MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); + // Return to `MainWebViewActivity`. NavUtils.navigateUpFromSameTask(bookmarksActivity); } @@ -164,16 +175,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `MultiChoiceModeListener` handles long clicks. bookmarksListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { - // `moveBookmarkUpMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`. - MenuItem moveBookmarkUpMenuItem; - - // `moveBookmarkDownMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`. - MenuItem moveBookmarkDownMenuItem; - - // `editBookmarkMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`. + // Instantiate the common variables. MenuItem editBookmarkMenuItem; - - // `selectAllBookmarks` is used in `onCreateActionMode()` and `onItemCheckedStateChanges`. MenuItem selectAllBookmarksMenuItem; @Override @@ -189,15 +192,16 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma mode.setTitle(currentFolder); } - // Get a handle for MenuItems we need to selectively disable. + // Get a handle for `MenuItems` that need to be selectively disabled. moveBookmarkUpMenuItem = menu.findItem(R.id.move_bookmark_up); moveBookmarkDownMenuItem = menu.findItem(R.id.move_bookmark_down); editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark); selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks); - // Store `contextualActionMode` so we can close it programatically. + // Store `contextualActionMode` so it can be closed programatically. contextualActionMode = mode; + // Make it so. return true; } @@ -212,22 +216,23 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Enable the move to folder menu item if at least one folder exists. moveToFolderMenuItem.setVisible(folderCursor.getCount() > 0); - // `return true` indicates that the menu has been updated. + // Make it so. return true; } @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { - // Get an array of the selected bookmarks. + // Get a long array of the selected bookmarks. long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds(); // Calculate the number of selected bookmarks. int numberOfSelectedBookmarks = selectedBookmarksLongArray.length; - // Adjust the `mode` and the menu for the number of selected bookmarks. - if (numberOfSelectedBookmarks == 0) { + // Adjust the `ActionMode` and the `Menu` according to the number of selected bookmarks. + if (numberOfSelectedBookmarks == 0) { // No bookmarks are selected. + // Close the `ActionMode`. mode.finish(); - } else if (numberOfSelectedBookmarks == 1) { + } else if (numberOfSelectedBookmarks == 1) { // One bookmark is selected. // List the number of selected bookmarks in the subtitle. mode.setSubtitle(getString(R.string.one_selected)); @@ -236,41 +241,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma moveBookmarkDownMenuItem.setVisible(true); editBookmarkMenuItem.setVisible(true); - // Get the database IDs for the bookmarks. - int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0]; - int firstBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(0); - // bookmarksListView is 0 indexed. - int lastBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(bookmarksListView.getCount() - 1); - - // Disable `moveBookmarkUpMenuItem` if the selected bookmark is at the top of the ListView. - if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) { - moveBookmarkUpMenuItem.setEnabled(false); - moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled); - } else { // Otherwise enable `moveBookmarkUpMenuItem`. - moveBookmarkUpMenuItem.setEnabled(true); - - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark); - } else { - moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light); - } - } - - // Disable `moveBookmarkDownMenuItem` if the selected bookmark is at the bottom of the ListView. - if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) { - moveBookmarkDownMenuItem.setEnabled(false); - moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled); - } else { // Otherwise enable `moveBookmarkDownMenuItem`. - moveBookmarkDownMenuItem.setEnabled(true); - - // Set the icon according to the theme. - if (MainWebViewActivity.darkTheme) { - moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark); - } else { - moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light); - } - } + // Update the enabled status of the move icons. + updateMoveIcons(); } else { // More than one bookmark is selected. // List the number of selected bookmarks in the subtitle. mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected)); @@ -295,21 +267,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma int menuItemId = item.getItemId(); // Instantiate the common variables. - int numberOfBookmarks; int selectedBookmarkPosition; int selectedBookmarkNewPosition; final SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray; switch (menuItemId) { case R.id.move_bookmark_up: - // Get the array of checked bookmarks. + // Get the array of checked bookmark positions. selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions(); - // Store the position of the selected bookmark. + // Store the position of the selected bookmark. Only one bookmark is selected when `move_bookmark_up` is enabled. selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0); - // Initialize `selectedBookmarkNewPosition`. - selectedBookmarkNewPosition = 0; + // Calculate the new position of the selected bookmark. + selectedBookmarkNewPosition = selectedBookmarkPosition - 1; // Iterate through the bookmarks. for (int i = 0; i < bookmarksListView.getCount(); i++) { @@ -320,7 +291,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma if (i == selectedBookmarkPosition) { // The current bookmark is the selected bookmark. // Move the current bookmark up one. bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i - 1); - selectedBookmarkNewPosition = i - 1; } else if ((i + 1) == selectedBookmarkPosition){ // The current bookmark is immediately above the selected bookmark. // Move the current bookmark down one. bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i + 1); @@ -335,26 +305,28 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } } - // Refresh the ListView. - updateBookmarksListView(currentFolder); + // Update `bookmarksCursor` with the current contents of the bookmarks database. + bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentFolder); - // Select the previously selected bookmark in the new location. - bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true); + // Update the `ListView`. + bookmarksCursorAdapter.changeCursor(bookmarksCursor); - // Scroll `bookmarksListView` to five items above `selectedBookmarkNewPosition`. - bookmarksListView.setSelection(selectedBookmarkNewPosition - 5); + // Scroll with the bookmark. + scrollBookmarks(selectedBookmarkNewPosition); + // Update the enabled status of the move icons. + updateMoveIcons(); break; case R.id.move_bookmark_down: - // Get the array of checked bookmarks. + // Get the array of checked bookmark positions. selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions(); - // Store the position of the selected bookmark. + // Store the position of the selected bookmark. Only one bookmark is selected when `move_bookmark_down` is enabled. selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0); - // Initialize `selectedBookmarkNewPosition`. - selectedBookmarkNewPosition = 0; + // Calculate the new position of the selected bookmark. + selectedBookmarkNewPosition = selectedBookmarkPosition + 1; // Iterate through the bookmarks. for (int i = 0; i