add DatePickerPresenterImpl, rename UserCanCalculatePsychomatrixByDate -> UserCalculatePsychomatrixByDate

This commit is contained in:
InsanusMokrassar 2018-09-04 10:44:01 +08:00
parent d3b9f88985
commit b1d752bfa1
3 changed files with 35 additions and 3 deletions

View File

@ -6,7 +6,7 @@ import kotlinx.coroutines.experimental.channels.ReceiveChannel
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.* import java.util.*
interface UserCanCalculatePsychomatrixByDate { interface UserCalculatePsychomatrixByDate {
suspend fun calculate(date: Long): Deferred<Psychomatrix> suspend fun calculate(date: Long): Deferred<Psychomatrix>
suspend fun calculate(date: DateTime): Deferred<Psychomatrix> suspend fun calculate(date: DateTime): Deferred<Psychomatrix>
suspend fun calculate(date: Date): Deferred<Psychomatrix> suspend fun calculate(date: Date): Deferred<Psychomatrix>

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.PsychomatrixBase.domain.interactors 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.domain.entities.Psychomatrix
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_MEDIUM import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_MEDIUM
import kotlinx.coroutines.experimental.Deferred import kotlinx.coroutines.experimental.Deferred
@ -10,7 +10,7 @@ import kotlinx.coroutines.experimental.channels.ReceiveChannel
import org.joda.time.DateTime import org.joda.time.DateTime
import java.util.* import java.util.*
class UserCanCalculatePsychomatrixByDateInteractor : UserCanCalculatePsychomatrixByDate { class UserCalculatePsychomatrixByDateInteractor : UserCalculatePsychomatrixByDate {
private val psychomatrixCreatedBroadcast = BroadcastChannel<Psychomatrix>(SUBSCRIPTIONS_MEDIUM) private val psychomatrixCreatedBroadcast = BroadcastChannel<Psychomatrix>(SUBSCRIPTIONS_MEDIUM)
override suspend fun calculate(date: Long): Deferred<Psychomatrix> { override suspend fun calculate(date: Long): Deferred<Psychomatrix> {

View File

@ -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<Psychomatrix>(SUBSCRIPTIONS_MEDIUM)
override suspend fun openPsychomatrixCreatedSubscription(): ReceiveChannel<Psychomatrix> {
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)
}
}
}
}