mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	First baby steps into the world of dependency injection using Dagger.
This commit is contained in:
		
							parent
							
								
									04f676c320
								
							
						
					
					
						commit
						8fe2816ca9
					
				
					 32 changed files with 351 additions and 115 deletions
				
			
		|  | @ -0,0 +1,45 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import dagger.Module; | ||||
| import dagger.android.ContributesAndroidInjector; | ||||
| import fr.free.nrw.commons.AboutActivity; | ||||
| import fr.free.nrw.commons.WelcomeActivity; | ||||
| import fr.free.nrw.commons.auth.LoginActivity; | ||||
| import fr.free.nrw.commons.auth.SignupActivity; | ||||
| import fr.free.nrw.commons.contributions.ContributionsActivity; | ||||
| import fr.free.nrw.commons.nearby.NearbyActivity; | ||||
| import fr.free.nrw.commons.settings.SettingsActivity; | ||||
| import fr.free.nrw.commons.upload.MultipleShareActivity; | ||||
| import fr.free.nrw.commons.upload.ShareActivity; | ||||
| 
 | ||||
| @Module | ||||
| public abstract class ActivityBuilderModule { | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract ContributionsActivity bindContributionsActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract MultipleShareActivity bindMultipleShareActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract ShareActivity bindShareActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract LoginActivity bindLoginActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract SignupActivity bindSignupActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract NearbyActivity bindNearbyActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract AboutActivity bindAboutActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract SettingsActivity bindSettingsActivity(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract WelcomeActivity bindWelcomeActivity(); | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,35 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import javax.inject.Singleton; | ||||
| 
 | ||||
| import dagger.Component; | ||||
| import dagger.android.AndroidInjectionModule; | ||||
| import dagger.android.AndroidInjector; | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| import fr.free.nrw.commons.auth.WikiAccountAuthenticatorService; | ||||
| import fr.free.nrw.commons.contributions.ContributionsSyncAdapter; | ||||
| import fr.free.nrw.commons.modifications.ModificationsSyncAdapter; | ||||
| 
 | ||||
| @Singleton | ||||
| @Component(modules = { | ||||
|         CommonsApplicationModule.class, | ||||
|         AndroidInjectionModule.class, | ||||
|         ActivityBuilderModule.class, | ||||
|         ContentProviderBuilderModule.class | ||||
| }) | ||||
| public interface CommonsApplicationComponent extends AndroidInjector<CommonsApplication> { | ||||
|     void inject(CommonsApplication application); | ||||
| 
 | ||||
|     void inject(WikiAccountAuthenticatorService service); | ||||
| 
 | ||||
|     void inject(ContributionsSyncAdapter syncAdapter); | ||||
| 
 | ||||
|     void inject(ModificationsSyncAdapter syncAdapter); | ||||
| 
 | ||||
|     @Component.Builder | ||||
|     interface Builder { | ||||
|         Builder appModule(CommonsApplicationModule applicationModule); | ||||
| 
 | ||||
|         CommonsApplicationComponent build(); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,29 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import javax.inject.Singleton; | ||||
| 
 | ||||
| import dagger.Module; | ||||
| import dagger.Provides; | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| import fr.free.nrw.commons.mwapi.ApacheHttpClientMediaWikiApi; | ||||
| import fr.free.nrw.commons.mwapi.MediaWikiApi; | ||||
| 
 | ||||
| @Module | ||||
| public class CommonsApplicationModule { | ||||
|     private CommonsApplication application; | ||||
| 
 | ||||
|     public CommonsApplicationModule(CommonsApplication application) { | ||||
|         this.application = application; | ||||
|     } | ||||
| 
 | ||||
|     @Provides | ||||
|     public CommonsApplication providesCommonsApplication() { | ||||
|         return application; | ||||
|     } | ||||
| 
 | ||||
|     @Provides | ||||
|     @Singleton | ||||
|     public MediaWikiApi provideMediaWikiApi() { | ||||
|         return new ApacheHttpClientMediaWikiApi(CommonsApplication.API_URL); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,24 @@ | |||
| package fr.free.nrw.commons.di; | ||||
| 
 | ||||
| import dagger.Module; | ||||
| import dagger.android.ContributesAndroidInjector; | ||||
| import fr.free.nrw.commons.auth.LoginActivity; | ||||
| import fr.free.nrw.commons.auth.SignupActivity; | ||||
| import fr.free.nrw.commons.category.CategoryContentProvider; | ||||
| import fr.free.nrw.commons.contributions.ContributionsActivity; | ||||
| import fr.free.nrw.commons.contributions.ContributionsContentProvider; | ||||
| import fr.free.nrw.commons.modifications.ModificationsContentProvider; | ||||
| 
 | ||||
| @Module | ||||
| public abstract class ContentProviderBuilderModule { | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract CategoryContentProvider bindCategoryContentProvider(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract ContributionsContentProvider bindContributionsContentProvider(); | ||||
| 
 | ||||
|     @ContributesAndroidInjector | ||||
|     abstract ModificationsContentProvider bindModificationsContentProvider(); | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke