Skip to content

Instantly share code, notes, and snippets.

View lawloretienne's full-sized avatar
💭
Check out the surf report app I'm working on https://pitted.app

Etienne Lawlor lawloretienne

💭
Check out the surf report app I'm working on https://pitted.app
View GitHub Profile

Make two API calls and update in one event

Observable.combineLatest(
    Api.getService(Api.getEndpointUrl()).getUserProfile(SoundcloudConstants.USERNAME),
    Api.getService(Api.getEndpointUrl()).getFavoriteTracks(SoundcloudConstants.USERNAME),
    new Func2<UserProfile, List<Track>, Account>() {
        @Override
        public Account call(UserProfile userProfile, List<Track> tracks) {
            return new Account(userProfile, tracks);
        }
public class CustomViewGroup extends FrameLayout {
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
Timber.d("");
if(event != null){
int keyCode = event.getKeyCode();
if(keyCode == KeyEvent.KEYCODE_BACK){
// hide search suggestions UI
while true; do
    ./adb shell input swipe 100 400 4000 400 400;
done
  • Functional Programming is a model of programming that transform and compose stream of immutable sequences by applying map, filter and reduce. Events are immutable because you can't change history.
  • Reactive Programming is a model of programming focuses on data flow and change propagation.
  • ReactiveX is an API that focuses on asynchronous composition and manipulation of observable streams of data or events by using a combination of the Observer pattern, Iterator pattern, and features of Functional Programming.
  • RxJava is the open-source implementation of ReactiveX in Java.
  • RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.
  • RxAndroid is a lightweight extension to RxJava that providers a Scheduler for Android’s Main Thread, as well as the ability to create a Scheduler that runs on any given Android Handler class.
  • The two main classes are Observable and Subscriber.
  • `O
public class RxImageView extends ImageView {
// region Member Variables
private PublishSubject<Boolean> publishSubject = PublishSubject.create();
// endregion
// region Constructors
public RxImageView(Context context) {
super(context);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = recyclerView.getChildCount();
int totalItemCount = recyclerView.getAdapter().getItemCount();
int[] positions = layoutManager.findFirstVisibleItemPositions(null);
int firstVisibleItem = positions[1];
if (!isLoading && !isLastPage) {
public class NetworkLogUtility {
public static void logFailure(Call call, Throwable throwable){
if(call != null){
if (call.isCanceled())
Timber.e("Request was cancelled");
Request request = call.request();
if(request != null){
HttpUrl httpUrl = request.url();
  • CacheControl.FORCE_CACHE adds an only-if-cache flag and also sets the max-stale to a very high value which overrides the max-stale value.
  • The max-age request directive indicates that the client is unwilling to accept a response whose age is greater than the specified number of seconds. Unless the max-stale request directive is also present, the client is not willing to accept a stale response.
  • The max-stale request directive indicates that the client is willing to accept a response that has exceeded its freshness lifetime. If max-stale is assigned a value, then the client is willing to accept a response that has exceeded its freshness lifetime by no more than the specified number of seconds.
  • The max-age request directive is the oldest that a response can be, as long as the Cache-Control from the origin server indicates that it is still fresh. The max-stale request directive indicates that, even if the response is known to be stale, you will also accept it as long as it's only stale by
@OnClick(R.id.fab)
public void onFiltersButtonClicked(View view) {
Event event = new Event(EventNames.EVENT_FILTERS_FAB_CLICKED, null);
EventLogger.logEvent(event);
if(getActivity().isFinishing())
return;
Intent intent = new Intent(view.getContext(), EventFiltersActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {