Finally, I found some time to sit down and work on my library RSS Parser. Before starting to describe all the cool stuff that I’ve introduced with this update, I want to thank you all for the support. In fact this year, the library exceeded 100 stars on Github, that seems a little goal but it means a lot to me.
I wrote this library back in 2016 and now in 2018, the code was “ugly” compared to all the coolest stuff provided by Kotlin.
So I decided to rewrite the library using Kotlin and Coroutines, so I can (finally) get rid of Async Task.
Of course, I maintained the compatibility of the library for the projects that still use Java.
Shortly, the library allows to parse an RSS feed and retrieve some information like title, content, author, etc. You can found more information about the features of the library in the blog post that I’ve published some time ago or in the README available on Github.
But now let’s see some code. In this article, I’ll show only how to use the library because I’m planning to publish another blog post with all the technical details and decisions that I have made during the development of this new version.
The usage is very simple both if you are using Java or Kotlin. If you are using Kotlin, you need to create a Parser object and then call the suspend method getArticles passing the URL of the RSS feed as parameter. Since this is a suspend function, you need to “launch” the coroutine. Of course, you need also to handle the error case.
Here is an example:
A complete example with Kotlin is available on Github.
If you don’t know anything about the coroutines, I suggest you give a look to the Codelab provided by Google.
Instead, if you are still using Java in your Android project, the usage is pretty the same as the older version of the library. You need to create a Parser object, implements the callbacks that handle the result and the error and finally start the parsing by calling the execute method passing the URL as parameter.
Here is an example:
A complete example in Java is also available on Github.
That’s all! For all the details or to report a bug, please visit the repo on Github.
Published also on Medium