package com.stoutner.privacybrowser.adapters;
-import com.stoutner.privacybrowser.fragments.WebViewTabFragment;
-
-import java.util.LinkedList;
-
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import com.stoutner.privacybrowser.fragments.WebViewTabFragment;
+
+import java.util.LinkedList;
public class WebViewPagerAdapter extends FragmentPagerAdapter {
// The WebView fragments list contains all the WebViews.
@Override
public long getItemId(int position) {
// Return the unique ID for this page.
- return webViewFragmentsList.get(position).tabId;
+ return webViewFragmentsList.get(position).fragmentId;
}
- public int getPositionForId(long pageId) {
+ public int getPositionForId(long fragmentId) {
// Initialize the position variable.
int position = -1;
// Find the current position of the WebView fragment with the given ID.
while (position < 0 && i < webViewFragmentsList.size()) {
// Check to see if the tab ID of this WebView matches the page ID.
- if (webViewFragmentsList.get(i).tabId == pageId) {
+ if (webViewFragmentsList.get(i).fragmentId == fragmentId) {
// Store the position if they are a match.
position = i;
}
return position;
}
- public void addPage(int pageNumber) {
+ public void addPage(int pageNumber, ViewPager webViewPager) {
// Add a new page.
webViewFragmentsList.add(WebViewTabFragment.createPage(pageNumber));
// Update the view pager.
notifyDataSetChanged();
+
+ // Move to the new page if it isn't the first one.
+ if (pageNumber > 0) {
+ webViewPager.setCurrentItem(pageNumber);
+ }
}
public void deletePage(int pageNumber) {