]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/adapters/AboutPagerAdapter.java
Combine the light and dark Guide and About pages. https://redmine.stoutner.com/issue...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / adapters / AboutPagerAdapter.java
index 0d9a15867db8a0c2ef436b9a02a5b487758a9863..27f972906d7a1648a8d526bf6c4ceb3e04e70a76 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -21,26 +21,29 @@ package com.stoutner.privacybrowser.adapters;
 
 import android.content.Context;
 
+import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentPagerAdapter;
 
 import com.stoutner.privacybrowser.R;
-import com.stoutner.privacybrowser.fragments.AboutTabFragment;
+import com.stoutner.privacybrowser.fragments.AboutVersionFragment;
+import com.stoutner.privacybrowser.fragments.AboutWebViewFragment;
+
+import java.util.LinkedList;
 
 public class AboutPagerAdapter extends FragmentPagerAdapter {
-    // Define the class variable to store the blocklist versions.
-    private Context context;
-    private String[] blocklistVersions;
+    // Define the class variables.
+    private final Context context;
+    private final String[] blocklistVersions;
+    private final LinkedList<Fragment> aboutFragmentList = new LinkedList<>();
 
     public AboutPagerAdapter(FragmentManager fragmentManager, Context context, String[] blocklistVersions) {
         // Run the default commands.
-        super(fragmentManager);
+        super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
 
-        // Store the context in a class variable.
+        // Store the class variables.
         this.context = context;
-
-        // Store the blocklist versions in a class variable.
         this.blocklistVersions = blocklistVersions;
     }
 
@@ -55,25 +58,25 @@ public class AboutPagerAdapter extends FragmentPagerAdapter {
     public CharSequence getPageTitle(int tab) {
         switch (tab) {
             case 0:
-                return context.getResources().getString(R.string.version);
+                return context.getString(R.string.version);
 
             case 1:
-                return context.getResources().getString(R.string.permissions);
+                return context.getString(R.string.permissions);
 
             case 2:
-                return context.getResources().getString(R.string.privacy_policy);
+                return context.getString(R.string.privacy_policy);
 
             case 3:
-                return context.getResources().getString(R.string.changelog);
+                return context.getString(R.string.changelog);
 
             case 4:
-                return context.getResources().getString(R.string.licenses);
+                return context.getString(R.string.licenses);
 
             case 5:
-                return context.getResources().getString(R.string.contributors);
+                return context.getString(R.string.contributors);
 
             case 6:
-                return context.getResources().getString(R.string.links);
+                return context.getString(R.string.links);
 
             default:
                 return "";
@@ -81,8 +84,24 @@ public class AboutPagerAdapter extends FragmentPagerAdapter {
     }
 
     @Override
+    @NonNull
     // Setup each tab.
     public Fragment getItem(int tabNumber) {
-        return AboutTabFragment.createTab(tabNumber, blocklistVersions);
+        // Create the tab fragment and add it to the list.
+        if (tabNumber == 0){
+            // Add the version tab to the list.
+            aboutFragmentList.add(AboutVersionFragment.createTab(blocklistVersions));
+        } else {
+            // Add the WebView tab to the list.
+            aboutFragmentList.add(AboutWebViewFragment.createTab(tabNumber));
+        }
+
+        // Return the tab number fragment.
+        return aboutFragmentList.get(tabNumber);
+    }
+
+    public Fragment getTabFragment(int tabNumber) {
+        // Return the tab fragment.
+        return aboutFragmentList.get(tabNumber);
     }
 }
\ No newline at end of file