package com.azhar.alquran.viewmodel import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.azhar.alquran.model.nearby.ModelResults import com.azhar.alquran.model.response.ModelResultNearby import com.azhar.alquran.networking.ApiInterface import com.azhar.alquran.networking.ApiMaps import retrofit2.Call import retrofit2.Callback import retrofit2.Response import java.util.* /** * Created by Azhar Rivaldi on 10-11-2021 * Youtube Channel : https://bit.ly/2PJMowZ * Github : https://github.com/AzharRivaldi * Twitter : https://twitter.com/azharrvldi_ * Instagram : https://www.instagram.com/azhardvls_ * LinkedIn : https://www.linkedin.com/in/azhar-rivaldi */ class MasjidViewModel : ViewModel() { private val modelResultsMutableLiveData = MutableLiveData>() var strApiKey = "YOUR API KEY" fun setMarkerLocation(strLocation: String) { val apiService: ApiInterface = ApiMaps.getMaps() val call = apiService.getDataResult(strApiKey, "Masjid", strLocation, "distance") call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (!response.isSuccessful) { Log.e("response", response.toString()) } else if (response.body() != null) { val items = ArrayList(response.body()?.modelResults) modelResultsMutableLiveData.postValue(items) } } override fun onFailure(call: Call, t: Throwable) { Log.e("failure", t.toString()) } }) } fun getMarkerLocation(): LiveData> = modelResultsMutableLiveData }