This file contains hidden or 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 static Action1<Throwable> crashOnError() { | |
| final Throwable checkpoint = new Throwable(); | |
| return throwable -> { | |
| StackTraceElement[] stackTrace = checkpoint.getStackTrace(); | |
| StackTraceElement element = stackTrace[1]; // First element after `crashOnError()` | |
| String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)", | |
| element.getClassName(), | |
| element.getMethodName(), | |
| element.getFileName(), | |
| element.getLineNumber()); |
This file contains hidden or 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
| @SuppressWarnings({ "WeakerAccess", "unused" }) public class SQLQueryBuilder { | |
| private static final String STATEMENT_SELECT = "SELECT"; | |
| private static final String STATEMENT_DISTINCT_SELECT = "SELECT DISTINCT"; | |
| private static final String STATEMENT_UPDATE = "UPDATE"; | |
| private static final String STATEMENT_INSERT_INTO = "INSERT INTO"; | |
| private static final String STATEMENT_DELETE = "DELETE FROM"; | |
| private static final String WHERE = "WHERE"; | |
| private static final String FROM = "FROM"; |
This file contains hidden or 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 BetterRecyclerView extends RecyclerView{ | |
| private static final int INVALID_POINTER = -1; | |
| private int mScrollPointerId = INVALID_POINTER; | |
| private int mInitialTouchX, mInitialTouchY; | |
| private int mTouchSlop; | |
| public BetterRecyclerView(Context context) { | |
| this(context, null); | |
| } | |
| public BetterRecyclerView(Context context, @Nullable AttributeSet attrs) { |
This file contains hidden or 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 android.support.v4.app.Fragment | |
| import org.jetbrains.anko.bundleOf | |
| /** | |
| * Pass arguments to a Fragment without the hassle of | |
| * creating a static newInstance() method for every Fragment. | |
| * | |
| * Declared outside any class to have full access in any | |
| * part of your package. | |
| * |
This file contains hidden or 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 android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.IntentFilter; | |
| import android.os.Build; | |
| import android.os.PowerManager; | |
| import android.support.annotation.NonNull; | |
| import android.support.v4.view.ViewCompat; | |
| import android.view.View; |
This file contains hidden or 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 android.animation.TypeEvaluator; | |
| import android.animation.ValueAnimator; | |
| import static java.lang.Math.pow; | |
| public class GammaEvaluator implements TypeEvaluator { | |
| private static final GammaEvaluator sInstance = new GammaEvaluator(); | |
| /** |
This file contains hidden or 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 android.support.v7.widget.RecyclerView | |
| import android.view.View | |
| interface OnItemClickListener { | |
| fun onItemClicked(position: Int, view: View) | |
| } | |
| fun RecyclerView.addOnItemClickListener(onClickListener: OnItemClickListener) { | |
| this.addOnChildAttachStateChangeListener(object: RecyclerView.OnChildAttachStateChangeListener { | |
| override fun onChildViewDetachedFromWindow(view: View?) { |
This file contains hidden or 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
| fun BriteDatabase.createQuery(query: SqlDelightStatement) = createQuery(query.tables, query.statement, *query.args) | |
| inline fun <T: SqlDelightCompiledStatement> BriteDatabase.bindAndExecute(compiledStatement: T, bind: T.() -> Unit): Long { | |
| synchronized(compiledStatement) { | |
| compiledStatement.bind() | |
| return when (compiledStatement) { | |
| is SqlDelightCompiledStatement.Insert -> { | |
| executeInsert(compiledStatement.table, compiledStatement.program) | |
| } | |
| is SqlDelightCompiledStatement.Update -> { |
This file contains hidden or 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 com.squareup.moshi.JsonAdapter; | |
| import com.squareup.moshi.JsonDataException; | |
| import com.squareup.moshi.JsonReader; | |
| import com.squareup.moshi.JsonWriter; | |
| import com.squareup.moshi.Moshi; | |
| import com.squareup.moshi.Types; | |
| import java.io.IOException; | |
| import java.lang.annotation.Annotation; | |
| import java.lang.reflect.Type; | |
| import java.util.LinkedHashMap; |
This file contains hidden or 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 Observable<SearchResult> search(@NotNull EditText searchView) { | |
| return RxTextView.textChanges(searchView) // In production, share this text view observable, don't create a new one each time | |
| .map(CharSequence::toString) | |
| .debounce(500, TimeUnit.MILLISECONDS) // Avoid getting spammed with key stroke changes | |
| .filter(s -> s.length() > 1) // Only interested in queries of length greater than 1 | |
| .observeOn(workerScheduler) // Next set of operations will be network so switch to an IO Scheduler (or worker) | |
| .switchMap(query -> searchService.query(query) // Take the latest observable from upstream and unsubscribe from any previous subscriptions | |
| .onErrorResumeNext(Observable.empty()); // <-- This fixes the problem since the error is not seen by the upstream observable | |
| } |