Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Wikis as HTML in a WebView #2815

Merged
merged 2 commits into from Jul 13, 2018

Conversation

CometDog
Copy link
Contributor

@CometDog CometDog commented Jul 8, 2018

  • I removed any native implementation for the Wiki rendering. If there is something still hanging out let me know so I can remove it
  • I replaced everything in the layout for the WikiPage with a single webView that just gets the HTML data from the API loaded into it
    • I added a cover over the WebView that hides when the page finishes loading. This is to avoid a white flash before the styles are loaded in
  • The customCss is set on the Wiki activity statically then accessed from the WikiPage. This is the prevent every fragment from recreating it since it only needs created once per subreddit as it is now
    • This CSS only modifies the background color, font color, and idle link text to match the default themes
    • There is a commented out method that makes tables horizontally scrollable in the view but that conflicted with the ViewPager so I commented it out and added a TODO
  • I redid the AsyncTask on the WikiPage because it was in the way too often. It's a static inner class now that does the same thing but "safer"
  • I overrode loading Urls on the WikiPage WebView
    • If the link out of the WikiPage is to itself, it calls a listener up to the Wiki activity to select the correct fragment
    • Otherwise is just tries to open it however it needs to via the app or externally based on the user's browser preferences
    • If it tries to open an embedded WikiPage that does not exist, I show a dialog matching Reddit's error for that situation

@ccrama
Copy link
Collaborator

ccrama commented Jul 9, 2018

This is very awesome! Would it be possible to add a fade in so the white isn't blinding on the initial load?

Thanks again :)

}
return null;
return true;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I found a way to get rid of the white flashes, adding:

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                webView.setBackgroundColor(Color.TRANSPARENT);
                super.onPageStarted(view, url, favicon);
            }

took care of it for me. Might be more performant to set the correct background colour rather than transparent but I couldn't figure out which class to use for that. Seems to be some duplicated things between Palette.java and ColorPreferences.java

private void onDomRetrieved(String dom) {
webView.loadDataWithBaseURL(
wikiUrl,
"<head>".concat(Wiki.getGlobalCustomCss()).concat("</head>").concat(StringEscapeUtils.unescapeHtml4(dom)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the super huge wikis, the majority of the execution time is spent in unescapeHtml4, moving the call into the WikiAsyncTask doInBackground seems to completely alleviate the main thread blocking

@CometDog CometDog force-pushed the feature/display-wikis-as-html branch from 8e47596 to 1b3f595 Compare July 13, 2018 21:04
@ccrama
Copy link
Collaborator

ccrama commented Jul 13, 2018

Looks great, amazing work! We're lucky to have you helping out with Slide :)

@ccrama ccrama merged commit 726e5b0 into Haptic-Apps:master Jul 13, 2018
@CometDog CometDog deleted the feature/display-wikis-as-html branch July 13, 2018 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants