package cgmblelib.database.livedata;


import androidx.annotation.MainThread;
import androidx.lifecycle.LiveData;

import cgmblelib.database.entity.PocDevice;

/**
 * Created by minyuchun on 2019/10/23.
 * 用户在Service中获取设备信息变化
 * @author minyuchun
 */

public class LatestDeviceLiveData extends LiveData<PocDevice> {

    private static LatestDeviceLiveData sInstance;

    private SimpleDeviceListener mListener;

    public void setListener(SimpleDeviceListener listener) {
        mListener = listener;
    }

    private LatestDeviceLiveData() {

    }

    @MainThread
    public static LatestDeviceLiveData get() {
        if (sInstance == null) {
            sInstance = new LatestDeviceLiveData();
        }
        return sInstance;
    }


    @Override
    protected void onActive() {
        super.onActive();

    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    public interface LatestDeviceListener{
        void change(PocDevice device);
    }


    public void set(PocDevice device){
        setValue(device);
    }


    interface SimpleDeviceListener{
        void onDeviceChanged(PocDevice device);
    }
}
