Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created January 25, 2019 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andijakl/092369476bd08ccd011dc038b9e2ab09 to your computer and use it in GitHub Desktop.
Save andijakl/092369476bd08ccd011dc038b9e2ab09 to your computer and use it in GitHub Desktop.
Functions to perform Add, Delete and Update operations with the web service using Retrofit and Kotlin Coroutines
private fun addPart(partItem: PartData) {
GlobalScope.launch(Dispatchers.Main) {
val webResponse = WebAccess.partsApi.addPartAsync(partItem).await()
Log.d(tag, "Add success: ${webResponse.isSuccessful}")
// TODO: Re-load list for the recycler view
}
}
private fun deletePart(itemId : Long) {
GlobalScope.launch(Dispatchers.Main) {
val webResponse = WebAccess.partsApi.deletePartAsync(itemId).await()
Log.d(tag, "Delete success: ${webResponse.isSuccessful}")
}
}
private fun updatePart(originalItemId: Long, newItem: PartData) {
GlobalScope.launch(Dispatchers.Main) {
val webResponse = WebAccess.partsApi.updatePartAsync(originalItemId, newItem).await()
Log.d(tag, "Update success: ${webResponse.isSuccessful}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment