mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Introduce dagger
This commit is contained in:
		
							parent
							
								
									c926437a0e
								
							
						
					
					
						commit
						6a7b7cbbe8
					
				
					 7 changed files with 108 additions and 6 deletions
				
			
		|  | @ -0,0 +1,12 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import dagger.Module; | ||||
| import dagger.android.ContributesAndroidInjector; | ||||
| import fr.free.nrw.commons.contributions.ContributionsActivity; | ||||
| 
 | ||||
| @Module | ||||
| public abstract class ActivityBuilder { | ||||
| 
 | ||||
|     @ContributesAndroidInjector() | ||||
|     abstract ContributionsActivity bindSplashScreenActivity(); | ||||
| } | ||||
							
								
								
									
										29
									
								
								app/src/main/java/fr/free/nrw/commons/di/AppComponent.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/src/main/java/fr/free/nrw/commons/di/AppComponent.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import android.app.Application; | ||||
| 
 | ||||
| import javax.inject.Singleton; | ||||
| 
 | ||||
| import dagger.BindsInstance; | ||||
| import dagger.Component; | ||||
| import dagger.android.support.AndroidSupportInjectionModule; | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| 
 | ||||
| @Singleton | ||||
| @Component(modules = { | ||||
|         AndroidSupportInjectionModule.class, | ||||
|         AppModule.class, | ||||
|         ActivityBuilder.class | ||||
| }) | ||||
| public interface AppComponent { | ||||
| 
 | ||||
|     @Component.Builder | ||||
|     interface Builder { | ||||
|         @BindsInstance | ||||
|         Builder application(Application application); | ||||
| 
 | ||||
|         AppComponent build(); | ||||
|     } | ||||
| 
 | ||||
|     void inject(CommonsApplication application); | ||||
| } | ||||
							
								
								
									
										28
									
								
								app/src/main/java/fr/free/nrw/commons/di/AppModule.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								app/src/main/java/fr/free/nrw/commons/di/AppModule.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import android.app.Application; | ||||
| import android.content.Context; | ||||
| 
 | ||||
| import javax.inject.Singleton; | ||||
| 
 | ||||
| import dagger.Module; | ||||
| import dagger.Provides; | ||||
| import fr.free.nrw.commons.BuildConfig; | ||||
| import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi; | ||||
| import fr.free.nrw.commons.mwapi.MediaWikiApi; | ||||
| 
 | ||||
| @Module | ||||
| public class AppModule { | ||||
| 
 | ||||
|     @Provides | ||||
|     @Singleton | ||||
|     Context provideContext(Application application) { | ||||
|         return application; | ||||
|     } | ||||
| 
 | ||||
|     @Provides | ||||
|     @Singleton | ||||
|     public MediaWikiApi getMWApi() { | ||||
|         return new ApacheHttpClientMediaWikiApi(BuildConfig.WIKIMEDIA_API_HOST); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 maskara
						maskara