Skip to content

Commit

Permalink
Create a "gravatar-noop" module and inject it in wear/automotive builds
Browse files Browse the repository at this point in the history
Injecting the "gravatar-noop" we prevent the Gravatar SDK from landing in those builds.
  • Loading branch information
hamorillo committed Dec 11, 2024
1 parent df81f5b commit 8c38274
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 6 deletions.
1 change: 1 addition & 0 deletions automotive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies {
implementation(projects.modules.services.analytics)
implementation(projects.modules.services.compose)
implementation(projects.modules.services.crashlogging)
implementation(projects.modules.services.gravatarNoop)
implementation(projects.modules.services.localization)
implementation(projects.modules.services.mediaNoop)
implementation(projects.modules.services.model)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package au.com.shiftyjelly.pocketcasts.di

import au.com.shiftyjelly.pocketcasts.NoOpGravatarSdkService
import au.com.shiftyjelly.pocketcasts.servers.di.Downloads
import au.com.shiftyjelly.pocketcasts.utils.gravatar.GravatarService
import dagger.Binds
import dagger.Module
import dagger.Provides
Expand All @@ -23,4 +25,7 @@ abstract class AutomotiveAppModule {
@Binds
@Downloads
abstract fun downloadsCallFactory(@Downloads client: OkHttpClient): Call.Factory

@Binds
abstract fun gravatarService(factory: NoOpGravatarSdkService.Factory): GravatarService.Factory
}
24 changes: 24 additions & 0 deletions modules/services/gravatar-noop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
}

android {
namespace = "au.com.shiftyjelly.pocketcasts.gravatar"
buildFeatures {
buildConfig = true
viewBinding = false
compose = false
}
}

dependencies {
ksp(libs.dagger.hilt.compiler)
ksp(libs.hilt.compiler)

api(libs.dagger.hilt.android)

implementation(projects.modules.services.utils)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package au.com.shiftyjelly.pocketcasts

import androidx.fragment.app.Fragment
import au.com.shiftyjelly.pocketcasts.utils.gravatar.GravatarService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.FragmentComponent

@Module
@InstallIn(FragmentComponent::class)
object GravatarModule {
@Provides
fun provideGravatarService(
fragment: Fragment,
onAvatarSelected: () -> Unit,
): GravatarService = NoOpGravatarSdkService(fragment, onAvatarSelected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package au.com.shiftyjelly.pocketcasts

import androidx.fragment.app.Fragment
import au.com.shiftyjelly.pocketcasts.utils.gravatar.GravatarService
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject

class NoOpGravatarSdkService @AssistedInject constructor(@Assisted fragment: Fragment?, @Assisted onAvatarSelected: (() -> Unit)?) :
GravatarService {

override fun launchExternalQuickEditor(email: String) {
error("Operation not supported")
}

override fun launchQuickEditor(isLightTheme: Boolean, email: String) {
error("Operation not supported")
}

override suspend fun logout(email: String) {
error("Operation not supported")
}

@AssistedFactory
interface Factory : GravatarService.Factory {
override fun create(fragment: Fragment?, onAvatarSelected: (() -> Unit)?): NoOpGravatarSdkService
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ include(":modules:services:utils")
include(":modules:services:views")
include(":modules:services:sharedtest")
include(":modules:services:gravatar")
include(":modules:services:gravatar-noop")
1 change: 1 addition & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ dependencies {
implementation(projects.modules.services.analytics)
implementation(projects.modules.services.compose)
implementation(projects.modules.services.crashlogging)
implementation(projects.modules.services.gravatarNoop)
implementation(projects.modules.services.images)
implementation(projects.modules.services.localization)
implementation(projects.modules.services.mediaNoop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package au.com.shiftyjelly.pocketcasts.wear.di

import android.content.Context
import android.net.ConnectivityManager
import au.com.shiftyjelly.pocketcasts.NoOpGravatarSdkService
import au.com.shiftyjelly.pocketcasts.utils.gravatar.GravatarService
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -10,11 +13,16 @@ import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
object WearAppModule {
abstract class WearAppModule {

@Provides
fun connectivityManager(
@ApplicationContext application: Context,
): ConnectivityManager =
application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
companion object {
@Provides
fun connectivityManager(
@ApplicationContext application: Context,
): ConnectivityManager =
application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}

@Binds
abstract fun gravatarService(factory: NoOpGravatarSdkService.Factory): GravatarService.Factory
}

0 comments on commit 8c38274

Please sign in to comment.