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

Reduce messages by broadcast

This commit is contained in:
Gregor Santner 2016-12-18 16:10:48 +01:00
parent 175125996e
commit 05e6e4d2bd
No known key found for this signature in database
GPG key ID: 2AEB822A5CF48C9F
6 changed files with 25 additions and 13 deletions

View file

@ -332,7 +332,6 @@ public class DiasporaStreamFragment extends BrowserFragment {
@JavascriptInterface
public void setUserProfile(final String webMessage) throws JSONException {
final DiasporaUserProfile pup = ((App) getActivity().getApplication()).getDiasporaUserProfile();
AppLog.spam(this, "StreamFragment.JavaScriptInterface.setUserProfile()");
if (pup.isRefreshNeeded()) {
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
pup.parseJson(webMessage);
@ -341,8 +340,6 @@ public class DiasporaStreamFragment extends BrowserFragment {
pup.analyzeUrl(webView.getUrl());
}
});
} else {
AppLog.spam(this, "No DiasporaUserProfile refresh needed");
}
}

View file

@ -58,7 +58,7 @@ public class ContextMenuWebView extends NestedWebView {
private final Context context;
private Activity parentActivity;
private String lasLoadUrl = "";
private String lastLoadUrl = "";
public ContextMenuWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@ -226,14 +226,7 @@ public class ContextMenuWebView extends NestedWebView {
@Override
public void loadUrl(String url) {
super.loadUrl(url);
// Don't spam intents ;)
if (!lasLoadUrl.equals(url)) {
Intent updateActivityTitleIntent = new Intent(MainActivity.ACTION_UPDATE_TITLE_FROM_URL);
updateActivityTitleIntent.putExtra(MainActivity.EXTRA_URL, getUrl());
LocalBroadcastManager.getInstance(context).sendBroadcast(updateActivityTitleIntent);
}
lasLoadUrl = url;
WebHelper.sendUpdateTitleByUrlIntent(url, getContext());
}
public void setParentActivity(Activity activity) {

View file

@ -29,6 +29,7 @@ import com.github.dfa.diaspora_android.activity.MainActivity;
public class CustomWebViewClient extends WebViewClient {
private final App app;
private String lastLoadUrl ="";
public CustomWebViewClient(App app, WebView webView) {
this.app = app;

View file

@ -45,6 +45,7 @@ public class DiasporaStreamWebChromeClient extends FileUploadWebChromeClient {
public void onProgressChanged(WebView wv, int progress) {
super.onProgressChanged(wv, progress);
WebHelper.optimizeMobileSiteLayout(wv);
WebHelper.sendUpdateTitleByUrlIntent(wv.getUrl(), wv.getContext());
if (progress > 0 && progress <= 85) {
WebHelper.getUserProfile(wv);

View file

@ -20,12 +20,16 @@
package com.github.dfa.diaspora_android.web;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v4.content.LocalBroadcastManager;
import android.text.Html;
import android.webkit.URLUtil;
import android.webkit.WebView;
import com.github.dfa.diaspora_android.activity.MainActivity;
/**
* Created by Gregor Santner on 07.08.16.
* https://gsantner.github.io
@ -102,4 +106,20 @@ public class WebHelper {
" }" +
"})();");
}
private static String lastUpdateTitleByUrl ="";
public static synchronized void sendUpdateTitleByUrlIntent(String url, Context context){
// Ignore javascript stuff
if (url != null && url.startsWith("javascript:")){
return;
}
// Don't spam intents
if (lastUpdateTitleByUrl != null && !lastUpdateTitleByUrl.equals(url) && url != null) {
Intent updateActivityTitleIntent = new Intent(MainActivity.ACTION_UPDATE_TITLE_FROM_URL);
updateActivityTitleIntent.putExtra(MainActivity.EXTRA_URL, url);
LocalBroadcastManager.getInstance(context).sendBroadcast(updateActivityTitleIntent);
}
lastUpdateTitleByUrl = url;
}
}

View file

@ -113,5 +113,5 @@
<string name="https" translatable="false">https</string>
<string name="pod_address">Pod address</string>
<string name="missing_value">Missing value</string>
<string name="jump_to_last_visited_timestamp_in_stream">Jump to last visited page?</string>
<string name="jump_to_last_visited_timestamp_in_stream">Jump to last visited page in stream?</string>
</resources>