X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksDatabaseViewActivity.java;h=c4b97517f12b4624ebd5b4985586c8c710de333d;hb=74655c0cd0ba72c80ac6c48df55bc3d2f5280ad2;hp=61b5e84582278088be4674358fba1298dd02c962;hpb=9df712df3780161d77d10c6f3a2444bf8f218c99;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java index 61b5e845..c4b97517 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java @@ -24,6 +24,7 @@ import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.database.Cursor; import android.database.MatrixCursor; import android.database.MergeCursor; @@ -51,6 +52,7 @@ import android.widget.ResourceCursorAdapter; import android.widget.Spinner; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API is >= 21. @@ -72,7 +74,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements EditBookmarkFolderDatabaseViewDialog.EditBookmarkFolderDatabaseViewListener { // Instantiate the constants. private static final int ALL_FOLDERS_DATABASE_ID = -2; - private static final int HOME_FOLDER_DATABASE_ID = -1; + public static final int HOME_FOLDER_DATABASE_ID = -1; // `bookmarksDatabaseHelper` is used in `onCreate()`, `updateBookmarksListView()`, `selectAllBookmarksInFolder()`, and `onDestroy()`. private BookmarksDatabaseHelper bookmarksDatabaseHelper; @@ -106,8 +108,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Get a handle for the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - // Get the theme and screenshot preferences. - boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + // Get the screenshot preference. boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); // Disable screenshots if not allowed. @@ -116,11 +117,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Set the activity theme. - if (darkTheme) { - setTheme(R.style.PrivacyBrowserDark_SecondaryActivity); - } else { - setTheme(R.style.PrivacyBrowserLight_SecondaryActivity); - } + setTheme(R.style.PrivacyBrowser); // Run the default commands. super.onCreate(savedInstanceState); @@ -333,8 +330,12 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements parentFolderImageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.folder_dark_blue)); bookmarkParentFolderTextView.setText(bookmarkParentFolder); + // Get the current theme status. + int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + // Set the text color according to the theme. - if (darkTheme) { + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + // This color is a little darker than the default night mode text. But the effect is rather nice. bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.gray_300)); } else { bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black)); @@ -589,12 +590,6 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements @Override public boolean onOptionsItemSelected(MenuItem menuItem) { - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - - // Get the theme preferences. - boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); - // Get the ID of the menu item that was selected. int menuItemId = menuItem.getItemId(); @@ -609,26 +604,29 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Update the sort by display order tracker. sortByDisplayOrder = !sortByDisplayOrder; - // Get a handle for the bookmarks `ListView`. + // Get a handle for the bookmarks list view. ListView bookmarksListView = findViewById(R.id.bookmarks_databaseview_listview); + // Get the current theme status. + int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + // Update the icon and display a snackbar. if (sortByDisplayOrder) { // Sort by display order. // Update the icon according to the theme. - if (darkTheme) { - menuItem.setIcon(R.drawable.sort_selected_dark); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + menuItem.setIcon(R.drawable.sort_selected_night); } else { - menuItem.setIcon(R.drawable.sort_selected_light); + menuItem.setIcon(R.drawable.sort_selected_day); } // Display a Snackbar indicating the current sort type. Snackbar.make(bookmarksListView, R.string.sorted_by_display_order, Snackbar.LENGTH_SHORT).show(); } else { // Sort by database id. // Update the icon according to the theme. - if (darkTheme) { - menuItem.setIcon(R.drawable.sort_dark); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + menuItem.setIcon(R.drawable.sort_night); } else { - menuItem.setIcon(R.drawable.sort_light); + menuItem.setIcon(R.drawable.sort_day); } // Display a Snackbar indicating the current sort type. @@ -753,7 +751,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } @Override - public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, Bitmap favoriteIconBitmap) { + public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, @NonNull Bitmap favoriteIconBitmap) { // Get the dialog from the dialog fragment. Dialog dialog = dialogFragment.getDialog(); @@ -777,7 +775,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements String parentFolderNameString; // Set the parent folder name. - if (folderDatabaseId == EditBookmarkDatabaseViewDialog.HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`. + if (folderDatabaseId == HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`. parentFolderNameString = ""; } else { // Get the parent folder name from the database. parentFolderNameString = bookmarksDatabaseHelper.getFolderName(folderDatabaseId); @@ -829,7 +827,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements String parentFolderNameString; // Set the parent folder name. - if (parentFolderDatabaseId == EditBookmarkFolderDatabaseViewDialog.HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`. + if (parentFolderDatabaseId == HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`. parentFolderNameString = ""; } else { // Get the parent folder name from the database. parentFolderNameString = bookmarksDatabaseHelper.getFolderName(parentFolderDatabaseId);