Update to include variable toast messages based on api calls

This commit is contained in:
2019-12-14 22:25:25 +11:00
parent e800824cc1
commit 0e32a65d16
6 changed files with 17 additions and 11 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -10,7 +10,8 @@ import java.net.URL
class AsyncApiCall(
val urlString : String,
val callBack : ResponseListener?
val callBack : ResponseListener?,
val toastErrorString : String
): AsyncTask<String, Void, String>() {
override fun onPreExecute() {
@@ -50,7 +51,7 @@ class AsyncApiCall(
override fun onPostExecute(result: String) {
if (result.isEmpty()){
callBack?.onFailure("Failed to retrieve")
callBack?.onFailure(toastErrorString)
}else{
callBack?.onSuccess()
}

View File

@@ -24,7 +24,8 @@ class CartViewModel(
val response =
AsyncApiCall(
"https://private-anon-21a48b3d0e-ddshop.apiary-mock.com/cart/1",
cartResponseListener
cartResponseListener,
"Failed to delete item"
)
.execute()
.get()
@@ -37,9 +38,4 @@ class CartViewModel(
return response
}
fun getTotalPrice(): String{
return ""
}
}

View File

@@ -26,7 +26,8 @@ class ListViewModel(
val response =
AsyncApiCall(
"https://private-anon-f3c1195210-ddshop.apiary-mock.com/products",
responseListener
responseListener,
"Failed to insert"
)
.execute()
.get()

View File

@@ -25,7 +25,8 @@ class MainViewModel(
val jsonResponse =
AsyncApiCall(
"https://private-anon-f3c1195210-ddshop.apiary-mock.com/products",
responseListener
responseListener,
"Failed To retrieve list"
)
.execute()
.get()

View File

@@ -24,7 +24,8 @@ class WishListViewModel(
val response =
AsyncApiCall(
"https://private-anon-f3c1195210-ddshop.apiary-mock.com/products",
wishResponseListener
wishResponseListener,
"Failed to insert item"
)
.execute()
.get()