-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5589e86
commit c8b2890
Showing
47 changed files
with
404 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../work/src/androidMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...aelbel/movies/gallery/ktx/ImageTypeKtx.kt → ...ichaelbel/movies/work/ktx/ImageTypeKtx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
7 changes: 7 additions & 0 deletions
7
core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkInfoState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
core/work/src/commonMain/kotlin/org/michaelbel/movies/work/WorkManagerInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
5 changes: 5 additions & 0 deletions
5
...rk/src/commonMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
.../work/src/iosMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} |
18 changes: 18 additions & 0 deletions
18
core/work/src/iosMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../work/src/jvmMain/kotlin/org/michaelbel/movies/work/di/WorkManagerInteractorKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} |
18 changes: 18 additions & 0 deletions
18
core/work/src/jvmMain/kotlin/org/michaelbel/movies/work/impl/WorkManagerInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
...rc/androidMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...re/debug/src/commonMain/kotlin/org/michaelbel/movies/debug/DebugNotificationInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.michaelbel.movies.debug | ||
|
||
interface DebugNotificationInteractor { | ||
fun showDebugNotification() | ||
} |
5 changes: 5 additions & 0 deletions
5
...src/commonMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
...ug/src/iosMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} |
8 changes: 8 additions & 0 deletions
8
...ug/src/iosMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ug/src/jvmMain/kotlin/org/michaelbel/movies/debug/di/DebugNotificationClientKoinModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() } | ||
} |
8 changes: 8 additions & 0 deletions
8
...ug/src/jvmMain/kotlin/org/michaelbel/movies/debug/impl/DebugNotificationInteractorImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
Oops, something went wrong.