mirror of
https://github.com/hmalik144/Android-developer-tech-test---Deloitte.git
synced 2025-12-10 02:55:22 +00:00
Update to include variable toast messages based on api calls
This commit is contained in:
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal 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>
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user