Ensure you can't set null values in DefaultValueLiveData.

master
Greyson Parrelli 2020-04-30 12:52:04 -04:00
parent 3b601896d2
commit a2de8a2a05
1 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.util;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import org.whispersystems.libsignal.util.guava.Preconditions;
/**
* Helps prevent all the @Nullable warnings when working with LiveData.
*/
@ -15,6 +17,18 @@ public class DefaultValueLiveData<T> extends MutableLiveData<T> {
this.defaultValue = defaultValue;
}
@Override
public void postValue(@NonNull T value) {
Preconditions.checkNotNull(value);
super.postValue(value);
}
@Override
public void setValue(@NonNull T value) {
Preconditions.checkNotNull(value);
super.setValue(value);
}
@Override
public @NonNull T getValue() {
T value = super.getValue();