Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Dec 15, 2024
1 parent 5589e86 commit c8b2890
Show file tree
Hide file tree
Showing 47 changed files with 404 additions and 298 deletions.
6 changes: 3 additions & 3 deletions core/platform-services/inject-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -23,4 +27,5 @@ val workKoinModule = module {
workerOf(::AccountUpdateWorker)
workerOf(::DownloadImageWorker)
workerOf(::MoviesDatabaseWorker)
singleOf(::WorkManagerInteractorImpl) { bind<WorkManagerInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -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<WorkInfoState> {
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<DownloadImageWorker>()
.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<MoviesDatabaseWorker>()
.setInputData(workDataOf(MoviesDatabaseWorker.KEY_FILENAME to MOVIES_DATA_FILENAME))
.build()
workManager.enqueue(request)
}

override fun updateAccountDetails() {
val request = OneTimeWorkRequestBuilder<AccountUpdateWorker>()
.build()
workManager.enqueue(request)
}

private companion object {
private const val MOVIES_DATA_FILENAME = "movies.json"
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions core/work/src/androidMain/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="gallery_downloading_image">Загрузка изображения...</string>
<string name="gallery_poster">Постер</string>
<string name="gallery_backdrop">Обложка</string>
<string name="gallery_logo">Логотип</string>
</resources>
7 changes: 7 additions & 0 deletions core/work/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="gallery_downloading_image">Downloading Image...</string>
<string name="gallery_poster">Poster</string>
<string name="gallery_backdrop">Backdrop</string>
<string name="gallery_logo">Logo</string>
</resources>
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<WorkInfoState>

fun prepopulateDatabase()

fun updateAccountDetails()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.michaelbel.movies.work.di

import org.koin.core.module.Module

expect val workManagerInteractorKoinModule: Module
Original file line number Diff line number Diff line change
@@ -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<WorkManagerInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -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<WorkInfoState> {
return flowOf(WorkInfoState.Success(""))
}

override fun prepopulateDatabase() {}

override fun updateAccountDetails() {}
}
Original file line number Diff line number Diff line change
@@ -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<WorkManagerInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -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<WorkInfoState> {
return flowOf(WorkInfoState.Success(""))
}

override fun prepopulateDatabase() {}

override fun updateAccountDetails() {}
}
4 changes: 4 additions & 0 deletions feature/debug-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ plugins {

kotlin {
androidTarget()
jvm()
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
commonMain.dependencies {
Expand Down
7 changes: 6 additions & 1 deletion feature/debug/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ plugins {

kotlin {
androidTarget()
jvm()
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
androidMain.dependencies {
commonMain.dependencies {
api(projects.core.ui)
api(projects.feature.debugImpl)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DebugNotificationInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.michaelbel.movies.debug

interface DebugNotificationInteractor {
fun showDebugNotification()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.michaelbel.movies.debug.di

import org.koin.core.module.Module

expect val debugNotificationClientKoinModule: Module
Original file line number Diff line number Diff line change
@@ -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<DebugNotificationInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.michaelbel.movies.debug.impl

import org.michaelbel.movies.debug.DebugNotificationInteractor

internal class DebugNotificationInteractorImpl: DebugNotificationInteractor {

override fun showDebugNotification() {}
}
Original file line number Diff line number Diff line change
@@ -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<DebugNotificationInteractor>() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.michaelbel.movies.debug.impl

import org.michaelbel.movies.debug.DebugNotificationInteractor

internal class DebugNotificationInteractorImpl: DebugNotificationInteractor {

override fun showDebugNotification() {}
}
Loading

0 comments on commit c8b2890

Please sign in to comment.