package `in`.zelish.zelish.dish_like import `in`.zelish.zelish.rest.ApiService import `in`.zelish.zelish.rest.Resource import `in`.zelish.zelish.rest.RestClient import android.app.Application import android.content.Context import android.util.Log import androidx.lifecycle.MutableLiveData import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers class DishLikeRepo private constructor(context: Context) { private val mApiService: ApiService private val dishData: MutableLiveData> fun getLikedDishes(userId: String?): MutableLiveData> { dishData.value = Resource.loading("") mApiService.getAllLikedRecipes(userId) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( { response -> dishData.value = Resource.success(response) }, { throwable: Throwable? -> Log.d("ProfileRepo", "getUserDetails ERROR=$throwable") throwable?.printStackTrace() dishData.setValue(Resource.error("", throwable)) } ) return dishData } companion object { private var ourInstance: DishLikeRepo? = null fun getInstance(context: Application): DishLikeRepo? { if (ourInstance == null) { ourInstance = DishLikeRepo(context) } return ourInstance } } init { val mRestClient = RestClient() mApiService = mRestClient.apiService dishData = MutableLiveData() } }