MCPcopy Create free account
hub / github.com/JakeWharton/u2020 / DataModule

Class DataModule

app/src/main/java/com/jakewharton/u2020/data/DataModule.java:25–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23import static com.jakewharton.byteunits.DecimalByteUnit.MEGABYTES;
24
25@Module(
26 includes = ApiModule.class,
27 complete = false,
28 library = true
29)
30public final class DataModule {
31 static final long DISK_CACHE_SIZE = MEGABYTES.toBytes(50);
32
33 @Provides @Singleton SharedPreferences provideSharedPreferences(Application app) {
34 return app.getSharedPreferences("u2020", MODE_PRIVATE);
35 }
36
37 @Provides @Singleton RxSharedPreferences provideRxSharedPreferences(SharedPreferences prefs) {
38 return RxSharedPreferences.create(prefs);
39 }
40
41 @Provides @Singleton @AccessToken
42 Preference<String> provideAccessToken(RxSharedPreferences prefs) {
43 return prefs.getString("access-token");
44 }
45
46 @Provides @Singleton Moshi provideMoshi() {
47 return new Moshi.Builder()
48 .add(new InstantAdapter())
49 .build();
50 }
51
52 @Provides @Singleton Clock provideClock() {
53 return Clock.systemDefaultZone();
54 }
55
56 @Provides @Singleton IntentFactory provideIntentFactory() {
57 return IntentFactory.REAL;
58 }
59
60 @Provides @Singleton OkHttpClient provideOkHttpClient(Application app) {
61 return createOkHttpClient(app).build();
62 }
63
64 @Provides @Singleton Picasso providePicasso(Application app, OkHttpClient client) {
65 return new Picasso.Builder(app)
66 .downloader(new OkHttp3Downloader(client))
67 .listener((picasso, uri, e) -> Timber.e(e, "Failed to load image: %s", uri))
68 .build();
69 }
70
71 static OkHttpClient.Builder createOkHttpClient(Application app) {
72 // Install an HTTP cache in the application cache directory.
73 File cacheDir = new File(app.getCacheDir(), "http");
74 Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
75
76 return new OkHttpClient.Builder()
77 .cache(cache);
78 }
79}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected