0

I am trying to write simple httpclient, and i am trying to figure out how to get data from response. I have two classess:

class HttpClient(private val ctx: Context) {
private var queue: RequestQueue = Volley.newRequestQueue(this.ctx)
private lateinit var gpsModel: GpsModel
companion object {
    const val BASE_URL: String = "https://uawk2yh00j.execute-api.eu-central-1.amazonaws.com/"
}

fun getGpsData() : GpsModel
{
    this.queue.add(
            StringRequest(
                    Request.Method.GET, BASE_URL + "production",
                    {
                        Log.d("GET_ALL_DATA", it.toString())
                        Log.d("GET_ALL_DATA", GpsModel.fromJson(it.toString())?.body?.size.toString())
                        this.gpsModel = GpsModel.fromJson(it.toString())!!
                        Log.d("GET_ALL_DATA", this.gpsModel.toString())
                    },
                    {
                        Log.d("GET_ALL_DATA", "Coś poszło nie tak")
                    }
            )
    )
    return this.gpsModel
}

}

and main activity:

class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

private lateinit var mMap: GoogleMap
private lateinit var httpClient: HttpClient

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_maps)
    this.httpClient = HttpClient(this)
    var gpsModel = this.httpClient.getGpsData()
    Log.d("GET_ALL_DATA", gpsModel.toString())
    val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as SupportMapFragment
    mapFragment.getMapAsync(this)
}

override fun onMapReady(googleMap: GoogleMap) {
}

}

And i would like to know when Request is successfull and when is error, but i dont see any onSuccess or onFailure methods.

River
  • 13
  • 2

1 Answers1

0

I found the answer: Its about creating interface. The link is here: Android Volley - How to isolate requests in another class

River
  • 13
  • 2