Commit 654419dd authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

fix user session behaviour

parent 33732db9
...@@ -49,13 +49,13 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -49,13 +49,13 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
lateinit var snackbar: ISnackBarProvider lateinit var snackbar: ISnackBarProvider
override fun onAttach(view: View) { override fun onAttach(view: View) {
Timber.d("On Attach") Timber.d("On Attach $view")
super.onAttach(view) super.onAttach(view)
} }
override fun onDetach(view: View) { override fun onDetach(view: View) {
Timber.d("On Detach") Timber.d("On Detach $view" )
detachDisposable.clear() detachDisposable.clear()
super.onDetach(view) super.onDetach(view)
} }
......
...@@ -37,7 +37,7 @@ class EstateRepository @Inject constructor( ...@@ -37,7 +37,7 @@ class EstateRepository @Inject constructor(
init { init {
Timber.d("Estate Repository Created") Timber.d("Estate Repository Created $this")
} }
private val getFavoritesApi: Observable<List<EstateEntity>> = private val getFavoritesApi: Observable<List<EstateEntity>> =
...@@ -202,6 +202,7 @@ class EstateRepository @Inject constructor( ...@@ -202,6 +202,7 @@ class EstateRepository @Inject constructor(
else -> throw CustomApiException.NotAuthorizedException() else -> throw CustomApiException.NotAuthorizedException()
} }
} }
.doOnError (Timber::e)
.flatMap { user -> .flatMap { user ->
api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken) api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken)
.doOnError(Timber::e) .doOnError(Timber::e)
...@@ -222,16 +223,21 @@ class EstateRepository @Inject constructor( ...@@ -222,16 +223,21 @@ class EstateRepository @Inject constructor(
else -> throw CustomApiException.NotAuthorizedException() else -> throw CustomApiException.NotAuthorizedException()
} }
} }
.doOnNext { Timber.d("deals db: $it") }
.map { it.deals?.map {deal -> deal as DealEntity } } .map { it.deals?.map {deal -> deal as DealEntity } }
override fun getDeals(): Observable<List<DealModel>> { override fun getDeals(): Observable<List<DealModel>> {
return Observable.mergeDelayError( return Observable.mergeDelayError(
arrayListOf( arrayListOf(
getDealsApi,getDealsDb getDealsDb,getDealsApi
) )
).map { fromEntity(it, ::fromEntity) } )
.doOnNext { Timber.d("step 3: $it") }
.map { fromEntity(it, ::fromEntity) }
.doOnError(Timber::e) .doOnError(Timber::e)
.subscribeOn (Schedulers.io())
} }
} }
...@@ -4,10 +4,12 @@ import android.app.Application ...@@ -4,10 +4,12 @@ import android.app.Application
import com.afollestad.rxkprefs.Pref import com.afollestad.rxkprefs.Pref
import com.afollestad.rxkprefs.rxkPrefs import com.afollestad.rxkprefs.rxkPrefs
import com.biganto.visual.androidplayer.data.repository.local.ILocalStore import com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import com.jakewharton.rxrelay2.BehaviorRelay
import dagger.Module import dagger.Module
import dagger.Provides import dagger.Provides
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
...@@ -31,12 +33,29 @@ class LocalStorage(){ ...@@ -31,12 +33,29 @@ class LocalStorage(){
class UserHolder @Inject constructor(val context : Application) : ILocalStore class UserHolder @Inject constructor(val context : Application) : ILocalStore
{ {
private val prefs = rxkPrefs(context)
private val userSession : Pref<String> = prefs.string(RECENT_UUID_KEY, EMPTY_PREF_VALUE_KEY)
private val sessionSubject = BehaviorRelay.create<UserState>()
private val disposable = CompositeDisposable()
init { init {
Timber.d(" inited") Timber.d(" inited")
disposable.add(userSession.observe().subscribe {
sessionSubject.accept(
if (it == EMPTY_PREF_VALUE_KEY) UserState.NotAuthenticated()
else UserState.Authenticated(it)
)
})
val s = userSession.get()
sessionSubject.accept(
if ( s== EMPTY_PREF_VALUE_KEY) UserState.NotAuthenticated()
else UserState.Authenticated(s)
)
} }
private val prefs = rxkPrefs(context)
private val userSession : Pref<String> = prefs.string(RECENT_UUID_KEY, EMPTY_PREF_VALUE_KEY)
companion object { companion object {
const val RECENT_UUID_KEY = "com.biganto.visual.androidplayer.LAST_USER_UUD" const val RECENT_UUID_KEY = "com.biganto.visual.androidplayer.LAST_USER_UUD"
...@@ -57,26 +76,19 @@ class UserHolder @Inject constructor(val context : Application) : ILocalStore ...@@ -57,26 +76,19 @@ class UserHolder @Inject constructor(val context : Application) : ILocalStore
override fun recentUserObs() = userSession.observe() override fun recentUserObs() = userSession.observe()
override fun recentUser(): Observable<in UserState> = override fun recentUser(): Observable<UserState> = sessionSubject
userSession
.observe()
.map {
Timber.d(" AUTH VALUE: $it")
Timber.d(" EMPTY_PREF_VALUE_KEY: $EMPTY_PREF_VALUE_KEY")
if (it == EMPTY_PREF_VALUE_KEY) return@map UserState.NotAuthenticated()
else return@map UserState.Authenticated(it)
}
override fun setRecentUser(uuid: String?) = override fun setRecentUser(uuid: String?) =
Completable.defer { Completable.defer {
Completable.fromCallable { userSession.set(uuid ?: EMPTY_PREF_VALUE_KEY) } Completable.fromCallable {
userSession.set(uuid ?: EMPTY_PREF_VALUE_KEY) }
.doOnComplete { Timber.d("complete save null value") } .doOnComplete { Timber.d("complete save null value") }
} }
} }
sealed class UserState{ sealed class UserState{
class NotAuthenticated class NotAuthenticated:UserState()
data class Authenticated(val uuid: String) data class Authenticated(val uuid: String):UserState()
} }
data class UserPrefModel( data class UserPrefModel(
......
...@@ -28,16 +28,20 @@ interface DataComponent{ ...@@ -28,16 +28,20 @@ interface DataComponent{
@Module(includes = [DataModule::class, RetrofitModule::class, DbModule::class,LocalStorage::class]) @Module(includes = [DataModule::class, RetrofitModule::class, DbModule::class,LocalStorage::class])
abstract class ContractRepositoryModule { abstract class ContractRepositoryModule {
@Singleton
@Binds @Binds
abstract fun provideAuth(contract:AuthContractModule):AuthContract abstract fun provideAuth(contract:AuthContractModule):AuthContract
@Singleton
@Binds @Binds
abstract fun provideFeedsContract(impl: FeedsContractModule): FeedsContract abstract fun provideFeedsContract(impl: FeedsContractModule): FeedsContract
@Binds @Binds
@Singleton
abstract fun provideDevProgressContract(impl: AlbumsContractModule): DevProgressContract abstract fun provideDevProgressContract(impl: AlbumsContractModule): DevProgressContract
@Binds @Binds
@Singleton
abstract fun provideEstateContract(impl: EstateRepository): DealContract abstract fun provideEstateContract(impl: EstateRepository): DealContract
} }
......
package com.biganto.visual.roompark.domain.interactor package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.contract.DealContract
import com.biganto.visual.roompark.domain.model.* import com.biganto.visual.roompark.domain.model.*
import com.biganto.visual.roompark.domain.use_case.DealseUseCase
import io.reactivex.Observable import io.reactivex.Observable
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -10,15 +11,20 @@ import javax.inject.Inject ...@@ -10,15 +11,20 @@ import javax.inject.Inject
*/ */
class DealInteractor @Inject constructor( class DealInteractor @Inject constructor(
val useCase : DealContract val useCase : DealseUseCase
){ ){
fun getDeal(id:String): Observable<DealModel> = fun getDeal(id:String): Observable<DealModel> =
useCase.getDeals() useCase.getDeals()
.map { it.first { it.id==id } } .doOnNext { Timber.d("$it") }
.map {deals -> deals.first { it.id==id } }
fun getStatusList() = Observable.just(statusList.sortedBy{ it.orderId }) fun getStatusList() = Observable.just(statusList.sortedBy{ it.orderId })
fun getStatusListSync() = statusList.asSequence().sortedBy{ it.orderId }.toList()
fun getFakeDeal(): Observable<DealModel> = Observable.just(dealParkign)
companion object{ companion object{
...@@ -76,8 +82,8 @@ class DealInteractor @Inject constructor( ...@@ -76,8 +82,8 @@ class DealInteractor @Inject constructor(
, ,
StatusModel( StatusModel(
11, 11,
"Неведанный новый статус", "Договор выдан",
"Договор отдан или тип того" "Договор выдан"
) )
) )
......
...@@ -73,8 +73,8 @@ class DealsInteractor @Inject constructor( ...@@ -73,8 +73,8 @@ class DealsInteractor @Inject constructor(
), ),
StatusModel( StatusModel(
11, 11,
"AAAA aa a a aAA a a", "Договор выдан",
"AAAA" "Договор выдан"
) )
) )
......
...@@ -4,6 +4,7 @@ import android.content.Context ...@@ -4,6 +4,7 @@ import android.content.Context
import androidx.annotation.StringRes import androidx.annotation.StringRes
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.DealInteractor import com.biganto.visual.roompark.domain.interactor.DealInteractor
import com.biganto.visual.roompark.domain.interactor.EstateInteractor
import com.biganto.visual.roompark.domain.model.DealModel import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.presentation.screen.estate.InfoShowType import com.biganto.visual.roompark.presentation.screen.estate.InfoShowType
...@@ -21,6 +22,7 @@ import javax.inject.Named ...@@ -21,6 +22,7 @@ import javax.inject.Named
class DealScreenPresenter @Inject constructor( class DealScreenPresenter @Inject constructor(
private val interactor: DealInteractor, private val interactor: DealInteractor,
private val interactor2: EstateInteractor,
private val context: Context, private val context: Context,
@Named(SELECTED_DEAL_ID_KEY) private val dealId:String @Named(SELECTED_DEAL_ID_KEY) private val dealId:String
) )
...@@ -39,11 +41,10 @@ class DealScreenPresenter @Inject constructor( ...@@ -39,11 +41,10 @@ class DealScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchDeal = interactor.getDeal(dealId) val fetchDeal = interactor.getDeal(dealId)
.flatMap { deal -> .map<DealScreenViewState>{ deal ->
interactor.getStatusList().map { DealScreenViewState.LoadDeal(deal,it) } DealScreenViewState.LoadDeal(deal ,interactor.getStatusListSync())
} }
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchDeal) .mergeWith(fetchDeal)
.doOnError { Timber.e(it) } .doOnError { Timber.e(it) }
......
...@@ -12,7 +12,6 @@ import com.biganto.visual.roompark.presentation.screen.deal.DealScreenController ...@@ -12,7 +12,6 @@ import com.biganto.visual.roompark.presentation.screen.deal.DealScreenController
import com.biganto.visual.roompark.presentation.screen.deals.util.DealsListAdapter import com.biganto.visual.roompark.presentation.screen.deals.util.DealsListAdapter
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
...@@ -72,8 +71,8 @@ class DealsScreenController : ...@@ -72,8 +71,8 @@ class DealsScreenController :
.subscribe { .subscribe {
Timber.d("got card clicked $it") Timber.d("got card clicked $it")
router.pushController(RouterTransaction.with(DealScreenController(it.id)) router.pushController(RouterTransaction.with(DealScreenController(it.id))
.pushChangeHandler(FadeChangeHandler()) // .pushChangeHandler(FadeChangeHandler())
.popChangeHandler(FadeChangeHandler()) // .popChangeHandler(FadeChangeHandler())
) )
} }
) )
......
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