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
internal sealed class UpdateListOperation { | |
object Clear : UpdateListOperation() | |
data class Insert(val newList: List<*>) : UpdateListOperation() | |
} | |
private val updateActor = actor<UpdateListOperation>(UI, CONFLATED, parent = job) { | |
consumeEach { | |
if (!isActive) return@actor |
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
PROMPT='%{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)%{$fg_bold[grey]%}[%*]: %{$reset_color%}' | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}[%{$fg[red]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}●%{$fg_bold[blue]%}]" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}●%{$fg_bold[blue]%}]" |
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 MyActivity : AppCompatActivity { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
val recyclerView = findViewById(R.id.list) as RecyclerView | |
recyclerView.layoutManager = LinearLayoutManager(this) | |
recyclerView.adapter = ExampleAdapter() | |
LinearSnapHelper().attachToRecyclerView(recyclerView) // Configures the snap helper and attaches itself to the recycler view -- now items will snap to the center | |
} | |
} |
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 const val MILLISECONDS_PER_INCH = 100 | |
private const val MAX_SCROLL_ON_FLING_DURATION = 250 // ms | |
override fun createSnapScroller(layoutManager: LayoutManager?): LinearSmoothScroller? { | |
if (layoutManager !is ScrollVectorProvider) return null | |
return object : LinearSmoothScroller(context) { | |
override fun onTargetFound(targetView: View?, state: State?, action: Action?) { | |
if (targetView == null) return | |
val snapDistances = calculateDistanceToFinalSnap(layoutManager, targetView) | |
val dx = snapDistances[0] |
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 var scroller: Scroller? = null | |
private val minX = -2000 | |
private val maxX = 2000 | |
private val minY = -2000 | |
private val maxY = 2000 | |
override fun attachToRecyclerView(recyclerView: RecyclerView?) { | |
scroller = Scroller(recyclerView?.context, DecelerateInterpolator()) | |
super.attachToRecyclerView(recyclerView) | |
} |
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 RxUtils { | |
private RxUtils() { | |
} | |
@NonNull | |
public static Func1<Observable<? extends Throwable>, Observable<?>> retryWithBackoff( | |
final int maxAttempts, final long initialDelay, final TimeUnit unit) { | |
return errors -> errors | |
.zipWith(Observable.range(1, maxAttempts), (error, attempt) -> { | |
if (!isRetryable(error)) { |
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 RxEndlessScroller { | |
interface OnLoadMoreListener { | |
void loadMore(); | |
} | |
private static class EndlessScrollListener extends RecyclerView.OnScrollListener { | |
private final int visibleItemCountThreshold; | |
@Nullable private OnLoadMoreListener loadMoreListener; |
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
# Compiled source # | |
################### | |
*.class | |
# Packages # | |
############ | |
# it's better to unpack these files and commit the raw source | |
# git has its own built in compression methods | |
*.7z | |
*.dmg |
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 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 | |
} |
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 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 will terminate upstream (ie. we will stop receiving text view changes after an error!) | |
} |
NewerOlder