added Psychomatrix CeilDescription functionality

This commit is contained in:
InsanusMokrassar 2018-09-11 18:28:50 +08:00
parent 39429be769
commit a749fcc6f7
12 changed files with 168 additions and 17 deletions

View File

@ -0,0 +1,8 @@
package com.github.insanusmokrassar.PsychomatrixBase.data.repository
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo
interface PsychomatrixCeilDescriptionRepository {
fun getCeilDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo): CeilDescription
}

View File

@ -0,0 +1,20 @@
package com.github.insanusmokrassar.PsychomatrixBase.data.repository.realisations
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.PsychomatrixCeilDescriptionRepository
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CeilDescriptionUseCase
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.subscribe
abstract class PsychomatrixCeilDescriptionRepositoryImpl(
ceilDescriptionUseCase: CeilDescriptionUseCase
) : PsychomatrixCeilDescriptionRepository {
init {
ceilDescriptionUseCase.openCeilDescriptionRequestedSubscription().subscribe {
getCeilDescription(it).also {
description ->
ceilDescriptionUseCase.descriptionReady(
it, description
)
}
}
}
}

View File

@ -1,14 +1,15 @@
package com.github.insanusmokrassar.PsychomatrixBase.di
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.HistoryDatesRepository
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.PsychomatrixCeilDescriptionRepository
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.*
interface PresentationLayerDI : UseCasesDI {
val datePickerPresenter: DatePickerPresenter
val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter
val ceilDescriptionPresenter: CeilDescriptionPresenter
val historyDatesRepository: HistoryDatesRepository
val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter
val psychomatrixCeilDescriptionRepository: PsychomatrixCeilDescriptionRepository
}

View File

@ -1,9 +1,9 @@
package com.github.insanusmokrassar.PsychomatrixBase.di
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CalculatePsychomatrixByDateUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.*
interface UseCasesDI : EntitiesDI {
val calculatePsychomatrixByDateUseCase: CalculatePsychomatrixByDateUseCase
val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase
val ceilDescriptionUseCase: CeilDescriptionUseCase
}

View File

@ -2,10 +2,8 @@ package com.github.insanusmokrassar.PsychomatrixBase.di.realisations
import com.github.insanusmokrassar.PsychomatrixBase.di.PresentationLayerDI
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.DatePickerPresenterImpl
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.ModifyPsychomatrixPresenterImpl
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.*
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.*
abstract class PresentationLayerDIImpl(
useCasesDI: UseCasesDI
@ -17,7 +15,15 @@ abstract class PresentationLayerDIImpl(
)
}
override val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter = ModifyPsychomatrixPresenterImpl(
override val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter by lazy {
ModifyPsychomatrixPresenterImpl(
modifyPsychomatrixUseCase
)
}
override val ceilDescriptionPresenter: CeilDescriptionPresenter by lazy {
CeilDescriptionPresenterImpl(
ceilDescriptionUseCase
)
}
}

View File

@ -2,10 +2,8 @@ package com.github.insanusmokrassar.PsychomatrixBase.di.realisations
import com.github.insanusmokrassar.PsychomatrixBase.di.EntitiesDI
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CalculatePsychomatrixByDateUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.CalculatePsychomatrixByDateUseCaseInteractor
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.ModifyPsychomatrixUseCaseInteractor
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.*
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.*
open class UseCasesDIImpl(
entitiesDI: EntitiesDI
@ -17,4 +15,8 @@ open class UseCasesDIImpl(
override val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase by lazy {
ModifyPsychomatrixUseCaseInteractor()
}
override val ceilDescriptionUseCase: CeilDescriptionUseCase by lazy {
CeilDescriptionInteractor()
}
}

View File

@ -0,0 +1,17 @@
package com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo
import kotlinx.coroutines.experimental.channels.ReceiveChannel
typealias CeilDescriptionReady = Pair<PsychomatrixCeilInfo, CeilDescription>
interface CeilDescriptionUseCase {
fun openCeilDescriptionReadySubscription(): ReceiveChannel<CeilDescriptionReady>
fun openCeilDescriptionRequestedSubscription(): ReceiveChannel<PsychomatrixCeilInfo>
fun descriptionReady(psychomatrixCeilInfo: PsychomatrixCeilInfo, ceilDescription: CeilDescription)
fun requestDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo)
}

View File

@ -0,0 +1,3 @@
package com.github.insanusmokrassar.PsychomatrixBase.domain.entities
typealias CeilDescription = String

View File

@ -0,0 +1,42 @@
package com.github.insanusmokrassar.PsychomatrixBase.domain.interactors
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CeilDescriptionReady
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CeilDescriptionUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_EXTRA_SMALL
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_SMALL
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.launch
class CeilDescriptionInteractor : CeilDescriptionUseCase {
private val ceilDescriptionReadyBroadcastChannel = BroadcastChannel<CeilDescriptionReady>(
SUBSCRIPTIONS_SMALL
)
private val ceilDescriptionRequestedBroadcastChannel = BroadcastChannel<PsychomatrixCeilInfo>(
SUBSCRIPTIONS_EXTRA_SMALL
)
override fun openCeilDescriptionReadySubscription(): ReceiveChannel<CeilDescriptionReady> {
return ceilDescriptionReadyBroadcastChannel.openSubscription()
}
override fun openCeilDescriptionRequestedSubscription(): ReceiveChannel<PsychomatrixCeilInfo> {
return ceilDescriptionRequestedBroadcastChannel.openSubscription()
}
override fun descriptionReady(psychomatrixCeilInfo: PsychomatrixCeilInfo, ceilDescription: CeilDescription) {
launch {
ceilDescriptionReadyBroadcastChannel.send(psychomatrixCeilInfo to ceilDescription)
}
}
override fun requestDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo) {
launch {
ceilDescriptionRequestedBroadcastChannel.send(
psychomatrixCeilInfo
)
}
}
}

View File

@ -0,0 +1,9 @@
package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo
import kotlinx.coroutines.experimental.Deferred
interface CeilDescriptionPresenter {
fun onUserChooseCeil(ceilInfo: PsychomatrixCeilInfo): Deferred<CeilDescription>
}

View File

@ -0,0 +1,37 @@
package com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CeilDescriptionUseCase
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription
import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.CeilDescriptionPresenter
import com.github.insanusmokrassar.PsychomatrixBase.utils.Container
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.subscribeChecking
import kotlinx.coroutines.experimental.*
class CeilDescriptionPresenterImpl(
private val ceilDescriptionUseCase: CeilDescriptionUseCase
) : CeilDescriptionPresenter {
override fun onUserChooseCeil(ceilInfo: PsychomatrixCeilInfo): Deferred<CeilDescription> {
return async {
val container = Container<CeilDescription>()
val subscription = ceilDescriptionUseCase.openCeilDescriptionReadySubscription().subscribeChecking(
{
container.throwable = it
false
}
) {
if (it.first == ceilInfo) {
container.value = it.second
false
} else {
true
}
}
ceilDescriptionUseCase.requestDescription(ceilInfo)
subscription.join()
container.value ?: throw container.throwable ?: throw IllegalStateException("Strange state - must be set value or error")
}
}
}

View File

@ -0,0 +1,6 @@
package com.github.insanusmokrassar.PsychomatrixBase.utils
class Container<T>(
var value: T? = null,
var throwable: Throwable? = null
)