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
import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.domain.contract.FilesContract
import com.biganto.visual.roompark.util.extensions.folderSize
import timber.log.Timber
import java.io.File
import javax.inject.Inject
import kotlin.reflect.full.primaryConstructor
......@@ -23,23 +22,11 @@ class FilesContractModule @Inject constructor(
private val context: Application
): FilesContract {
private inline fun <reified T:FileModule.FileDirectory> getDirectory(): T? {
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> getDirectory(): T? =
T::class.primaryConstructor?.call()
private inline fun <reified T:FileModule.FileDirectory> getFile(): File {
Timber.d("type: ${T::class}")
val d = getDirectory<T>()
Timber.d("d: ${d}")
if (d==null) error("Unresolved class type")
val d = getDirectory<T>() ?: error("Unresolved class type")
return FileModule.getDirectory(context,d)
}
......
......@@ -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)
:super(dir.plus(childName.slashed()))
class PlanTypeDir(): FileDirectory(dirName){
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
, planId:Int
, furniture:Boolean? = null
, sizes:Boolean? = null
, walls: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}" +
"${sizes?.asInt?.toString()?.map { "_s$it" }?:""}" +
"${furniture?.asInt?.toString()?.map { "_f$it" }?:""}" +
......@@ -99,13 +103,25 @@ class FileModule @Inject constructor(val context: Application) {
"${electric?.asInt?.toString()?.map { "_e$it" }?:""}")
.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)
: FileDirectory(dir.plus(childName.slashed()))
class FeedsDir(dir:String = "/feeds",childName:String? = null)
: FileDirectory(dir.plus(childName.slashed()))
class Albums(dir:String = "/photos",childName:String? = null)
: FileDirectory(dir.plus(childName.slashed()))
class FeedsDir(): FileDirectory(dirName) {
private companion object {const val dirName = "/feeds"}
constructor (childName:String? = null)
: this(){path = dirName.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(
data class SettingsModel(
val pushItems:List<PushSwitchModel>,
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(
val fetchSettings = interactor.fetchSettings()
.flatMap {settings ->
interactor.getCacheInfo()
.doOnNext{ settings.offlineStoreData = it }
.doOnNext { Timber.d("$it") }
.doOnNext{ settings.cachedData = it }
.map { settings }}
.map { SettingsScreenViewState.LoadSettingsList(it) }
.map { SettingsScreenViewState.LoadSettingsList(it)}
val onSignOut = intent(SettingsScreen::signOut)
.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