Skip to content

Instantly share code, notes, and snippets.

View aballano's full-sized avatar
🏠
Working from home

Alberto Ballano aballano

🏠
Working from home
View GitHub Profile
@aballano
aballano / WrapHeightViewPager.java
Created October 23, 2015 23:50
Dynamic view pager which sets it´s height to the maximum size of it´s children if set to wrap_content.
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by Shyish on 11/10/2015.
*/

Keybase proof

I hereby claim:

  • I am aballano on github.
  • I am shyish (https://keybase.io/shyish) on keybase.
  • I have a public key whose fingerprint is 7A8E 75FD 9052 EDC5 1477 A839 53E8 B507 F7EF 6CE4

To claim this, I am signing this object:

@aballano
aballano / RecyclerViewItemLongClickOnSubscribe.java
Last active June 14, 2018 19:54
Create an observable of long click events on RecyclerView items (refer to RxBinding tests for the whole picture).
import android.support.v7.widget.RecyclerView;
import android.view.View;
import rx.Observable;
import rx.Subscriber;
import rx.android.MainThreadSubscription;
import static rx.android.MainThreadSubscription.verifyMainThread;
final class RecyclerViewItemLongClickOnSubscribe implements Observable.OnSubscribe<Integer> {
@aballano
aballano / RxSnackbarTest.java
Last active February 17, 2017 13:28
Create an observable which emits the action clicked events from a Snackbar.
@RunWith(AndroidJUnit4.class)
public final class RxSnackbarTest {
@Rule public final ActivityTestRule<RxSnackbarTestActivity> activityRule =
new ActivityTestRule<>(RxSnackbarTestActivity.class);
private Snackbar view;
@Before public void setUp() {
RxSnackbarTestActivity activity = activityRule.getActivity();
view = activity.snackbar;
public static Observable<Integer> itemLongClick(RecyclerView view) {
return Observable.create(new RecyclerViewItemLongClickOnSubscribe(view));
}
@Override public Observable<Integer> bindRecyclerViewLongClickToObservable() {
return RxRecycler.itemLongClick(recyclerView));
}
public void onDeleteChatAt(int id) {
interactor.deleteChat(id)
.subscribe(() -> view.removeChat(id), logError())
}
@aballano
aballano / View.java
Last active November 18, 2016 10:18
@Override public Observable showDeleteFailedWithRetry() {
Snackbar snackbar = Snackbar.make(rootView, "Can't delete chat", Snackbar.LENGTH_LONG);
Observable<Integer> observable = RxSnackbar.actionClicked(snackbar, "Retry"));
snackbar.show();
return observable;
}
public void onDeleteChatAt(int id) {
interactor.deleteChat(id)
.retryWhen(errors -> view.showDeleteFailedWithRetry())
.subscribe(() -> view.removeChat(id), logError())
}
public void onDeleteChatAt(int id) {
interactor.deleteChat(id)
.retryWhen(errors -> errors.flatMap(error -> view.showDeleteFailedWithRetry()))
.subscribe(() -> view.removeChat(id), logError())
}