|
| 1 | +package com.d4rk.androidtutorials.java.di; |
| 2 | + |
| 3 | +import android.app.Application; |
| 4 | +import android.content.res.AssetManager; |
| 5 | + |
| 6 | +import com.android.volley.RequestQueue; |
| 7 | +import com.android.volley.toolbox.Volley; |
| 8 | +import com.d4rk.androidtutorials.java.data.repository.DefaultHomeRepository; |
| 9 | +import com.d4rk.androidtutorials.java.data.repository.DefaultQuizRepository; |
| 10 | +import com.d4rk.androidtutorials.java.data.repository.HomeRepository; |
| 11 | +import com.d4rk.androidtutorials.java.data.repository.QuizRepository; |
| 12 | +import com.d4rk.androidtutorials.java.data.source.DefaultHomeLocalDataSource; |
| 13 | +import com.d4rk.androidtutorials.java.data.source.DefaultHomeRemoteDataSource; |
| 14 | +import com.d4rk.androidtutorials.java.data.source.DefaultQuizLocalDataSource; |
| 15 | +import com.d4rk.androidtutorials.java.data.source.HomeLocalDataSource; |
| 16 | +import com.d4rk.androidtutorials.java.data.source.HomeRemoteDataSource; |
| 17 | +import com.d4rk.androidtutorials.java.data.source.QuizLocalDataSource; |
| 18 | +import com.d4rk.androidtutorials.java.domain.about.GetCurrentYearUseCase; |
| 19 | +import com.d4rk.androidtutorials.java.domain.about.GetVersionStringUseCase; |
| 20 | +import com.d4rk.androidtutorials.java.domain.help.LaunchReviewFlowUseCase; |
| 21 | +import com.d4rk.androidtutorials.java.domain.help.RequestReviewFlowUseCase; |
| 22 | +import com.d4rk.androidtutorials.java.domain.home.GetDailyTipUseCase; |
| 23 | +import com.d4rk.androidtutorials.java.domain.home.GetPromotedAppsUseCase; |
| 24 | +import com.d4rk.androidtutorials.java.domain.main.ApplyLanguageSettingsUseCase; |
| 25 | +import com.d4rk.androidtutorials.java.domain.main.ApplyThemeSettingsUseCase; |
| 26 | +import com.d4rk.androidtutorials.java.domain.main.BuildShortcutIntentUseCase; |
| 27 | +import com.d4rk.androidtutorials.java.domain.main.GetAppUpdateManagerUseCase; |
| 28 | +import com.d4rk.androidtutorials.java.domain.main.GetBottomNavLabelVisibilityUseCase; |
| 29 | +import com.d4rk.androidtutorials.java.domain.main.GetDefaultTabPreferenceUseCase; |
| 30 | +import com.d4rk.androidtutorials.java.domain.main.IsAppInstalledUseCase; |
| 31 | +import com.d4rk.androidtutorials.java.domain.main.MarkStartupScreenShownUseCase; |
| 32 | +import com.d4rk.androidtutorials.java.domain.main.ShouldShowStartupScreenUseCase; |
| 33 | +import com.d4rk.androidtutorials.java.domain.quiz.LoadQuizQuestionsUseCase; |
| 34 | +import com.d4rk.androidtutorials.java.domain.settings.ApplyConsentUseCase; |
| 35 | +import com.d4rk.androidtutorials.java.domain.settings.GetSharedPreferencesUseCase; |
| 36 | +import com.d4rk.androidtutorials.java.domain.settings.OnPreferenceChangedUseCase; |
| 37 | +import com.d4rk.androidtutorials.java.domain.startup.LoadConsentFormUseCase; |
| 38 | +import com.d4rk.androidtutorials.java.domain.startup.RequestConsentInfoUseCase; |
| 39 | +import com.d4rk.androidtutorials.java.domain.support.InitBillingClientUseCase; |
| 40 | +import com.d4rk.androidtutorials.java.domain.support.InitMobileAdsUseCase; |
| 41 | +import com.d4rk.androidtutorials.java.domain.support.InitiatePurchaseUseCase; |
| 42 | +import com.d4rk.androidtutorials.java.domain.support.QueryProductDetailsUseCase; |
| 43 | +import com.d4rk.androidtutorials.java.ui.screens.about.repository.AboutRepository; |
| 44 | +import com.d4rk.androidtutorials.java.ui.screens.help.repository.HelpRepository; |
| 45 | +import com.d4rk.androidtutorials.java.ui.screens.main.repository.MainRepository; |
| 46 | +import com.d4rk.androidtutorials.java.ui.screens.settings.repository.SettingsRepository; |
| 47 | +import com.d4rk.androidtutorials.java.ui.screens.startup.repository.StartupRepository; |
| 48 | +import com.d4rk.androidtutorials.java.ui.screens.support.repository.SupportRepository; |
| 49 | + |
| 50 | +import java.util.concurrent.ExecutorService; |
| 51 | +import java.util.concurrent.Executors; |
| 52 | + |
| 53 | +import dagger.Module; |
| 54 | +import dagger.Provides; |
| 55 | +import dagger.hilt.InstallIn; |
| 56 | +import dagger.hilt.components.SingletonComponent; |
| 57 | +import javax.inject.Singleton; |
| 58 | + |
| 59 | +@Module |
| 60 | +@InstallIn(SingletonComponent.class) |
| 61 | +public class AppModule { |
| 62 | + |
| 63 | + @Provides |
| 64 | + @Singleton |
| 65 | + public ExecutorService provideExecutorService() { |
| 66 | + return Executors.newSingleThreadExecutor(); |
| 67 | + } |
| 68 | + |
| 69 | + @Provides |
| 70 | + @Singleton |
| 71 | + public RequestQueue provideRequestQueue(Application application) { |
| 72 | + return Volley.newRequestQueue(application); |
| 73 | + } |
| 74 | + |
| 75 | + @Provides |
| 76 | + @Singleton |
| 77 | + public HomeRemoteDataSource provideHomeRemoteDataSource(RequestQueue queue) { |
| 78 | + return new DefaultHomeRemoteDataSource(queue, |
| 79 | + "https://raw.githubusercontent.com/D4rK7355608/com.d4rk.apis/refs/heads/main/App%20Toolkit/release/en/home/api_android_apps.json"); |
| 80 | + } |
| 81 | + |
| 82 | + @Provides |
| 83 | + @Singleton |
| 84 | + public HomeLocalDataSource provideHomeLocalDataSource(Application application) { |
| 85 | + return new DefaultHomeLocalDataSource(application); |
| 86 | + } |
| 87 | + |
| 88 | + @Provides |
| 89 | + @Singleton |
| 90 | + public HomeRepository provideHomeRepository(HomeRemoteDataSource remote, |
| 91 | + HomeLocalDataSource local) { |
| 92 | + return new DefaultHomeRepository(remote, local); |
| 93 | + } |
| 94 | + |
| 95 | + @Provides |
| 96 | + public GetDailyTipUseCase provideGetDailyTipUseCase(HomeRepository repository) { |
| 97 | + return new GetDailyTipUseCase(repository); |
| 98 | + } |
| 99 | + |
| 100 | + @Provides |
| 101 | + public GetPromotedAppsUseCase provideGetPromotedAppsUseCase(HomeRepository repository) { |
| 102 | + return new GetPromotedAppsUseCase(repository); |
| 103 | + } |
| 104 | + |
| 105 | + @Provides |
| 106 | + @Singleton |
| 107 | + public AboutRepository provideAboutRepository(Application application) { |
| 108 | + return new AboutRepository(application); |
| 109 | + } |
| 110 | + |
| 111 | + @Provides |
| 112 | + public GetVersionStringUseCase provideGetVersionStringUseCase(AboutRepository repository) { |
| 113 | + return new GetVersionStringUseCase(repository); |
| 114 | + } |
| 115 | + |
| 116 | + @Provides |
| 117 | + public GetCurrentYearUseCase provideGetCurrentYearUseCase(AboutRepository repository) { |
| 118 | + return new GetCurrentYearUseCase(repository); |
| 119 | + } |
| 120 | + |
| 121 | + @Provides |
| 122 | + @Singleton |
| 123 | + public MainRepository provideMainRepository(Application application) { |
| 124 | + return new MainRepository(application); |
| 125 | + } |
| 126 | + |
| 127 | + @Provides |
| 128 | + public ApplyThemeSettingsUseCase provideApplyThemeSettingsUseCase(MainRepository repository) { |
| 129 | + return new ApplyThemeSettingsUseCase(repository); |
| 130 | + } |
| 131 | + |
| 132 | + @Provides |
| 133 | + public GetBottomNavLabelVisibilityUseCase provideGetBottomNavLabelVisibilityUseCase(MainRepository repository) { |
| 134 | + return new GetBottomNavLabelVisibilityUseCase(repository); |
| 135 | + } |
| 136 | + |
| 137 | + @Provides |
| 138 | + public GetDefaultTabPreferenceUseCase provideGetDefaultTabPreferenceUseCase(MainRepository repository) { |
| 139 | + return new GetDefaultTabPreferenceUseCase(repository); |
| 140 | + } |
| 141 | + |
| 142 | + @Provides |
| 143 | + public ApplyLanguageSettingsUseCase provideApplyLanguageSettingsUseCase(MainRepository repository) { |
| 144 | + return new ApplyLanguageSettingsUseCase(repository); |
| 145 | + } |
| 146 | + |
| 147 | + @Provides |
| 148 | + public ShouldShowStartupScreenUseCase provideShouldShowStartupScreenUseCase(MainRepository repository) { |
| 149 | + return new ShouldShowStartupScreenUseCase(repository); |
| 150 | + } |
| 151 | + |
| 152 | + @Provides |
| 153 | + public MarkStartupScreenShownUseCase provideMarkStartupScreenShownUseCase(MainRepository repository) { |
| 154 | + return new MarkStartupScreenShownUseCase(repository); |
| 155 | + } |
| 156 | + |
| 157 | + @Provides |
| 158 | + public IsAppInstalledUseCase provideIsAppInstalledUseCase(MainRepository repository) { |
| 159 | + return new IsAppInstalledUseCase(repository); |
| 160 | + } |
| 161 | + |
| 162 | + @Provides |
| 163 | + public BuildShortcutIntentUseCase provideBuildShortcutIntentUseCase(MainRepository repository) { |
| 164 | + return new BuildShortcutIntentUseCase(repository); |
| 165 | + } |
| 166 | + |
| 167 | + @Provides |
| 168 | + public GetAppUpdateManagerUseCase provideGetAppUpdateManagerUseCase(MainRepository repository) { |
| 169 | + return new GetAppUpdateManagerUseCase(repository); |
| 170 | + } |
| 171 | + |
| 172 | + @Provides |
| 173 | + @Singleton |
| 174 | + public SettingsRepository provideSettingsRepository(Application application) { |
| 175 | + return new SettingsRepository(application); |
| 176 | + } |
| 177 | + |
| 178 | + @Provides |
| 179 | + public OnPreferenceChangedUseCase provideOnPreferenceChangedUseCase(SettingsRepository repository) { |
| 180 | + return new OnPreferenceChangedUseCase(repository); |
| 181 | + } |
| 182 | + |
| 183 | + @Provides |
| 184 | + public GetSharedPreferencesUseCase provideGetSharedPreferencesUseCase(SettingsRepository repository) { |
| 185 | + return new GetSharedPreferencesUseCase(repository); |
| 186 | + } |
| 187 | + |
| 188 | + @Provides |
| 189 | + public ApplyConsentUseCase provideApplyConsentUseCase(SettingsRepository repository) { |
| 190 | + return new ApplyConsentUseCase(repository); |
| 191 | + } |
| 192 | + |
| 193 | + @Provides |
| 194 | + @Singleton |
| 195 | + public QuizLocalDataSource provideQuizLocalDataSource(Application application) { |
| 196 | + AssetManager manager = application.getAssets(); |
| 197 | + return new DefaultQuizLocalDataSource(manager); |
| 198 | + } |
| 199 | + |
| 200 | + @Provides |
| 201 | + @Singleton |
| 202 | + public QuizRepository provideQuizRepository(QuizLocalDataSource local) { |
| 203 | + return new DefaultQuizRepository(local); |
| 204 | + } |
| 205 | + |
| 206 | + @Provides |
| 207 | + public LoadQuizQuestionsUseCase provideLoadQuizQuestionsUseCase(QuizRepository repository) { |
| 208 | + return new LoadQuizQuestionsUseCase(repository); |
| 209 | + } |
| 210 | + |
| 211 | + @Provides |
| 212 | + @Singleton |
| 213 | + public StartupRepository provideStartupRepository(Application application) { |
| 214 | + return new StartupRepository(application); |
| 215 | + } |
| 216 | + |
| 217 | + @Provides |
| 218 | + public RequestConsentInfoUseCase provideRequestConsentInfoUseCase(StartupRepository repository) { |
| 219 | + return new RequestConsentInfoUseCase(repository); |
| 220 | + } |
| 221 | + |
| 222 | + @Provides |
| 223 | + public LoadConsentFormUseCase provideLoadConsentFormUseCase(StartupRepository repository) { |
| 224 | + return new LoadConsentFormUseCase(repository); |
| 225 | + } |
| 226 | + |
| 227 | + @Provides |
| 228 | + @Singleton |
| 229 | + public SupportRepository provideSupportRepository(Application application) { |
| 230 | + return new SupportRepository(application); |
| 231 | + } |
| 232 | + |
| 233 | + @Provides |
| 234 | + public InitBillingClientUseCase provideInitBillingClientUseCase(SupportRepository repository) { |
| 235 | + return new InitBillingClientUseCase(repository); |
| 236 | + } |
| 237 | + |
| 238 | + @Provides |
| 239 | + public QueryProductDetailsUseCase provideQueryProductDetailsUseCase(SupportRepository repository) { |
| 240 | + return new QueryProductDetailsUseCase(repository); |
| 241 | + } |
| 242 | + |
| 243 | + @Provides |
| 244 | + public InitiatePurchaseUseCase provideInitiatePurchaseUseCase(SupportRepository repository) { |
| 245 | + return new InitiatePurchaseUseCase(repository); |
| 246 | + } |
| 247 | + |
| 248 | + @Provides |
| 249 | + public InitMobileAdsUseCase provideInitMobileAdsUseCase(SupportRepository repository) { |
| 250 | + return new InitMobileAdsUseCase(repository); |
| 251 | + } |
| 252 | + |
| 253 | + @Provides |
| 254 | + @Singleton |
| 255 | + public HelpRepository provideHelpRepository(Application application) { |
| 256 | + return new HelpRepository(application); |
| 257 | + } |
| 258 | + |
| 259 | + @Provides |
| 260 | + public RequestReviewFlowUseCase provideRequestReviewFlowUseCase(HelpRepository repository) { |
| 261 | + return new RequestReviewFlowUseCase(repository); |
| 262 | + } |
| 263 | + |
| 264 | + @Provides |
| 265 | + public LaunchReviewFlowUseCase provideLaunchReviewFlowUseCase(HelpRepository repository) { |
| 266 | + return new LaunchReviewFlowUseCase(repository); |
| 267 | + } |
| 268 | +} |
0 commit comments