Skip to content

Commit

Permalink
Reduce messages by broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Santner committed Dec 18, 2016
1 parent 1751259 commit 05e6e4d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ private class JavaScriptInterface {
@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);
Expand All @@ -341,8 +340,6 @@ public void run() {
pup.analyzeUrl(webView.getUrl());
}
});
} else {
AppLog.spam(this, "No DiasporaUserProfile refresh needed");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -226,14 +226,7 @@ public void loadUrlNew(String url) {
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

public class CustomWebViewClient extends WebViewClient {
private final App app;
private String lastLoadUrl ="";

public CustomWebViewClient(App app, WebView webView) {
this.app = app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public DiasporaStreamWebChromeClient(WebView webView, ProgressBar progressBar, F
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,4 +106,20 @@ public static void shareTextIntoWebView(final WebView webView, String sharedText
" }" +
"})();");
}

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;
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 05e6e4d

Please sign in to comment.