package com.hi.music.player.ui.fragmnt.viewmodel;

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

import com.hi.music.player.api.RequestListener;
import com.hi.music.player.helper.CommonUtils;
import com.hi.music.player.javabean.response.ResponseCategoryList;
import com.hi.music.player.javabean.response.ResponseHome;
import com.hi.music.player.javabean.response.ResponsePlayUrl;
import com.hi.music.player.network.JsonHelper;
import com.hi.music.player.network.RetrofitManager;

import org.json.JSONObject;

import okhttp3.ResponseBody;

public class VMCategoryList extends ViewModel {
    private MutableLiveData<ResponseCategoryList> _data = new MutableLiveData<>();
    public LiveData<ResponseCategoryList> 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) {
                    ResponseCategoryList responseCategoryList = JsonHelper.ResolveCategoryList(data,browseId);
                    _data.setValue(responseCategoryList);
                }
            }
        });
    }
}
