Commit f697ad78 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix album subscription

parent 991e8526
......@@ -31,8 +31,8 @@ class DbModule{
Timber.d("Kotlin store creating..")
val source = DatabaseSource(context, Models.DEFAULT, "BigantoPerfect", DATABASE_VERSION)
source.setLoggingEnabled(true)
source.setWriteAheadLoggingEnabled(true)
// source.setLoggingEnabled(true)
// source.setWriteAheadLoggingEnabled(true)
source.setTableCreationMode(TableCreationMode.DROP_CREATE)
val store = KotlinEntityDataStore<Persistable>(source.configuration)
Timber.d("Kotlin store %s",source)
......
......@@ -81,9 +81,9 @@ class SubscriptionUseCase @Inject constructor(
fun getSubscriptions(topic: SubscriptionTopic): Observable<SubscriptionModel> =
auth.currentUser()
.map {user ->
Timber.w("user is : $user")
var sub = user.subscriptions
?.firstOrNull { it.topic == topic.topicName && it.number == topic.topicId }
Timber.d("fetched topic: $sub")
if (sub == null) {
sub = SubscriptionEntity()
sub.setOwner(user)
......
......@@ -71,6 +71,9 @@ class AlbumsScreenController :
@BindView(R.id.bubble_slider)
lateinit var bubble: BubbleSlider
@BindView(R.id.switch1)
lateinit var albumSubscription: SwitchMaterial
//
// private val photosBackgroundTarget = object : com.squareup.picasso.Target {
......@@ -135,7 +138,7 @@ class AlbumsScreenController :
override fun onSubscription(): Observable<Boolean> =
toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
albumSubscription
.checkedChanges()
.skip(1) //skip init switcher check state
.filter {
......@@ -146,6 +149,7 @@ class AlbumsScreenController :
.doOnNext { }
.debounce(600L, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.share()
......@@ -178,8 +182,8 @@ class AlbumsScreenController :
private var silentCheck = false
private fun render(viewState: AlbumsScreenViewState.SubscriptionStatus) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
Timber.d()
val sw = albumSubscription
Timber.d("")
if (sw.isChecked != viewState.subState)
{
silentCheck = true
......@@ -188,7 +192,7 @@ class AlbumsScreenController :
}
private fun render(viewState: AlbumsScreenViewState.SubscriptionError) {
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
val sw = albumSubscription
if (sw.isChecked != viewState.subState)
{
silentCheck = true
......@@ -268,7 +272,7 @@ class AlbumsScreenController :
}
}
val sw = toolBar.headerToolbar.findViewById<SwitchMaterial>(R.id.switch1)
val sw = albumSubscription
if (sw.isChecked != viewState.restore.sub?.state)
{
silentCheck = true
......
......@@ -35,6 +35,13 @@ class AlbumsScreenPresenter @Inject constructor(
.doOnNext { restoreModel.albumList = it }
.map { AlbumsScreenViewState.AlbumsSelected(it) }
private fun fetchSubscription(albumId: Int): Observable<AlbumsScreenViewState> =
interactor.getSubscriptions(currentAlbumTopic(albumId))
.doAfterNext { restoreModel.sub = it }
.map<AlbumsScreenViewState> { AlbumsScreenViewState.SubscriptionStatus(it.state) }
// .startWith(Observable.just<AlbumsScreenViewState>(AlbumsScreenViewState.Idle()))
override fun bindIntents() {
val onSubChecked = intent(AlbumsScreen::onSubscription)
......@@ -51,10 +58,6 @@ class AlbumsScreenPresenter @Inject constructor(
.onErrorReturn { AlbumsScreenViewState.SubscriptionError(!newState) }
}
val fetchSubscription = interactor.getSubscriptions(currentAlbumTopic)
.doAfterNext { restoreModel.sub = it }
.map<AlbumsScreenViewState> { AlbumsScreenViewState.SubscriptionStatus(it.state) }
// .startWith(Observable.just<AlbumsScreenViewState>(AlbumsScreenViewState.Idle()))
val fetchParents = interactor.fetchHeaderAlbums()
.filter { !it.isNullOrEmpty() }
......@@ -63,19 +66,19 @@ class AlbumsScreenPresenter @Inject constructor(
val fetchSelected = requestAlbum(selectedIndex)
val headerItemSelected =
Observable.mergeDelayError(
arrayListOf(
intent(AlbumsScreen::onAlbumSelected)
val headerItemSelected = intent(AlbumsScreen::onAlbumSelected)
.doOnNext { selectedIndex = it.albumId }
.doOnNext { restoreModel.currentIndex = it.albumId }
.flatMap<AlbumsScreenViewState> { model ->
requestAlbum(model.albumId)
.startWith(Observable.just<AlbumsScreenViewState>(AlbumsScreenViewState.HeaderAlbumChoosed(item = model))
)
}, fetchSubscription))
}
val fetchHeaderSubscription = intent(AlbumsScreen::onAlbumSelected)
.map { it.albumId }
.doOnNext { selectedIndex = it ; restoreModel.currentIndex = it }
.switchMap { fetchSubscription(it) }
val photoSelected = intent(AlbumsScreen::onPhotoSelected)
......@@ -88,7 +91,8 @@ class AlbumsScreenPresenter @Inject constructor(
fetchSelected,
headerItemSelected,
photoSelected,
fetchSubscription,
fetchSubscription(selectedIndex),
fetchHeaderSubscription,
onSubChecked
)
)
......@@ -104,12 +108,15 @@ class AlbumsScreenPresenter @Inject constructor(
restoreStateObservable.accept(AlbumsScreenViewState.RestoreView(restoreModel))
}
private val currentAlbumTopic = when(selectedIndex){
9 -> SubscriptionTopic.Progress_1()
10 -> SubscriptionTopic.Progress_2()
11 -> SubscriptionTopic.Progress_3()
106 -> SubscriptionTopic.Progress_kindergarden()
else -> error("unknown parent album type!")
private fun currentAlbumTopic(albumId:Int):SubscriptionTopic {
val z = when(albumId){
9 -> SubscriptionTopic.Progress_2()
10 -> SubscriptionTopic.Progress_1()
11 -> SubscriptionTopic.Progress_3()
106 -> SubscriptionTopic.Progress_kindergarden()
else -> error("unknown parent album type!")
}
return z
}
}
......
......@@ -69,6 +69,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:baselineAligned="false"
android:gravity="center_vertical|end" />
......
......@@ -10,9 +10,11 @@
android:id="@+id/bellSwitcherTitle"
style="@style/Common_Text.Default"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="start|center_vertical"
android:includeFontPadding="false"
android:text="блабла" />
<include
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment