mirror of
https://github.com/InsanusMokrassar/PsychomatrixBase.git
synced 2024-11-24 19:18:53 +00:00
add HistoryDatesRepository
This commit is contained in:
parent
108fd4276d
commit
003886605c
@ -0,0 +1,15 @@
|
||||
package com.github.insanusmokrassar.PsychomatrixBase.data.repository
|
||||
|
||||
import kotlinx.coroutines.experimental.Deferred
|
||||
import kotlinx.coroutines.experimental.channels.ReceiveChannel
|
||||
import org.joda.time.DateTime
|
||||
|
||||
interface HistoryDatesRepository {
|
||||
|
||||
suspend fun openDateAddedSubscription(): ReceiveChannel<DateTime>
|
||||
suspend fun openDateRemovedSubscription(): ReceiveChannel<DateTime>
|
||||
|
||||
suspend fun getDates(from: DateTime? = null, to: DateTime? = null): Deferred<List<DateTime>>
|
||||
suspend fun removeDate(date: DateTime): Deferred<Boolean>
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.github.insanusmokrassar.PsychomatrixBase.data.repository.realisations
|
||||
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.HistoryDatesRepository
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.domain.UseCases.CalculatePsychomatrixByDate
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.SUBSCRIPTIONS_EXTRA_SMALL
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.utils.extensions.subscribe
|
||||
import kotlinx.coroutines.experimental.*
|
||||
import kotlinx.coroutines.experimental.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.experimental.channels.ReceiveChannel
|
||||
import org.joda.time.DateTime
|
||||
|
||||
abstract class HistoryDatesRepositoryImpl(
|
||||
calculatePsychomatrixByDate: CalculatePsychomatrixByDate
|
||||
) : HistoryDatesRepository {
|
||||
private val dateAddedBroadcast = BroadcastChannel<DateTime>(SUBSCRIPTIONS_EXTRA_SMALL)
|
||||
private val dateRemovedBroadcast = BroadcastChannel<DateTime>(SUBSCRIPTIONS_EXTRA_SMALL)
|
||||
|
||||
init {
|
||||
runBlocking {
|
||||
calculatePsychomatrixByDate.openPsychomatrixCreatedSubscription().subscribe {
|
||||
it.date.also {
|
||||
date ->
|
||||
onDateCalculated(date)
|
||||
dateAddedBroadcast.send(date)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun openDateAddedSubscription(): ReceiveChannel<DateTime> {
|
||||
return dateAddedBroadcast.openSubscription()
|
||||
}
|
||||
|
||||
override suspend fun openDateRemovedSubscription(): ReceiveChannel<DateTime> {
|
||||
return dateRemovedBroadcast.openSubscription()
|
||||
}
|
||||
|
||||
protected abstract fun onDateCalculated(dateTime: DateTime)
|
||||
|
||||
override suspend fun removeDate(date: DateTime): Deferred<Boolean> {
|
||||
return async {
|
||||
internalRemoveDate(date).also {
|
||||
if (it) {
|
||||
dateRemovedBroadcast.send(date)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun internalRemoveDate(date: DateTime): Boolean
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package com.github.insanusmokrassar.PsychomatrixBase.di
|
||||
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.data.repository.HistoryDatesRepository
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
|
||||
|
||||
interface PresentationLayerDI : UseCasesDI {
|
||||
|
||||
val datePickerPresenter: DatePickerPresenter
|
||||
|
||||
val historyDatesRepository: HistoryDatesRepository
|
||||
}
|
@ -5,7 +5,7 @@ import com.github.insanusmokrassar.PsychomatrixBase.di.UseCasesDI
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DatePickerPresenter
|
||||
import com.github.insanusmokrassar.PsychomatrixBase.presentation.presenters.DefaultRealisations.DatePickerPresenterImpl
|
||||
|
||||
open class PresentationLayerDIImpl(
|
||||
abstract class PresentationLayerDIImpl(
|
||||
useCasesDI: UseCasesDI
|
||||
) : PresentationLayerDI, UseCasesDI by useCasesDI {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user