From b1d752bfa1ec097b3b2846a6272fde951f77136e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 4 Sep 2018 10:44:01 +0800 Subject: [PATCH] add DatePickerPresenterImpl, rename UserCanCalculatePsychomatrixByDate -> UserCalculatePsychomatrixByDate --- ....kt => UserCalculatePsychomatrixByDate.kt} | 2 +- ...rCalculatePsychomatrixByDateInteractor.kt} | 4 +-- .../DatePickerPresenterImpl.kt | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) rename src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/{UserCanCalculatePsychomatrixByDate.kt => UserCalculatePsychomatrixByDate.kt} (92%) rename src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/{UserCanCalculatePsychomatrixByDateInteractor.kt => UserCalculatePsychomatrixByDateInteractor.kt} (91%) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/DatePickerPresenterImpl.kt diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCanCalculatePsychomatrixByDate.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCalculatePsychomatrixByDate.kt similarity index 92% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCanCalculatePsychomatrixByDate.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCalculatePsychomatrixByDate.kt index 3de23a4..7fa6dc3 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCanCalculatePsychomatrixByDate.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/UserCalculatePsychomatrixByDate.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.experimental.channels.ReceiveChannel import org.joda.time.DateTime import java.util.* -interface UserCanCalculatePsychomatrixByDate { +interface UserCalculatePsychomatrixByDate { suspend fun calculate(date: Long): Deferred suspend fun calculate(date: DateTime): Deferred suspend fun calculate(date: Date): Deferred diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCanCalculatePsychomatrixByDateInteractor.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCalculatePsychomatrixByDateInteractor.kt similarity index 91% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCanCalculatePsychomatrixByDateInteractor.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCalculatePsychomatrixByDateInteractor.kt index 47a5bf3..1829198 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCanCalculatePsychomatrixByDateInteractor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/UserCalculatePsychomatrixByDateInteractor.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.PsychomatrixBase.domain.interactors -import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.UserCanCalculatePsychomatrixByDate +import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.UserCalculatePsychomatrixByDate import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_MEDIUM import kotlinx.coroutines.experimental.Deferred @@ -10,7 +10,7 @@ import kotlinx.coroutines.experimental.channels.ReceiveChannel import org.joda.time.DateTime import java.util.* -class UserCanCalculatePsychomatrixByDateInteractor : UserCanCalculatePsychomatrixByDate { +class UserCalculatePsychomatrixByDateInteractor : UserCalculatePsychomatrixByDate { private val psychomatrixCreatedBroadcast = BroadcastChannel(SUBSCRIPTIONS_MEDIUM) override suspend fun calculate(date: Long): Deferred { diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/DatePickerPresenterImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/DatePickerPresenterImpl.kt new file mode 100644 index 0000000..2197e51 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/DatePickerPresenterImpl.kt @@ -0,0 +1,32 @@ +package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations + +import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.UserCalculatePsychomatrixByDate +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.Psychomatrix +import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter +import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_MEDIUM +import kotlinx.coroutines.experimental.channels.BroadcastChannel +import kotlinx.coroutines.experimental.channels.ReceiveChannel +import kotlinx.coroutines.experimental.launch +import org.joda.time.DateTime + +class DatePickerPresenterImpl( + private val userCalculatePsychomatrixByDate: UserCalculatePsychomatrixByDate +) : DatePickerPresenter { + private val psychomatrixCreateBroadcastChannel = BroadcastChannel(SUBSCRIPTIONS_MEDIUM) + + override suspend fun openPsychomatrixCreatedSubscription(): ReceiveChannel { + return psychomatrixCreateBroadcastChannel.openSubscription() + } + + override fun userPickDate(date: Long) { + userPickDate(DateTime(date)) + } + + override fun userPickDate(date: DateTime) { + launch { + userCalculatePsychomatrixByDate.calculate(date).await().also { + psychomatrixCreateBroadcastChannel.send(it) + } + } + } +}