Skip to content

Instantly share code, notes, and snippets.

Marco Gomiero prof18

Block or report user

Report or block prof18

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View publish.gradle
apply plugin: 'com.jfrog.bintray'
group 'com.your.awesome.lib'
version '1.0.0'
project.ext {
mavGitUrl = ''
mavProjectName = 'AwesomeLib'
mavLibraryLicenses = ["Apache-2.0":'']
mavLibraryDescription = "An Awesome Android library"
View publish.gradle.old
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
group 'com.your.awesome.lib'
version '1.0.0'
publishing {
publications {
Production(MavenPublication) {
artifact("$buildDir/outputs/aar/awesomelibrary-release.aar") {
View RecyclerViewAdapterTemplate.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class ${NAME}(val items: MutableList<${ITEM_CLASS}>) : RecyclerView.Adapter<${NAME}.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.${LAYOUT_RES_ID}, parent, false))
View ViewModel.kt
coroutineScope.launch(Dispatchers.Main) {
try {
val parser = Parser()
val articleList = parser.getArticles(url)
} catch (e: Exception) {
_snackbar.value = "An error has occurred. Please retry"
View ParserCoroutines.kt
suspend fun getArticles(url: String) =
withContext(Dispatchers.IO) {
val xml = async { CoroutineEngine.fetchXML(url) }
return@withContext CoroutineEngine.parseXML(xml)
View CoroutineEngine.kt
object CoroutineEngine {
suspend fun fetchXML(url: String) =
withContext(Dispatchers.IO) {
return@withContext CoreXMLFetcher.fetchXML(url)
suspend fun parseXML(xml: Deferred<String>) =
withContext(Dispatchers.IO) {
View ParserJava.kt
fun execute(url: String) {
val service = Executors.newFixedThreadPool(2)
val f1 = service.submit<String>(XMLFetcher(url))
try {
val rssFeed = f1.get()
val f2 = service.submit(XMLParser(rssFeed))
} catch (e: Exception) {
View XMLFetcher.kt
class XMLFetcher(private val url: String) : Callable<String> {
override fun call(): String {
return CoreXMLFetcher.fetchXML(url)
Parser parser = new Parser();
parser.onFinish(new Parser.OnTaskCompleted() {
//what to do when the parsing is done
public void onTaskCompleted(ArrayList<Article> list) {
//list is an Array List with all article's information
//set the adapter to recycler view
mAdapter = new ArticleAdapter(list, R.layout.row, MainActivity.this);
public class Parser extends AsyncTask<String, Void, String> implements Observer {
private XMLParser xmlParser;
private static ArrayList<Article> articles = new ArrayList<>();
private OnTaskCompleted onComplete;
public Parser() {
xmlParser = new XMLParser();
You can’t perform that action at this time.