This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.+' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OKHttp { | |
//Pretend this is how we hit an endpoint | |
public String rawResponse(){ | |
return UUID.randomUUID().toString(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class ApplicationModule { | |
private static Application sApplication; | |
public ApplicationModule(Application application) { | |
sApplication = application; | |
} | |
@Provides |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = ApplicationModule.class) | |
public interface ApplicationComponent { | |
//Exposes Application to any component which depends on this | |
Application getApplication(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class LocalModule { | |
@Provides | |
LocalDataCache providesDataCache(Application application){ | |
return new LocalDataCache(application); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
public class NetworkModule { | |
@Provides | |
OKHttp providesOkHTTP(){ | |
return new OKHttp(); | |
} | |
@Provides | |
Retrofit providesRetrofit(OKHttp okHttp){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = {LocalModule.class, NetworkModule.class}, dependencies = ApplicationComponent.class) | |
public interface BaseComponent { | |
OKHttp getOkHTTP(); | |
Retrofit getRetrofit(); | |
LocalDataCache getLocalDataCache(); | |
} |
OlderNewer