Advertisement
Sirallens

kotlin fragment

Jul 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.79 KB | None | 0 0
  1. private fun update()
  2.     {
  3.         // Get status of SW1 and LED1
  4.         val Sprinkle_status = if (switchSprinkle.isChecked) 1 else 0
  5.         val Photo_status = if (switchPhoto.isChecked) 1 else 0
  6.         val url = "https://unlimitedphelotelia.000webhostapp.com/scripts/sync_data.php"
  7.         val jsonObject = JSONObject()
  8.         jsonObject.put("username", "ben")
  9.         jsonObject.put("password", "benpass")
  10.         jsonObject.put("SW1", Sprinkle_status)
  11.         jsonObject.put("SW2", Photo_status)
  12.         jsonObject.put("sender", "ANDROID")
  13.         Toast.makeText(this, jsonObject.toString(), Toast.LENGTH_LONG).show()
  14.  
  15.         val jsonObjectRequest = JsonObjectRequest(Request.Method.POST, url,
  16.                 jsonObject,
  17.                 Response.Listener<JSONObject> {response ->
  18.  
  19.                     if (response["success"] == 1) {
  20.  
  21.                         switchRain.text = response.toString()
  22.  
  23.  
  24.                         // Set the statuses to the ones received
  25.                         //refreshSwitch = false
  26.                         //switchRain.isChecked = (response.get("rain") == 1)
  27.                         //switchMotion.isChecked = (response.get("motion") == 1)
  28.                         //refreshSwitch = true
  29.                         //Toast.makeText(this, "It succeeded!",
  30.                           //      Toast.LENGTH_LONG).show()
  31.                     }
  32.                     else
  33.                     {
  34.                         Toast.makeText(this, "It failed...",
  35.                                 Toast.LENGTH_LONG).show()
  36.                     }
  37.                 },
  38.                 Response.ErrorListener {
  39.                     Toast.makeText(this, it.toString(), Toast.LENGTH_LONG).show()
  40.  
  41.                 })
  42.  
  43.  
  44.  
  45.         Volley.newRequestQueue(this).add(jsonObjectRequest)
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement