Skip to content

Instantly share code, notes, and snippets.

@kassim
kassim / RxBottomSheetDialogFragment.kt
Created Nov 23, 2017
an addition to RxLifecycle for a BottomSheetDialogFragment
View RxBottomSheetDialogFragment.kt
import android.os.Bundle
import android.support.annotation.CallSuper
import android.support.annotation.CheckResult
import android.support.design.widget.BottomSheetDialogFragment
import android.view.View
import com.trello.rxlifecycle2.LifecycleProvider
import com.trello.rxlifecycle2.LifecycleTransformer
import com.trello.rxlifecycle2.RxLifecycle
import com.trello.rxlifecycle2.android.FragmentEvent
import com.trello.rxlifecycle2.android.RxLifecycleAndroid
@kassim
kassim / BottomPaddingDecoration.java
Created Sep 13, 2017
Adds padding to the bottom of a RecyclerView's contents
View BottomPaddingDecoration.java
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class BottomPaddingDecoration extends RecyclerView.ItemDecoration {
private final int bottomPadding;
public BottomPaddingDecoration(int bottomPadding) {
this.bottomPadding = bottomPadding;
}
@kassim
kassim / SingleValueRelay.java
Created Jun 26, 2017
an RxRelay BehaviorRelay wrapper that only allows a value to be added once
View SingleValueRelay.java
package com.jakewharton.rxrelay2;
import io.reactivex.Observer;
public class SingleValueRelay<T> extends Relay<T> {
private final BehaviorRelay<T> behaviorRelay = BehaviorRelay.create();
public SingleValueRelay() {}
@kassim
kassim / ListWrapper.java
Created May 10, 2017
Wrapper for a List, that implements List
View ListWrapper.java
import android.support.annotation.NonNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class ListWrapper<T> implements List<T> {
private final List<T> list;
@kassim
kassim / CalligraphyTextInputLayout.java
Last active Oct 25, 2018
TextInputLayout for use with Calligraphy that supports a fontPath defined by the hintTextAppearance attribute
View CalligraphyTextInputLayout.java
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.support.design.widget.TextInputLayout;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
@kassim
kassim / NullSafe.java
Created May 6, 2016
Collection of null-safe methods, consisting of a few `isEmpty()` checks and a `equals()` check
View NullSafe.java
import java.util.Collection;
import java.util.Map;
public class NullSafe {
public static boolean isEmpty(Collection<?> collection) {
return collection == null || collection.isEmpty();
}
public static boolean isEmpty(Map<?, ?> map) {
@kassim
kassim / DbCompat.java
Last active Mar 7, 2016
A support method for the API 11 method Cursor.getType(int i) - for a cursor retuned by an SQL query
View DbCompat.java
public class DbCompat {
protected static final int FIELD_TYPE_BLOB = 4;
protected static final int FIELD_TYPE_FLOAT = 2;
protected static final int FIELD_TYPE_INTEGER = 1;
protected static final int FIELD_TYPE_NULL = 0;
protected static final int FIELD_TYPE_STRING = 3;
public static int getType(Cursor cursor, int i) throws Exception {
SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;