diff --git a/core/platform-services/inject-android/build.gradle.kts b/core/platform-services/inject-android/build.gradle.kts index c35c7ebe5..546a1be40 100644 --- a/core/platform-services/inject-android/build.gradle.kts +++ b/core/platform-services/inject-android/build.gradle.kts @@ -43,8 +43,8 @@ android { val hmsImplementation by configurations val fossImplementation by configurations dependencies { - gmsImplementation(project(":core:platform-services:gms")) - hmsImplementation(project(":core:platform-services:hms")) - fossImplementation(project(":core:platform-services:foss")) + gmsImplementation(projects.core.platformServices.gms) + hmsImplementation(projects.core.platformServices.hms) + fossImplementation(projects.core.platformServices.foss) } } \ No newline at end of file diff --git a/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkKoinModule.kt b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt similarity index 74% rename from core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkKoinModule.kt rename to core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt index 3a44d2660..c0cb6b56c 100644 --- a/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkKoinModule.kt +++ b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt @@ -3,6 +3,8 @@ package org.michaelbel.movies.work.di import androidx.work.WorkManager import org.koin.android.ext.koin.androidContext import org.koin.androidx.workmanager.dsl.workerOf +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf import org.koin.dsl.module import org.michaelbel.movies.common.dispatchers.di.dispatchersKoinModule import org.michaelbel.movies.interactor.di.interactorKoinModule @@ -11,8 +13,10 @@ import org.michaelbel.movies.persistence.database.di.persistenceKoinModule import org.michaelbel.movies.work.AccountUpdateWorker import org.michaelbel.movies.work.DownloadImageWorker import org.michaelbel.movies.work.MoviesDatabaseWorker +import org.michaelbel.movies.work.WorkManagerInteractor +import org.michaelbel.movies.work.impl.WorkManagerInteractorImpl -val workKoinModule = module { +actual val workManagerInteractorKoinModule = module { includes( interactorKoinModule, dispatchersKoinModule, @@ -23,4 +27,5 @@ val workKoinModule = module { workerOf(::AccountUpdateWorker) workerOf(::DownloadImageWorker) workerOf(::MoviesDatabaseWorker) + singleOf(::WorkManagerInteractorImpl) { bind() } } \ No newline at end of file diff --git a/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt new file mode 100644 index 000000000..4dad02815 --- /dev/null +++ b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt @@ -0,0 +1,79 @@ +package org.michaelbel.movies.work.impl + +import androidx.work.Constraints +import androidx.work.Data +import androidx.work.ExistingWorkPolicy +import androidx.work.NetworkType +import androidx.work.OneTimeWorkRequestBuilder +import androidx.work.WorkInfo +import androidx.work.WorkManager +import androidx.work.workDataOf +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo +import org.michaelbel.movies.persistence.database.ktx.original +import org.michaelbel.movies.work.AccountUpdateWorker +import org.michaelbel.movies.work.DownloadImageWorker +import org.michaelbel.movies.work.MoviesDatabaseWorker +import org.michaelbel.movies.work.R +import org.michaelbel.movies.work.WorkInfoState +import org.michaelbel.movies.work.WorkManagerInteractor +import org.michaelbel.movies.work.ktx.nameRes + +class WorkManagerInteractorImpl( + private val workManager: WorkManager +): WorkManagerInteractor { + + override fun downloadImage(image: ImagePojo): Flow { + return flow { + val workData = Data.Builder() + .putString(DownloadImageWorker.KEY_IMAGE_URL, image.original) + .putInt(DownloadImageWorker.KEY_CONTENT_TITLE, R.string.gallery_downloading_image) + .putInt(DownloadImageWorker.KEY_CONTENT_TEXT, image.type.nameRes) + .build() + val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresStorageNotLow(true) + .setRequiresBatteryNotLow(true) + .build() + val downloadImageWorker = OneTimeWorkRequestBuilder() + .addTag(DownloadImageWorker.DOWNLOAD_IMAGE_WORKER_TAG) + .setConstraints(constraints) + .setInputData(workData) + .build() + workManager.run { + enqueueUniqueWork(image.toString(), ExistingWorkPolicy.KEEP, downloadImageWorker) + getWorkInfoByIdFlow(downloadImageWorker.id).collect { workInfo -> + when (workInfo?.state) { + WorkInfo.State.SUCCEEDED -> { + val result = workInfo.outputData.getString(DownloadImageWorker.KEY_IMAGE_URL).orEmpty() + emit(WorkInfoState.Success(result)) + } + WorkInfo.State.FAILED -> { + val result = workInfo.outputData.getString(DownloadImageWorker.KEY_IMAGE_URL).orEmpty() + emit(WorkInfoState.Failure(result)) + } + else -> {} + } + } + } + } + } + + override fun prepopulateDatabase() { + val request = OneTimeWorkRequestBuilder() + .setInputData(workDataOf(MoviesDatabaseWorker.KEY_FILENAME to MOVIES_DATA_FILENAME)) + .build() + workManager.enqueue(request) + } + + override fun updateAccountDetails() { + val request = OneTimeWorkRequestBuilder() + .build() + workManager.enqueue(request) + } + + private companion object { + private const val MOVIES_DATA_FILENAME = "movies.json" + } +} \ No newline at end of file diff --git a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ktx/ImageTypeKtx.kt b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/ktx/ImageTypeKtx.kt similarity index 80% rename from feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ktx/ImageTypeKtx.kt rename to core/work/src/androidMain/kotlin/org/michaelbel/movies/work/ktx/ImageTypeKtx.kt index 2f94d195e..8f4a7ff3d 100644 --- a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ktx/ImageTypeKtx.kt +++ b/core/work/src/androidMain/kotlin/org/michaelbel/movies/work/ktx/ImageTypeKtx.kt @@ -1,8 +1,8 @@ -package org.michaelbel.movies.gallery.ktx +package org.michaelbel.movies.work.ktx import androidx.annotation.StringRes -import org.michaelbel.movies.gallery_impl.R import org.michaelbel.movies.persistence.database.entity.pojo.ImageType +import org.michaelbel.movies.work.R internal val ImageType.nameRes: Int @StringRes get() = when (this) { diff --git a/core/work/src/androidMain/res/values-ru/strings.xml b/core/work/src/androidMain/res/values-ru/strings.xml new file mode 100644 index 000000000..8ee728a29 --- /dev/null +++ b/core/work/src/androidMain/res/values-ru/strings.xml @@ -0,0 +1,7 @@ + + + Загрузка изображения... + Постер + Обложка + Логотип + \ No newline at end of file diff --git a/core/work/src/androidMain/res/values/strings.xml b/core/work/src/androidMain/res/values/strings.xml new file mode 100644 index 000000000..453568335 --- /dev/null +++ b/core/work/src/androidMain/res/values/strings.xml @@ -0,0 +1,7 @@ + + + Downloading Image... + Poster + Backdrop + Logo + \ No newline at end of file diff --git a/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkInfoState.kt b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkInfoState.kt new file mode 100644 index 000000000..02267192e --- /dev/null +++ b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkInfoState.kt @@ -0,0 +1,7 @@ +package org.michaelbel.movies.work + +sealed interface WorkInfoState { + data class Success(val result: String): WorkInfoState + data class Failure(val result: String): WorkInfoState + data object None: WorkInfoState +} \ No newline at end of file diff --git a/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkManagerInteractor.kt b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkManagerInteractor.kt new file mode 100644 index 000000000..803c5289f --- /dev/null +++ b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkManagerInteractor.kt @@ -0,0 +1,13 @@ +package org.michaelbel.movies.work + +import kotlinx.coroutines.flow.Flow +import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo + +interface WorkManagerInteractor { + + fun downloadImage(image: ImagePojo): Flow + + fun prepopulateDatabase() + + fun updateAccountDetails() +} \ No newline at end of file diff --git a/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt new file mode 100644 index 000000000..d9c504b7a --- /dev/null +++ b/core/work/src/commonMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt @@ -0,0 +1,5 @@ +package org.michaelbel.movies.work.di + +import org.koin.core.module.Module + +expect val workManagerInteractorKoinModule: Module \ No newline at end of file diff --git a/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt b/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt new file mode 100644 index 000000000..16013a9e9 --- /dev/null +++ b/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt @@ -0,0 +1,11 @@ +package org.michaelbel.movies.work.di + +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module +import org.michaelbel.movies.work.WorkManagerInteractor +import org.michaelbel.movies.work.impl.WorkManagerInteractorImpl + +actual val workManagerInteractorKoinModule = module { + singleOf(::WorkManagerInteractorImpl) { bind() } +} \ No newline at end of file diff --git a/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt b/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt new file mode 100644 index 000000000..374905e28 --- /dev/null +++ b/core/work/src/iosMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt @@ -0,0 +1,18 @@ +package org.michaelbel.movies.work.impl + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo +import org.michaelbel.movies.work.WorkInfoState +import org.michaelbel.movies.work.WorkManagerInteractor + +class WorkManagerInteractorImpl: WorkManagerInteractor { + + override fun downloadImage(image: ImagePojo): Flow { + return flowOf(WorkInfoState.Success("")) + } + + override fun prepopulateDatabase() {} + + override fun updateAccountDetails() {} +} \ No newline at end of file diff --git a/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt b/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt new file mode 100644 index 000000000..16013a9e9 --- /dev/null +++ b/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt @@ -0,0 +1,11 @@ +package org.michaelbel.movies.work.di + +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module +import org.michaelbel.movies.work.WorkManagerInteractor +import org.michaelbel.movies.work.impl.WorkManagerInteractorImpl + +actual val workManagerInteractorKoinModule = module { + singleOf(::WorkManagerInteractorImpl) { bind() } +} \ No newline at end of file diff --git a/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt b/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt new file mode 100644 index 000000000..374905e28 --- /dev/null +++ b/core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt @@ -0,0 +1,18 @@ +package org.michaelbel.movies.work.impl + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo +import org.michaelbel.movies.work.WorkInfoState +import org.michaelbel.movies.work.WorkManagerInteractor + +class WorkManagerInteractorImpl: WorkManagerInteractor { + + override fun downloadImage(image: ImagePojo): Flow { + return flowOf(WorkInfoState.Success("")) + } + + override fun prepopulateDatabase() {} + + override fun updateAccountDetails() {} +} \ No newline at end of file diff --git a/feature/debug-impl/build.gradle.kts b/feature/debug-impl/build.gradle.kts index 63c9ca27d..b5f02a1bb 100644 --- a/feature/debug-impl/build.gradle.kts +++ b/feature/debug-impl/build.gradle.kts @@ -7,6 +7,10 @@ plugins { kotlin { androidTarget() + jvm() + iosX64() + iosArm64() + iosSimulatorArm64() sourceSets { commonMain.dependencies { diff --git a/feature/debug/build.gradle.kts b/feature/debug/build.gradle.kts index aaab8274d..7a45d7c7b 100644 --- a/feature/debug/build.gradle.kts +++ b/feature/debug/build.gradle.kts @@ -7,9 +7,14 @@ plugins { kotlin { androidTarget() + jvm() + iosX64() + iosArm64() + iosSimulatorArm64() sourceSets { - androidMain.dependencies { + commonMain.dependencies { + api(projects.core.ui) api(projects.feature.debugImpl) } } diff --git a/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt b/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt index f7bc7daa1..ad0bb786f 100644 --- a/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt +++ b/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt @@ -1,9 +1,11 @@ package org.michaelbel.movies.debug.di -import org.koin.android.ext.koin.androidContext +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf import org.koin.dsl.module -import org.michaelbel.movies.debug.notification.DebugNotificationClient +import org.michaelbel.movies.debug.DebugNotificationInteractor +import org.michaelbel.movies.debug.impl.DebugNotificationInteractorImpl -val debugNotificationClientKoinModule = module { - single { DebugNotificationClient(androidContext()) } +actual val debugNotificationClientKoinModule = module { + singleOf(::DebugNotificationInteractorImpl) { bind() } } \ No newline at end of file diff --git a/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/notification/DebugNotificationClient.kt b/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt similarity index 92% rename from feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/notification/DebugNotificationClient.kt rename to feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt index 456ff0fca..a1b0e341e 100644 --- a/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/notification/DebugNotificationClient.kt +++ b/feature/debug/src/androidMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt @@ -1,6 +1,6 @@ @file:SuppressLint("MissingPermission") -package org.michaelbel.movies.debug.notification +package org.michaelbel.movies.debug.impl import android.annotation.SuppressLint import android.app.PendingIntent @@ -13,14 +13,15 @@ import androidx.core.app.NotificationManagerCompat import org.michaelbel.movies.common.ktx.isPostNotificationsPermissionGranted import org.michaelbel.movies.common.ktx.notificationManager import org.michaelbel.movies.debug.DebugActivity +import org.michaelbel.movies.debug.DebugNotificationInteractor import org.michaelbel.movies.debug.R import org.michaelbel.movies.ui.icons.MoviesAndroidIcons -class DebugNotificationClient( +internal class DebugNotificationInteractorImpl( private val context: Context -) { +): DebugNotificationInteractor { - fun showDebugNotification() { + override fun showDebugNotification() { createChannel( channelId = R.string.notification_debug_channel_id, channelName = R.string.notification_debug_channel_name, diff --git a/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/DebugNotificationInteractor.kt b/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/DebugNotificationInteractor.kt new file mode 100644 index 000000000..11f9d96f8 --- /dev/null +++ b/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/DebugNotificationInteractor.kt @@ -0,0 +1,5 @@ +package org.michaelbel.movies.debug + +interface DebugNotificationInteractor { + fun showDebugNotification() +} \ No newline at end of file diff --git a/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt b/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt new file mode 100644 index 000000000..6e21c95ef --- /dev/null +++ b/feature/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt @@ -0,0 +1,5 @@ +package org.michaelbel.movies.debug.di + +import org.koin.core.module.Module + +expect val debugNotificationClientKoinModule: Module \ No newline at end of file diff --git a/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt b/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt new file mode 100644 index 000000000..ad0bb786f --- /dev/null +++ b/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt @@ -0,0 +1,11 @@ +package org.michaelbel.movies.debug.di + +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module +import org.michaelbel.movies.debug.DebugNotificationInteractor +import org.michaelbel.movies.debug.impl.DebugNotificationInteractorImpl + +actual val debugNotificationClientKoinModule = module { + singleOf(::DebugNotificationInteractorImpl) { bind() } +} \ No newline at end of file diff --git a/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt b/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt new file mode 100644 index 000000000..d5a6d7364 --- /dev/null +++ b/feature/debug/src/iosMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt @@ -0,0 +1,8 @@ +package org.michaelbel.movies.debug.impl + +import org.michaelbel.movies.debug.DebugNotificationInteractor + +internal class DebugNotificationInteractorImpl: DebugNotificationInteractor { + + override fun showDebugNotification() {} +} \ No newline at end of file diff --git a/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt b/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt new file mode 100644 index 000000000..ad0bb786f --- /dev/null +++ b/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt @@ -0,0 +1,11 @@ +package org.michaelbel.movies.debug.di + +import org.koin.core.module.dsl.bind +import org.koin.core.module.dsl.singleOf +import org.koin.dsl.module +import org.michaelbel.movies.debug.DebugNotificationInteractor +import org.michaelbel.movies.debug.impl.DebugNotificationInteractorImpl + +actual val debugNotificationClientKoinModule = module { + singleOf(::DebugNotificationInteractorImpl) { bind() } +} \ No newline at end of file diff --git a/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt b/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt new file mode 100644 index 000000000..d5a6d7364 --- /dev/null +++ b/feature/debug/src/jvmMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt @@ -0,0 +1,8 @@ +package org.michaelbel.movies.debug.impl + +import org.michaelbel.movies.debug.DebugNotificationInteractor + +internal class DebugNotificationInteractorImpl: DebugNotificationInteractor { + + override fun showDebugNotification() {} +} \ No newline at end of file diff --git a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt deleted file mode 100644 index 6b41ea4ba..000000000 --- a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt +++ /dev/null @@ -1,76 +0,0 @@ -package org.michaelbel.movies.gallery - -import androidx.lifecycle.SavedStateHandle -import androidx.work.Constraints -import androidx.work.Data -import androidx.work.ExistingWorkPolicy -import androidx.work.NetworkType -import androidx.work.OneTimeWorkRequestBuilder -import androidx.work.WorkInfo -import androidx.work.WorkManager -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.launch -import org.michaelbel.movies.common.ktx.require -import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.gallery.ktx.nameRes -import org.michaelbel.movies.gallery_impl.R -import org.michaelbel.movies.interactor.Interactor -import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo -import org.michaelbel.movies.persistence.database.ktx.original -import org.michaelbel.movies.persistence.database.typealiases.MovieId -import org.michaelbel.movies.work.DownloadImageWorker - -class GalleryViewModel( - savedStateHandle: SavedStateHandle, - private val interactor: Interactor, - private val workManager: WorkManager -): BaseViewModel() { - - private val movieId: Int = savedStateHandle.require("movieId") - - val movieImagesFlow: StateFlow> = interactor.imagesFlow(movieId) - .stateIn( - scope = scope, - started = SharingStarted.Lazily, - initialValue = emptyList() - ) - - private val _workInfoFlow: MutableStateFlow = MutableStateFlow(null) - val workInfoFlow: StateFlow get() = _workInfoFlow.asStateFlow() - - init { - loadMovieImages(movieId) - } - - fun downloadImage(image: ImagePojo) = scope.launch { - val workData = Data.Builder() - .putString(DownloadImageWorker.KEY_IMAGE_URL, image.original) - .putInt(DownloadImageWorker.KEY_CONTENT_TITLE, R.string.gallery_downloading_image) - .putInt(DownloadImageWorker.KEY_CONTENT_TEXT, image.type.nameRes) - .build() - val constraints = Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresStorageNotLow(true) - .setRequiresBatteryNotLow(true) - .build() - val downloadImageWorker = OneTimeWorkRequestBuilder() - .addTag(DownloadImageWorker.DOWNLOAD_IMAGE_WORKER_TAG) - .setConstraints(constraints) - .setInputData(workData) - .build() - workManager.run { - enqueueUniqueWork(image.toString(), ExistingWorkPolicy.KEEP, downloadImageWorker) - getWorkInfoByIdFlow(downloadImageWorker.id).collect { workInfo -> - _workInfoFlow.emit(workInfo) - } - } - } - - private fun loadMovieImages(movieId: MovieId) = scope.launch { - interactor.images(movieId) - } -} \ No newline at end of file diff --git a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.android.kt b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.android.kt deleted file mode 100644 index fb720e3c3..000000000 --- a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.android.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.michaelbel.movies.gallery.di - -import org.koin.core.module.dsl.viewModelOf -import org.koin.dsl.module -import org.michaelbel.movies.gallery.GalleryViewModel -import org.michaelbel.movies.interactor.di.interactorKoinModule -import org.michaelbel.movies.work.di.workKoinModule - -actual val galleryKoinModule = module { - includes( - interactorKoinModule, - workKoinModule - ) - viewModelOf(::GalleryViewModel) -} \ No newline at end of file diff --git a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.android.kt b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.android.kt index 2bdbe7318..228c3447a 100644 --- a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.android.kt +++ b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.android.kt @@ -3,22 +3,21 @@ package org.michaelbel.movies.gallery.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import org.koin.androidx.compose.koinViewModel import org.michaelbel.movies.gallery.GalleryViewModel import org.michaelbel.movies.ui.ktx.collectAsStateCommon @Composable -fun GalleryRoute( +actual fun GalleryRoute( onBackClick: () -> Unit, - modifier: Modifier = Modifier, - viewModel: GalleryViewModel = koinViewModel() + modifier: Modifier, + viewModel: GalleryViewModel ) { val movieImages by viewModel.movieImagesFlow.collectAsStateCommon() - val workInfo by viewModel.workInfoFlow.collectAsStateCommon() + val workInfoState by viewModel.workInfoStateFlow.collectAsStateCommon() GalleryScreenContent( movieImages = movieImages, - workInfo = workInfo, + workInfoState = workInfoState, onBackClick = onBackClick, onDownloadClick = viewModel::downloadImage, modifier = modifier diff --git a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryScreenContent.kt b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryScreenContent.kt index 2d4bf6bf9..79aa8b7d2 100644 --- a/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryScreenContent.kt +++ b/feature/gallery-impl/src/androidMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryScreenContent.kt @@ -43,7 +43,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.core.net.toUri -import androidx.work.WorkInfo import coil.compose.AsyncImage import coil.compose.AsyncImagePainter import coil.request.ImageRequest @@ -60,11 +59,12 @@ import org.michaelbel.movies.ui.compose.iconbutton.DownloadIcon import org.michaelbel.movies.ui.ktx.displayCutoutWindowInsets import org.michaelbel.movies.ui.theme.MoviesTheme import org.michaelbel.movies.work.DownloadImageWorker +import org.michaelbel.movies.work.WorkInfoState @Composable internal fun GalleryScreenContent( movieImages: List, - workInfo: WorkInfo?, + workInfoState: WorkInfoState, onBackClick: () -> Unit, onDownloadClick: (ImagePojo) -> Unit, modifier: Modifier = Modifier @@ -111,18 +111,16 @@ internal fun GalleryScreenContent( } } - when (workInfo?.state) { - WorkInfo.State.SUCCEEDED -> { - val result = workInfo.outputData.getString(DownloadImageWorker.KEY_IMAGE_URL).orEmpty() + when (workInfoState) { + is WorkInfoState.Success -> { onSuccessSnackbar( stringResource(R.string.gallery_success), stringResource(R.string.gallery_action_open), - result.toUri() + workInfoState.result.toUri() ) } - WorkInfo.State.FAILED -> { - val result = workInfo.outputData.getString(DownloadImageWorker.KEY_IMAGE_URL).orEmpty() - if (result == DownloadImageWorker.FAILURE_RESULT) { + is WorkInfoState.Failure -> { + if (workInfoState.result == DownloadImageWorker.FAILURE_RESULT) { onFailureSnackbar(stringResource(R.string.gallery_failure)) } } @@ -252,7 +250,7 @@ private fun GalleryScreenContentPreview() { MoviesTheme { GalleryScreenContent( movieImages = emptyList(), - workInfo = null, + workInfoState = WorkInfoState.None, onBackClick = {}, onDownloadClick = {}, modifier = Modifier.fillMaxSize() diff --git a/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt new file mode 100644 index 000000000..11d8e0b36 --- /dev/null +++ b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt @@ -0,0 +1,49 @@ +package org.michaelbel.movies.gallery + +import androidx.lifecycle.SavedStateHandle +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch +import org.michaelbel.movies.common.ktx.require +import org.michaelbel.movies.common.viewmodel.BaseViewModel +import org.michaelbel.movies.interactor.Interactor +import org.michaelbel.movies.persistence.database.entity.pojo.ImagePojo +import org.michaelbel.movies.persistence.database.typealiases.MovieId +import org.michaelbel.movies.work.WorkInfoState +import org.michaelbel.movies.work.WorkManagerInteractor + +class GalleryViewModel( + savedStateHandle: SavedStateHandle, + private val interactor: Interactor, + private val workManagerInteractor: WorkManagerInteractor +): BaseViewModel() { + + private val movieId: Int = savedStateHandle.require("movieId") + + val movieImagesFlow: StateFlow> = interactor.imagesFlow(movieId) + .stateIn( + scope = scope, + started = SharingStarted.Lazily, + initialValue = emptyList() + ) + + private val _workInfoStateFlow: MutableStateFlow = MutableStateFlow(WorkInfoState.None) + val workInfoStateFlow: StateFlow get() = _workInfoStateFlow.asStateFlow() + + init { + loadMovieImages(movieId) + } + + fun downloadImage(image: ImagePojo) = scope.launch { + workManagerInteractor.downloadImage(image).collect { workInfoState -> + _workInfoStateFlow.emit(workInfoState) + } + } + + private fun loadMovieImages(movieId: MovieId) = scope.launch { + interactor.images(movieId) + } +} \ No newline at end of file diff --git a/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.kt b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.kt index c63d31765..8ad04ee8c 100644 --- a/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.kt +++ b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.kt @@ -1,5 +1,15 @@ package org.michaelbel.movies.gallery.di -import org.koin.core.module.Module +import org.koin.core.module.dsl.viewModelOf +import org.koin.dsl.module +import org.michaelbel.movies.gallery.GalleryViewModel +import org.michaelbel.movies.interactor.di.interactorKoinModule +import org.michaelbel.movies.work.di.workManagerInteractorKoinModule -expect val galleryKoinModule: Module \ No newline at end of file +val galleryKoinModule = module { + includes( + interactorKoinModule, + workManagerInteractorKoinModule + ) + viewModelOf(::GalleryViewModel) +} \ No newline at end of file diff --git a/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.kt b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.kt new file mode 100644 index 000000000..4a1abc18f --- /dev/null +++ b/feature/gallery-impl/src/commonMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.kt @@ -0,0 +1,13 @@ +package org.michaelbel.movies.gallery.ui + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import org.koin.compose.viewmodel.koinViewModel +import org.michaelbel.movies.gallery.GalleryViewModel + +@Composable +expect fun GalleryRoute( + onBackClick: () -> Unit, + modifier: Modifier = Modifier, + viewModel: GalleryViewModel = koinViewModel() +) \ No newline at end of file diff --git a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt b/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt deleted file mode 100644 index cc78c4826..000000000 --- a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.michaelbel.movies.gallery - -import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.interactor.Interactor - -class GalleryViewModel( - private val interactor: Interactor -): BaseViewModel() \ No newline at end of file diff --git a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.ios.kt b/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.ios.kt deleted file mode 100644 index 3d1f4ff80..000000000 --- a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.ios.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.michaelbel.movies.gallery.di - -import org.koin.dsl.module -import org.michaelbel.movies.gallery.GalleryViewModel -import org.michaelbel.movies.interactor.di.interactorKoinModule - -actual val galleryKoinModule = module { - includes( - interactorKoinModule - ) - single { GalleryViewModel(get()) } -} \ No newline at end of file diff --git a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.ios.kt b/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.ios.kt index 697057f9c..18e244583 100644 --- a/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.ios.kt +++ b/feature/gallery-impl/src/iosMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.ios.kt @@ -4,14 +4,13 @@ import androidx.compose.foundation.clickable import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import org.koin.compose.koinInject import org.michaelbel.movies.gallery.GalleryViewModel @Composable -fun GalleryRoute( +actual fun GalleryRoute( onBackClick: () -> Unit, - modifier: Modifier = Modifier, - viewModel: GalleryViewModel = koinInject() + modifier: Modifier, + viewModel: GalleryViewModel ) { Text( text = "Gallery", diff --git a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt b/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt deleted file mode 100644 index cc78c4826..000000000 --- a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryViewModel.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.michaelbel.movies.gallery - -import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.interactor.Interactor - -class GalleryViewModel( - private val interactor: Interactor -): BaseViewModel() \ No newline at end of file diff --git a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.jvm.kt b/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.jvm.kt deleted file mode 100644 index 3d1f4ff80..000000000 --- a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/di/GalleryKoinModule.jvm.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.michaelbel.movies.gallery.di - -import org.koin.dsl.module -import org.michaelbel.movies.gallery.GalleryViewModel -import org.michaelbel.movies.interactor.di.interactorKoinModule - -actual val galleryKoinModule = module { - includes( - interactorKoinModule - ) - single { GalleryViewModel(get()) } -} \ No newline at end of file diff --git a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.jvm.kt b/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.jvm.kt index 697057f9c..18e244583 100644 --- a/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.jvm.kt +++ b/feature/gallery-impl/src/jvmMain/kotlin/org/michaelbel/movies/gallery/ui/GalleryRoute.jvm.kt @@ -4,14 +4,13 @@ import androidx.compose.foundation.clickable import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import org.koin.compose.koinInject import org.michaelbel.movies.gallery.GalleryViewModel @Composable -fun GalleryRoute( +actual fun GalleryRoute( onBackClick: () -> Unit, - modifier: Modifier = Modifier, - viewModel: GalleryViewModel = koinInject() + modifier: Modifier, + viewModel: GalleryViewModel ) { Text( text = "Gallery", diff --git a/feature/gallery/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.android.kt b/feature/gallery/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.android.kt deleted file mode 100644 index fe4d3b89d..000000000 --- a/feature/gallery/src/androidMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.android.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.michaelbel.movies.gallery - -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import org.michaelbel.movies.gallery.ui.GalleryRoute - -actual fun NavGraphBuilder.galleryGraph( - navigateBack: () -> Unit, -) { - composable { - GalleryRoute( - onBackClick = navigateBack - ) - } -} \ No newline at end of file diff --git a/feature/gallery/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.kt b/feature/gallery/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.kt index 1d8705600..fd869f3a8 100644 --- a/feature/gallery/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.kt +++ b/feature/gallery/src/commonMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.kt @@ -2,11 +2,19 @@ package org.michaelbel.movies.gallery import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import org.michaelbel.movies.gallery.ui.GalleryRoute import org.michaelbel.movies.persistence.database.typealiases.MovieId -expect fun NavGraphBuilder.galleryGraph( +fun NavGraphBuilder.galleryGraph( navigateBack: () -> Unit, -) +) { + composable { + GalleryRoute( + onBackClick = navigateBack + ) + } +} fun NavController.navigateToGallery(movieId: MovieId) { navigate(GalleryDestination(movieId)) diff --git a/feature/gallery/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.ios.kt b/feature/gallery/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.ios.kt deleted file mode 100644 index fe4d3b89d..000000000 --- a/feature/gallery/src/iosMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.ios.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.michaelbel.movies.gallery - -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import org.michaelbel.movies.gallery.ui.GalleryRoute - -actual fun NavGraphBuilder.galleryGraph( - navigateBack: () -> Unit, -) { - composable { - GalleryRoute( - onBackClick = navigateBack - ) - } -} \ No newline at end of file diff --git a/feature/gallery/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.jvm.kt b/feature/gallery/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.jvm.kt deleted file mode 100644 index fe4d3b89d..000000000 --- a/feature/gallery/src/jvmMain/kotlin/org/michaelbel/movies/gallery/GalleryNavigation.jvm.kt +++ /dev/null @@ -1,15 +0,0 @@ -package org.michaelbel.movies.gallery - -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import org.michaelbel.movies.gallery.ui.GalleryRoute - -actual fun NavGraphBuilder.galleryGraph( - navigateBack: () -> Unit, -) { - composable { - GalleryRoute( - onBackClick = navigateBack - ) - } -} \ No newline at end of file diff --git a/feature/main-impl/build.gradle.kts b/feature/main-impl/build.gradle.kts index 0418f8e75..a361fc5f1 100644 --- a/feature/main-impl/build.gradle.kts +++ b/feature/main-impl/build.gradle.kts @@ -22,10 +22,14 @@ kotlin { api(projects.feature.gallery) api(projects.feature.search) api(projects.feature.settings) - } - androidMain.dependencies { api(projects.feature.debug) } + jvmMain.dependencies { + implementation(projects.core.platformServices.injectDesktop) + } + iosMain.dependencies { + implementation(projects.core.platformServices.injectIos) + } } compilerOptions { @@ -64,8 +68,8 @@ android { val hmsImplementation by configurations val fossImplementation by configurations dependencies { - gmsImplementation(project(":core:platform-services:inject-android")) - hmsImplementation(project(":core:platform-services:inject-android")) - fossImplementation(project(":core:platform-services:inject-android")) + gmsImplementation(projects.core.platformServices.injectAndroid) + hmsImplementation(projects.core.platformServices.injectAndroid) + fossImplementation(projects.core.platformServices.injectAndroid) } } \ No newline at end of file diff --git a/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.android.kt b/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.android.kt index d728a9124..a65c39ad6 100644 --- a/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.android.kt +++ b/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.android.kt @@ -7,14 +7,14 @@ import org.michaelbel.movies.debug.di.debugNotificationClientKoinModule import org.michaelbel.movies.interactor.di.interactorKoinModule import org.michaelbel.movies.main.MainViewModel import org.michaelbel.movies.platform.inject.flavorServiceKtorModule -import org.michaelbel.movies.work.di.workKoinModule +import org.michaelbel.movies.work.di.workManagerInteractorKoinModule actual val mainKoinModule = module { includes( interactorKoinModule, moviesAnalyticsKoinModule, flavorServiceKtorModule, - workKoinModule, + workManagerInteractorKoinModule, debugNotificationClientKoinModule ) viewModelOf(::MainViewModel) diff --git a/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt b/feature/main-impl/src/commonMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt similarity index 75% rename from feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt rename to feature/main-impl/src/commonMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt index f0f933f24..8e619b0c8 100644 --- a/feature/main-impl/src/androidMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt +++ b/feature/main-impl/src/commonMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt @@ -1,11 +1,5 @@ package org.michaelbel.movies.main -import androidx.core.bundle.Bundle -import androidx.fragment.app.FragmentActivity -import androidx.navigation.NavDestination -import androidx.work.OneTimeWorkRequestBuilder -import androidx.work.WorkManager -import androidx.work.workDataOf import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -16,27 +10,26 @@ import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import org.michaelbel.movies.analytics.MoviesAnalytics -import org.michaelbel.movies.common.BuildConfig import org.michaelbel.movies.common.ThemeData import org.michaelbel.movies.common.biometric.BiometricInteractor import org.michaelbel.movies.common.biometric.BiometricListener import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.debug.notification.DebugNotificationClient +import org.michaelbel.movies.debug.DebugNotificationInteractor import org.michaelbel.movies.interactor.Interactor import org.michaelbel.movies.platform.config.ConfigService import org.michaelbel.movies.platform.messaging.MessagingService import org.michaelbel.movies.platform.review.ReviewService import org.michaelbel.movies.platform.update.UpdateService -import org.michaelbel.movies.work.AccountUpdateWorker -import org.michaelbel.movies.work.MoviesDatabaseWorker +import org.michaelbel.movies.ui.ktx.isDebug +import org.michaelbel.movies.work.WorkManagerInteractor class MainViewModel( private val interactor: Interactor, private val biometricController: BiometricInteractor, private val analytics: MoviesAnalytics, private val messagingService: MessagingService, - private val workManager: WorkManager, - private val debugNotificationClient: DebugNotificationClient, + private val workManagerInteractor: WorkManagerInteractor, + private val debugNotificationInteractor: DebugNotificationInteractor, private val configService: ConfigService, private val reviewService: ReviewService, private val updateService: UpdateService, @@ -74,15 +67,15 @@ class MainViewModel( showDebugNotification() } - fun analyticsTrackDestination(destination: NavDestination, arguments: Bundle?) { + /*fun analyticsTrackDestination(destination: NavDestination, arguments: Bundle?) { val hashMap = hashMapOf() arguments?.keySet()?.forEach { key -> hashMap[key] = arguments.getString(key).orEmpty() } analytics.trackDestination(destination.route, hashMap) - } + }*/ - fun authenticate(activity: FragmentActivity) { + fun authenticate(activity: Any) { val biometricListener = object: BiometricListener { override fun onSuccess() { _splashLoading.value = false @@ -124,25 +117,16 @@ class MainViewModel( } private fun prepopulateDatabase() { - val request = OneTimeWorkRequestBuilder() - .setInputData(workDataOf(MoviesDatabaseWorker.KEY_FILENAME to MOVIES_DATA_FILENAME)) - .build() - workManager.enqueue(request) + workManagerInteractor.prepopulateDatabase() } private fun updateAccountDetails() { - val request = OneTimeWorkRequestBuilder() - .build() - workManager.enqueue(request) + workManagerInteractor.updateAccountDetails() } private fun showDebugNotification() { - if (BuildConfig.DEBUG) { - debugNotificationClient.showDebugNotification() + if (isDebug) { + debugNotificationInteractor.showDebugNotification() } } - - companion object { - const val MOVIES_DATA_FILENAME = "movies.json" - } } \ No newline at end of file diff --git a/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt b/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt deleted file mode 100644 index 78ed3b120..000000000 --- a/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.michaelbel.movies.main - -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.stateIn -import org.michaelbel.movies.common.ThemeData -import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.interactor.Interactor - -class MainViewModel( - interactor: Interactor -): BaseViewModel() { - - val themeData: StateFlow = interactor.themeData - .stateIn( - scope = scope, - started = SharingStarted.Lazily, - initialValue = ThemeData.Default - ) -} \ No newline at end of file diff --git a/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.ios.kt b/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.ios.kt index 0334e2784..a65c39ad6 100644 --- a/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.ios.kt +++ b/feature/main-impl/src/iosMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.ios.kt @@ -1,12 +1,21 @@ package org.michaelbel.movies.main.di +import org.koin.core.module.dsl.viewModelOf import org.koin.dsl.module +import org.michaelbel.movies.analytics.di.moviesAnalyticsKoinModule +import org.michaelbel.movies.debug.di.debugNotificationClientKoinModule import org.michaelbel.movies.interactor.di.interactorKoinModule import org.michaelbel.movies.main.MainViewModel +import org.michaelbel.movies.platform.inject.flavorServiceKtorModule +import org.michaelbel.movies.work.di.workManagerInteractorKoinModule actual val mainKoinModule = module { includes( - interactorKoinModule + interactorKoinModule, + moviesAnalyticsKoinModule, + flavorServiceKtorModule, + workManagerInteractorKoinModule, + debugNotificationClientKoinModule ) - single { MainViewModel(get()) } + viewModelOf(::MainViewModel) } \ No newline at end of file diff --git a/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt b/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt deleted file mode 100644 index 78ed3b120..000000000 --- a/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/MainViewModel.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.michaelbel.movies.main - -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.stateIn -import org.michaelbel.movies.common.ThemeData -import org.michaelbel.movies.common.viewmodel.BaseViewModel -import org.michaelbel.movies.interactor.Interactor - -class MainViewModel( - interactor: Interactor -): BaseViewModel() { - - val themeData: StateFlow = interactor.themeData - .stateIn( - scope = scope, - started = SharingStarted.Lazily, - initialValue = ThemeData.Default - ) -} \ No newline at end of file diff --git a/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.jvm.kt b/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.jvm.kt index 0334e2784..a65c39ad6 100644 --- a/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.jvm.kt +++ b/feature/main-impl/src/jvmMain/kotlin/org/michaelbel/movies/main/di/MainKoinModule.jvm.kt @@ -1,12 +1,21 @@ package org.michaelbel.movies.main.di +import org.koin.core.module.dsl.viewModelOf import org.koin.dsl.module +import org.michaelbel.movies.analytics.di.moviesAnalyticsKoinModule +import org.michaelbel.movies.debug.di.debugNotificationClientKoinModule import org.michaelbel.movies.interactor.di.interactorKoinModule import org.michaelbel.movies.main.MainViewModel +import org.michaelbel.movies.platform.inject.flavorServiceKtorModule +import org.michaelbel.movies.work.di.workManagerInteractorKoinModule actual val mainKoinModule = module { includes( - interactorKoinModule + interactorKoinModule, + moviesAnalyticsKoinModule, + flavorServiceKtorModule, + workManagerInteractorKoinModule, + debugNotificationClientKoinModule ) - single { MainViewModel(get()) } + viewModelOf(::MainViewModel) } \ No newline at end of file