This repository was archived by the owner on Oct 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +67
-1
lines changed
app/src/main/java/com/esoxjem/movieguide Expand file tree Collapse file tree 4 files changed +67
-1
lines changed Original file line number Diff line number Diff line change
1
+ package com .esoxjem .movieguide ;
2
+
3
+ import com .esoxjem .movieguide .favorites .FavoritesStore ;
4
+
5
+ import javax .inject .Singleton ;
6
+
7
+ import dagger .Component ;
8
+
9
+ /**
10
+ * @author arun
11
+ */
12
+
13
+ @ Singleton
14
+ @ Component (modules = {AppModule .class })
15
+ public interface AppComponent
16
+ {
17
+ void inject (FavoritesStore target );
18
+ }
Original file line number Diff line number Diff line change
1
+ package com .esoxjem .movieguide ;
2
+
3
+ import android .app .Application ;
4
+ import android .content .Context ;
5
+
6
+ import javax .inject .Singleton ;
7
+
8
+ import dagger .Module ;
9
+ import dagger .Provides ;
10
+
11
+ /**
12
+ * @author arun
13
+ */
14
+ @ Module
15
+ public class AppModule
16
+ {
17
+ private final Application application ;
18
+
19
+ public AppModule (Application application )
20
+ {
21
+ this .application = application ;
22
+ }
23
+
24
+ @ Provides
25
+ @ Singleton
26
+ Context providesContext ()
27
+ {
28
+ return application ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change 11
11
public class BaseApplication extends Application
12
12
{
13
13
private static Context appContext ;
14
+ private AppComponent appComponent ;
14
15
15
16
@ Override
16
17
public void onCreate ()
17
18
{
18
19
super .onCreate ();
19
20
StrictMode .enableDefaults ();
20
21
appContext = getApplicationContext ();
22
+ appComponent = DaggerAppComponent .builder ()
23
+ .appnModule (new AppModule (this ))
24
+ .build ();
21
25
}
22
26
23
27
@ NonNull
24
28
public static Context getAppContext ()
25
29
{
26
30
return appContext ;
27
31
}
32
+
33
+ public AppComponent getAppComponent ()
34
+ {
35
+ return appComponent ;
36
+ }
28
37
}
Original file line number Diff line number Diff line change 1
1
package com .esoxjem .movieguide .favorites ;
2
2
3
+ import android .content .Context ;
3
4
import android .content .SharedPreferences ;
4
5
import android .text .TextUtils ;
5
6
13
14
import java .util .List ;
14
15
import java .util .Map ;
15
16
17
+ import javax .inject .Inject ;
18
+
16
19
/**
17
20
* @author arun
18
21
*/
19
22
public class FavoritesStore
20
23
{
24
+
25
+ @ Inject
26
+ Context context ;
27
+
21
28
private SharedPreferences pref ;
22
29
private static final int PRIVATE_MODE = 0 ;
23
30
private static final String PREF_NAME = "FavoritesStore" ;
24
31
25
32
public FavoritesStore ()
26
33
{
27
- pref = BaseApplication .getAppContext ().getSharedPreferences (PREF_NAME , PRIVATE_MODE );
34
+ ((BaseApplication ) Application ).getAppComponent ().inject (this );
35
+
36
+ pref = context .getSharedPreferences (PREF_NAME , PRIVATE_MODE );
28
37
}
29
38
30
39
public void setFavorite (Movie movie )
You can’t perform that action at this time.
0 commit comments