Skip to content

Commit

Permalink
Convert dependency inject ("di") package to kotlin (commons-app#5976)
Browse files Browse the repository at this point in the history
* Convert a batch of easier modules

* Convert the NetworkingModule to kotlin

* Converted the ApplicationlessInjection to kotlin

* Convert CommonsDaggerAppCompatActivity to kotlin

* Convert CommonsDaggerContentProvider to kotlin

* Convert CommonsDaggerIntentService to kotlin

* Convert CommonsDaggerService to kotlin

* Convert CommonsDaggerSupportFragment to kotlin

* Convert CommonsDaggerBroadcastReceiver to kotlin

* Convert CommonsApplicationModule to kotlin

* Fix imports and make them consistent
  • Loading branch information
psh authored Nov 30, 2024
1 parent dac3657 commit 1e5521b
Show file tree
Hide file tree
Showing 41 changed files with 1,274 additions and 1,465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fr.free.nrw.commons.actions
import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
import fr.free.nrw.commons.di.NetworkingModule.NAMED_COMMONS_CSRF
import fr.free.nrw.commons.di.NetworkingModule.Companion.NAMED_COMMONS_CSRF
import io.reactivex.Observable
import javax.inject.Inject
import javax.inject.Named
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package fr.free.nrw.commons.campaigns
import android.annotation.SuppressLint
import fr.free.nrw.commons.BasePresenter
import fr.free.nrw.commons.campaigns.models.Campaign
import fr.free.nrw.commons.di.CommonsApplicationModule
import fr.free.nrw.commons.di.CommonsApplicationModule.IO_THREAD
import fr.free.nrw.commons.di.CommonsApplicationModule.MAIN_THREAD
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.IO_THREAD
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.MAIN_THREAD
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
import fr.free.nrw.commons.utils.CommonsDateUtil.getIso8601DateFormatShort
import io.reactivex.Scheduler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.free.nrw.commons.contributions
import androidx.paging.PagedList.BoundaryCallback
import fr.free.nrw.commons.auth.SessionManager
import fr.free.nrw.commons.di.CommonsApplicationModule
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.IO_THREAD
import fr.free.nrw.commons.media.MediaClient
import io.reactivex.Scheduler
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -20,7 +21,7 @@ class ContributionBoundaryCallback
private val repository: ContributionsRepository,
private val sessionManager: SessionManager,
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler,
@param:Named(IO_THREAD) private val ioThreadScheduler: Scheduler,
) : BoundaryCallback<Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.free.nrw.commons.contributions;

