Commit 60e9bf89 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

to flat now correctly seaking for estate

parent c68b4f84
......@@ -6,6 +6,7 @@ import com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.PlanPresetEntity
import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.data.repository.mapper.fromRaw
import com.biganto.visual.roompark.data.repository.mapper.fromRawList
......@@ -93,7 +94,7 @@ class EstateRepository @Inject constructor(
}
fun getPlanTypesApi(estateId: Int) =
private fun getPlanTypesApi(estateId: Int): Observable<List<PlanPresetEntity>> =
api.getEstatePlanTypes(estateId)
.doOnNext { Timber.d("raw0 $it") }
.map { fromRawList(it, ::fromRaw) }
......@@ -223,7 +224,6 @@ class EstateRepository @Inject constructor(
else -> throw CustomApiException.NotAuthorizedException()
}
}
.doOnNext { Timber.d("deals db: $it") }
.map { it.deals?.map {deal -> deal as DealEntity } }
......@@ -234,10 +234,31 @@ class EstateRepository @Inject constructor(
)
)
.doOnNext { Timber.d("step 3: $it") }
.map { fromEntity(it, ::fromEntity) }
.doOnError(Timber::e)
.subscribeOn (Schedulers.io())
}
private fun fetchEstateApi(building: Int,number:Int)=
api.getEstate(building,number)
.doOnNext { Timber.d("raw0 $it") }
.map (::fromRaw)
.doOnNext(db::upsertEstate)
.subscribeOn(Schedulers.io())
private fun fetchEstateDb(building: Int,number:Int) =
db.fetchEstateByNumber(building,number.toString())
.observable()
.subscribeOn(Schedulers.io())
override fun fetchEstate(building: Int,number:Int): Observable<EstateModel> =
Observable.mergeDelayError(
arrayListOf(fetchEstateApi(building,number),
fetchEstateDb(building,number)
)
).map (::fromEntity)
}
......@@ -10,10 +10,6 @@ import retrofit2.http.*
* Created by Vladislav Bogdashkin on 13.06.2018.
*/
interface IRoomParkMobileApi{
companion object{
......@@ -117,15 +113,15 @@ interface IRoomParkMobileApi{
//region Get MultitourId
const val GET_MULTITOUR_ID="estates.getMultiTour"
const val MULTITOUR_BUILDING_NUMBER_PARAM="building "
const val MULTITOUR_FLAT_NUMBER_PARAM="number "
const val MULTITOUR_BUILDING_NUMBER_PARAM="building"
const val MULTITOUR_FLAT_NUMBER_PARAM="number"
//endregion
//region Get Estate
const val GET_ESTATE_ID="estates.getEstate"
const val ESTATE_BUILDING_NUMBER_PARAM="building "
const val ESTATE_FLAT_NUMBER_PARAM="number "
const val ESTATE_BUILDING_NUMBER_PARAM="building"
const val ESTATE_FLAT_NUMBER_PARAM="number"
//endregion
//region Get Web Cams
......@@ -145,7 +141,6 @@ interface IRoomParkMobileApi{
@Field(PASSWORD_AUTH_PARAM) pwd: String
): Observable<Response<AuthRaw>>
@POST("$API_URL${SUBSCRIBE_METHOD}OD$DELIMITER")
fun subscribe(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -166,7 +161,6 @@ interface IRoomParkMobileApi{
@Query(TOPIC_SUBSCRIBTION_PARAM) topic: String
): Observable<Response<StatusResponse>>
@GET("$API_URL$DEALS_METHOD$DELIMITER")
fun getDeals(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -175,7 +169,6 @@ interface IRoomParkMobileApi{
@Query(AUTH_TOKEN) token: String
): Observable<Response<List<DealRaw>>>
@GET("$API_URL$FAVORITES_METHOD$DELIMITER")
fun getFavorites(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -191,7 +184,6 @@ interface IRoomParkMobileApi{
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<FeedRaw>>>
@GET("$API_URL$GET_WEB_CAMS_METHOD$DELIMITER")
fun getWebCams(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -199,7 +191,6 @@ interface IRoomParkMobileApi{
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<WebCamRaw>>>
@GET("$API_URL$GET_ARTICLES_PAGE_METHOD$DELIMITER")
fun getArticlesPage(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -210,7 +201,6 @@ interface IRoomParkMobileApi{
@Query(ARTICLES_PAGINATION_PAGE_PARAM) page: Int
): Observable<Response<ArticlesListPaginationRaw>>
@GET("$API_URL$GET_ARTICLE_METHOD$DELIMITER")
fun getArticle(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -219,8 +209,6 @@ interface IRoomParkMobileApi{
@Query(ARTICLE_ID_PARAM) id: Int
): Observable<Response<ArticleRaw>>
@GET("$API_URL$ALBUMS_METHOD$DELIMITER")
fun getAlbums(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -229,7 +217,6 @@ interface IRoomParkMobileApi{
@Query(PARENT_ALBUMD_ID_PARAM) id: Int?
): Observable<Response<List<ImageAlbumRaw>>>
@GET("$API_URL$PHOTOS_METHOD$DELIMITER")
fun getPhotos(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -238,7 +225,6 @@ interface IRoomParkMobileApi{
@Query(PHOTOS_ALBUMD_ID_PARAM) id: Int
): Observable<Response<List<GalleryImageRaw>>>
@GET("$API_URL$GET_PLAN_TYPES_METHOD$DELIMITER")
fun getPlanTypes(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -247,7 +233,6 @@ interface IRoomParkMobileApi{
@Query(PLAN_TYPES_ESTATE_ID_PARAM) estateId: Int
): Observable<Response<List<PlanTypeRaw>>>
@GET("$API_URL$GET_DIRECT_PLAN_METHOD$DELIMITER")
fun getPlan(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......@@ -261,7 +246,6 @@ interface IRoomParkMobileApi{
@Query(DIRECT_PLAN_ELECTRIC_PARAM) electric:Int
): Observable<Response<String>>
@Deprecated("change to estates.getEstate method as more common")
@GET("$API_URL$GET_MULTITOUR_ID$DELIMITER")
fun getMultiTourId(
......@@ -280,6 +264,4 @@ interface IRoomParkMobileApi{
@Query(ESTATE_BUILDING_NUMBER_PARAM) building:Int,
@Query(ESTATE_FLAT_NUMBER_PARAM) flatNumber:Int
): Observable<Response<EstateRaw>>
}
\ No newline at end of file
......@@ -29,4 +29,6 @@ interface IDb {
fun getUserFavorites(uuid: Int): Observable<EstateEntity>
fun fetchAllUsers(): Observable<List<UserEntity>>
fun getEstate(estateId: Int): Observable<EstateEntity>
fun upsertEstate(entity: EstateEntity)
fun fetchEstateByNumber(building: Int, number: String): ReactiveResult<EstateEntity>
}
\ No newline at end of file
......@@ -58,10 +58,18 @@ class RequeryRepository @Inject constructor(
override fun <T : List<Persistable>> blockingUpsert(entity: T) =
store.upsert(entity).toObservable().blockingSubscribe()
override fun upsertEstate(entity:EstateEntity) =
store.upsert(entity).toObservable().blockingSubscribe()
override fun fetchFeeds(): Observable<FeedEntity> =
fetchAll<FeedEntity>().get().observable()
override fun fetchEstateByNumber(building:Int,number:String): ReactiveResult<EstateEntity> =
store.select(EstateEntity::class)
.where(EstateEntity.NUMBER.eq(number))
.and(EstateEntity.INFO_BUILDING.eq(building))
.get()
override fun getFeed(feedAlias: String): ReactiveResult<FeedEntity> =
fetchAll<FeedEntity>().where(FeedEntity.ALIAS.eq(feedAlias))
.get()
......
......@@ -26,4 +26,5 @@ interface DealContract{
fun getDeals(): Observable<List<DealModel>>
fun fetchEstate(building: Int, number: Int): Observable<EstateModel>
}
\ No newline at end of file
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.domain.model.TourRequestModel
import com.biganto.visual.roompark.domain.model.TourResponse
import com.biganto.visual.roompark.domain.use_case.EstateUseCase
import io.reactivex.Observable
import javax.inject.Inject
......@@ -11,18 +9,11 @@ import javax.inject.Inject
*/
class FindFlatInteractor @Inject constructor(
val useCase:EstateUseCase
){
fun getFlat(requaest: TourRequestModel): Observable<TourResponse> =
Observable.just(tourResponseMock)
fun getFlat(building:Int,flat:Int): Observable<Int>
= useCase.fetchEstate(building,flat)
.map { it.id }
companion object{
val tourResponseMock = TourResponse(arrayListOf(
TourModel("125","Tour s otdelkoj",null),
TourModel("126","Tour bez otdelki",null)
)
)
}
}
\ No newline at end of file
......@@ -5,6 +5,6 @@ package com.biganto.visual.roompark.domain.model
*/
data class TourRequestModel(val building:Int, val flat:String)
data class TourRequestModel(val building:Int, val flat:Int)
data class TourResponse(val response:List<TourModel>)
data class TourModel(val tourId:String, val title:String, val preview:String?)
data class TourModel(val tourId:String, val title:Int, val preview:String?)
......@@ -15,6 +15,9 @@ class EstateUseCase @Inject constructor(
fun getEstate(estateId: Int) = contract.getEstate(estateId)
fun fetchEstate(building:Int, number:Int) =
contract.fetchEstate(building, number)
fun getEstatePlanPresets(estateId: Int) =
contract.getPlanTypes(estateId)
......
......@@ -12,6 +12,7 @@ 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
......@@ -71,8 +72,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())
)
}
)
......
package com.biganto.visual.roompark.presentation.screen.to_flat
import com.biganto.visual.roompark.conductor.BigantoBaseContract
import com.biganto.visual.roompark.domain.model.TourRequestModel
import io.reactivex.Observable
/**
......@@ -9,7 +8,7 @@ import io.reactivex.Observable
*/
interface FindFlatScreen : BigantoBaseContract<FindFlatScreenViewState> {
fun getFlat() : Observable<TourRequestModel>
fun startTour() : Observable<String>
fun getFlat() : Observable<FlatRequestModel>
}
data class FlatRequestModel(val number:Int,val building:Int)
\ No newline at end of file
......@@ -9,13 +9,16 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.domain.model.TourRequestModel
import com.biganto.visual.roompark.presentation.screen.estate.EstateScreenController
import com.biganto.visual.roompark.presentation.screen.feeds.EstateTabModel
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.google.android.material.button.MaterialButton
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
import com.jakewharton.rxbinding3.view.keys
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import javax.inject.Inject
......@@ -30,17 +33,17 @@ class FindFlatScreenController :
, FindFlatScreen {
override fun getFlat(): Observable<TourRequestModel> =
override fun getFlat(): Observable<FlatRequestModel> =
flatNumberEditor.keys { it.keyCode == KeyEvent.KEYCODE_ENTER }
.doOnNext { flatNumberEditor.hideKeyboard() }
.map {
TourRequestModel(
FlatRequestModel(
estateTabs[flatTabs.selectedTabPosition].building
, flatNumberInput.editText?.text.toString()
, flatNumberInput.editText?.text.toString().toInt()
)
}
.observeOn(AndroidSchedulers.mainThread())
override fun startTour(): Observable<String> = Observable.just("1")
override fun injectDependencies() {
getComponent()
......@@ -101,8 +104,8 @@ class FindFlatScreenController :
Timber.d("Render state $viewState")
when(viewState){
is FindFlatScreenViewState.Idle -> render(viewState)
is FindFlatScreenViewState.StartTour -> render(viewState)
is FindFlatScreenViewState.SomeError -> render(viewState)
is FindFlatScreenViewState.FlatFounded -> render(viewState)
}
}
......@@ -110,7 +113,14 @@ class FindFlatScreenController :
showError(viewState.exception)
private fun render(viewState: FindFlatScreenViewState.Idle){
}
private fun render(viewState: FindFlatScreenViewState.FlatFounded){
router.pushController(
RouterTransaction.with(EstateScreenController(viewState.esateId))
.pushChangeHandler(FadeChangeHandler())
.popChangeHandler(FadeChangeHandler())
)
}
private fun getComponent() = DaggerFindFlatScreenComponent.factory()
......
......@@ -25,26 +25,18 @@ class FindFlatScreenPresenter @Inject constructor(
override fun bindIntents() {
val startTourIntent = intent(FindFlatScreen::startTour)
.filter { false }
.map { FindFlatScreenViewState.StartTour(it) }
val getFlatIntent = intent(FindFlatScreen::getFlat)
.doOnNext{Timber.d(" flat is $it")}
.flatMap { request ->
interactor.getFlat(request)
.map {
if (it.response.isNullOrEmpty()) FindFlatScreenViewState.FlatNotFound()
else FindFlatScreenViewState.TourFounded(it.response)
}
.onErrorReturn { Timber.e(it);FindFlatScreenViewState.RequstFlatProgress() }
interactor.getFlat(request.building,request.number)
.map<FindFlatScreenViewState> {FindFlatScreenViewState.FlatFounded(it)}
.onErrorReturn (::parseError)
}
.startWith(Observable.just(FindFlatScreenViewState.RequstFlatProgress()))
val state = restoreStateObservable
.mergeWith(getFlatIntent)
.mergeWith(startTourIntent)
.doOnError { Timber.e(it) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.to_flat
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -12,8 +11,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class FindFlatScreenViewState : BigantoBaseViewState() {
class Idle : FindFlatScreenViewState()
class RequstFlatProgress : FindFlatScreenViewState()
class TourFounded(val items:List<TourModel>) : FindFlatScreenViewState()
class StartTour(val tourId:String) : FindFlatScreenViewState()
class FlatNotFound() : FindFlatScreenViewState()
class FlatFounded(val esateId:Int) : FindFlatScreenViewState()
class FlatNotFound : FindFlatScreenViewState()
class SomeError(val exception: ExceptionString) : FindFlatScreenViewState()
}
\ No newline at end of file
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