Emil Kantis
Jan
Gaurav Tyagi
T
data class NewsData ( val author: String, val title: String, val url: String, val publishedAt: String )
class NewsViewModel : ViewModel() { // The internal MutableLiveData String that stores the most recent response private val _response = MutableLiveData<String>() // The external immutable LiveData for the response String val response: LiveData<String> get() = _response /** * Call getNewsData() on init so we can display status immediately. */ init { getNewsData() } /** * Sets the value of the status LiveData to the News API status. */ private fun getNewsData() { _response.value = NewsApi.retrofitService.getProperties().enqueue( object : Callback<ResponseBody> { override fun onFailure(call: Call<ResponseBody>, t: Throwable) { _response.value = "Failure: " + t.message //Log.i("response", t.message) } override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { val root = JSONObject(response.body().toString()) val jsonArr = root.getJSONArray("articles") val ob = jsonArr.getJSONObject(0) val name = ob.getString("author") _response.value = name } }).toString() } }
nkiesel
Shivam Kanodia
John Aoussou
Shivam Dhuria
debounce
fullNameFlow
//This is inside a Composable val fullNameFlow = MutableStateFlow("") fullNameFlow.debounce(3000).mapLatest { Log.i(TAG,it) //Change Composable State } FormTextField( onValueChange = { fullNameFlow.value = it } )
iamkdblue
Fudge
A modern programming language that makes developers happier.