Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit 578d04b

Browse files
committed
initial commit
1 parent 877fcea commit 578d04b

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

app/src/main/java/com/esoxjem/movieguide/BaseApplication.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@
1111
public class BaseApplication extends Application
1212
{
1313
private static Context appContext;
14+
private AppComponent appComponent;
1415

1516
@Override
1617
public void onCreate()
1718
{
1819
super.onCreate();
1920
StrictMode.enableDefaults();
2021
appContext = getApplicationContext();
22+
appComponent = DaggerAppComponent.builder()
23+
.appnModule(new AppModule(this))
24+
.build();
2125
}
2226

2327
@NonNull
2428
public static Context getAppContext()
2529
{
2630
return appContext;
2731
}
32+
33+
public AppComponent getAppComponent()
34+
{
35+
return appComponent;
36+
}
2837
}

app/src/main/java/com/esoxjem/movieguide/favorites/FavoritesStore.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.esoxjem.movieguide.favorites;
22

3+
import android.content.Context;
34
import android.content.SharedPreferences;
45
import android.text.TextUtils;
56

@@ -13,18 +14,26 @@
1314
import java.util.List;
1415
import java.util.Map;
1516

17+
import javax.inject.Inject;
18+
1619
/**
1720
* @author arun
1821
*/
1922
public class FavoritesStore
2023
{
24+
25+
@Inject
26+
Context context;
27+
2128
private SharedPreferences pref;
2229
private static final int PRIVATE_MODE = 0;
2330
private static final String PREF_NAME = "FavoritesStore";
2431

2532
public FavoritesStore()
2633
{
27-
pref = BaseApplication.getAppContext().getSharedPreferences(PREF_NAME, PRIVATE_MODE);
34+
((BaseApplication) Application).getAppComponent().inject(this);
35+
36+
pref = context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
2837
}
2938

3039
public void setFavorite(Movie movie)

0 commit comments

Comments
 (0)