indent preformatted text by 4 spaces
/**
-
The [ViewModel] that is attached to the [NewsHomeFragment].
*/
class NewsViewModel : ViewModel() {// The internal MutableLiveData String that stores the most recent response
private val _response = MutableLiveData()// The external immutable LiveData for the response String
val response: LiveData
get() = _response/**
- Call getMarsRealEstateProperties() on init so we can display status immediately.
*/
init {
getMarsRealEstateProperties()
}
/**
-
Sets the value of the status LiveData to the Mars API status.
*/
private fun getMarsRealEstateProperties() {
_response.value = NewsApi.retrofitService.getProperties().enqueue(
object: Callback {
override fun onFailure(call: Call, t: Throwable) {
_response.value = "Failure: " + t.message
}override fun onResponse(call: Call<NewsData>, response: Response<NewsData>) { _response.value = response.body().toString() } }).toString()
}
} - Call getMarsRealEstateProperties() on init so we can display status immediately.
private val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
private val retrofit = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create())
.baseUrl(BASE_URL)
.build()
interface NewsApiService {
@GET(“top-headlines?country=us&apiKey=${API_KEY}”)
fun getProperties():
Call
}
object NewsApi {
val retrofitService : NewsApiService by lazy {
retrofit.create(NewsApiService::class.java) }
}
//Json response from the webservice
//image of how the data appears on my device