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

fix album subscription

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