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