This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.MediatorLiveData | |
class BiSourceMergerLiveData<T, U, R>( | |
source1: LiveData<T>, | |
source2: LiveData<U>, | |
block: (T?, U?) -> R? | |
) : MediatorLiveData<R>() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Event<out T>(private val data: T) { | |
/** | |
* Collection of distinct scopes this [Event] has been consumed with | |
*/ | |
private val consumedScopes by lazy { hashSetOf<String>() } | |
/** | |
* Checks if this [Event] is consumed for the given scope | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiComparator<T> implements Comparator<T> { | |
private final List<Comparator<T>> comparators; | |
public MultiComparator(List<Comparator<T>> comparators) { | |
this.comparators = comparators; | |
} | |
public MultiComparator(Comparator<T>... comparators) { | |
this(Arrays.asList(comparators)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DividerItemDecorator extends ItemDecoration { | |
public static final int HORIZONTAL = LinearLayout.HORIZONTAL; | |
public static final int VERTICAL = LinearLayout.VERTICAL; | |
private Drawable mDivider; | |
private int mOrientation; | |
private final Rect mBounds = new Rect(); | |
public DividerItemDecorator(Drawable divider, int orientation) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void attachSnapHelper(RecyclerView recyclerView, final RecyclerView.LayoutManager layoutManager) { | |
final SnapHelper snapHelper = new LinearSnapHelper(); | |
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | |
boolean mScrolled = false; | |
int snapPosition; | |
@Override | |
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | |
super.onScrollStateChanged(recyclerView, newState); |