File tree 3 files changed +46
-5
lines changed
src/main/java/org/amahi/anywhere
3 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public void onCreate() {
21
21
}
22
22
23
23
private void setUpInjections () {
24
- injector = ObjectGraph .create (new AmahiModule ());
24
+ injector = ObjectGraph .create (new AmahiModule (this ));
25
25
}
26
26
27
27
public void inject (Object injectionsConsumer ) {
Original file line number Diff line number Diff line change 1
1
package org .amahi .anywhere ;
2
2
3
+ import android .app .Application ;
4
+
3
5
import org .amahi .anywhere .activity .ServersActivity ;
4
6
import org .amahi .anywhere .server .ApiModule ;
5
7
8
+ import javax .inject .Singleton ;
9
+
6
10
import dagger .Module ;
11
+ import dagger .Provides ;
7
12
8
13
@ Module (
9
14
includes = {
15
20
)
16
21
class AmahiModule
17
22
{
23
+ private final Application application ;
24
+
25
+ public AmahiModule (Application application ) {
26
+ this .application = application ;
27
+ }
28
+
29
+ @ Provides
30
+ @ Singleton
31
+ Application provideApplication () {
32
+ return application ;
33
+ }
18
34
}
Original file line number Diff line number Diff line change 1
1
package org .amahi .anywhere .server ;
2
2
3
+ import android .app .Application ;
4
+
5
+ import com .squareup .okhttp .HttpResponseCache ;
3
6
import com .squareup .okhttp .OkHttpClient ;
7
+ import com .squareup .okhttp .OkResponseCache ;
4
8
5
9
import org .amahi .anywhere .server .header .ApiHeaders ;
6
10
11
+ import java .io .File ;
12
+ import java .io .IOException ;
13
+
7
14
import javax .inject .Singleton ;
8
15
9
16
import dagger .Module ;
12
19
import retrofit .client .OkClient ;
13
20
14
21
@ Module (
22
+ complete = false ,
15
23
library = true
16
24
)
17
25
public class ApiModule
18
26
{
19
27
@ Provides
20
28
@ Singleton
21
- OkHttpClient provideHttpClient ( ) {
22
- return new OkHttpClient ( );
29
+ Client provideClient ( OkHttpClient httpClient ) {
30
+ return new OkClient ( httpClient );
23
31
}
24
32
25
33
@ Provides
26
34
@ Singleton
27
- Client provideClient (OkHttpClient httpClient ) {
28
- return new OkClient (httpClient );
35
+ OkHttpClient provideHttpClient (OkResponseCache httpCache ) {
36
+ OkHttpClient httpClient = new OkHttpClient ();
37
+
38
+ httpClient .setOkResponseCache (httpCache );
39
+
40
+ return httpClient ;
41
+ }
42
+
43
+ @ Provides
44
+ @ Singleton
45
+ OkResponseCache provideHttpCache (Application application ) {
46
+ try {
47
+ File cacheDirectory = new File (application .getCacheDir (), "http-cache" );
48
+ int cacheSize = 5 * 1024 * 1024 ;
49
+
50
+ return new HttpResponseCache (cacheDirectory , cacheSize );
51
+ } catch (IOException e ) {
52
+ return null ;
53
+ }
29
54
}
30
55
31
56
@ Provides
You can’t perform that action at this time.
0 commit comments