package com.bbitcn.silk.base;

import android.app.Application;

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

/**
 * @Description ViewModel 逻辑层
 * @Author DuanKaiji
 * @CreateTime 2024年01月17日 09:32
 */
public class BasePresenter extends AndroidViewModel {

    private MutableLiveData<String> isLoadingLiveData = new MutableLiveData<>();
    private MutableLiveData<String> errorTips = new MutableLiveData<>();
    private MutableLiveData<String> successTips = new MutableLiveData<>();
    public BasePresenter(@NonNull Application application) {
        super(application);
    }
    public MutableLiveData<String> getIsLoadingLiveData() {
        return isLoadingLiveData;
    }

    public MutableLiveData<String> getErrorTips() {
        return errorTips;
    }

    public MutableLiveData<String> getSuccessTips() {
        return successTips;
    }

    public void showLoadingDialog(String content) {
        isLoadingLiveData.setValue(content);
    }

    public void showLoadingDialogInIO(String content) {
        isLoadingLiveData.postValue(content);
    }

    public void hideLoadingDialog() {
        isLoadingLiveData.setValue(null);
    }

    public void errorTips() {
        errorTips(null);
    }

    public void errorTips(String msg) {
        errorTips.setValue(msg);
    }

    public void successTips() {
        successTips(null);
    }

    public void successTips(String msg) {
        successTips.setValue(msg);
    }

    public String getString(int id) {
        return getApplication().getString(id);
    }
}
