X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksActivity.java;h=c822e0e78d1112bf7b94c9dafd786211ac540239;hp=763f63851cec91512347eb9ed8d504324df0bfb1;hb=b3d5be23f259bbfef8dad813a9302e77f6fdc19f;hpb=9f551f25b53a30cca7b19b6e6bfc2d2520d9aa1b 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 763f6385..c822e0e7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 Soren Stoutner . + * Copyright © 2016-2018 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -43,6 +43,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.AbsListView; import android.widget.CursorAdapter; import android.widget.EditText; @@ -103,6 +104,11 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override protected void onCreate(Bundle savedInstanceState) { + // Disable screenshots if not allowed. + if (!MainWebViewActivity.allowScreenshots) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + // Set the activity theme. if (MainWebViewActivity.darkTheme) { setTheme(R.style.PrivacyBrowserDark_SecondaryActivity); @@ -130,15 +136,15 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma final Toolbar bookmarksAppBar = findViewById(R.id.bookmarks_toolbar); setSupportActionBar(bookmarksAppBar); - // Get a handle for the activity, the app bar, and the `ListView`. + // Get a handle for the activity, the app bar, and the ListView. final Activity bookmarksActivity = this; appBar = getSupportActionBar(); bookmarksListView = findViewById(R.id.bookmarks_listview); - // This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null. + // Remove the incorrect lint warning that `appBar` might be null. assert appBar != null; - // Display the home arrow on `SupportActionBar`. + // Display the home arrow on the app bar. appBar.setDisplayHomeAsUpEnabled(true); // Initialize the database helper. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`. @@ -153,21 +159,24 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert the id from long to int to match the format of the bookmarks database. int databaseID = (int) id; - // Get the bookmark `Cursor` for this ID and move it to the first row. + // Get the bookmark cursor for this ID and move it to the first row. Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID); bookmarkCursor.moveToFirst(); // 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`. + // Update the current folder. currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); // 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. + // Get the bookmark URL and assign it to `formattedUrlString`. MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); + // Set `MainWebViewActivity` to load the new URL on restart. + MainWebViewActivity.loadUrlOnRestart = true; + // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`. MainWebViewActivity.currentBookmarksFolder = currentFolder; @@ -261,8 +270,24 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // 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)); + // List the number of selected bookmarks according to the language. + if (getString(R.string.android_asset_path).equals("ru")) { // The Russian translation is used. + // Convert the number of selected bookmarks to a string. + String numberOfSelectedBookmarksString = String.valueOf(numberOfSelectedBookmarks); + + // Russian follows rule #7 at . + if (numberOfSelectedBookmarksString.endsWith("1") && !numberOfSelectedBookmarksString.equals("11")) { // Ends in 1. + mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_ends_in_1)); + } else if ((numberOfSelectedBookmarksString.endsWith("2") || numberOfSelectedBookmarksString.endsWith("3") || numberOfSelectedBookmarksString.endsWith("4")) && + !numberOfSelectedBookmarksString.equals("12") && !numberOfSelectedBookmarksString.equals("13") && !numberOfSelectedBookmarksString.equals("14")) { // Ends in 2-4. + mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_ends_in_2)); + } else { // Everything else. + mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected_russian_everything_else)); + } + } else { // Another language is used. + // List the number of selected bookmarks in the subtitle. + mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected)); + } // Hide non-applicable `MenuItems`. moveBookmarkUpMenuItem.setVisible(false); @@ -438,11 +463,27 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Instantiate `snackbarMessage`. String snackbarMessage; - // Determine how many items are in the array and prepare an appropriate `Snackbar` message. + // Determine how many items are in the array and prepare an appropriate snackbar message. if (selectedBookmarksIdsLongArray.length == 1) { snackbarMessage = getString(R.string.one_bookmark_deleted); } else { - snackbarMessage = selectedBookmarksIdsLongArray.length + " " + getString(R.string.bookmarks_deleted); + // Prepare a snackbar according to the language. + if (getString(R.string.android_asset_path).equals("ru")) { // The Russian translation is used. + // Convert the number of selected bookmarks to a string. + String numberOfBookmarksString = String.valueOf(selectedBookmarksIdsLongArray.length); + + // Russian follows rule #7 at . + if (numberOfBookmarksString.endsWith("1") && !numberOfBookmarksString.equals("11")) { // Ends in 1. + snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_ends_in_1); + } else if ((numberOfBookmarksString.endsWith("2") || numberOfBookmarksString.endsWith("3") || numberOfBookmarksString.endsWith("4")) && + !numberOfBookmarksString.equals("12") && !numberOfBookmarksString.equals("13") && !numberOfBookmarksString.equals("14")) { // Ends in 2-4. + snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_ends_in_2); + } else { // Everything else. + snackbarMessage = numberOfBookmarksString + " " + getString(R.string.bookmarks_deleted_russian_everything_else); + } + } else { // Another language is used. + snackbarMessage = selectedBookmarksIdsLongArray.length + " " + getString(R.string.bookmarks_deleted); + } } // Show a SnackBar.