That fuck shit the fascists are using
at master 37 lines 775 B view raw
1package org.tm.archive.util; 2 3import androidx.lifecycle.MutableLiveData; 4 5import org.signal.core.util.StreamUtil; 6 7import java.io.Closeable; 8 9/** 10 * Implementation of {@link androidx.lifecycle.LiveData} that will handle closing the contained 11 * {@link Closeable} when the value changes. 12 */ 13public class CloseableLiveData<E extends Closeable> extends MutableLiveData<E> { 14 15 @Override 16 public void setValue(E value) { 17 setValue(value, true); 18 } 19 20 public void setValue(E value, boolean closePrevious) { 21 E previous = getValue(); 22 23 if (previous != null && closePrevious) { 24 StreamUtil.close(previous); 25 } 26 27 super.setValue(value); 28 } 29 30 public void close() { 31 E value = getValue(); 32 33 if (value != null) { 34 StreamUtil.close(value); 35 } 36 } 37}