diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/PsychomatrixCeilDescriptionRepository.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/PsychomatrixCeilDescriptionRepository.kt index c13cb42..0c0e1a1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/PsychomatrixCeilDescriptionRepository.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/PsychomatrixCeilDescriptionRepository.kt @@ -1,8 +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 +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState interface PsychomatrixCeilDescriptionRepository { - fun getCeilDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo): CeilDescription + fun getCeilDescription(ceilState: CeilState): CeilInfo } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/realisations/PsychomatrixCeilDescriptionRepositoryImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/realisations/PsychomatrixCeilDescriptionRepositoryImpl.kt index 4c05a19..e105603 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/realisations/PsychomatrixCeilDescriptionRepositoryImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/data/repository/realisations/PsychomatrixCeilDescriptionRepositoryImpl.kt @@ -2,9 +2,9 @@ package com.github.insanusmokrassar.PsychomatrixBase.data.repository.realisation import com.github.insanusmokrassar.PsychomatrixBase.data.repository.PsychomatrixCeilDescriptionRepository 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.CeilDescriptions.models.CeilsDescriptionsRoot +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState +import com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models.CeilsInfosRoot import com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.resolveCeilsDescriptionsByLanguage import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.subscribe @@ -15,7 +15,7 @@ class PsychomatrixCeilDescriptionRepositoryImpl( language: String = CEILS_DESCRIPTION_ENGLISH ) : PsychomatrixCeilDescriptionRepository { - private val ceilsDescriptionsRoot: CeilsDescriptionsRoot = resolveCeilsDescriptionsByLanguage(language) + private val ceilsInfosRoot: CeilsInfosRoot = resolveCeilsDescriptionsByLanguage(language) init { ceilDescriptionUseCase.openCeilDescriptionRequestedSubscription().subscribe { @@ -29,7 +29,7 @@ class PsychomatrixCeilDescriptionRepositoryImpl( } } - override fun getCeilDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo): CeilDescription { - return ceilsDescriptionsRoot.resolveCeilDescription(psychomatrixCeilInfo) + override fun getCeilDescription(ceilState: CeilState): CeilInfo { + return ceilsInfosRoot.resolveCeilDescription(ceilState) } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/CeilDescriptionUseCase.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/CeilDescriptionUseCase.kt index ca18674..352c67d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/CeilDescriptionUseCase.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/UseCases/CeilDescriptionUseCase.kt @@ -1,17 +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 com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState import kotlinx.coroutines.experimental.channels.ReceiveChannel -typealias CeilDescriptionReady = Pair +typealias CeilDescriptionReady = Pair interface CeilDescriptionUseCase { fun openCeilDescriptionReadySubscription(): ReceiveChannel - fun openCeilDescriptionRequestedSubscription(): ReceiveChannel + fun openCeilDescriptionRequestedSubscription(): ReceiveChannel - fun descriptionReady(psychomatrixCeilInfo: PsychomatrixCeilInfo, ceilDescription: CeilDescription) + fun descriptionReady(ceilState: CeilState, ceilInfo: CeilInfo) - fun requestDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo) + fun requestDescription(ceilState: CeilState) } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilDescription.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilInfo.kt similarity index 87% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilDescription.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilInfo.kt index c87ec6f..f35d305 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilDescription.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilInfo.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.PsychomatrixBase.domain.entities -data class CeilDescription( +data class CeilInfo( val title: String, val description: String, val characteristicDescription: String, diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilState.kt similarity index 97% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilState.kt index ca10fa7..04365a9 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/CeilState.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.PsychomatrixBase.domain.entities -data class PsychomatrixCeilInfo( +data class CeilState( val x: Int, val y: Int, val count: Int? diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt index 3f7ddb2..def96c2 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt @@ -65,7 +65,7 @@ open class Psychomatrix(val date: DateTime) { * Always array 4*5 of values. In rows was put columns * */ - val asMatrix: Array> + val asMatrix: Array> get() = arrayOf( arrayOf( null, @@ -99,7 +99,7 @@ open class Psychomatrix(val date: DateTime) { x, yArray -> yArray.mapIndexed { y, value -> - PsychomatrixCeilInfo( + CeilState( x, y, value ?.toInt() diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/CeilDescriptionInteractor.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/CeilDescriptionInteractor.kt index 1da31a0..678964f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/CeilDescriptionInteractor.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/interactors/CeilDescriptionInteractor.kt @@ -2,8 +2,8 @@ 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.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState 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 @@ -14,7 +14,7 @@ class CeilDescriptionInteractor : CeilDescriptionUseCase { private val ceilDescriptionReadyBroadcastChannel = BroadcastChannel( SUBSCRIPTIONS_SMALL ) - private val ceilDescriptionRequestedBroadcastChannel = BroadcastChannel( + private val ceilDescriptionRequestedBroadcastChannel = BroadcastChannel( SUBSCRIPTIONS_EXTRA_SMALL ) @@ -22,20 +22,20 @@ class CeilDescriptionInteractor : CeilDescriptionUseCase { return ceilDescriptionReadyBroadcastChannel.openSubscription() } - override fun openCeilDescriptionRequestedSubscription(): ReceiveChannel { + override fun openCeilDescriptionRequestedSubscription(): ReceiveChannel { return ceilDescriptionRequestedBroadcastChannel.openSubscription() } - override fun descriptionReady(psychomatrixCeilInfo: PsychomatrixCeilInfo, ceilDescription: CeilDescription) { + override fun descriptionReady(ceilState: CeilState, ceilInfo: CeilInfo) { launch { - ceilDescriptionReadyBroadcastChannel.send(psychomatrixCeilInfo to ceilDescription) + ceilDescriptionReadyBroadcastChannel.send(ceilState to ceilInfo) } } - override fun requestDescription(psychomatrixCeilInfo: PsychomatrixCeilInfo) { + override fun requestDescription(ceilState: CeilState) { launch { ceilDescriptionRequestedBroadcastChannel.send( - psychomatrixCeilInfo + ceilState ) } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/CeilDescriptionPresenter.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/CeilDescriptionPresenter.kt index 256b147..b17ab22 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/CeilDescriptionPresenter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/CeilDescriptionPresenter.kt @@ -1,9 +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 com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState import kotlinx.coroutines.experimental.Deferred interface CeilDescriptionPresenter { - fun onUserChooseCeil(ceilInfo: PsychomatrixCeilInfo): Deferred + fun onUserChooseCeil(ceilState: CeilState): Deferred } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/CeilDescriptionPresenterImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/CeilDescriptionPresenterImpl.kt index df5c69d..960c150 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/CeilDescriptionPresenterImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/presentation/presenters/DefaultRealisations/CeilDescriptionPresenterImpl.kt @@ -1,8 +1,8 @@ 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.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.CeilDescriptionPresenter import com.github.insanusmokrassar.PsychomatrixBase.utils.Container import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.subscribeChecking @@ -11,16 +11,16 @@ import kotlinx.coroutines.experimental.* class CeilDescriptionPresenterImpl( private val ceilDescriptionUseCase: CeilDescriptionUseCase ) : CeilDescriptionPresenter { - override fun onUserChooseCeil(ceilInfo: PsychomatrixCeilInfo): Deferred { + override fun onUserChooseCeil(ceilState: CeilState): Deferred { return async { - val container = Container() + val container = Container() val subscription = ceilDescriptionUseCase.openCeilDescriptionReadySubscription().subscribeChecking( { container.throwable = it false } ) { - if (it.first == ceilInfo) { + if (it.first == ceilState) { container.value = it.second false } else { @@ -28,7 +28,7 @@ class CeilDescriptionPresenterImpl( } } - ceilDescriptionUseCase.requestDescription(ceilInfo) + ceilDescriptionUseCase.requestDescription(ceilState) subscription.join() container.value ?: throw container.throwable ?: throw IllegalStateException("Strange state - must be set value or error") diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilDescriptionResolver.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilInfoResolver.kt similarity index 78% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilDescriptionResolver.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilInfoResolver.kt index 1fa9e8f..68c46fe 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilDescriptionResolver.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/CeilInfoResolver.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions -import com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models.CeilsDescriptionsRoot +import com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models.CeilsInfosRoot import com.github.insanusmokrassar.PsychomatrixBase.utils.FilesLoader.load import com.google.gson.Gson import com.google.gson.GsonBuilder @@ -10,8 +10,8 @@ const val characteristicsFolder = "characteristics" private val gson: Gson = GsonBuilder().create() -fun resolveCeilsDescriptionsByLanguage(language: String = "en_US"): CeilsDescriptionsRoot { +fun resolveCeilsDescriptionsByLanguage(language: String = "en_US"): CeilsInfosRoot { return load("$characteristicsFolder/$language.json").let { - gson.fromJson(InputStreamReader(it), CeilsDescriptionsRoot::class.java) + gson.fromJson(InputStreamReader(it), CeilsInfosRoot::class.java) } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilDescriptionConfig.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilInfoConfig.kt similarity index 80% rename from src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilDescriptionConfig.kt rename to src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilInfoConfig.kt index 94d2c84..354d2c6 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilDescriptionConfig.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilInfoConfig.kt @@ -1,15 +1,15 @@ package com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models -import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo -data class CeilDescriptionConfig( +data class CeilInfoConfig( val title: String = "", val description: String = "", val note: String? = null, val characteristics: List = emptyList() ) { - fun toCeilDescription(countOfCharacteristic: Int): CeilDescription { - return CeilDescription( + fun toCeilDescription(countOfCharacteristic: Int): CeilInfo { + return CeilInfo( title, description, countOfCharacteristic.let { diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsDescriptionsRoot.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsDescriptionsRoot.kt deleted file mode 100644 index 6f15c48..0000000 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsDescriptionsRoot.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models - -import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilDescription -import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.PsychomatrixCeilInfo - -data class CeilsDescriptionsRoot( - val language: String? = "en_US", - private val descriptionsList: List> = emptyList() -) { - fun resolveCeilDescription( - psychomatrixCeilInfo: PsychomatrixCeilInfo - ): CeilDescription { - return descriptionsList[psychomatrixCeilInfo.x][psychomatrixCeilInfo.y].toCeilDescription( - psychomatrixCeilInfo.count ?: 0 - ) - } -} diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsInfosRoot.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsInfosRoot.kt new file mode 100644 index 0000000..e1babb5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/utils/CeilDescriptions/models/CeilsInfosRoot.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.PsychomatrixBase.utils.CeilDescriptions.models + +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilInfo +import com.github.insanusmokrassar.PsychomatrixBase.domain.entities.CeilState + +data class CeilsInfosRoot( + val language: String? = "en_US", + private val descriptionsList: List> = emptyList() +) { + fun resolveCeilDescription( + ceilState: CeilState + ): CeilInfo { + return descriptionsList[ceilState.x][ceilState.y].toCeilDescription( + ceilState.count ?: 0 + ) + } +}