Merge pull request #4521 from vector-im/feature/bma/di_cleanup

Fix "@JvmStatic used for @Provides function in an object class" Lint warning
This commit is contained in:
Benoit Marty 2021-11-19 16:08:32 +01:00 committed by GitHub
commit eb32fd95e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 32 deletions

View file

@ -84,4 +84,7 @@
<!-- Bug in lint agp 4.1 incorrectly thinks kotlin forEach is using java 8 API's. -->
<!-- FIXME this workaround should be removed in a near future -->
<issue id="NewApi" severity="warning" />
<!-- DI -->
<issue id="JvmStaticProvidesInObjectDetector" severity="error" />
</lint>

View file

@ -25,16 +25,12 @@ import im.vector.app.core.services.GuardServiceStarter
import im.vector.app.fdroid.service.FDroidGuardServiceStarter
import im.vector.app.features.settings.VectorPreferences
@Module
@InstallIn(SingletonComponent::class)
abstract class FlavorModule {
companion object {
@Module
object FlavorModule {
@Provides
@JvmStatic
fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter {
return FDroidGuardServiceStarter(preferences, appContext)
}
}
}

View file

@ -24,14 +24,10 @@ import im.vector.app.core.services.GuardServiceStarter
@InstallIn(SingletonComponent::class)
@Module
abstract class FlavorModule {
companion object {
object FlavorModule {
@Provides
@JvmStatic
fun provideGuardServiceStarter(): GuardServiceStarter {
return object : GuardServiceStarter {}
}
}
}

View file

@ -28,7 +28,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.TimelineAsyncHelp
@InstallIn(ActivityComponent::class)
object HomeModule {
@Provides
@JvmStatic
@TimelineEventControllerHandler
fun providesTimelineBackgroundHandler(): Handler {
return TimelineAsyncHelper.getBackgroundHandler()

View file

@ -30,11 +30,9 @@ import im.vector.app.core.glide.GlideApp
object ScreenModule {
@Provides
@JvmStatic
fun providesGlideRequests(context: AppCompatActivity) = GlideApp.with(context)
@Provides
@JvmStatic
@ActivityScoped
fun providesSharedViewPool() = RecyclerView.RecycledViewPool()
}

View file

@ -73,69 +73,58 @@ abstract class VectorBindModule {
object VectorStaticModule {
@Provides
@JvmStatic
fun providesContext(application: Application): Context {
return application.applicationContext
}
@Provides
@JvmStatic
fun providesResources(context: Context): Resources {
return context.resources
}
@Provides
@JvmStatic
fun providesSharedPreferences(context: Context): SharedPreferences {
return context.getSharedPreferences("im.vector.riot", MODE_PRIVATE)
}
@Provides
@JvmStatic
fun providesMatrix(context: Context): Matrix {
return Matrix.getInstance(context)
}
@Provides
@JvmStatic
fun providesCurrentSession(activeSessionHolder: ActiveSessionHolder): Session {
// TODO: handle session injection better
return activeSessionHolder.getActiveSession()
}
@Provides
@JvmStatic
fun providesLegacySessionImporter(matrix: Matrix): LegacySessionImporter {
return matrix.legacySessionImporter()
}
@Provides
@JvmStatic
fun providesAuthenticationService(matrix: Matrix): AuthenticationService {
return matrix.authenticationService()
}
@Provides
@JvmStatic
fun providesRawService(matrix: Matrix): RawService {
return matrix.rawService()
}
@Provides
@JvmStatic
fun providesHomeServerHistoryService(matrix: Matrix): HomeServerHistoryService {
return matrix.homeServerHistoryService()
}
@Provides
@JvmStatic
@Singleton
fun providesApplicationCoroutineScope(): CoroutineScope {
return CoroutineScope(SupervisorJob() + Dispatchers.Main)
}
@Provides
@JvmStatic
fun providesCoroutineDispatchers(): CoroutineDispatchers {
return CoroutineDispatchers(io = Dispatchers.IO, computation = Dispatchers.Default)
}

View file

@ -28,7 +28,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.TimelineAsyncHelp
object HomeModule {
@Provides
@JvmStatic
@TimelineEventControllerHandler
fun providesTimelineBackgroundHandler(): Handler {
return TimelineAsyncHelper.getBackgroundHandler()