X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fadapters%2FWebViewPagerAdapter.java;h=510ac7396a1a63a6d813061652274ca696eb706a;hp=da8e6729a74700eacad960ed98df0720afb4565e;hb=b82022327701273b1b56419e8d6042895c0bc7b9;hpb=498e34f7a4548cb791e4dea7e072787ec5943a69 diff --git a/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java b/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java index da8e6729..510ac739 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java +++ b/app/src/main/java/com/stoutner/privacybrowser/adapters/WebViewPagerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Soren Stoutner . + * Copyright © 2019-2020 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -19,6 +19,8 @@ package com.stoutner.privacybrowser.adapters; +import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -34,9 +36,9 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter { private LinkedList webViewFragmentsList = new LinkedList<>(); // Define the constructor. - public WebViewPagerAdapter(FragmentManager fragmentManager){ + public WebViewPagerAdapter(FragmentManager fragmentManager) { // Run the default commands. - super(fragmentManager); + super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); } @Override @@ -59,6 +61,7 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter { } @Override + @NonNull public Fragment getItem(int pageNumber) { // Get the fragment for a particular page. Page numbers are 0 indexed. return webViewFragmentsList.get(pageNumber); @@ -100,19 +103,27 @@ public class WebViewPagerAdapter extends FragmentPagerAdapter { return position; } - public void addPage(int pageNumber, ViewPager webViewPager, String url) { + public void addPage(int pageNumber, ViewPager webViewPager, String url, boolean moveToNewPage) { // Add a new page. webViewFragmentsList.add(WebViewTabFragment.createPage(pageNumber, url)); // Update the view pager. notifyDataSetChanged(); - // Move to the new page if it isn't the first one. - if (pageNumber > 0) { + // Move to the new page if indicated. + if (moveToNewPage) { webViewPager.setCurrentItem(pageNumber); } } + public void restorePage(Bundle savedState, Bundle savedNestedScrollWebViewState) { + // Restore the page. + webViewFragmentsList.add(WebViewTabFragment.restorePage(savedState, savedNestedScrollWebViewState)); + + // Update the view pager. + notifyDataSetChanged(); + } + public boolean deletePage(int pageNumber, ViewPager webViewPager) { // Delete the page. webViewFragmentsList.remove(pageNumber);