Skip to content

Instantly share code, notes, and snippets.

View pwittchen's full-sized avatar
🎯
Focusing

Piotr Wittchen pwittchen

🎯
Focusing
View GitHub Profile
@Override protected void onPause() {
super.onPause();
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
}
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);
swipe = new Swipe();
subscription = swipe.observe()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
@Override public boolean dispatchTouchEvent(MotionEvent event) {
swipe.dispatchTouchEvent(event);
return super.dispatchTouchEvent(event);
}
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);
swipe = new Swipe();
swipe.addListener(new SwipeListener() {
@Override public void onSwipingLeft(final MotionEvent event) {
info.setText("SWIPING_LEFT");
@pwittchen
pwittchen / find.sh
Last active March 2, 2016 12:15
finding file in the Unix system in entire $HOME directory
find ~/ -type f -name "myfile.xml"
@Override protected void onCreate(Bundle savedInstanceState) {
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
layoutManager = new LinearLayoutManager(this);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(layoutManager);
// set your custom adapter
recyclerView.setAdapter(new MyAdapter(items));
private InfiniteScrollListener createInfiniteScrollListener() {
return new InfiniteScrollListener(maxItemsPerRequest, layoutManager) {
@Override public void onScrolledToEnd(final int firstVisibleItemPosition) {
// load your items here
// logic of loading items will be different depending on your specific use case
// when new items are loaded, combine old and new items, pass them to your adapter
// and call refreshView(...) method from InfiniteScrollListener class to refresh RecyclerView
refreshView(recyclerView, new MyAdapter(items), firstVisibleItemPosition);
}
@pwittchen
pwittchen / EventBus.java
Created February 25, 2016 14:57 — forked from benjchristensen/EventBus.java
EventBus.java
import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;
/**
* Simple pass-thru event bus with error handling and reconnect.
*/
public class EventBus {
@pwittchen
pwittchen / MyAdapter.java
Created February 16, 2016 20:42 — forked from niusounds/MyAdapter.java
How to simplify RecyclerView.Adapter and RecyclerView.ViewHolder
import android.content.Context;
import org.androidannotations.annotations.EBean;
public class MyAdapter extends SimpleListAdapter<String, TextView> {
public MyAdapter(Context ctx) {
super(ctx);
}
@pwittchen
pwittchen / git-merged.sh
Created February 15, 2016 14:33
checking if commit was merged to develop
git rev-list 59848ab..develop --ancestry-path | grep -f <(git rev-list 59848ab..develop --first-parent) | tail -1