Create a dark theme for `DomainsActivity` and `DomainsSettingsActivity`.
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / DomainSettingsFragment.java
index a231391c40ab0cffdf7bc8a268519b6a87da25a7..ff18669c5719742acba30277c511bfe37e91473f 100644 (file)
@@ -152,7 +152,13 @@ public class DomainSettingsFragment extends Fragment {
             firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
         } else {  // First-party cookies are disabled.
             firstPartyCookiesEnabledSwitch.setChecked(false);
-            firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+
+            // Set the icon according to the theme.
+            if (MainWebViewActivity.darkTheme) {
+                firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
+            } else {
+                firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+            }
         }
 
         // Only display third-party cookies if SDK_INT >= 21.
@@ -165,17 +171,29 @@ public class DomainSettingsFragment extends Fragment {
                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
                 } else {  // First party cookies are enabled but third-party cookies are disabled.
                     thirdPartyCookiesEnabledSwitch.setChecked(false);
-                    thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+
+                    // Set the icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
+                    } else {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                    }
                 }
             } else {  // First-party cookies are disabled.
-                // Set the status of third-party cookies, but disable it.
-                if (thirdPartyCookiesEnabledInt == 1) {  // Third-party cookies are enabled but first-party cookies are disabled.
+                // Set the status of third-party cookies.
+                if (thirdPartyCookiesEnabledInt == 1) {
                     thirdPartyCookiesEnabledSwitch.setChecked(true);
-                    thirdPartyCookiesEnabledSwitch.setEnabled(false);
-                    thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
-                } else {  // Both first party and third-party cookies are disabled.
+                } else {
                     thirdPartyCookiesEnabledSwitch.setChecked(false);
-                    thirdPartyCookiesEnabledSwitch.setEnabled(false);
+                }
+
+                // Disable the third-party cookies switch.
+                thirdPartyCookiesEnabledSwitch.setEnabled(false);
+
+                // Set the icon according to the theme.
+                if (MainWebViewActivity.darkTheme) {
+                    thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_dark));
+                } else {
                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
                 }
             }
@@ -191,8 +209,15 @@ public class DomainSettingsFragment extends Fragment {
                 domStorageEnabledSwitch.setChecked(true);
                 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
             } else {  // JavaScript is enabled but DOM storage is disabled.
+                // Set the DOM storage switch to off.
                 domStorageEnabledSwitch.setChecked(false);
-                domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+
+                // Set the icon according to the theme.
+                if (MainWebViewActivity.darkTheme) {
+                    domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
+                } else {
+                    domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+                }
             }
         } else {  // JavaScript is disabled.
             // Set the checked status of DOM storage.
@@ -202,9 +227,15 @@ public class DomainSettingsFragment extends Fragment {
                 domStorageEnabledSwitch.setChecked(false);
             }
 
-            // Disable `domStorageEnabledSwitch` and set the icon to be ghosted.
+            // Disable `domStorageEnabledSwitch`.
             domStorageEnabledSwitch.setEnabled(false);
-            domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
+
+            // Set the icon according to the theme.
+            if (MainWebViewActivity.darkTheme) {
+                domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_dark));
+            } else {
+                domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
+            }
         }
 
         // Set the form data status.  Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
@@ -212,8 +243,15 @@ public class DomainSettingsFragment extends Fragment {
             formDataEnabledSwitch.setChecked(true);
             formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
         } else {  // Form data is disabled.
+            // Set the form data switch to off.
             formDataEnabledSwitch.setChecked(false);
-            formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
+
+            // Set the icon according to the theme.
+            if (MainWebViewActivity.darkTheme) {
+                formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_dark));
+            } else {
+                formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
+            }
         }
 
         // We need to inflated a `WebView` to get the default user agent.
@@ -269,18 +307,38 @@ public class DomainSettingsFragment extends Fragment {
         switch (displayImagesInt) {
             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
                 if (MainWebViewActivity.displayWebpageImagesBoolean) {
-                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                    // Set the icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
+                    } else {
+                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                    }
                 } else {
-                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                    // Set the icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
+                    } else {
+                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                    }
                 }
                 break;
 
             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
