Skip to content

Instantly share code, notes, and snippets.

View ffgiraldez's full-sized avatar

Fernando Franco Gíraldez ffgiraldez

View GitHub Profile
buildscript {
repositories {
// rather than hit central each time with this:
// mavenCentral()
// we hit our company Nexus server ont he public group
// which includes the Central Repository
// and is local, so more performant
maven {
url "http://localhost:8081/nexus/content/groups/public"
}
@ffgiraldez
ffgiraldez / AccountActivity.java
Last active August 29, 2015 14:19
Dagger 2 Generic Injections
public class AccountActivity extends BaseActivity {
// ----------------------------------
// ATTRIBUTES
// ----------------------------------
private AccountComponent component;
// ----------------------------------
// LIFE CYCLE
// ----------------------------------
@Override
@ffgiraldez
ffgiraldez / BaseActivity.java
Last active August 29, 2015 14:25
Dagger 2 Activity Injection
/**
* @author Fernando Franco Giráldez
*/
public abstract class BaseActivity<T> extends ComponentActivity {
// ----------------------------------
// ATTRIBUTES
// ----------------------------------
private T component;
private ActivityComponent activityComponent;
@Inject
@ffgiraldez
ffgiraldez / ToolbarActivity.java
Last active May 4, 2016 16:11
Disable toolbar scroll flag when content it's not enough to fill the screen
public class ToolbarActivity extends AppCompatActivity {
// Set the flags that fit your needs
private static final int ENABLED_SCROLL_BEHAVIOR = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS | AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL;
private static final int DISABLED_SCROLL_BEHAVIOR = 0;
private static final int SCROLL_DOWN = 1;
//Injected via ButterKnife (http://jakewharton.github.io/butterknife)
@InjectView(R.id.toolbar)
Toolbar toolbar;
@InjectView(R.id.recyclerview)
@ffgiraldez
ffgiraldez / Pager.java
Created June 1, 2016 08:19 — forked from mttkay/Pager.java
A simple Rx based pager
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
@ffgiraldez
ffgiraldez / EndpointInterceptor.java
Created November 16, 2016 08:45
Change host at runtime with Retrofit 2
public abstract class EndpointInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
HttpUrl newUrl = replaceHost(originalRequest);
Request completeRequest = originalRequest.newBuilder()
.url(newUrl)
.build();
@ffgiraldez
ffgiraldez / FpToTheMax.kt
Last active March 29, 2019 14:10
FP to the Max on Arrow FX
package es.ffgiraldez.gist.arrow
import arrow.core.Option
import arrow.core.Try
import arrow.effects.extensions.io.fx.fx
import arrow.effects.extensions.io.unsafeRun.runBlocking
import arrow.unsafe
import java.util.Random
interface Console {
@ffgiraldez
ffgiraldez / VolatileLiveData.kt
Created April 24, 2019 12:59 — forked from d4vidi/VolatileLiveData.kt
A MutableLiveData variant that introduces a volatile behavior
package com.und0.vocabularymate.x.utils
import androidx.annotation.MainThread
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import java.util.concurrent.atomic.AtomicInteger
/**
* A [MutableLiveData] variant that introduces a _volatile_ behavior. Namely, it has no "memory" of values set
@ffgiraldez
ffgiraldez / JavaFXTrayIconSample.java
Created March 2, 2020 15:49 — forked from jewelsea/JavaFXTrayIconSample.java
Demonstrate using the System Tray (AWT) to control a JavaFX application.
import javafx.application.*;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.*;
import javax.imageio.ImageIO;
import java.io.IOException;