Commit 413f7f1b authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

refactor and fix abstract generic primary constructor call

parent 64cd117d
...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.data.repository.db.IDb ...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.file.FileModule import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.domain.contract.FilesContract import com.biganto.visual.roompark.domain.contract.FilesContract
import com.biganto.visual.roompark.util.extensions.folderSize import com.biganto.visual.roompark.util.extensions.folderSize
import timber.log.Timber
import java.io.File import java.io.File
import javax.inject.Inject import javax.inject.Inject
import kotlin.reflect.full.primaryConstructor import kotlin.reflect.full.primaryConstructor
...@@ -23,23 +22,11 @@ class FilesContractModule @Inject constructor( ...@@ -23,23 +22,11 @@ class FilesContractModule @Inject constructor(
private val context: Application private val context: Application
): FilesContract { ): FilesContract {
private inline fun <reified T:FileModule.FileDirectory> getDirectory(): T? =
private inline fun <reified T:FileModule.FileDirectory> getDirectory(): T? { T::class.primaryConstructor?.call()
val type = T::class
Timber.d("Type is :$type")
val inst = type.primaryConstructor?.call(null,null)
Timber.d("inst is :$inst")
//val inst2 = type.constructors.first().call()
//Timber.d("inst2 is :$inst2")
return inst
}
private inline fun <reified T:FileModule.FileDirectory> getFile(): File { private inline fun <reified T:FileModule.FileDirectory> getFile(): File {
Timber.d("type: ${T::class}") val d = getDirectory<T>() ?: error("Unresolved class type")
val d = getDirectory<T>()
Timber.d("d: ${d}")
if (d==null) error("Unresolved class type")
return FileModule.getDirectory(context,d) return FileModule.getDirectory(context,d)
} }
......
...@@ -77,21 +77,25 @@ class FileModule @Inject constructor(val context: Application) { ...@@ -77,21 +77,25 @@ class FileModule @Inject constructor(val context: Application) {
} }
sealed class FileDirectory(val dir:String) { sealed class FileDirectory(protected var path:String) {
class PlanTypeDir: FileDirectory{ val dir:String get() = path
constructor (dir:String = "/estates",childName:String? = null) class PlanTypeDir(): FileDirectory(dirName){
:super(dir.plus(childName.slashed())) private companion object {const val dirName = "/estates"}
constructor (catalog:String = "/estates" constructor (childName:String? = null)
: this(){path = dirName.plus(childName.slashed())}
constructor (catalog:String = dirName
,estateId: Int ,estateId: Int
, planId:Int , planId:Int
, furniture:Boolean? = null , furniture:Boolean? = null
, sizes:Boolean? = null , sizes:Boolean? = null
, walls:Boolean? = null , walls:Boolean? = null
, electric:Boolean? = null , electric:Boolean? = null
) : super(catalog.plus("/plan").plus("/$estateId").plus("/$planId") ) : this(){
path = (catalog.plus("/plan").plus("/$estateId").plus("/$planId")
.plus("/plan${planId}" + .plus("/plan${planId}" +
"${sizes?.asInt?.toString()?.map { "_s$it" }?:""}" + "${sizes?.asInt?.toString()?.map { "_s$it" }?:""}" +
"${furniture?.asInt?.toString()?.map { "_f$it" }?:""}" + "${furniture?.asInt?.toString()?.map { "_f$it" }?:""}" +
...@@ -99,13 +103,25 @@ class FileModule @Inject constructor(val context: Application) { ...@@ -99,13 +103,25 @@ class FileModule @Inject constructor(val context: Application) {
"${electric?.asInt?.toString()?.map { "_e$it" }?:""}") "${electric?.asInt?.toString()?.map { "_e$it" }?:""}")
.plus(".html")) .plus(".html"))
} }
}
class ToursDir() : FileDirectory(dirName){
private companion object {const val dirName = "/tours"}
constructor (childName:String? = null)
: this(){path = dirName.plus(childName.slashed())}
}
class ToursDir(dir:String = "/tours",childName:String? = null) class FeedsDir(): FileDirectory(dirName) {
: FileDirectory(dir.plus(childName.slashed())) private companion object {const val dirName = "/feeds"}
class FeedsDir(dir:String = "/feeds",childName:String? = null) constructor (childName:String? = null)
: FileDirectory(dir.plus(childName.slashed())) : this(){path = dirName.plus(childName.slashed())}
class Albums(dir:String = "/photos",childName:String? = null) }
: FileDirectory(dir.plus(childName.slashed()))
class Albums(): FileDirectory(dirName) {
private companion object {const val dirName = "/photos"}
constructor (childName:String? = null)
: this(){path = dirName.plus(childName.slashed())}
}
} }
} }
......
...@@ -21,5 +21,5 @@ data class CachedDataModel( ...@@ -21,5 +21,5 @@ data class CachedDataModel(
data class SettingsModel( data class SettingsModel(
val pushItems:List<PushSwitchModel>, val pushItems:List<PushSwitchModel>,
var offlineStoreData:List<CachedDataModel>, var offlineStoreData:List<CachedDataModel>,
val cachedData:List<CachedDataModel> var cachedData:List<CachedDataModel>
) )
\ No newline at end of file
...@@ -29,9 +29,11 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -29,9 +29,11 @@ class SettingsScreenPresenter @Inject constructor(
val fetchSettings = interactor.fetchSettings() val fetchSettings = interactor.fetchSettings()
.flatMap {settings -> .flatMap {settings ->
interactor.getCacheInfo() interactor.getCacheInfo()
.doOnNext{ settings.offlineStoreData = it } .doOnNext { Timber.d("$it") }
.doOnNext{ settings.cachedData = it }
.map { settings }} .map { settings }}
.map { SettingsScreenViewState.LoadSettingsList(it) } .map { SettingsScreenViewState.LoadSettingsList(it)}
val onSignOut = intent(SettingsScreen::signOut) val onSignOut = intent(SettingsScreen::signOut)
.flatMap { .flatMap {
......
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