Saturday, October 3, 2015

Content without the Webview

I've always liked the Reader View in Safari browser (and now I believe evry other browser has it)

For those who don't know what Reader View is, it removes all the clutter from a web page and shows only the text and few relevant images.

Before applying the Reader View
After applying the Reader View





















I've been working on an Android application and wanted to implement something like Reader View for the News section in the application. Webview didn't seem to be the perfect solution.

I thought what if I could extract the text from html on the server side and just send the text to the client and then show the text in whatever format I want to show it. This approach also saves the bandwidth for the user, as less data would be downloaded.

I came across this Python library, newspaper, which did exactly which I expected it to do. With just couple of lines of code I could extract the text from the html page. Sample code:

from newspaper import Article

article = Article(url)
article.download()
article.parse()

news['text'] = article.text.encode("utf-8")

I'm using a firebase based server and the extracted text above could be saved directly at the firebase URL. The client simply connects to it and shows the news.

This is how the news looks on the client at the moment. It's implemented using the plain old TextView.


Of course, a lot has to improve still. Time to explore TextView Spannable! 

Links

  • Newspaper Python library: Link
  • Iphone's Reader View: Link

No comments:

Post a Comment