Skip to content

Commit

Permalink
Fix blank initial pages when the WebView is (re)created
Browse files Browse the repository at this point in the history
This basically does a refresh call when the HTML is loaded and the
container is first initialised. If the container wasn't ready when a
"display content" call came in, then it ends up loading it here

It's *possible* that some content might refresh the display twice, if
the container initialised refresh coincides with the app setting the
content, so there are two JS #showPageHtml calls after bodyHtml is set.
I'm only mentioning it in case it comes up as a "why's that happening"
issue - it should be rare if it ever happens, and it would only be a
single glitch when the WebView is first initialised

Fixes #653
  • Loading branch information
baka-kaba committed Jan 20, 2019
1 parent 38529cb commit f13558a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Awful.apk/src/main/assets/javascript/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ function containerInit() {
window.addEventListener('awful-scroll-post', function scrollToPost() {
window.topScrollID = window.requestAnimationFrame(scrollPost.bind(null, null));
});

// trigger a page content load, in case some was sent before the container was ready to handle it
loadPageHtml();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.ferg.awfulapp.preferences.AwfulPreferences;
Expand All @@ -12,6 +10,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import timber.log.Timber;

/**
* Created by baka kaba on 23/01/2017.
* <p>
Expand All @@ -21,27 +21,17 @@
* be used in a {@link com.ferg.awfulapp.ThreadDisplayFragment} and needs to react to other UI clicks.
*/
// TODO: 12/02/2017 JS interface methods are called on a separate thread apparently - none of our implementations are thread-safe at all
@WorkerThread
public class WebViewJsInterface {

private static final String TAG = "WebViewJsInterface";

private final Map<String, String> preferences = new ConcurrentHashMap<>();

@NonNull
private String bodyHtml = "";

@Nullable
private AwfulWebView webView = null;
private volatile String bodyHtml = "";

public WebViewJsInterface() {
updatePreferences();
}

void setWebView(@NonNull AwfulWebView webView) {
this.webView = webView;
}

/**
* Updates the JavaScript-accessible preference store from the current values in AwfulPreferences.
*/
Expand Down Expand Up @@ -77,8 +67,6 @@ public final void updatePreferences() {
protected void setCustomPreferences(Map<String, String> preferences) {
}

// TODO: sync for threads? check html -> update html needs to be atomic?

@NonNull
@JavascriptInterface
public final String getBodyHtml() {
Expand All @@ -97,7 +85,7 @@ public String getPreference(String preference) {

@JavascriptInterface
public void debugMessage(final String msg) {
Log.d(TAG, "Awful DEBUG: " + msg);
Timber.d("Awful DEBUG: %s", msg);
}

// TODO: 28/01/2017 work out if any other common interface methods can go in here
Expand Down

0 comments on commit f13558a

Please sign in to comment.