From 16ccee9956383ad3a38b09f7a4f7e9aeee92cd42 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 20 Mar 2019 14:12:46 -0700 Subject: [PATCH] Create separate progress bars for each tab. --- .../activities/MainWebViewActivity.java | 15 +++--- .../fragments/WebViewTabFragment.java | 8 ++-- app/src/main/res/layout/main_framelayout.xml | 22 +-------- .../main/res/layout/nestedscroll_webview.xml | 27 ----------- .../main/res/layout/webview_framelayout.xml | 48 +++++++++++++++++++ app/src/main/res/values-v21/styles.xml | 10 ++-- app/src/main/res/values/attrs.xml | 7 +-- app/src/main/res/values/styles.xml | 10 ++-- 8 files changed, 77 insertions(+), 70 deletions(-) delete mode 100644 app/src/main/res/layout/nestedscroll_webview.xml create mode 100644 app/src/main/res/layout/webview_framelayout.xml diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index a174230d..1ec5a020 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -707,8 +707,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Get the current WebView fragment. Instantiate item returns the current item if it already exists. Fragment webViewFragment = (Fragment) webViewPagerAdapter.instantiateItem(webViewPager, position); + // Remove the lint error below that the WebView fragment might be null. + assert webViewFragment.getView() != null; + // Store the current WebView. - currentWebView = (NestedScrollWebView) webViewFragment.getView(); + currentWebView = webViewFragment.getView().findViewById(R.id.nestedscroll_webview); // Select the corresponding tab if it does not match the currently selected page. This will happen if the page was scrolled via swiping in the view pager. if (tabLayout.getSelectedTabPosition() != position) { @@ -835,10 +838,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Set the swipe to refresh color according to the theme. if (darkTheme) { - swipeRefreshLayout.setColorSchemeResources(R.color.blue_600); + swipeRefreshLayout.setColorSchemeResources(R.color.blue_800); swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_850); } else { - swipeRefreshLayout.setColorSchemeResources(R.color.blue_700); + swipeRefreshLayout.setColorSchemeResources(R.color.blue_500); } // `DrawerTitle` identifies the `DrawerLayouts` in accessibility mode. @@ -4444,7 +4447,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } @Override - public void initializeWebView(NestedScrollWebView nestedScrollWebView, int tabNumber) { + public void initializeWebView(int tabNumber, ProgressBar progressBar, NestedScrollWebView nestedScrollWebView) { // Get handles for the activity views. final FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout); final DrawerLayout drawerLayout = findViewById(R.id.drawerlayout); @@ -4487,10 +4490,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook ImageView tabFavoriteIconImageView = currentTabView.findViewById(R.id.favorite_icon_imageview); TextView tabTitleTextView = currentTabView.findViewById(R.id.title_textview); - - //TODO - final ProgressBar progressBar = findViewById(R.id.progress_bar); - // Get a handle for the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java index 8ad76d7c..ce7e1a43 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/WebViewTabFragment.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -34,7 +35,7 @@ import com.stoutner.privacybrowser.views.NestedScrollWebView; public class WebViewTabFragment extends Fragment { // The public interface is used to send information back to the parent activity. public interface NewTabListener { - void initializeWebView(NestedScrollWebView nestedScrollWebView, int tabNumber); + void initializeWebView(int tabNumber, ProgressBar progressBar, NestedScrollWebView nestedScrollWebView); } // The new tab listener is used in `onAttach()` and `onCreateView()`. @@ -78,13 +79,14 @@ public class WebViewTabFragment extends Fragment { int tabNumber = arguments.getInt("tab_number"); // Inflate the tab's WebView. 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 tabView = layoutInflater.inflate(R.layout.nestedscroll_webview, container, false); + View tabView = layoutInflater.inflate(R.layout.webview_framelayout, container, false); // Get a handle for the nested scroll WebView. NestedScrollWebView nestedScrollWebView = tabView.findViewById(R.id.nestedscroll_webview); + ProgressBar progressBar = tabView.findViewById(R.id.progress_bar); // Request the main activity initialize the WebView. - newTabListener.initializeWebView(nestedScrollWebView, tabNumber); + newTabListener.initializeWebView(tabNumber, progressBar, nestedScrollWebView); // Return the tab view. return tabView; diff --git a/app/src/main/res/layout/main_framelayout.xml b/app/src/main/res/layout/main_framelayout.xml index b04c6bc8..070eb559 100644 --- a/app/src/main/res/layout/main_framelayout.xml +++ b/app/src/main/res/layout/main_framelayout.xml @@ -86,7 +86,7 @@ android:paddingStart="15dp" android:paddingEnd="15dp" android:src="@drawable/add_light" - android:tint="@color/gray_700" + android:tint="?attr/addTabIconTintColor" android:onClick="addTab" android:contentDescription="@string/add_tab" /> @@ -167,30 +167,10 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" > - - - - - - - diff --git a/app/src/main/res/layout/nestedscroll_webview.xml b/app/src/main/res/layout/nestedscroll_webview.xml deleted file mode 100644 index 3ece03d3..00000000 --- a/app/src/main/res/layout/nestedscroll_webview.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/webview_framelayout.xml b/app/src/main/res/layout/webview_framelayout.xml new file mode 100644 index 00000000..27e62773 --- /dev/null +++ b/app/src/main/res/layout/webview_framelayout.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index a22b10c3..d884248c 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -24,14 +24,15 @@