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

show and cache plans via api

parent 394e26c4
......@@ -3,6 +3,7 @@
package="com.biganto.visual.roompark">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".base.RoomParkApplication"
android:allowBackup="true"
......
......@@ -5,6 +5,7 @@ import com.biganto.visual.roompark.data.local.UserState
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.EstateEntity
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
import com.biganto.visual.roompark.domain.contract.DealContract
......@@ -26,7 +27,8 @@ import javax.inject.Inject
class EstateRepository @Inject constructor(
private val local: ILocalStore,
private val api: IRoomParkApi,
private val db: IDb
private val db: IDb,
private val file: FileModule
): DealContract {
......@@ -115,6 +117,12 @@ class EstateRepository @Inject constructor(
, walls:Boolean = false
, electric:Boolean = false) =
api.getDirectPlan(estateId, planId,furniture,sizes,walls,electric)
.map{
val sFile = FileModule.getDirectory(file.context
,FileModule.FileDirectory.PlanTypeDir(childName = "planType-$estateId-$planId.html"))
file.saveFileToDisk(sFile,it)
sFile.path
}
.subscribeOn(Schedulers.io())
......@@ -124,4 +132,12 @@ class EstateRepository @Inject constructor(
arrayListOf(getPlanApi(estateId,planId))
)
// fun getPlanRequestString(estateId: Int
// , planId:Int
// , furniture:Boolean
// , sizes:Boolean
// , walls:Boolean
// , electric:Boolean
// ) = api.getDirectPlan(estateId,planId,furniture,sizes,electric).
}
......@@ -112,6 +112,21 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
)
.compose(RetrofitResponseValidation())
// fun getPlanString(
// estateId: Int,
// planType: Int,
// showFurniture: Boolean,
// showSizes: Boolean,
// showWalls: Boolean,
// showElectric: Boolean) = api.getPlan(
// estate_id = estateId,
// planType = planType,
// furniture = showFurniture.asInt,
// sizes = showSizes.asInt,
// walls = showWalls.asInt,
// electric = showElectric.asInt
// ).req
@Deprecated("hidden by states.getEstate method")
override fun getMultiTour(building: Int, flat: Int): Observable<Int> =
......
package com.biganto.visual.roompark.data.repository.file
import android.app.Application
import android.content.Context
import android.os.Environment
import com.google.gson.JsonElement
import dagger.Module
import timber.log.Timber
import java.io.File
import javax.inject.Inject
/**
......@@ -14,7 +16,7 @@ import java.io.File
@Module
class FilesModule(private val context: Context) {
class FileModule @Inject constructor(val context: Application) {
private val rootFolder: File
get() {
......@@ -49,7 +51,10 @@ class FilesModule(private val context: Context) {
}
fun saveFileToDisk(file:File,content: String){
Timber.d("write to : $file")
Timber.d("write to : ${file.name}")
// file.createNewFile()
file.parentFile.mkdirs()
file.writeText(content) //to json array because core unity method parse data like TourData[] Estate[] etc..
}
......@@ -61,18 +66,20 @@ class FilesModule(private val context: Context) {
}
companion object {
fun getDirectory(context: Context?, dirType: FileDirectory): String =
fun getDirectory(context: Context?, dirType: FileDirectory): File =
File(
context?.filesDir?.absolutePath?.plus(dirType.dir)
?: throw IllegalArgumentException("Context cannot be null!")
)
fun assetsDirectory(context: Context?): String = context?.filesDir?.absolutePath
?: throw IllegalArgumentException("Context cannot be null!")
}
sealed class FileDirectory(val dir:String) {
class PlanTypeDir(dir:String = "estates") : FileDirectory(dir)
class ToursDir(dir:String = "tours") : FileDirectory(dir)
class FeedsDir(dir:String = "feeds") : FileDirectory(dir)
class Albums(dir:String = "photos") : FileDirectory(dir)
class PlanTypeDir(dir:String = "/estates",childName:String? = null) : FileDirectory(dir.plus("/$childName"))
class ToursDir(dir:String = "/tours",childName:String? = null) : FileDirectory(dir.plus("/childName"))
class FeedsDir(dir:String = "/feeds",childName:String? = null) : FileDirectory(dir.plus("/childName"))
class Albums(dir:String = "/photos",childName:String? = null) : FileDirectory(dir.plus("/childName"))
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import com.biganto.visual.roompark.data.repository.api.retrofit.di.RetrofitModule
import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.DbModule
import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roompark.domain.contract.DealContract
import com.biganto.visual.roompark.domain.contract.DevProgressContract
......@@ -43,7 +44,8 @@ import javax.inject.Singleton
PicassoModule::class,
ActivityModule::class,
ContractRepositoryModule::class,
AppActivityModule ::class])
AppActivityModule ::class,
FileModule::class])
interface AppComponent : AndroidInjector<RoomParkApplication>{
fun authC(): AuthContract
......@@ -65,6 +67,8 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{
fun providePicassoAsync(): Picasso
fun provideFileSystem(): FileModule
@Component.Factory
interface Factory{
......
package com.biganto.visual.roompark.presentation.screen.estate
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.webkit.WebView
......@@ -15,9 +16,12 @@ import com.jakewharton.rxbinding3.material.selections
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import timber.log.Timber
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.concurrent.TimeUnit
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
......@@ -120,13 +124,40 @@ class EstateScreenController :
}
private fun render(viewState: EstateScreenViewState.LoadPlan) {
val mimeTypeSvg = "image/svg+xml"
// val mimeTypeSvg = "image/svg+xml"
val mimeTypeSvg = "text/html"
val encoding = "utf-8"
viewState.planBody.replace("<br>","<br />")
viewState.planBody.replace("<\\br>","<br />")
// viewState.planBody.replace("<br>","<br />")
// viewState.planBody.replace("<\\br>","<br />")
// Timber.w("counts br : ${})
planWebView.settings.javaScriptEnabled = true
planWebView.loadData(viewState.planBody,mimeTypeSvg,encoding)
planWebView.clearCache(true)
// planWebView.loadUrl("https://room-park.ru/choose/flat/2/1/74/")
val svgStream = resources?.openRawResource(R.raw.flat_plan_test)
val inputStreamReader = InputStreamReader(svgStream!!)
val sb = StringBuilder()
var line: String?
val br = BufferedReader(inputStreamReader)
line = br.readLine()
while (line != null) {
sb.append(line)
line = br.readLine()
}
br.close()
var svgBody : String = sb.toString()
Timber.d("ulr : ${viewState.planBody}")
val uri = "file:///${Uri.parse(viewState.planBody).path}"
Timber.d("uri: ${uri}")
svgBody ="https://room-park.ru/api/estates.getPlan?&client=androidplayer&client_version=3.0&v=2.0&estate_id=4902&plan_id=0&furniture=0&sizes=0&walls=0&electric=0"
svgBody = uri
planWebView.loadUrl(svgBody)
// planWebView.loadUrl("https://room-park.ru/api/estates.getPlan?&client=androidplayer&client_version=3.0&v=2.0&estate_id=4009&plan_id=1&furniture=1&sizes=0&walls=0&electric=1")
// planWebView.loadDataWithBaseURL(
// "",viewState.planBody,mimeTypeSvg,encoding,null
// )
// planWebView.load(svgBody,mimeTypeSvg,encoding)
}
private fun getComponent() = DaggerEstateScreenComponent.factory()
......
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