Skip to content

Commit

Permalink
- Dagger 2.11 eklemeye çalışıyok
Browse files Browse the repository at this point in the history
  • Loading branch information
andanicalik committed Sep 19, 2017
1 parent 53e038a commit 55296db
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 234 deletions.
13 changes: 11 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ dependencies {
compile 'com.android.support:cardview-v7:25.3.1'

//dagger
compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'

compile 'com.google.dagger:dagger:2.11'
compile 'com.google.dagger:dagger-android:2.11'
compile 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'

/*compile 'com.google.dagger:dagger:2.11'
compile 'com.google.dagger:dagger-android:2.11'
compile 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'*/

//rxjava
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
Expand Down
28 changes: 19 additions & 9 deletions app/src/main/java/com/aac/andcun/themoviedb_mvvm/TMDBApp.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.aac.andcun.themoviedb_mvvm;

import android.app.Activity;
import android.app.Application;

import com.aac.andcun.themoviedb_mvvm.di.app.AppComponent;
import com.aac.andcun.themoviedb_mvvm.di.app.AppModule;
import com.aac.andcun.themoviedb_mvvm.di.app.DaggerAppComponent;
import com.aac.andcun.themoviedb_mvvm.di.app.NetworkModule;

import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;

/**
* Created by cuneytcarikci on 24/07/2017.
*/

public class TMDBApp extends Application {
public class TMDBApp extends Application implements HasActivityInjector {

private AppComponent appComponent;
@Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

@Override
public void onCreate() {
Expand All @@ -24,15 +31,18 @@ public void onCreate() {

private void initAppComponent() {

appComponent = DaggerAppComponent.builder()
/*DaggerAppComponent
.builder()
.appModule(new AppModule(this))
.networkModule(new NetworkModule()).build();

appComponent.inject(this);
.networkModule(new NetworkModule())
.build()
.inject(this);*/

}

public AppComponent getAppComponent() {
return appComponent;
@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingAndroidInjector;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.aac.andcun.themoviedb_mvvm.di.app;

import com.aac.andcun.themoviedb_mvvm.ui.detail.MovieDetailActivity;
import com.aac.andcun.themoviedb_mvvm.ui.main.MainActivity;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;

/**
* Created by andani on 19.09.2017.
*/

@Module
public abstract class ActivityBuilderModule {

@ContributesAndroidInjector(modules = FragmentBuilderModule.class)
abstract MainActivity mainActivity();

@ContributesAndroidInjector
abstract MovieDetailActivity movieDetailActivity();

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package com.aac.andcun.themoviedb_mvvm.di.app;

import android.app.Application;
import android.content.Context;

import com.aac.andcun.themoviedb_mvvm.TMDBApp;
import com.aac.andcun.themoviedb_mvvm.repository.MovieRepository;
import com.aac.andcun.themoviedb_mvvm.repository.TvRepository;

import javax.inject.Singleton;

import dagger.BindsInstance;
import dagger.Component;
import dagger.android.AndroidInjectionModule;

/**
* Created by cuneytcarikci on 23/05/2017.
*/

@Singleton
@Component(modules = {AppModule.class, NetworkModule.class})
@Component(
modules = {
AppModule.class,
AndroidInjectionModule.class,
ActivityBuilderModule.class
}
)
public interface AppComponent {

Context context();
@Component.Builder
interface Builder {

MovieRepository movieRepository();
AppComponent build();

TvRepository tvRepository();
}

void inject(TMDBApp app);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

import android.app.Application;
import android.content.Context;

import com.aac.andcun.themoviedb_mvvm.api.TMDBService;
import com.aac.andcun.themoviedb_mvvm.repository.MovieRepository;
import com.aac.andcun.themoviedb_mvvm.repository.TvRepository;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.aac.andcun.themoviedb_mvvm.api.ApiConstants.BASE_URL;

/**
* Created by cuneytcarikci on 23/05/2017.
Expand All @@ -23,33 +35,42 @@ public AppModule(Application app) {
this.app = app;
}

@Provides
@Singleton
Application provideApplication() {
return app;
@Singleton @Provides
Gson provideGson() {
return new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
}

@Provides
@Singleton
Context provideContext() {
return app.getApplicationContext();
@Singleton @Provides
OkHttpClient provideOkHttpClient() {
return new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.build();
}

@Provides
@Singleton
Gson provideGson() {
return new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
@Singleton @Provides
Retrofit provideRetrofit(OkHttpClient okHttpClient, Gson gson) {
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}

@Singleton @Provides
TMDBService provideService(Retrofit retrofit) {
return retrofit.create(TMDBService.class);
}

@Singleton @Provides
MovieRepository provideMovieRepository(TMDBService service) {
return new MovieRepository(service);
}

/* @Provides
@Singleton
SharedPreferences providesSharedPreferences(Application application) {
return application.getSharedPreferences("the_movie_db_prefs", Context.MODE_PRIVATE);
@Singleton @Provides
TvRepository provideTvRepository(TMDBService service) {
return new TvRepository(service);
}

@Provides
@Singleton
PreferencesHelper providePreferencesHelper(SharedPreferences preferences, Gson gson) {
return new PreferencesHelperImpl(preferences, gson);
}*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.aac.andcun.themoviedb_mvvm.di.app;

import com.aac.andcun.themoviedb_mvvm.ui.movie.MovieFragment;
import com.aac.andcun.themoviedb_mvvm.ui.movie.MoviePageFragment;
import com.aac.andcun.themoviedb_mvvm.ui.tv.TvFragment;
import com.aac.andcun.themoviedb_mvvm.ui.tv.TvPageFragment;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;

/**
* Created by andani on 19.09.2017.
*/

@Module
public abstract class FragmentBuilderModule {

@ContributesAndroidInjector
abstract MovieFragment movieFragment();

@ContributesAndroidInjector
abstract MoviePageFragment moviePageFragment();

@ContributesAndroidInjector
abstract TvFragment tvFragment();

@ContributesAndroidInjector
abstract TvPageFragment tvPageFragment();

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,5 @@
public class NetworkModule {


@Provides
@Singleton
OkHttpClient provideOkHttpClient() {
return new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.build();
}

@Provides
@Singleton
Retrofit provideRetrofit(OkHttpClient okHttpClient, Gson gson) {
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}


@Provides
@Singleton
TMDBService provideService(Retrofit retrofit) {
return retrofit.create(TMDBService.class);
}


@Provides
@Singleton
MovieRepository provideMovieRepository(TMDBService service) {
return new MovieRepository(service);
}

@Provides
@Singleton
TvRepository provideTvRepository(TMDBService service) {
return new TvRepository(service);
}
/*
@Provides
@Singleton
ApiSource provideApiSource(Retrofit retrofit) {
return new ApiSourceImpl(retrofit);
}
*/
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 55296db

Please sign in to comment.