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
Display Wikis as HTML in a WebView #2815
Conversation
CometDog
commented
Jul 8, 2018
•
edited
edited
- 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
d2c980e
to
8e47596
Compare
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; | ||
} | ||
|
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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
Show Wikis in WebView
8e47596
to
1b3f595
Compare
Looks great, amazing work! We're lucky to have you helping out with Slide :) |