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=2bf499e4d21ffb28d91d0bb92c92668031713da8;hp=b28289b0dfcea6bcad8da2640681528b810adabb;hb=f0393ca22075be3e5fe9199c7db87381256236fa;hpb=ba40295dffd761ccdc95d3b46ca7acbad1f00d5e 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 b28289b0..2bf499e4 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/DomainsListFragment.java @@ -19,7 +19,10 @@ package com.stoutner.privacybrowser.fragments; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -34,9 +37,24 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.stoutner.privacybrowser.R; import com.stoutner.privacybrowser.activities.DomainsActivity; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; public class DomainsListFragment extends Fragment { + // Instantiate the dismiss snackbar interface handle. + private DismissSnackbarInterface dismissSnackbarInterface; + + // Define the public dismiss snackbar interface. + public interface DismissSnackbarInterface { + void dismissSnackbar(); + } + + public void onAttach(Context context) { + // Run the default commands. + super.onAttach(context); + + // Get a handle for the dismiss snackbar interface. + dismissSnackbarInterface = (DismissSnackbarInterface) context; + } + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate `domains_list_fragment`. `false` does not attach it to the root `container`. View domainsListFragmentView = inflater.inflate(R.layout.domains_list_fragment, container, false); @@ -47,16 +65,12 @@ public class DomainsListFragment extends Fragment { // Remove the incorrect lint error below that `.getSupportFragmentManager()` might be null. assert getActivity() != null; - // Get a handle for `supportFragmentManager`. + // Get a handle for the support fragment manager. final FragmentManager supportFragmentManager = getActivity().getSupportFragmentManager(); domainsListView.setOnItemClickListener((AdapterView parent, View view, int position, long id) -> { - // Dismiss `undoDeleteSnackbar` if it is currently displayed (because a domain has just been deleted). - if ((DomainsActivity.undoDeleteSnackbar != null) && (DomainsActivity.undoDeleteSnackbar.isShown())) { - DomainsActivity.dismissingSnackbar = true; - - DomainsActivity.undoDeleteSnackbar.dismiss(); - } + // Dismiss the snackbar if it is visible. + dismissSnackbarInterface.dismissSnackbar(); // Save the current domain settings if operating in two-paned mode and a domain is currently selected. if (DomainsActivity.twoPanedMode && DomainsActivity.deleteMenuItem.isEnabled()) { @@ -94,8 +108,14 @@ public class DomainsListFragment extends Fragment { // 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); + // Set the delete icon according to the theme. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_dark); } else { DomainsActivity.deleteMenuItem.setIcon(R.drawable.delete_light); @@ -121,4 +141,4 @@ public class DomainsListFragment extends Fragment { return domainsListFragmentView; } -} +} \ No newline at end of file