1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Removed buggy swipe refresh layout and added reload button to top toolbar

This commit is contained in:
vanitasvitae 2016-08-07 23:11:47 +02:00
parent e1b02c42d2
commit 9ecf55ca82
9 changed files with 38 additions and 56 deletions

View file

@ -45,7 +45,6 @@ import android.support.design.widget.Snackbar;
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;
@ -73,6 +72,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -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;
@ -206,7 +206,7 @@ public class MainActivity extends AppCompatActivity
//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) {
@ -215,18 +215,18 @@ public class MainActivity extends AppCompatActivity
}
});
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();
@ -234,9 +234,6 @@ public class MainActivity extends AppCompatActivity
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)) {
@ -291,20 +288,9 @@ public class MainActivity extends AppCompatActivity
/*
* 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
@ -345,7 +331,7 @@ public class MainActivity extends AppCompatActivity
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;
}
@ -634,6 +620,16 @@ public class MainActivity extends AppCompatActivity
}
}
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();
@ -701,7 +697,7 @@ public class MainActivity extends AppCompatActivity
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);
@ -785,7 +781,7 @@ public class MainActivity extends AppCompatActivity
}
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;

View file

@ -21,7 +21,6 @@ package com.github.dfa.diaspora_android.ui;
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;
@ -30,12 +29,10 @@ import com.github.dfa.diaspora_android.App;
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;
}
@ -49,18 +46,8 @@ public class CustomWebViewClient extends WebViewClient {
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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

View file

@ -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"

View file

@ -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>