mirror of
https://github.com/InsanusMokrassar/PsychomatrixBase.git
synced 2024-11-14 20:33:57 +00:00
added Psychomatrix CeilDescription functionality
This commit is contained in:
parent
39429be769
commit
a749fcc6f7
@ -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
|
||||||
|
}
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.PsychomatrixBase.di
|
package com.github.insanusmokrassar.PsychomatrixBase.di
|
||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.HistoryDatesRepository
|
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.HistoryDatesRepository
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
|
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.PsychomatrixCeilDescriptionRepository
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
|
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.*
|
||||||
|
|
||||||
interface PresentationLayerDI : UseCasesDI {
|
interface PresentationLayerDI : UseCasesDI {
|
||||||
|
|
||||||
val datePickerPresenter: DatePickerPresenter
|
val datePickerPresenter: DatePickerPresenter
|
||||||
|
val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter
|
||||||
|
val ceilDescriptionPresenter: CeilDescriptionPresenter
|
||||||
|
|
||||||
val historyDatesRepository: HistoryDatesRepository
|
val historyDatesRepository: HistoryDatesRepository
|
||||||
|
val psychomatrixCeilDescriptionRepository: PsychomatrixCeilDescriptionRepository
|
||||||
val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter
|
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package com.github.insanusmokrassar.PsychomatrixBase.di
|
package com.github.insanusmokrassar.PsychomatrixBase.di
|
||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CalculatePsychomatrixByDateUseCase
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
|
|
||||||
|
|
||||||
interface UseCasesDI : EntitiesDI {
|
interface UseCasesDI : EntitiesDI {
|
||||||
val calculatePsychomatrixByDateUseCase: CalculatePsychomatrixByDateUseCase
|
val calculatePsychomatrixByDateUseCase: CalculatePsychomatrixByDateUseCase
|
||||||
val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase
|
val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase
|
||||||
|
val ceilDescriptionUseCase: CeilDescriptionUseCase
|
||||||
}
|
}
|
@ -2,10 +2,8 @@ package com.github.insanusmokrassar.PsychomatrixBase.di.realisations
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.di.PresentationLayerDI
|
import com.github.insanusmokrassar.PsychomatrixBase.di.PresentationLayerDI
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
|
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
|
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.DatePickerPresenterImpl
|
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.ModifyPsychomatrixPresenterImpl
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.ModifyPsychomatrixPresenter
|
|
||||||
|
|
||||||
abstract class PresentationLayerDIImpl(
|
abstract class PresentationLayerDIImpl(
|
||||||
useCasesDI: UseCasesDI
|
useCasesDI: UseCasesDI
|
||||||
@ -17,7 +15,15 @@ abstract class PresentationLayerDIImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter = ModifyPsychomatrixPresenterImpl(
|
override val modifyPsychomatrixPresenter: ModifyPsychomatrixPresenter by lazy {
|
||||||
modifyPsychomatrixUseCase
|
ModifyPsychomatrixPresenterImpl(
|
||||||
)
|
modifyPsychomatrixUseCase
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val ceilDescriptionPresenter: CeilDescriptionPresenter by lazy {
|
||||||
|
CeilDescriptionPresenterImpl(
|
||||||
|
ceilDescriptionUseCase
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,10 +2,8 @@ package com.github.insanusmokrassar.PsychomatrixBase.di.realisations
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.di.EntitiesDI
|
import com.github.insanusmokrassar.PsychomatrixBase.di.EntitiesDI
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
|
import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CalculatePsychomatrixByDateUseCase
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.ModifyPsychomatrixUseCase
|
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.*
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.CalculatePsychomatrixByDateUseCaseInteractor
|
|
||||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.interactors.ModifyPsychomatrixUseCaseInteractor
|
|
||||||
|
|
||||||
open class UseCasesDIImpl(
|
open class UseCasesDIImpl(
|
||||||
entitiesDI: EntitiesDI
|
entitiesDI: EntitiesDI
|
||||||
@ -17,4 +15,8 @@ open class UseCasesDIImpl(
|
|||||||
override val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase by lazy {
|
override val modifyPsychomatrixUseCase: ModifyPsychomatrixUseCase by lazy {
|
||||||
ModifyPsychomatrixUseCaseInteractor()
|
ModifyPsychomatrixUseCaseInteractor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val ceilDescriptionUseCase: CeilDescriptionUseCase by lazy {
|
||||||
|
CeilDescriptionInteractor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package com.github.insanusmokrassar.PsychomatrixBase.domain.entities
|
||||||
|
|
||||||
|
typealias CeilDescription = String
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
||||||
|
}
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.github.insanusmokrassar.PsychomatrixBase.utils
|
||||||
|
|
||||||
|
class Container<T>(
|
||||||
|
var value: T? = null,
|
||||||
|
var throwable: Throwable? = null
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user