-                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                // Set the icon according to the theme.
+                if (MainWebViewActivity.darkTheme) {
+                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
+                } else {
+                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                }
                 break;
 
             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
-                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                // Set the icon according to the theme.
+                if (MainWebViewActivity.darkTheme) {
+                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
+                } else {
+                    displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                }
                 break;
         }
 
@@ -300,7 +358,12 @@ public class DomainSettingsFragment extends Fragment {
                     if (domStorageEnabledSwitch.isChecked()) {  // DOM storage is enabled.
                         domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
                     } else {  // DOM storage is disabled.
-                        domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+                        // Set the icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
+                        } else {
+                            domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+                        }
                     }
                 } else {  // JavaScript is disabled.
                     // Update the JavaScript icon.
@@ -309,8 +372,12 @@ public class DomainSettingsFragment extends Fragment {
                     // Disable the DOM storage `Switch`.
                     domStorageEnabledSwitch.setEnabled(false);
 
-                    // Set the DOM storage icon to be ghosted.
-                    domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
+                    // Set the DOM storage icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_dark));
+                    } else {
+                        domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
+                    }
                 }
             }
         });
@@ -330,17 +397,30 @@ public class DomainSettingsFragment extends Fragment {
                     if (thirdPartyCookiesEnabledSwitch.isChecked()) {  // Third-party cookies are enabled.
                         thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
                     } else {  // Third-party cookies are disabled.
-                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                        // Set the third-party cookies icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
+                        } else {
+                            thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                        }
                     }
                 } else {  // First-party cookies are disabled.
-                    // Update the first-party cookies icon.
-                    firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                    // Update the first-party cookies icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
+                    } else {
+                        firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                    }
 
                     // Disable the third-party cookies `Switch`.
                     thirdPartyCookiesEnabledSwitch.setEnabled(false);
 
-                    // Set the third-party cookies icon to be ghosted.
-                    thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
+                    // Set the third-party cookies icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_dark));
+                    } else {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
+                    }
                 }
             }
         });
@@ -353,7 +433,12 @@ public class DomainSettingsFragment extends Fragment {
                 if (isChecked) {
                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
                 } else {
-                    thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                    // Update the third-party cookies icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
+                    } else {
+                        thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
+                    }
                 }
             }
         });
@@ -366,7 +451,12 @@ public class DomainSettingsFragment extends Fragment {
                 if (isChecked) {
                     domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
                 } else {
-                    domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+                    // Set the icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
+                    } else {
+                        domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
+                    }
                 }
             }
         });
@@ -379,7 +469,12 @@ public class DomainSettingsFragment extends Fragment {
                 if (isChecked) {
                     formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
                 } else {
-                    formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
+                    // Set the icon according to the theme.
+                    if (MainWebViewActivity.darkTheme) {
+                        formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_dark));
+                    } else {
+                        formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
+                    }
                 }
             }
         });
@@ -436,18 +531,38 @@ public class DomainSettingsFragment extends Fragment {
                 switch (position) {
                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
                         if (MainWebViewActivity.displayWebpageImagesBoolean) {
-                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                            // Set the icon according to the theme.
+                            if (MainWebViewActivity.darkTheme) {
+                                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
+                            } else {
+                                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                            }
                         } else {
-                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                            // Set the icon according to the theme.
+                            if (MainWebViewActivity.darkTheme) {
+                                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
+                            } else {
+                                displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                            }
                         }
                         break;
 
                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
-                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                        // Set the icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
+                        } else {
+                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
+                        }
                         break;
 
                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
-                        displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                        // Set the icon according to the theme.
+                        if (MainWebViewActivity.darkTheme) {
+                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
+                        } else {
+                            displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
+                        }
                         break;
                 }
             }