Skip to content

Instantly share code, notes, and snippets.

@patrykpoborca
patrykpoborca / gist:fec40b74c5cbf96fc40a
Created May 30, 2015 21:25
Data binding manifests
build.gradle (Project)
----------------------------------------------------------------------
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.+'
public class TweeterApi {
protected final Scheduler mainScheduler;
Retrofit retrofit;
LocalDataCache localDataCache;
private UserProfile userName;
@Inject
public TweeterApi(Retrofit retro, LocalDataCache cache, @Named(Constants.MAIN_THREAD) Scheduler mainScheduler) {
this.localDataCache = cache;
public class LocalDataCache {
//pretend this is some read/write to disk :)
protected static ArrayList<String> sPastTweets;
private Context context;
public LocalDataCache(Context context) {
this.context = context;
sPastTweets = new ArrayList<>();
}
public class Retrofit {
protected OKHttp okHttp;
protected final Scheduler mainScheduler;
public Retrofit(OKHttp okHttp, Scheduler mainScheduler) {
this.okHttp = okHttp;
this.mainScheduler = mainScheduler;
}
public Observable<String> completeRequest(){
public class OKHttp {
//Pretend this is how we hit an endpoint
public String rawResponse(){
return UUID.randomUUID().toString();
}
}
@Module
public class ApplicationModule {
private static Application sApplication;
public ApplicationModule(Application application) {
sApplication = application;
}
@Provides
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
//Exposes Application to any component which depends on this
Application getApplication();
}
@Module
public class LocalModule {
@Provides
LocalDataCache providesDataCache(Application application){
return new LocalDataCache(application);
}
}
@Module
public class NetworkModule {
@Provides
OKHttp providesOkHTTP(){
return new OKHttp();
}
@Provides
Retrofit providesRetrofit(OKHttp okHttp){
@Component(modules = {LocalModule.class, NetworkModule.class}, dependencies = ApplicationComponent.class)
public interface BaseComponent {
OKHttp getOkHTTP();
Retrofit getRetrofit();
LocalDataCache getLocalDataCache();
}