package com.atmob.keyboard_android.util.livedata;

import androidx.lifecycle.MutableLiveData;

import java.util.Objects;

/**
 * 带去重功能的LiveData，如果新值和当前值一致时，不会触发观察者
 */
public class DistinctMutableLiveData<T> extends MutableLiveData<T> {
    public DistinctMutableLiveData(T value) {
        super(value);
    }

    @Override
    public void setValue(T value) {
        T currentValue = getValue();
        if (Objects.equals(currentValue, value)) {
            return;
        }
        super.setValue(value);
    }
}