Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory footprint of Hilt #159

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AddRecipeRepoImpl @Inject constructor(
private val addRecipeDataSource: AddRecipeDataSource,
private val addRecipeStorage: AddRecipeStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import gq.kirmanak.mealient.datasource.v0.models.CreateApiTokenRequestV0
import gq.kirmanak.mealient.datasource.v1.MealieDataSourceV1
import gq.kirmanak.mealient.datasource.v1.models.CreateApiTokenRequestV1
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AuthDataSourceImpl @Inject constructor(
private val serverInfoRepo: ServerInfoRepo,
private val v0Source: MealieDataSourceV0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import gq.kirmanak.mealient.logging.Logger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AuthRepoImpl @Inject constructor(
private val authStorage: AuthStorage,
private val authDataSource: AuthDataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ServerInfoRepoImpl @Inject constructor(
private val serverInfoStorage: ServerInfoStorage,
private val versionDataSource: VersionDataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class VersionDataSourceImpl @Inject constructor(
private val v0Source: MealieDataSourceV0,
private val v1Source: MealieDataSourceV1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import gq.kirmanak.mealient.data.baseurl.ServerInfoStorage
import gq.kirmanak.mealient.data.storage.PreferencesStorage
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ServerInfoStorageImpl @Inject constructor(
private val preferencesStorage: PreferencesStorage,
) : ServerInfoStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ package gq.kirmanak.mealient.data.configuration
import gq.kirmanak.mealient.BuildConfig
import gq.kirmanak.mealient.architecture.configuration.BuildConfiguration
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class BuildConfigurationImpl @Inject constructor() : BuildConfiguration {

@get:JvmName("_isDebug")
private val isDebug by lazy { BuildConfig.DEBUG }
override fun isDebug(): Boolean = BuildConfig.DEBUG

private val versionCode by lazy { BuildConfig.VERSION_CODE }

override fun isDebug(): Boolean = isDebug

override fun versionCode(): Int = versionCode
override fun versionCode(): Int = BuildConfig.VERSION_CODE
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import gq.kirmanak.mealient.logging.Logger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class DisclaimerStorageImpl @Inject constructor(
private val preferencesStorage: PreferencesStorage,
private val logger: Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import gq.kirmanak.mealient.datastore.DataStoreModule.Companion.ENCRYPTED
import gq.kirmanak.mealient.logging.Logger
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

@Singleton
class From24AuthMigrationExecutor @Inject constructor(
@Named(ENCRYPTED) private val sharedPreferences: SharedPreferences,
private val authRepo: AuthRepo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import gq.kirmanak.mealient.data.storage.PreferencesStorage
import gq.kirmanak.mealient.datasource.runCatchingExceptCancel
import gq.kirmanak.mealient.logging.Logger
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class MigrationDetectorImpl @Inject constructor(
private val preferencesStorage: PreferencesStorage,
private val migrationExecutors: Set<@JvmSuppressWildcards MigrationExecutor>,
private val buildConfiguration: BuildConfiguration,
private val logger: Logger,
) : MigrationDetector {


override suspend fun executeMigrations() {
val key = preferencesStorage.lastExecutedMigrationVersionKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import gq.kirmanak.mealient.datasource.v0.MealieDataSourceV0
import gq.kirmanak.mealient.datasource.v1.MealieDataSourceV1
import gq.kirmanak.mealient.model_mapper.ModelMapper
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class MealieDataSourceWrapper @Inject constructor(
private val serverInfoRepo: ServerInfoRepo,
private val v0Source: MealieDataSourceV0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import gq.kirmanak.mealient.data.baseurl.ServerInfoRepo
import gq.kirmanak.mealient.logging.Logger
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class RecipeImageUrlProviderImpl @Inject constructor(
private val serverInfoRepo: ServerInfoRepo,
private val logger: Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import gq.kirmanak.mealient.datasource.runCatchingExceptCancel
import gq.kirmanak.mealient.logging.Logger
import gq.kirmanak.mealient.model_mapper.ModelMapper
import javax.inject.Inject
import javax.inject.Singleton

@OptIn(ExperimentalPagingApi::class)
@Singleton
class RecipeRepoImpl @Inject constructor(
private val mediator: RecipesRemoteMediator,
private val storage: RecipeStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import androidx.core.util.PatternsCompat
import gq.kirmanak.mealient.datasource.models.ParseRecipeURLInfo
import gq.kirmanak.mealient.logging.Logger
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ShareRecipeRepoImpl @Inject constructor(
private val logger: Logger,
private val parseRecipeDataSource: ParseRecipeDataSource,
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/gq/kirmanak/mealient/di/AddRecipeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import gq.kirmanak.mealient.data.add.impl.AddRecipeRepoImpl
import gq.kirmanak.mealient.data.network.MealieDataSourceWrapper
import gq.kirmanak.mealient.datastore.recipe.AddRecipeStorage
import gq.kirmanak.mealient.datastore.recipe.AddRecipeStorageImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface AddRecipeModule {


@Binds
@Singleton
fun provideAddRecipeRepo(repo: AddRecipeRepoImpl): AddRecipeRepo

@Binds
@Singleton
fun bindAddRecipeDataSource(mealieDataSourceWrapper: MealieDataSourceWrapper): AddRecipeDataSource

@Binds
@Singleton
fun bindAddRecipeStorage(addRecipeStorageImpl: AddRecipeStorageImpl): AddRecipeStorage
}
1 change: 0 additions & 1 deletion app/src/main/java/gq/kirmanak/mealient/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ interface AppModule {
}

@Binds
@Singleton
fun bindPreferencesStorage(preferencesStorage: PreferencesStorageImpl): PreferencesStorage
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.architecture.configuration.BuildConfiguration
import gq.kirmanak.mealient.data.configuration.BuildConfigurationImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface ArchitectureModule {

@Binds
@Singleton
fun bindBuildConfiguration(buildConfigurationImpl: BuildConfigurationImpl): BuildConfiguration
}
19 changes: 0 additions & 19 deletions app/src/main/java/gq/kirmanak/mealient/di/AuthModule.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package gq.kirmanak.mealient.di

import android.accounts.AccountManager
import android.content.Context
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.data.auth.AuthDataSource
import gq.kirmanak.mealient.data.auth.AuthRepo
Expand All @@ -16,38 +12,23 @@ import gq.kirmanak.mealient.data.auth.impl.AuthRepoImpl
import gq.kirmanak.mealient.data.auth.impl.AuthStorageImpl
import gq.kirmanak.mealient.datasource.AuthenticationProvider
import gq.kirmanak.mealient.shopping_lists.repo.ShoppingListsAuthRepo
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface AuthModule {

companion object {

@Provides
@Singleton
fun provideAccountManager(@ApplicationContext context: Context): AccountManager {
return AccountManager.get(context)
}
}

@Binds
@Singleton
fun bindAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource

@Binds
@Singleton
fun bindAuthRepo(authRepo: AuthRepoImpl): AuthRepo

@Binds
@Singleton
fun bindAuthProvider(authRepo: AuthRepoImpl): AuthenticationProvider

@Binds
@Singleton
fun bindAuthStorage(authStorageImpl: AuthStorageImpl): AuthStorage

@Binds
@Singleton
fun bindShoppingListsAuthRepo(impl: AuthRepoImpl): ShoppingListsAuthRepo
}
5 changes: 0 additions & 5 deletions app/src/main/java/gq/kirmanak/mealient/di/BaseURLModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.data.baseurl.*
import gq.kirmanak.mealient.data.baseurl.impl.ServerInfoStorageImpl
import gq.kirmanak.mealient.datasource.ServerUrlProvider
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface BaseURLModule {

@Binds
@Singleton
fun bindVersionDataSource(versionDataSourceImpl: VersionDataSourceImpl): VersionDataSource

@Binds
@Singleton
fun bindBaseUrlStorage(baseURLStorageImpl: ServerInfoStorageImpl): ServerInfoStorage

@Binds
@Singleton
fun bindServerInfoRepo(serverInfoRepoImpl: ServerInfoRepoImpl): ServerInfoRepo

@Binds
@Singleton
fun bindServerUrlProvider(serverInfoRepoImpl: ServerInfoRepoImpl): ServerUrlProvider
}
2 changes: 0 additions & 2 deletions app/src/main/java/gq/kirmanak/mealient/di/DisclaimerModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import gq.kirmanak.mealient.data.disclaimer.DisclaimerStorage
import gq.kirmanak.mealient.data.disclaimer.DisclaimerStorageImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface DisclaimerModule {

@Binds
@Singleton
fun provideDisclaimerStorage(disclaimerStorageImpl: DisclaimerStorageImpl): DisclaimerStorage
}
3 changes: 0 additions & 3 deletions app/src/main/java/gq/kirmanak/mealient/di/MigrationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ import gq.kirmanak.mealient.data.migration.From24AuthMigrationExecutor
import gq.kirmanak.mealient.data.migration.MigrationDetector
import gq.kirmanak.mealient.data.migration.MigrationDetectorImpl
import gq.kirmanak.mealient.data.migration.MigrationExecutor
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface MigrationModule {

@Binds
@Singleton
@IntoSet
fun bindFrom24AuthMigrationExecutor(from24AuthMigrationExecutor: From24AuthMigrationExecutor): MigrationExecutor

@Binds
@Singleton
fun bindMigrationDetector(migrationDetectorImpl: MigrationDetectorImpl): MigrationDetector
}
7 changes: 0 additions & 7 deletions app/src/main/java/gq/kirmanak/mealient/di/RecipeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,29 @@ import gq.kirmanak.mealient.data.recipes.network.RecipeDataSource
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
import gq.kirmanak.mealient.ui.recipes.images.RecipeModelLoaderFactory
import java.io.InputStream
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface RecipeModule {

@Binds
@Singleton
fun provideRecipeDataSource(mealieDataSourceWrapper: MealieDataSourceWrapper): RecipeDataSource

@Binds
@Singleton
fun provideRecipeRepo(recipeRepoImpl: RecipeRepoImpl): RecipeRepo

@Binds
@Singleton
fun bindImageUrlProvider(recipeImageUrlProviderImpl: RecipeImageUrlProviderImpl): RecipeImageUrlProvider

@Binds
@Singleton
fun bindModelLoaderFactory(recipeModelLoaderFactory: RecipeModelLoaderFactory): ModelLoaderFactory<RecipeSummaryEntity, InputStream>

@Binds
@Singleton
fun bindRecipePagingSourceFactory(recipePagingSourceFactoryImpl: RecipePagingSourceFactoryImpl): RecipePagingSourceFactory

companion object {

@Provides
@Singleton
fun provideGlideRequestOptions(): RequestOptions = RequestOptions.centerCropTransform()
.placeholder(R.drawable.placeholder_recipe)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import gq.kirmanak.mealient.data.network.MealieDataSourceWrapper
import gq.kirmanak.mealient.data.share.ParseRecipeDataSource
import gq.kirmanak.mealient.data.share.ShareRecipeRepo
import gq.kirmanak.mealient.data.share.ShareRecipeRepoImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface ShareRecipeModule {

@Binds
@Singleton
fun bindShareRecipeRepo(shareRecipeRepoImpl: ShareRecipeRepoImpl): ShareRecipeRepo

@Binds
@Singleton
fun bindParseRecipeDataSource(mealieDataSourceWrapper: MealieDataSourceWrapper): ParseRecipeDataSource
}
Loading
Loading