X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FDomainsListFragment.java;h=2d22d9c7225e26cbded4b03e62bcefb97383e2f2;hp=2bf499e4d21ffb28d91d0bb92c92668031713da8;hb=b82022327701273b1b56419e8d6042895c0bc7b9;hpb=f0393ca22075be3e5fe9199c7db87381256236fa diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java index 2bf499e4..2d22d9c7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2019 Soren Stoutner . + * Copyright © 2017-2020 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,9 +20,8 @@ package com.stoutner.privacybrowser.fragments; import android.content.Context; -import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Bundle; -import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -30,7 +29,7 @@ import android.widget.AdapterView; import android.widget.ListView; import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; // The AndroidX fragment must be used until minimum API >= 23. Otherwise `getContext()` does not work. +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -39,7 +38,7 @@ import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.DomainsActivity; public class DomainsListFragment extends Fragment { - // Instantiate the dismiss snackbar interface handle. + // Instantiate the dismiss snackbar interface. private DismissSnackbarInterface dismissSnackbarInterface; // Define the public dismiss snackbar interface. @@ -47,11 +46,11 @@ public class DomainsListFragment extends Fragment { void dismissSnackbar(); } - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { // Run the default commands. super.onAttach(context); - // Get a handle for the dismiss snackbar interface. + // Populate the dismiss snackbar interface. dismissSnackbarInterface = (DismissSnackbarInterface) context; } @@ -59,7 +58,7 @@ public class DomainsListFragment extends Fragment { // Inflate `domains_list_fragment`. `false` does not attach it to the root `container`. View domainsListFragmentView = inflater.inflate(R.layout.domains_list_fragment, container, false); - // Initialize `domainsListView`. + // Get a handle for the domains listview. ListView domainsListView = domainsListFragmentView.findViewById(R.id.domains_listview); // Remove the incorrect lint error below that `.getSupportFragmentManager()` might be null. @@ -77,12 +76,15 @@ public class DomainsListFragment extends Fragment { // Get a handle for the domain settings fragment. Fragment domainSettingsFragment = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container); - // Remove the incorrect lint error below that the domain settings fragment might be null. + // Remove the incorrect lint warning below that the domain settings fragment might be null. assert domainSettingsFragment != null; // Get a handle for the domain settings fragment view. View domainSettingsFragmentView = domainSettingsFragment.getView(); + // Remove the incorrect lint warning below that the domain settings fragment view might be null. + assert domainSettingsFragmentView != null; + // Get a handle for the domains activity. DomainsActivity domainsActivity = new DomainsActivity(); @@ -101,30 +103,30 @@ public class DomainsListFragment extends Fragment { DomainSettingsFragment domainSettingsFragment = new DomainSettingsFragment(); domainSettingsFragment.setArguments(argumentsBundle); - // Display the domain settings fragment. + // Check to see if the device is in two paned mode. if (DomainsActivity.twoPanedMode) { // The device in in two-paned mode. // enable `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed. if (!DomainsActivity.dismissingSnackbar) { // Enable the delete menu item. DomainsActivity.deleteMenuItem.setEnabled(true); - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - - // Get the theme preferences. - boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + // Get the current theme status. + int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; // Set the delete icon according to the theme. - if (darkTheme) { - DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_dark); + if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { + DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_night); } else { - DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_light); + DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_day); } } // Display the domain settings fragment. supportFragmentManager.beginTransaction().replace(R.id.domain_settings_fragment_container, domainSettingsFragment).commit(); } else { // The device in in single-paned mode + // Save the domains listview position. + DomainsActivity.domainsListViewPosition = domainsListView.getFirstVisiblePosition(); + // Show `deleteMenuItem` if the system is not waiting for a `Snackbar` to be dismissed. if (!DomainsActivity.dismissingSnackbar) { DomainsActivity.deleteMenuItem.setVisible(true); @@ -139,6 +141,7 @@ public class DomainsListFragment extends Fragment { } }); + // Return the domains list fragment. return domainsListFragmentView; } } \ No newline at end of file