X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Ffragments%2FGuideTabFragment.java;h=3f1988ed6c6fe3923c022b7daae45ce40aa8132a;hp=9e5f568d0d2d0af4ecf1c0c1a94efc96d55bb579;hb=f0393ca22075be3e5fe9199c7db87381256236fa;hpb=afd9b8e690e34c11981eaed1fddbc259fc8cc49a diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTabFragment.java index 9e5f568d..3f1988ed 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/GuideTabFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,41 +20,60 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; +import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v4.app.Fragment; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebView; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; public class GuideTabFragment extends Fragment { // `tabNumber` is used in `onCreate()` and `onCreateView()`. private int tabNumber; - // GuideTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate(). + // Store the tab number in the arguments bundle. public static GuideTabFragment createTab (int tab) { - Bundle thisTabArguments = new Bundle(); - thisTabArguments.putInt("Tab", tab); + // Create a bundle. + Bundle bundle = new Bundle(); + + // Store the tab number in the bundle. + bundle.putInt("Tab", tab); - GuideTabFragment thisTab = new GuideTabFragment(); - thisTab.setArguments(thisTabArguments); - return thisTab; + // Add the bundle to the fragment. + GuideTabFragment guideTabFragment = new GuideTabFragment(); + guideTabFragment.setArguments(bundle); + + // Return the new fragment. + return guideTabFragment; } @Override public void onCreate(Bundle savedInstanceState) { + // Run the default commands. super.onCreate(savedInstanceState); - // Store the tab number in `tabNumber`. + // Remove the lint warning that `getArguments()` might be null. + assert getArguments() != null; + + // Store the tab number in a class variable. tabNumber = getArguments().getInt("Tab"); } @SuppressLint("SetJavaScriptEnabled") @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + // Get the theme preference. + boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically. View tabLayout = inflater.inflate(R.layout.bare_webview, container, false); @@ -62,8 +81,8 @@ public class GuideTabFragment extends Fragment { WebView tabWebView = (WebView) tabLayout; // Load the tabs according to the theme. - if (MainWebViewActivity.darkTheme) { // The dark theme is applied. - // Set the background color. We have to use the deprecated `.getColor()` until API >= 23. + if (darkTheme) { // The dark theme is applied. + // Set the background color. The deprecated `.getColor()` must be used until API >= 23. //noinspection deprecation tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850)); @@ -86,20 +105,28 @@ public class GuideTabFragment extends Fragment { break; case 4: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_dark.html"); break; case 5: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html"); break; case 6: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html"); break; case 7: + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html"); + break; + + case 8: tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html"); break; + + case 9: + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_dark.html"); + break; } } else { // The light theme is applied. // Tab numbers start at 0. @@ -121,24 +148,31 @@ public class GuideTabFragment extends Fragment { break; case 4: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_light.html"); break; case 5: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html"); break; case 6: - tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html"); + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html"); break; case 7: + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html"); + break; + + case 8: tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html"); break; + + case 9: + tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_light.html"); } } // Return the formatted `tabLayout`. return tabLayout; } -} +} \ No newline at end of file