Skip to content

Commit

Permalink
Removed buggy swipe refresh layout and added reload button to top too…
Browse files Browse the repository at this point in the history
…lbar
  • Loading branch information
vanitasvitae committed Aug 7, 2016
1 parent e1b02c4 commit 9ecf55c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ActionMenuView;
Expand Down Expand Up @@ -73,6 +72,7 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -136,8 +136,8 @@ public class MainActivity extends AppCompatActivity
/**
* UI Bindings
*/
@BindView(R.id.swipe)
SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.content_layout)
RelativeLayout contentLayout;

@BindView(R.id.progressBar)
ProgressBar progressBar;
Expand Down Expand Up @@ -206,7 +206,7 @@ public boolean onMenuItemClick(MenuItem item) {

//Setup snackbar
snackbarExitApp = Snackbar
.make(swipeRefreshLayout, R.string.confirm_exit, Snackbar.LENGTH_LONG)
.make(contentLayout, R.string.confirm_exit, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -215,28 +215,25 @@ public void onClick(View view) {
}
});
snackbarNewNotification = Snackbar
.make(swipeRefreshLayout, R.string.new_notifications, Snackbar.LENGTH_LONG)
.make(contentLayout, R.string.new_notifications, Snackbar.LENGTH_LONG)
.setAction(android.R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Helpers.isOnline(MainActivity.this)) {
webView.loadUrl("https://" + podDomain + "/notifications");
} else {
Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG).show();
}
}
});
snackbarNoInternet = Snackbar.make(swipeRefreshLayout, R.string.no_internet, Snackbar.LENGTH_LONG);
snackbarNoInternet = Snackbar.make(contentLayout, R.string.no_internet, Snackbar.LENGTH_LONG);

// Load app settings
setupNavigationSlider();

progressBar = (ProgressBar) findViewById(R.id.progressBar);
podDomain = appSettings.getPodDomain();

swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,
R.color.fab_big);

String url = "https://" + podDomain;
if (savedInstanceState == null) {
if (Helpers.isOnline(MainActivity.this)) {
Expand Down Expand Up @@ -291,20 +288,9 @@ private void setupWebView(Bundle savedInstanceState) {
/*
* WebViewClient
*/
webViewClient = new CustomWebViewClient(app, swipeRefreshLayout, webView);
webViewClient = new CustomWebViewClient(app, webView);
webView.setWebViewClient(webViewClient);

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (Helpers.isOnline(MainActivity.this)) {
webView.reload();
} else {
snackbarNoInternet.show();
swipeRefreshLayout.setRefreshing(false);
}
}
});

/*
* WebChromeClient
Expand Down Expand Up @@ -345,7 +331,7 @@ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathC
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
Snackbar.make(swipeRefreshLayout, R.string.unable_to_load_image, Snackbar.LENGTH_LONG).show();
Snackbar.make(contentLayout, R.string.unable_to_load_image, Snackbar.LENGTH_LONG).show();
return false;
}

Expand Down Expand Up @@ -634,6 +620,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

case R.id.action_reload: {
if(Helpers.isOnline(MainActivity.this)) {
webView.reload();
return true;
} else {
snackbarNoInternet.show();
return false;
}
}

case R.id.action_exit: {
moveTaskToBack(true);
finish();
Expand Down Expand Up @@ -701,7 +697,7 @@ public void onClick(DialogInterface dialog, int which) {
String cleanTag = inputTag.replaceAll(wasClickedOnSearchForPeople ? "\\*" : "\\#", "");
// this validate the input data for tagfind
if (cleanTag == null || cleanTag.equals("")) {
Snackbar.make(swipeRefreshLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag
if (wasClickedOnSearchForPeople) {
webView.loadUrl("https://" + podDomain + "/people.mobile?q=" + cleanTag);
Expand Down Expand Up @@ -785,7 +781,7 @@ public void onClick(DialogInterface dialog, int which) {
}

if (!hasToShareScreenshot) {
Snackbar.make(swipeRefreshLayout, getString(R.string.share__toast_screenshot) + " " + fileSaveName, Snackbar.LENGTH_LONG).show();
Snackbar.make(contentLayout, getString(R.string.share__toast_screenshot) + " " + fileSaveName, Snackbar.LENGTH_LONG).show();
}

Bitmap bitmap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand All @@ -30,12 +29,10 @@

public class CustomWebViewClient extends WebViewClient {
private App app;
private SwipeRefreshLayout swipeRefreshLayout;
private WebView webView;

public CustomWebViewClient(App app, SwipeRefreshLayout swipeRefreshLayout, WebView webView) {
public CustomWebViewClient(App app, WebView webView) {
this.app = app;
this.swipeRefreshLayout = swipeRefreshLayout;
this.webView = webView;
}

Expand All @@ -49,18 +46,8 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
swipeRefreshLayout.setEnabled(true);
if(url.contains(app.getSettings().getPodDomain()+"/conversations/") || url.endsWith("status_messages/new") || url.equals("about:blank")){
swipeRefreshLayout.setEnabled(false);
}
}

public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
swipeRefreshLayout.setRefreshing(false);

final CookieManager cookieManager = app.getCookieManager();
String cookies = cookieManager.getCookie(url);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 10 additions & 17 deletions app/src/main/res/layout/main__content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activity.MainActivity"
tools:showIn="@layout/main__app_bar">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<com.github.dfa.diaspora_android.ui.ContextMenuWebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />

</android.support.v4.widget.SwipeRefreshLayout>
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />

<ProgressBar
android:id="@+id/progressBar"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/main__menu_top.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
android:title="@string/conversations"
app:showAsAction="always" />

<item
android:id="@+id/action_reload"
android:icon="@drawable/ic_refresh_white_24dp"
android:title="@string/reload"
app:showAsAction="always"/>

</menu>

0 comments on commit 9ecf55c

Please sign in to comment.