Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added swipe down to refresh #89

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +113,7 @@ public abstract class BaseFacebookWebViewActivity extends Activity implements
protected WebSettings mWebSettings = null;
protected ValueCallback<Uri> mUploadMessage = null;
protected ValueCallback<Uri[]> mUploadMessageLollipop = null;
protected SwipeRefreshLayout mSwipeRefreshLayout = null;
private boolean mCreatingActivity = true;
private String mPendingImageUrlToSave = null;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions app/src/main/res/layout/main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Our actual WebView -->
<com.danvelazco.fbwrapper.webview.FacebookWebView
android:id="@+id/webview"
android:layout_width="match_parent"
<!--This is for swipe down to refresh -->
<android.support.v4.widget.SwipeRefreshLayout
android:layout_height="match_parent"
android:fadeScrollbars="true"
android:focusable="true"
android:focusableInTouchMode="true" />
android:layout_width="match_parent"
android:id="@+id/swiperefreshlayout" >
<!-- Our actual WebView -->
<com.danvelazco.fbwrapper.webview.FacebookWebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</android.support.v4.widget.SwipeRefreshLayout>

<!-- Progress bar used to show the loading progress -->
<ProgressBar
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@
<color name="blue_primary_dark">#ff293c68</color>
<color name="blue_accent">#738ffe</color>

<color name="swipe_color_1">#33B5E5</color>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the google colors? Wouldn't be using something like blue_accent with blue_primary better looking?

<color name="swipe_color_2">#99CC00</color>
<color name="swipe_color_3">#FFBB33</color>
<color name="swipe_color_4">#FF4444</color>

</resources>