Skip to content

Instantly share code, notes, and snippets.

View JorgeCastilloPrz's full-sized avatar
🎉
Mostly Android stuff now, also FP

Jorge Castillo JorgeCastilloPrz

🎉
Mostly Android stuff now, also FP
View GitHub Profile
@JorgeCastilloPrz
JorgeCastilloPrz / onresume.kt
Created March 31, 2017 16:42
snippet for article
override fun onResume() {
super.onResume()
presenter.getSuperHeroes().run(GetHeroesContext(this@MyActivity))
}
@JorgeCastilloPrz
JorgeCastilloPrz / reader.kt
Last active December 30, 2017 10:26
reader sample for medium article
class Reader<C, out A>(val run: (C) -> A) {
inline fun <B> map(crossinline fa: (A) -> B): Reader<C, B> = Reader {
c -> fa(run(c))
}
inline fun <B> flatMap(crossinline fa: (A) -> Reader<C, B>): Reader<C, B> = Reader {
c -> fa(run(c)).run(c)
}
public class ResizeAnimation extends Animation {
final int startWidth;
final int targetWidth;
View view;
public ResizeAnimation(View view, int targetWidth) {
this.view = view;
this.targetWidth = targetWidth;
startWidth = view.getWidth();
}
class GridingCoffeeMaker {
@Inject Lazy<Grinder> lazyGrinder;
public void brew() {
while (needsGrinding()) {
// Grinder created once on first call to .get() and cached.
lazyGrinder.get().grind();
}
}
}
/**
* Created by jorge on 5/3/14.
*/
public class InjectedActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((ApplicationClass) getApplicationContext()).inject(this);
}
@JorgeCastilloPrz
JorgeCastilloPrz / gist:94c4b3196a075a7bdba1
Created December 7, 2014 15:59
MainActivity injection
/**
* Created by jorge on 3/17/14.
*/
public class MainActivity extends InjectedActivity {
@Inject
GoogleApiClient mGoogleApiClient;
@Inject
LocationController mLocationController;
@Inject
@JorgeCastilloPrz
JorgeCastilloPrz / gist:564e2f3ddab9673ea127
Created December 7, 2014 15:35
LocationController Injection
public class LocationController implements LocationListener {
private static final int TWO_MINUTES = 1000 * 60 * 2;
private Context context;
private LocationManager locationManager;
private String provider;
private Location bestLocationUntilNow;
@Inject
@JorgeCastilloPrz
JorgeCastilloPrz / gist:615a3ce6956eec47d2ca
Created December 7, 2014 14:14
Dagger ContextModule
/**
* A module for dependencies which require a {@link android.content.Context} or
* {@link android.app.Application} to create.
*/
@Module(
library = true
)
public class ContextModule {
private Context appContext;
/**
* A module for more generic or external dependencies wich doesnt require a {@link android.content.Context} or
* {@link android.app.Application} to create.
*/
@Module(
library = true
)
public class AppModule {
@Provides
@Module(
injects = {
ApplicationClass.class,
AbstractFontFactory.class,
RobotoFontFactory.class,
DataController.class,
LocationController.class,
RestAnimalProvider.class,
MainActivity.class,
TutorialActivity.class,