mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 12:22:08 +01:00
Reduce messages by broadcast
This commit is contained in:
parent
175125996e
commit
05e6e4d2bd
6 changed files with 25 additions and 13 deletions
|
@ -332,7 +332,6 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void setUserProfile(final String webMessage) throws JSONException {
|
public void setUserProfile(final String webMessage) throws JSONException {
|
||||||
final DiasporaUserProfile pup = ((App) getActivity().getApplication()).getDiasporaUserProfile();
|
final DiasporaUserProfile pup = ((App) getActivity().getApplication()).getDiasporaUserProfile();
|
||||||
AppLog.spam(this, "StreamFragment.JavaScriptInterface.setUserProfile()");
|
|
||||||
if (pup.isRefreshNeeded()) {
|
if (pup.isRefreshNeeded()) {
|
||||||
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
AppLog.v(this, "DiasporaUserProfile needs refresh; Try to parse JSON");
|
||||||
pup.parseJson(webMessage);
|
pup.parseJson(webMessage);
|
||||||
|
@ -341,8 +340,6 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
||||||
pup.analyzeUrl(webView.getUrl());
|
pup.analyzeUrl(webView.getUrl());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
AppLog.spam(this, "No DiasporaUserProfile refresh needed");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Activity parentActivity;
|
private Activity parentActivity;
|
||||||
private String lasLoadUrl = "";
|
private String lastLoadUrl = "";
|
||||||
|
|
||||||
public ContextMenuWebView(Context context, AttributeSet attrs, int defStyle) {
|
public ContextMenuWebView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
@ -226,14 +226,7 @@ public class ContextMenuWebView extends NestedWebView {
|
||||||
@Override
|
@Override
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
super.loadUrl(url);
|
super.loadUrl(url);
|
||||||
|
WebHelper.sendUpdateTitleByUrlIntent(url, getContext());
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParentActivity(Activity activity) {
|
public void setParentActivity(Activity activity) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||||
|
|
||||||
public class CustomWebViewClient extends WebViewClient {
|
public class CustomWebViewClient extends WebViewClient {
|
||||||
private final App app;
|
private final App app;
|
||||||
|
private String lastLoadUrl ="";
|
||||||
|
|
||||||
public CustomWebViewClient(App app, WebView webView) {
|
public CustomWebViewClient(App app, WebView webView) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class DiasporaStreamWebChromeClient extends FileUploadWebChromeClient {
|
||||||
public void onProgressChanged(WebView wv, int progress) {
|
public void onProgressChanged(WebView wv, int progress) {
|
||||||
super.onProgressChanged(wv, progress);
|
super.onProgressChanged(wv, progress);
|
||||||
WebHelper.optimizeMobileSiteLayout(wv);
|
WebHelper.optimizeMobileSiteLayout(wv);
|
||||||
|
WebHelper.sendUpdateTitleByUrlIntent(wv.getUrl(), wv.getContext());
|
||||||
|
|
||||||
if (progress > 0 && progress <= 85) {
|
if (progress > 0 && progress <= 85) {
|
||||||
WebHelper.getUserProfile(wv);
|
WebHelper.getUserProfile(wv);
|
||||||
|
|
|
@ -20,12 +20,16 @@
|
||||||
package com.github.dfa.diaspora_android.web;
|
package com.github.dfa.diaspora_android.web;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.activity.MainActivity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Gregor Santner on 07.08.16.
|
* Created by Gregor Santner on 07.08.16.
|
||||||
* https://gsantner.github.io
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,5 +113,5 @@
|
||||||
<string name="https" translatable="false">https</string>
|
<string name="https" translatable="false">https</string>
|
||||||
<string name="pod_address">Pod address</string>
|
<string name="pod_address">Pod address</string>
|
||||||
<string name="missing_value">Missing value</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>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue