package com.bbitcn.silk.ui.activity;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.bbitcn.silk.base.BasePresenter;
import com.bbitcn.silk.model.net.About;
import com.bbitcn.silk.utils.network.Url;
import com.bbitcn.silk.utils.network.XHttpManager;
import com.bbitcn.silk.utils.network.XHttpShorthand;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * @Author DuanKaiji
 * @CreateTime 2024年4月7日 15:47:42
 */
public class AboutActivityPresenter extends BasePresenter {
    MutableLiveData<About.DataDTO> aboutLiveData = new MutableLiveData<>();

    public AboutActivityPresenter(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<About.DataDTO> getAboutLiveData() {
        return aboutLiveData;
    }

    public void getAboutInfo() {
        showLoadingDialog("正在加载信息");
        RequestParams params = XHttpManager.getInstance().getRequestParams(Url.getAboutInfo, false);
        x.http().get(params, new XHttpShorthand<About>() {
            @Override
            public void success(About model) {
                if (model.getResult()) {
                    aboutLiveData.setValue(model.getData());
                } else {
                    errorTips(model.getMsg());
                }
            }

            @Override
            public void error(Throwable e) {
                errorTips(e.getMessage());
            }

            @Override
            public void myFinish() {
                super.myFinish();
                hideLoadingDialog();
            }
        });

    }
}
