Commit 394e26c4 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

can't cast svg withing webview - tags parse error

parent d5e2c26e
......@@ -126,6 +126,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.2'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.14.0'
......
......@@ -10,6 +10,7 @@ import com.biganto.visual.roompark.data.repository.mapper.fromRawList
import com.biganto.visual.roompark.domain.contract.DealContract
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
......@@ -101,10 +102,26 @@ class EstateRepository @Inject constructor(
.subscribeOn(Schedulers.io())
override fun getPlanTypes(estateId: Int) =
override fun getPlanTypes(estateId: Int): Observable<List<PlanPresetModel>> =
Observable.mergeDelayError(
arrayListOf(getPlanTypesApi(estateId))
).map { l -> List(l.size) { fromEntity(l[it]) } }
private fun getPlanApi(estateId: Int
, planId:Int
, furniture:Boolean = false
, sizes:Boolean = false
, walls:Boolean = false
, electric:Boolean = false) =
api.getDirectPlan(estateId, planId,furniture,sizes,walls,electric)
.subscribeOn(Schedulers.io())
override fun getEmptyPlan(estateId: Int
,planId:Int): Observable<String> =
Observable.mergeDelayError(
arrayListOf(getPlanApi(estateId,planId))
)
.map { l -> List(l.size) { fromEntity(l[it]) } }
}
package com.biganto.visual.roompark.data.repository.api
import com.biganto.visual.roompark.data.repository.api.retrofit.DEFAULT_ARTICLE_PAGE_SIZE
import com.biganto.visual.roompark.data.repository.api.retrofit.PlanTypeCatalog
import com.biganto.visual.roompark.data.repository.api.retrofit.raw.*
import io.reactivex.Observable
......@@ -33,7 +32,7 @@ interface IRoomParkApi {
fun getEstatePlanTypes(estateId: Int): Observable<List<PlanTypeRaw>>
fun getDirectPlan(
estateId: Int,
planType: PlanTypeCatalog,
planType: Int,
showFurniture: Boolean,
showSizes: Boolean,
showWalls: Boolean,
......
......@@ -108,12 +108,7 @@ interface IRoomParkMobileApi{
//region Get Plan Types
const val GET_DIRECT_PLAN_METHOD="estates.getPlan"
const val DIRECT_PLAN_ESTATE_ID_PARAM="estate_id"
const val DIRECT_PLAN_TYPE_PARAM="plan_type"
val planTypes = arrayListOf(
Pair(0 , "проектная планировка"),
Pair(1 , "перепланировка №1"),
Pair(2 , "перепланировка №2")
)
const val DIRECT_PLAN_TYPE_PARAM="plan_id"
const val DIRECT_PLAN_FURNITURE_PARAM="furniture"
const val DIRECT_PLAN_SIZES_PARAM="sizes"
const val DIRECT_PLAN_WALLS_PARAM="walls"
......
......@@ -96,7 +96,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
override fun getDirectPlan(
estateId: Int,
planType: PlanTypeCatalog,
planType: Int,
showFurniture: Boolean,
showSizes: Boolean,
showWalls: Boolean,
......@@ -104,7 +104,7 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
): Observable<String> =
api.getPlan(
estate_id = estateId,
planType = planType.planId,
planType = planType,
furniture = showFurniture.asInt,
sizes = showSizes.asInt,
walls = showWalls.asInt,
......
......@@ -18,6 +18,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import timber.log.Timber
import java.util.*
import java.util.concurrent.TimeUnit
......@@ -106,6 +107,7 @@ class RetrofitModule{
Retrofit.Builder()
.baseUrl(IRoomParkMobileApi.BASE_URL)
.client(client(AppVersionManager(context), LiveNetworkMonitor(context)))
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(NullOnEmptyConverterFactory.create())
.addConverterFactory(gsonConverterFactory())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
......
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.Generated
import io.requery.Key
import io.requery.Persistable
import io.requery.*
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
......@@ -17,4 +14,6 @@ interface Explication : Persistable {
val living: Boolean
val area: Float
val title: String
@get:ManyToOne(cascade = [CascadeAction.NONE])
val owner: PlanPreset
}
......@@ -14,12 +14,12 @@ interface PlanPreset : Persistable {
@get:Generated
val id: Int
@get:ForeignKey(references = Estate::class)
@get:ManyToOne
@get:ManyToOne(cascade = [CascadeAction.NONE])
var estateId:Estate
val planId: Int
val title:String
@get:Convert(StringListConverter::class)
val features:List<String>
@get:OneToMany(mappedBy = "id", cascade = [CascadeAction.SAVE, CascadeAction.DELETE])
@get:OneToMany( mappedBy = "owner", cascade = [CascadeAction.SAVE, CascadeAction.DELETE])
val explication:MutableList<Explication>
}
\ No newline at end of file
......@@ -14,4 +14,5 @@ interface DealContract{
fun getFavorites() : Observable<List<EstateModel>>
fun getEstate(estateId: Int): Observable<EstateModel>
fun getPlanTypes(estateId: Int): Observable<List<PlanPresetModel>>
fun getEmptyPlan(estateId: Int, planId: Int): Observable<String>
}
\ No newline at end of file
......@@ -13,6 +13,9 @@ class EstateInteractor @Inject constructor(
fun getEstate(estateId:Int) = useCase.getEstate(estateId)
// fun getPlanTypes() =
fun getPlanTypes(estateId: Int) =
useCase.getEstatePlanPresets(estateId)
fun getPlan(estateId: Int,planId:Int) = useCase.getPlan(estateId,planId)
}
\ No newline at end of file
......@@ -15,4 +15,10 @@ class EstateUseCase @Inject constructor(
fun getEstate(estateId:Int) = contract.getEstate(estateId)
fun getEstatePlanPresets(estateId: Int) =
contract.getPlanTypes(estateId)
fun getPlan(estateId: Int,planId:Int) = contract.getEmptyPlan(estateId,planId)
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.estate
import com.biganto.visual.roompark.conductor.BigantoBaseContract
import io.reactivex.Observable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface EstateScreen : BigantoBaseContract<EstateScreenViewState> {
fun planTypesTabSelected(): Observable<Int>
}
......@@ -2,6 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.estate
import android.os.Bundle
import android.view.View
import android.webkit.WebView
import androidx.core.os.bundleOf
import butterknife.BindView
import com.biganto.visual.roompark.R
......@@ -10,7 +11,11 @@ import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textview.MaterialTextView
import com.jakewharton.rxbinding3.material.selections
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
......@@ -27,6 +32,13 @@ class EstateScreenController :
, EstateScreen {
override fun planTypesTabSelected(): Observable<Int> =
planTypesTabLayout.selections()
.debounce (200L, TimeUnit.MILLISECONDS)
.map { it.position }
.observeOn(AndroidSchedulers.mainThread())
constructor(args: Bundle):super(args)
constructor(id: Int) : super(bundleOf(SELECTED_ESTATE_ID_KEY to id))
......@@ -41,6 +53,9 @@ class EstateScreenController :
@BindView(R.id.planTypesTabs)
lateinit var planTypesTabLayout: TabLayout
@BindView(R.id.flat_plan_webview)
lateinit var planWebView: WebView
private fun setToolbar(){
toolBar.showAll()
......@@ -69,6 +84,7 @@ class EstateScreenController :
is EstateScreenViewState.Idle -> render(viewState)
is EstateScreenViewState.LoadEstate -> render(viewState)
is EstateScreenViewState.LoadPlanTypes -> render(viewState)
is EstateScreenViewState.LoadPlan -> render(viewState)
is EstateScreenViewState.SomeError -> render(viewState)
}
}
......@@ -88,14 +104,31 @@ class EstateScreenController :
private fun render(viewState: EstateScreenViewState.LoadPlanTypes) {
planTypesTabLayout.removeAllTabs()
var i = 1
viewState.types.forEach {
try {
val tab = planTypesTabLayout.newTab()
.setCustomView(R.layout.select_text_tab).setTag(it.planTypeId)
tab.customView?.findViewById<MaterialTextView>(R.id.textTitle)?.text = "Вариант $i"
.setCustomView(R.layout.select_text_tab).setTag(it.planId)
(tab.customView as MaterialTextView).text = "Вариант $i"
planTypesTabLayout.addTab(tab)
i++
} catch (e: Exception) {
Timber.e(e)
}
}
}
private fun render(viewState: EstateScreenViewState.LoadPlan) {
val mimeTypeSvg = "image/svg+xml"
val encoding = "utf-8"
viewState.planBody.replace("<br>","<br />")
viewState.planBody.replace("<\\br>","<br />")
// Timber.w("counts br : ${})
planWebView.settings.javaScriptEnabled = true
planWebView.loadData(viewState.planBody,mimeTypeSvg,encoding)
}
private fun getComponent() = DaggerEstateScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity
,args.getInt(SELECTED_ESTATE_ID_KEY))
......
......@@ -29,8 +29,17 @@ class EstateScreenPresenter @Inject constructor(
.map { EstateScreenViewState.LoadEstate(it) }
//.map { EstateScreenViewState.FavoriteEstatesLoaded(it) }
val fetchPlans = interactor.getPlanTypes(estateId)
.map { EstateScreenViewState.LoadPlanTypes(it) }
val fetchPlan = intent(EstateScreen::planTypesTabSelected)
.flatMap {planId -> interactor.getPlan(estateId,planId) }
.map { EstateScreenViewState.LoadPlan(it) }
val state = restoreStateObservable
.mergeWith(prefetchCards)
.mergeWith(fetchPlans)
.mergeWith(fetchPlan)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
......@@ -2,7 +2,7 @@ package com.biganto.visual.roompark.presentation.screen.estate
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.PlanTypeModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.util.monades.ExceptionString
/**
......@@ -13,6 +13,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class EstateScreenViewState : BigantoBaseViewState() {
class Idle : EstateScreenViewState()
class LoadEstate(val estate:EstateModel) : EstateScreenViewState()
class LoadPlanTypes(val types:List<PlanTypeModel>) : EstateScreenViewState()
class LoadPlanTypes(val types:List<PlanPresetModel>) : EstateScreenViewState()
class LoadPlan(val planBody:String) : EstateScreenViewState()
class SomeError(val exception: ExceptionString) : EstateScreenViewState()
}
\ No newline at end of file
......@@ -70,8 +70,6 @@ class FeedsScreenController :
.observeOn(AndroidSchedulers.mainThread())
.doOnNext { allFeedArticles.text = "ВСЕ ${allFeedName(it)} →" }
override fun injectDependencies() {
getComponent()
}
......@@ -95,7 +93,6 @@ class FeedsScreenController :
lateinit var allFeedArticles:MaterialButton
override fun requsetsNewArticles() =
feedsRecyclerView.scrollStateChanges()
.filter { it == RecyclerView.SCROLL_STATE_IDLE}
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/colorAccent" />
<item android:state_focused="true" android:color="@color/colorAccent" />
<item android:state_pressed="true" android:color="@color/colorAccent" />
<item android:color="@color/colorPrimary" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/accent_selector_rectangle" />
<item android:state_focused="true" android:drawable="@drawable/accent_selector_rectangle" />
<item android:state_pressed="true" android:drawable="@drawable/accent_selector_rectangle" />
<item android:drawable="@drawable/primary_selector_rectangle"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
\ No newline at end of file
......@@ -13,13 +13,11 @@
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/planTypesTabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:background="#00000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
......@@ -36,7 +34,7 @@
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/variants_choose_recycler_view" />
app:layout_constraintTop_toBottomOf="@+id/planTypesTabs" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/textView19"
......@@ -55,7 +53,7 @@
<WebView
android:id="@+id/flat_plan_webview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
......
......@@ -4,8 +4,11 @@
style="@style/Accent_Minor_TextView.Tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:orientation="vertical"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
android:text="Вариант 1">
</com.google.android.material.textview.MaterialTextView>
\ No newline at end of file
......@@ -349,7 +349,7 @@
<style name="Accent_Minor_TextView.Tab">
<item name="android:textColor">@color/plantype_tab_text_selector</item>
<item name="android:background">@color/plantype_tab_background_selector</item>
<item name="android:background">@drawable/plantype_tab_background_selector</item>
</style>
......
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