X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FDomainsListFragment.java;h=2aa974b9f2a9576d6b037ad6e17986495da51a84;hb=0488649384ddea89d768c1fc1cc5fb71f8af6528;hp=b28289b0dfcea6bcad8da2640681528b810adabb;hpb=ba40295dffd761ccdc95d3b46ca7acbad1f00d5e;p=PrivacyBrowserAndroid.git 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..2aa974b9 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 . * @@ -19,6 +19,8 @@ package com.stoutner.privacybrowser.fragments; +import android.content.Context; +import android.content.res.Configuration; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -27,16 +29,31 @@ 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; 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(@NonNull 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,28 +64,27 @@ 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()) { // 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(); @@ -94,11 +110,14 @@ public class DomainsListFragment extends Fragment { // Enable the delete menu item. DomainsActivity.deleteMenuItem.setEnabled(true); + // Get the current theme status. + int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + // Set the delete icon according to the theme. - if (MainWebViewActivity.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); } } @@ -121,4 +140,4 @@ public class DomainsListFragment extends Fragment { return domainsListFragmentView; } -} +} \ No newline at end of file