Skip to content

Instantly share code, notes, and snippets.

@kevinnls
Last active August 14, 2020 14:38
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 kevinnls/6463234aab8d431950dba32f8645180e to your computer and use it in GitHub Desktop.
Save kevinnls/6463234aab8d431950dba32f8645180e to your computer and use it in GitHub Desktop.
private fun getResCards() {
val urlAllResCards = "http://13.235.250.119/v2/restaurants/fetch_result/"
val queue = Volley.newRequestQueue(activity as Context)
val allResCardsReq = object : JsonObjectRequest(Method.GET, urlAllResCards, null,
Response.Listener {
val response = it.getJSONObject("data")
if (response.getString("success") == "true") {
val data = response.getJSONArray("data")
for (i in 0 until data.length()) {
val restJsonObject = data.getJSONObject(i)
val restObject = ResEntity(
restJsonObject.getString("id"),
restJsonObject.getString("name"),
restJsonObject.getString("rating"),
restJsonObject.getString("cost_for_one"),
restJsonObject.getString("image_url")
)
DBTasks(activity as Context, 40, restObject).execute()
if (restObject in resList)
continue
else
resList.add(restObject)
}
adapter.notifyDataSetChanged()
progressLay.visibility = View.GONE
}
},
Response.ErrorListener {
makeToast("vollerr")
progressLay.visibility = View.VISIBLE
getResCards()
}) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers["Content-type"] = "application/json"
headers["token"] = "c4d68c99358269"
return headers
}
}
queue.add(allResCardsReq)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment