diff --git a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java index 63f6532..aefaae3 100644 --- a/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java +++ b/app/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java @@ -36,6 +36,7 @@ import android.os.Bundle; import android.os.Environment; import android.support.annotation.NonNull; +import android.support.v4.widget.SwipeRefreshLayout; import android.text.TextUtils; import android.view.ContextMenu; import android.view.KeyEvent; @@ -112,6 +113,7 @@ public abstract class BaseFacebookWebViewActivity extends Activity implements protected WebSettings mWebSettings = null; protected ValueCallback mUploadMessage = null; protected ValueCallback mUploadMessageLollipop = null; + protected SwipeRefreshLayout mSwipeRefreshLayout = null; private boolean mCreatingActivity = true; private String mPendingImageUrlToSave = null; @@ -169,6 +171,14 @@ public void onCreate(Bundle savedInstanceState) { mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); + mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefreshlayout); + //Sets the different colors the loading indicator will show + mSwipeRefreshLayout.setColorSchemeResources( + R.color.swipe_color_1, R.color.swipe_color_2, + R.color.swipe_color_3, R.color.swipe_color_4); + + setOnSwipeListener(); + // Set the database path for this WebView so that // HTML5 Storage API works properly mWebSettings.setAppCacheEnabled(true); @@ -365,6 +375,18 @@ protected void jumpToTop() { loadNewPage("javascript:window.scrollTo(0,0);"); } + /** + * Sets swiping listener for the swipe refresh layout + */ + private void setOnSwipeListener() { + mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + refreshCurrentPage(); + } + }); + } + /** * Used to change the geolocation flag. * @@ -537,6 +559,11 @@ public void onProgressChanged(WebView view, int progress) { // Hide the progress bar as soon as it goes over 85% if (progress >= 85) { mProgressBar.setVisibility(View.GONE); + + //Checks if the swipe refresh indicator is active. Turns off if it is + if(mSwipeRefreshLayout.isRefreshing()) { + mSwipeRefreshLayout.setRefreshing(false); + } } } diff --git a/app/src/main/res/layout/main_layout.xml b/app/src/main/res/layout/main_layout.xml index bce0f7b..98c0cf3 100644 --- a/app/src/main/res/layout/main_layout.xml +++ b/app/src/main/res/layout/main_layout.xml @@ -27,14 +27,20 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + + android:layout_width="match_parent" + android:id="@+id/swiperefreshlayout" > + + + #ff293c68 #738ffe + #33B5E5 + #99CC00 + #FFBB33 + #FF4444 + \ No newline at end of file