From 6d46881972c8d59b3c2831f1afc1518f9269bb94 Mon Sep 17 00:00:00 2001 From: "DHNGL-ABHISHEKP\\Abhishek P" Date: Tue, 12 Mar 2024 20:48:32 +0530 Subject: [PATCH] Updated Application class and other documentation --- .../jetpack_compose_all_in_one/di/MainApp.kt | 21 +++++++++++----- .../di/RoomModules.kt | 20 +++++++++++++++- .../di/StateModule.kt | 24 ++++++++++++------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/MainApp.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/MainApp.kt index 05156850..6a055619 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/MainApp.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/MainApp.kt @@ -10,30 +10,39 @@ import com.google.android.libraries.places.api.Places import com.stripe.android.PaymentConfiguration import dagger.hilt.android.HiltAndroidApp +/** + * Main application class for the Android application. + */ @HiltAndroidApp -class MainApp: Application() { - companion object{ +class MainApp : Application() { + companion object { + /** + * Notification manager instance. + */ lateinit var notificationManager: NotificationManager } override fun onCreate() { super.onCreate() - // App is always above API 26 + // Create notification channel val notificationChannel = NotificationChannel( "channel_id", "channel_name", NotificationManager.IMPORTANCE_HIGH ) - notificationChannel.description = "notification channel desc.." + notificationChannel.description = "Notification channel description" notificationChannel.enableVibration(true) notificationChannel.enableLights(true) - notificationChannel.vibrationPattern = longArrayOf(100,200,300,400,300,200,100) + notificationChannel.vibrationPattern = longArrayOf(100, 200, 300, 400, 300, 200, 100) notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.createNotificationChannel(notificationChannel) + // Initialize Google Places SDK Places.initialize(applicationContext, resources.getString(R.string.GOOGLE_MAPS_API_KEY)) + + // Initialize Stripe SDK PaymentConfiguration.init(applicationContext, STRIPE_PUBLISHABLE_KEY) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/RoomModules.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/RoomModules.kt index 532abc26..67b14ddd 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/RoomModules.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/RoomModules.kt @@ -12,9 +12,17 @@ import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import javax.inject.Singleton +/** + * Dagger Hilt module for providing dependencies related to Room database. + */ @Module @InstallIn(SingletonComponent::class) class RoomModules { + /** + * Provides an instance of the Room database. + * @param context Application context. + * @return Instance of the Room database. + */ @Provides @Singleton fun provideAppDatabase(@ApplicationContext context: Context) = Room.databaseBuilder( @@ -26,11 +34,21 @@ class RoomModules { .addMigrations(migration1To2) .build() + /** + * Provides an instance of the AlarmDao. + * @param db Instance of the Room database. + * @return Instance of the AlarmDao. + */ @Provides @Singleton fun provideAlarmDao(db: AppDatabase) = db.getAlarmDao() + /** + * Provides an instance of the ProfileDao. + * @param db Instance of the Room database. + * @return Instance of the ProfileDao. + */ @Provides @Singleton fun provideProfileDao(db: AppDatabase) = db.getProfileDao() -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/StateModule.kt b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/StateModule.kt index 56797836..136a584c 100644 --- a/app/src/main/java/com/example/jetpack_compose_all_in_one/di/StateModule.kt +++ b/app/src/main/java/com/example/jetpack_compose_all_in_one/di/StateModule.kt @@ -9,14 +9,22 @@ import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import javax.inject.Singleton +/** + * Dagger Hilt module for providing dependencies related to state management. + */ @Module @InstallIn(SingletonComponent::class) - class StateModule { +class StateModule { - @Singleton - @Provides - @MviNewsAPI - fun provideNewsStates(repository: RemoteNewRepository):NewsState{ - return NewsState(repository) - } -} \ No newline at end of file + /** + * Provides an instance of NewsState for MVI (Model-View-Intent) architecture. + * @param repository RemoteNewRepository instance. + * @return Instance of NewsState. + */ + @Singleton + @Provides + @MviNewsAPI + fun provideNewsStates(repository: RemoteNewRepository): NewsState { + return NewsState(repository) + } +}