Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
@FireZenk
FireZenk / NetworkFragment.java
Created April 4, 2014 08:16
Android(fragment) abstract class that contains a background thread to handle network connections
package com.firezenk.util;
import android.os.AsyncTask;
import android.util.Log;
import com.actionbarsherlock.app.SherlockFragment;
/**
* NetworkFragment Class
* This class extends SherlockFragment and contains one AsyncTask
@FireZenk
FireZenk / MapperUtils.java
Created October 30, 2015 08:21
Functional programming map-like but in Java
package com.your.package;
import java.util.ArrayList;
import java.util.List;
/**
* MapperUtils Class
*
* Extracted from Facebook Android API by Jorge Garrido Oval <firezenk@gmail.com>
* Use case:

Trying to find a solution

I had a problem getting the new fancy SwipeRefreshLayout from the appcompat lib to work with a custom listview, in this case the StickyListHeaders. Since the First child of the SwipeRefreshLayout should be either a ScrollView or a pure List, some workaround had to be done.

@FireZenk
FireZenk / demo_data_layer.java
Last active October 13, 2016 22:11
Demo snippets from the "Clean Architecture: As we have applied in Mr.Milú" slides
public class Mediator {
public Observable<Auth> login(Login loginModel) {
if (loginStrategy.isAlreadyLogged())
return Observable.from(authCache);
else
return repository.login(loginMapper.toRequest(loginModel))
.map(entity -> authMapper.fromResponse(entity));
}
}
@FireZenk
FireZenk / SchedulerProvider.java
Created January 2, 2017 13:03
UseCase executor, that takes handle use cases, their possible errors and return the subscription
package com.sample.app.ui.schedulers;
import android.support.annotation.NonNull;
import rx.Scheduler;
/**
* Project: app
*
* Created by Jorge Garrido Oval on 01/12/2016.
@FireZenk
FireZenk / CustomActivity.java
Created May 2, 2017 12:34
Synchronizing animations in RecyclerView
@Bind(R.id.my_recyclerview) RecyclerView myList;
private PublishSubject<Long> animationTimer;
private Subscription animationSubscription;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
animationSubscription = Observable.interval(1, TimeUnit.SECONDS)
CustomRendererBuilder rendererBuilder = new CustomRendererBuilder(animationTimer)
RVRendererAdapter adapter = new RVRendererAdapter<>(rendererBuilder);
list.setAdapter(adapter);
public CustomRendererBuilder(PublishSubject<Long> animationTimer) {
ListAdapteeCollection<Renderer<? extends Item>> prototypes = new
ListAdapteeCollection<>();
prototypes.add(new CustomRenderer(animationTimer));
setPrototypes(prototypes);
}
@Override protected Class getPrototypeClass(Item item) {
return CustomRenderer.class;
}
@Override public void render() {
setupAnimation();
animationTimer.subscribe(timerValue -> startAnimation());
}
@Override public void onDestroy() {
if (!animationSubscription.isUnsubscribed()) {
super.onDestroy();
animationSubscription.unsubscribe();
}
}