import static fr.free.nrw.commons.di.CommonsApplicationModule.IO_THREAD;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.paging.DataSource;
Expand Down Expand Up @@ -34,7 +36,7 @@ public class ContributionsListPresenter implements UserActionListener {
final ContributionBoundaryCallback contributionBoundaryCallback,
final ContributionsRemoteDataSource contributionsRemoteDataSource,
final ContributionsRepository repository,
@Named(CommonsApplicationModule.IO_THREAD) final Scheduler ioThreadScheduler) {
@Named(IO_THREAD) final Scheduler ioThreadScheduler) {
this.contributionBoundaryCallback = contributionBoundaryCallback;
this.repository = repository;
this.ioThreadScheduler = ioThreadScheduler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.contributions;

import static fr.free.nrw.commons.di.CommonsApplicationModule.IO_THREAD;
import static fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK;

import androidx.work.ExistingWorkPolicy;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class ContributionsPresenter implements UserActionListener {
@Inject
ContributionsPresenter(ContributionsRepository repository,
UploadRepository uploadRepository,
@Named(CommonsApplicationModule.IO_THREAD) Scheduler ioThreadScheduler) {
@Named(IO_THREAD) Scheduler ioThreadScheduler) {
this.contributionsRepository = repository;
this.uploadRepository = uploadRepository;
this.ioThreadScheduler = ioThreadScheduler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.free.nrw.commons.contributions

import androidx.paging.ItemKeyedDataSource
import fr.free.nrw.commons.di.CommonsApplicationModule
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.IO_THREAD
import fr.free.nrw.commons.media.MediaClient
import io.reactivex.Scheduler
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -16,7 +16,7 @@ class ContributionsRemoteDataSource
@Inject
constructor(
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler,
@param:Named(IO_THREAD) private val ioThreadScheduler: Scheduler,
) : ItemKeyedDataSource<Int, Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/fr/free/nrw/commons/db/Converters.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
public class Converters {

public static Gson getGson() {
return ApplicationlessInjection.getInstance(CommonsApplication.getInstance()).getCommonsApplicationComponent().gson();
return ApplicationlessInjection
.getInstance(CommonsApplication.getInstance())
.getCommonsApplicationComponent()
.gson();
}

/**
Expand Down

This file was deleted.

89 changes: 89 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/di/ActivityBuilderModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package fr.free.nrw.commons.di

import dagger.Module
import dagger.android.ContributesAndroidInjector
import fr.free.nrw.commons.AboutActivity
import fr.free.nrw.commons.LocationPicker.LocationPickerActivity
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.category.CategoryDetailsActivity
import fr.free.nrw.commons.contributions.MainActivity
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorActivity
import fr.free.nrw.commons.description.DescriptionEditActivity
import fr.free.nrw.commons.explore.SearchActivity
import fr.free.nrw.commons.explore.depictions.WikidataItemDetailsActivity
import fr.free.nrw.commons.media.ZoomableActivity
import fr.free.nrw.commons.nearby.WikidataFeedback
import fr.free.nrw.commons.notification.NotificationActivity
import fr.free.nrw.commons.profile.ProfileActivity
import fr.free.nrw.commons.review.ReviewActivity
import fr.free.nrw.commons.settings.SettingsActivity
import fr.free.nrw.commons.upload.UploadActivity
import fr.free.nrw.commons.upload.UploadProgressActivity

/**
* This Class handles the dependency injection (using dagger)
* so, if a developer needs to add a new activity to the commons app
* then that must be mentioned here to inject the dependencies
*/
@Module
@Suppress("unused")
abstract class ActivityBuilderModule {
@ContributesAndroidInjector
abstract fun bindLoginActivity(): LoginActivity

@ContributesAndroidInjector
abstract fun bindWelcomeActivity(): WelcomeActivity

@ContributesAndroidInjector
abstract fun bindContributionsActivity(): MainActivity

@ContributesAndroidInjector
abstract fun bindCustomSelectorActivity(): CustomSelectorActivity

@ContributesAndroidInjector
abstract fun bindSettingsActivity(): SettingsActivity

@ContributesAndroidInjector
abstract fun bindAboutActivity(): AboutActivity

@ContributesAndroidInjector
abstract fun bindLocationPickerActivity(): LocationPickerActivity

@ContributesAndroidInjector
abstract fun bindSignupActivity(): SignupActivity

@ContributesAndroidInjector
abstract fun bindNotificationActivity(): NotificationActivity

@ContributesAndroidInjector
abstract fun bindUploadActivity(): UploadActivity

@ContributesAndroidInjector
abstract fun bindSearchActivity(): SearchActivity

@ContributesAndroidInjector
abstract fun bindCategoryDetailsActivity(): CategoryDetailsActivity

@ContributesAndroidInjector
abstract fun bindDepictionDetailsActivity(): WikidataItemDetailsActivity

@ContributesAndroidInjector
abstract fun bindAchievementsActivity(): ProfileActivity

@ContributesAndroidInjector
abstract fun bindReviewActivity(): ReviewActivity

@ContributesAndroidInjector
abstract fun bindDescriptionEditActivity(): DescriptionEditActivity

@ContributesAndroidInjector
abstract fun bindZoomableActivity(): ZoomableActivity

@ContributesAndroidInjector
abstract fun bindUploadProgressActivity(): UploadProgressActivity

@ContributesAndroidInjector
abstract fun bindWikiFeedback(): WikidataFeedback
}
105 changes: 0 additions & 105 deletions app/src/main/java/fr/free/nrw/commons/di/ApplicationlessInjection.java

This file was deleted.

Loading

0 comments on commit 1e5521b

Please sign in to comment.