package com.offline.music.playermp3.ui.fragmnt.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.offline.music.playermp3.api.RequestListener;
import com.offline.music.playermp3.javabean.response.ResponseResult;
import com.offline.music.playermp3.network.JsonHelper;
import com.offline.music.playermp3.network.RetrofitManager;

import org.json.JSONObject;

import okhttp3.ResponseBody;

public class VMResultList extends ViewModel {
    private MutableLiveData<ResponseResult> _data = new MutableLiveData<>();
    public LiveData<ResponseResult> data = _data;


    public void getList(String browseId) {

        RetrofitManager.getInstance().getCategoryList(browseId, new RequestListener<ResponseBody>() {
            @Override
            public void onFail(String errorMsg) {
                _data.setValue(null);
            }

            @Override
            public void onSuccess(JSONObject data) {
                if (data != null) {
                    ResponseResult responseResult = JsonHelper.ResolveSearchResultList(data);
                    _data.setValue(responseResult);
                }
            }
        });
    }
}
