/*
- * Copyright © 2017-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2017-2020 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
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;
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.
+ // Instantiate the dismiss snackbar interface.
private DismissSnackbarInterface dismissSnackbarInterface;
// Define the public dismiss snackbar interface.
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;
}
// 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.
// 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();
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 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);
}
}
// 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);
}
});
+ // Return the domains list fragment.
return domainsListFragmentView;
}
-}
+}
\ No newline at end of file