Instantly share code, notes, and snippets.

Embed
What would you like to do?
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