Reduce memory footprint of Hilt (#159)
* Remove @Singleton where it is not needed * Use @AssistedFactory where possible
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -5,9 +5,7 @@ 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>,
|
||||
@@ -15,7 +13,6 @@ class MigrationDetectorImpl @Inject constructor(
|
||||
private val logger: Logger,
|
||||
) : MigrationDetector {
|
||||
|
||||
|
||||
override suspend fun executeMigrations() {
|
||||
val key = preferencesStorage.lastExecutedMigrationVersionKey
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -10,7 +10,6 @@ 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)
|
||||
@@ -18,14 +17,11 @@ interface AddRecipeModule {
|
||||
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun provideAddRecipeRepo(repo: AddRecipeRepoImpl): AddRecipeRepo
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindAddRecipeDataSource(mealieDataSourceWrapper: MealieDataSourceWrapper): AddRecipeDataSource
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindAddRecipeStorage(addRecipeStorageImpl: AddRecipeStorageImpl): AddRecipeStorage
|
||||
}
|
||||
@@ -27,6 +27,5 @@ interface AppModule {
|
||||
}
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindPreferencesStorage(preferencesStorage: PreferencesStorageImpl): PreferencesStorage
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -5,31 +5,29 @@ import com.bumptech.glide.load.model.GlideUrl
|
||||
import com.bumptech.glide.load.model.ModelCache
|
||||
import com.bumptech.glide.load.model.ModelLoader
|
||||
import com.bumptech.glide.load.model.stream.BaseGlideUrlLoader
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import gq.kirmanak.mealient.data.recipes.impl.RecipeImageUrlProvider
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.InputStream
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RecipeModelLoader private constructor(
|
||||
class RecipeModelLoader @AssistedInject constructor(
|
||||
private val recipeImageUrlProvider: RecipeImageUrlProvider,
|
||||
private val logger: Logger,
|
||||
concreteLoader: ModelLoader<GlideUrl, InputStream>,
|
||||
cache: ModelCache<RecipeSummaryEntity, GlideUrl>,
|
||||
@Assisted concreteLoader: ModelLoader<GlideUrl, InputStream>,
|
||||
@Assisted cache: ModelCache<RecipeSummaryEntity, GlideUrl>,
|
||||
) : BaseGlideUrlLoader<RecipeSummaryEntity>(concreteLoader, cache) {
|
||||
|
||||
@Singleton
|
||||
class Factory @Inject constructor(
|
||||
private val recipeImageUrlProvider: RecipeImageUrlProvider,
|
||||
private val logger: Logger,
|
||||
) {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
|
||||
fun build(
|
||||
concreteLoader: ModelLoader<GlideUrl, InputStream>,
|
||||
cache: ModelCache<RecipeSummaryEntity, GlideUrl>,
|
||||
) = RecipeModelLoader(recipeImageUrlProvider, logger, concreteLoader, cache)
|
||||
): RecipeModelLoader
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@ import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.ListPreloader
|
||||
import com.bumptech.glide.RequestBuilder
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import dagger.hilt.android.scopes.FragmentScoped
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import javax.inject.Inject
|
||||
|
||||
class RecipePreloadModelProvider(
|
||||
private val adapter: PagingDataAdapter<RecipeSummaryEntity, *>,
|
||||
class RecipePreloadModelProvider @AssistedInject constructor(
|
||||
@Assisted private val adapter: PagingDataAdapter<RecipeSummaryEntity, *>,
|
||||
private val fragment: Fragment,
|
||||
private val requestOptions: RequestOptions,
|
||||
private val logger: Logger,
|
||||
@@ -28,15 +29,9 @@ class RecipePreloadModelProvider(
|
||||
return Glide.with(fragment).load(item).apply(requestOptions)
|
||||
}
|
||||
|
||||
@FragmentScoped
|
||||
class Factory @Inject constructor(
|
||||
private val fragment: Fragment,
|
||||
private val requestOptions: RequestOptions,
|
||||
private val logger: Logger,
|
||||
) {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
|
||||
fun create(
|
||||
adapter: PagingDataAdapter<RecipeSummaryEntity, *>,
|
||||
) = RecipePreloadModelProvider(adapter, fragment, requestOptions, logger)
|
||||
fun create(adapter: PagingDataAdapter<RecipeSummaryEntity, *>): RecipePreloadModelProvider
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,9 @@ class RecipeInfoFragment : BottomSheetDialogFragment() {
|
||||
private val binding by viewBinding(FragmentRecipeInfoBinding::bind)
|
||||
private val viewModel by viewModels<RecipeInfoViewModel>()
|
||||
private lateinit var ingredientsAdapter: RecipeIngredientsAdapter
|
||||
private val instructionsAdapter by lazy { recipeInstructionsAdapterFactory.build() }
|
||||
|
||||
@Inject
|
||||
lateinit var recipeInstructionsAdapterFactory: RecipeInstructionsAdapter.Factory
|
||||
lateinit var instructionsAdapter: RecipeInstructionsAdapter
|
||||
|
||||
@Inject
|
||||
lateinit var recipeIngredientsAdapterFactory: RecipeIngredientsAdapter.Factory
|
||||
|
||||
@@ -7,50 +7,38 @@ import androidx.core.view.isGone
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity
|
||||
import gq.kirmanak.mealient.databinding.ViewHolderIngredientBinding
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.ui.recipes.info.RecipeIngredientsAdapter.RecipeIngredientViewHolder
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RecipeIngredientsAdapter private constructor(
|
||||
class RecipeIngredientsAdapter @AssistedInject constructor(
|
||||
private val recipeIngredientViewHolderFactory: RecipeIngredientViewHolder.Factory,
|
||||
private val logger: Logger,
|
||||
private val disableAmounts: Boolean,
|
||||
@Assisted private val disableAmounts: Boolean,
|
||||
) : ListAdapter<RecipeIngredientEntity, RecipeIngredientViewHolder>(RecipeIngredientDiffCallback) {
|
||||
|
||||
@Singleton
|
||||
class Factory @Inject constructor(
|
||||
private val recipeIngredientViewHolderFactory: RecipeIngredientViewHolder.Factory,
|
||||
private val logger: Logger,
|
||||
) {
|
||||
fun build(disableAmounts: Boolean) = RecipeIngredientsAdapter(
|
||||
recipeIngredientViewHolderFactory = recipeIngredientViewHolderFactory,
|
||||
logger = logger,
|
||||
disableAmounts = disableAmounts,
|
||||
)
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun build(disableAmounts: Boolean): RecipeIngredientsAdapter
|
||||
}
|
||||
|
||||
class RecipeIngredientViewHolder private constructor(
|
||||
private val binding: ViewHolderIngredientBinding,
|
||||
class RecipeIngredientViewHolder @AssistedInject constructor(
|
||||
@Assisted private val binding: ViewHolderIngredientBinding,
|
||||
@Assisted private val disableAmounts: Boolean,
|
||||
private val logger: Logger,
|
||||
private val disableAmounts: Boolean,
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
@Singleton
|
||||
class Factory @Inject constructor(
|
||||
private val logger: Logger,
|
||||
) {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
|
||||
fun build(
|
||||
binding: ViewHolderIngredientBinding,
|
||||
disableAmounts: Boolean,
|
||||
) = RecipeIngredientViewHolder(
|
||||
binding = binding,
|
||||
logger = logger,
|
||||
disableAmounts = disableAmounts,
|
||||
)
|
||||
): RecipeIngredientViewHolder
|
||||
}
|
||||
|
||||
fun bind(item: RecipeIngredientEntity) {
|
||||
@@ -133,15 +121,18 @@ fun Double.mediantMethod(d: Int = 10, mixed: Boolean = true): Triple<Int, Int, I
|
||||
n1 += n2
|
||||
d2 = d + 1
|
||||
}
|
||||
|
||||
d1 > d2 -> d2 = d + 1
|
||||
else -> d1 = d + 1
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
x < m -> {
|
||||
n2 += n1
|
||||
d2 += d1
|
||||
}
|
||||
|
||||
else -> {
|
||||
n1 += n2
|
||||
d1 += d2
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import gq.kirmanak.mealient.R
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity
|
||||
import gq.kirmanak.mealient.databinding.ViewHolderInstructionBinding
|
||||
@@ -12,21 +15,12 @@ import gq.kirmanak.mealient.extensions.resources
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.ui.recipes.info.RecipeInstructionsAdapter.RecipeInstructionViewHolder
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RecipeInstructionsAdapter private constructor(
|
||||
class RecipeInstructionsAdapter @Inject constructor(
|
||||
private val logger: Logger,
|
||||
private val recipeInstructionViewHolderFactory: RecipeInstructionViewHolder.Factory,
|
||||
) : ListAdapter<RecipeInstructionEntity, RecipeInstructionViewHolder>(RecipeInstructionDiffCallback) {
|
||||
|
||||
@Singleton
|
||||
class Factory @Inject constructor(
|
||||
private val logger: Logger,
|
||||
private val recipeInstructionViewHolderFactory: RecipeInstructionViewHolder.Factory,
|
||||
) {
|
||||
fun build() = RecipeInstructionsAdapter(logger, recipeInstructionViewHolderFactory)
|
||||
}
|
||||
|
||||
private object RecipeInstructionDiffCallback :
|
||||
DiffUtil.ItemCallback<RecipeInstructionEntity>() {
|
||||
override fun areItemsTheSame(
|
||||
@@ -40,15 +34,14 @@ class RecipeInstructionsAdapter private constructor(
|
||||
): Boolean = oldItem == newItem
|
||||
}
|
||||
|
||||
class RecipeInstructionViewHolder private constructor(
|
||||
private val binding: ViewHolderInstructionBinding,
|
||||
class RecipeInstructionViewHolder @AssistedInject constructor(
|
||||
@Assisted private val binding: ViewHolderInstructionBinding,
|
||||
private val logger: Logger,
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
@Singleton
|
||||
class Factory @Inject constructor(private val logger: Logger) {
|
||||
fun build(binding: ViewHolderInstructionBinding) =
|
||||
RecipeInstructionViewHolder(binding, logger)
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun build(binding: ViewHolderInstructionBinding): RecipeInstructionViewHolder
|
||||
}
|
||||
|
||||
fun bind(item: RecipeInstructionEntity, position: Int) {
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package gq.kirmanak.mealient.architecture.configuration
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AppDispatchersImpl @Inject constructor() : AppDispatchers {
|
||||
|
||||
override val io = Dispatchers.IO
|
||||
override val io: CoroutineDispatcher get() = Dispatchers.IO
|
||||
|
||||
override val main = Dispatchers.Main
|
||||
override val main: CoroutineDispatcher get() = Dispatchers.Main
|
||||
|
||||
override val default = Dispatchers.Default
|
||||
override val default: CoroutineDispatcher get() = Dispatchers.Default
|
||||
|
||||
override val unconfined = Dispatchers.Unconfined
|
||||
override val unconfined: CoroutineDispatcher get() = Dispatchers.Unconfined
|
||||
}
|
||||
@@ -4,13 +4,11 @@ import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface ArchitectureModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindAppDispatchers(appDispatchersImpl: AppDispatchersImpl): AppDispatchers
|
||||
}
|
||||
@@ -26,11 +26,9 @@ internal interface DatabaseModule {
|
||||
.build()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRecipeDao(db: AppDb): RecipeDao = db.recipeDao()
|
||||
}
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun provideRecipeStorage(recipeStorageImpl: RecipeStorageImpl): RecipeStorage
|
||||
}
|
||||
@@ -10,9 +10,7 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeWithSummaryAndIngredientsAndInstructions
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
internal class RecipeStorageImpl @Inject constructor(
|
||||
private val db: AppDb,
|
||||
private val logger: Logger,
|
||||
|
||||
@@ -14,13 +14,11 @@ import gq.kirmanak.mealient.datasource.BuildConfig
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object DebugModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
@IntoSet
|
||||
fun provideLoggingInterceptor(logger: Logger): Interceptor {
|
||||
val interceptor = HttpLoggingInterceptor { message -> logger.v(tag = "OkHttp") { message } }
|
||||
@@ -32,7 +30,6 @@ object DebugModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@IntoSet
|
||||
fun provideChuckerInterceptor(@ApplicationContext context: Context): Interceptor {
|
||||
val collector = ChuckerCollector(
|
||||
|
||||
@@ -73,32 +73,25 @@ interface DataSourceModule {
|
||||
}
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindCacheBuilder(cacheBuilderImpl: CacheBuilderImpl): CacheBuilder
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindOkHttpBuilder(okHttpBuilderImpl: OkHttpBuilderImpl): OkHttpBuilder
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindMealieDataSource(mealientDataSourceImpl: MealieDataSourceV0Impl): MealieDataSourceV0
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindMealieDataSourceV1(mealientDataSourceImpl: MealieDataSourceV1Impl): MealieDataSourceV1
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindNetworkRequestWrapper(networkRequestWrapperImpl: NetworkRequestWrapperImpl): NetworkRequestWrapper
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
@IntoSet
|
||||
fun bindAuthInterceptor(authInterceptor: AuthInterceptor): LocalInterceptor
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
@IntoSet
|
||||
fun bindBaseUrlInterceptor(baseUrlInterceptor: BaseUrlInterceptor): LocalInterceptor
|
||||
}
|
||||
@@ -9,9 +9,7 @@ import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class AuthInterceptor @Inject constructor(
|
||||
private val logger: Logger,
|
||||
private val authenticationProviderProvider: Provider<AuthenticationProvider>,
|
||||
|
||||
@@ -10,9 +10,7 @@ import okhttp3.Response
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class BaseUrlInterceptor @Inject constructor(
|
||||
private val logger: Logger,
|
||||
private val serverUrlProviderProvider: Provider<ServerUrlProvider>,
|
||||
|
||||
@@ -8,9 +8,7 @@ import gq.kirmanak.mealient.logging.Logger
|
||||
import okhttp3.Cache
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class CacheBuilderImpl @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val logger: Logger,
|
||||
|
||||
@@ -6,9 +6,7 @@ import gq.kirmanak.mealient.datasource.runCatchingExceptCancel
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import retrofit2.HttpException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class NetworkRequestWrapperImpl @Inject constructor(
|
||||
private val logger: Logger,
|
||||
) : NetworkRequestWrapper {
|
||||
|
||||
@@ -7,9 +7,7 @@ import gq.kirmanak.mealient.logging.Logger
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class OkHttpBuilderImpl @Inject constructor(
|
||||
private val cacheBuilder: CacheBuilder,
|
||||
// Use @JvmSuppressWildcards because otherwise dagger can't inject it (https://stackoverflow.com/a/43149382)
|
||||
|
||||
@@ -5,9 +5,7 @@ import okhttp3.OkHttpClient
|
||||
import retrofit2.Converter.Factory
|
||||
import retrofit2.Retrofit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class RetrofitBuilder @Inject constructor(
|
||||
private val okHttpClient: OkHttpClient,
|
||||
private val converterFactory: Factory,
|
||||
|
||||
@@ -18,9 +18,7 @@ import retrofit2.HttpException
|
||||
import java.net.ConnectException
|
||||
import java.net.SocketTimeoutException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class MealieDataSourceV0Impl @Inject constructor(
|
||||
private val networkRequestWrapper: NetworkRequestWrapper,
|
||||
private val service: MealieServiceV0,
|
||||
|
||||
@@ -27,9 +27,7 @@ import retrofit2.HttpException
|
||||
import java.net.ConnectException
|
||||
import java.net.SocketTimeoutException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class MealieDataSourceV1Impl @Inject constructor(
|
||||
private val networkRequestWrapper: NetworkRequestWrapper,
|
||||
private val service: MealieServiceV1,
|
||||
|
||||
@@ -15,6 +15,5 @@ object ReleaseModule {
|
||||
// is required by Dagger, so an empty Set is provided here
|
||||
// Use @JvmSuppressWildcards because otherwise dagger can't inject it (https://stackoverflow.com/a/43149382)
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideInterceptors(): Set<@JvmSuppressWildcards Interceptor> = emptySet()
|
||||
}
|
||||
|
||||
@@ -5,9 +5,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 AddRecipeStorageImpl @Inject constructor(
|
||||
private val dataStore: DataStore<AddRecipeInput>,
|
||||
private val logger: Logger,
|
||||
|
||||
@@ -10,18 +10,15 @@ import gq.kirmanak.mealient.shopping_lists.repo.ShoppingListsRepo
|
||||
import gq.kirmanak.mealient.shopping_lists.repo.ShoppingListsRepoImpl
|
||||
import gq.kirmanak.mealient.shopping_lists.util.LoadingHelperFactory
|
||||
import gq.kirmanak.mealient.shopping_lists.util.LoadingHelperFactoryImpl
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface ShoppingListsModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindShoppingListsDataSource(impl: ShoppingListsDataSourceImpl): ShoppingListsDataSource
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindShoppingListsRepo(impl: ShoppingListsRepoImpl): ShoppingListsRepo
|
||||
|
||||
@Binds
|
||||
|
||||
@@ -5,9 +5,7 @@ import gq.kirmanak.mealient.datasource.models.ShoppingListInfo
|
||||
import gq.kirmanak.mealient.datasource.v1.MealieDataSourceV1
|
||||
import gq.kirmanak.mealient.model_mapper.ModelMapper
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ShoppingListsDataSourceImpl @Inject constructor(
|
||||
private val v1Source: MealieDataSourceV1,
|
||||
private val modelMapper: ModelMapper,
|
||||
|
||||
@@ -5,9 +5,7 @@ import gq.kirmanak.mealient.datasource.models.ShoppingListInfo
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.shopping_lists.network.ShoppingListsDataSource
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ShoppingListsRepoImpl @Inject constructor(
|
||||
private val dataSource: ShoppingListsDataSource,
|
||||
private val logger: Logger,
|
||||
|
||||
@@ -3,9 +3,7 @@ package gq.kirmanak.mealient.logging
|
||||
import android.util.Log
|
||||
import gq.kirmanak.mealient.architecture.configuration.BuildConfiguration
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class LogcatAppender @Inject constructor(
|
||||
private val buildConfiguration: BuildConfiguration,
|
||||
) : Appender {
|
||||
|
||||
@@ -3,9 +3,7 @@ package gq.kirmanak.mealient.logging
|
||||
import android.util.Log
|
||||
import java.util.regex.Pattern
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class LoggerImpl @Inject constructor(
|
||||
private val appenders: Set<@JvmSuppressWildcards Appender>,
|
||||
) : Logger {
|
||||
|
||||
@@ -5,18 +5,15 @@ import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoSet
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface LoggingModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindLogger(loggerImpl: LoggerImpl): Logger
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
@IntoSet
|
||||
fun bindLogcatAppender(logcatAppender: LogcatAppender): Appender
|
||||
}
|
||||
@@ -50,9 +50,7 @@ import gq.kirmanak.mealient.datasource.v1.models.VersionResponseV1
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ModelMapperImpl @Inject constructor() : ModelMapper {
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,11 @@ import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface ModelMapperModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindModelMapper(impl: ModelMapperImpl): ModelMapper
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package gq.kirmanak.mealient.test
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.logging.MessageSupplier
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class FakeLogger @Inject constructor() : Logger {
|
||||
override fun v(throwable: Throwable?, tag: String?, messageSupplier: MessageSupplier) {
|
||||
print("V", throwable, messageSupplier)
|
||||
|
||||
@@ -6,7 +6,6 @@ import dagger.hilt.components.SingletonComponent
|
||||
import dagger.hilt.testing.TestInstallIn
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.logging.LoggingModule
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@TestInstallIn(
|
||||
@@ -16,6 +15,5 @@ import javax.inject.Singleton
|
||||
interface FakeLoggingModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindFakeLogger(impl: FakeLogger): Logger
|
||||
}
|
||||
@@ -4,13 +4,11 @@ import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface UiModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindActivityUiStateController(impl: ActivityUiStateControllerImpl): ActivityUiStateController
|
||||
}
|
||||
Reference in New Issue
Block a user