From 97f96068634cc12ec80f56268f7ec0c59352c192 Mon Sep 17 00:00:00 2001 From: shabinder Date: Mon, 1 Feb 2021 22:03:30 +0530 Subject: [PATCH] List & Main Stores and Models --- build.gradle.kts | 9 ++ buildSrc/buildSrc/src/main/kotlin/Versions.kt | 2 + common/compose-ui/build.gradle.kts | 16 +++- .../shabinder/common/list/SpotiFlyerList.kt | 43 +++++++++ .../list/integration/SpotiFlyerListImpl.kt | 37 ++++++++ .../common/list/store/SpotiFlyerListStore.kt | 15 +++ .../list/store/SpotiFlyerListStoreProvider.kt | 57 ++++++++++++ .../shabinder/common/main/SpotiFlyerMain.kt | 37 +++++--- .../main/integration/SpotiFlyerMainImpl.kt | 27 ++++-- .../common/main/store/SpotiFlyerMainStore.kt | 11 +-- .../main/store/SpotiFlyerMainStoreProvider.kt | 93 ++++++++++++------- .../com/shabinder/common/utils/Consumer.kt | 16 ++++ .../common/utils/InstanceKeeperExt.kt | 20 ++++ .../shabinder/common/database/ReaktiveExt.kt | 28 ------ .../com/shabinder/common/PlatformImp.kt | 5 +- .../kotlin/com/shabinder/common/Expect.kt | 7 ++ .../common/FetchPlatformQueryResult.kt | 8 ++ 17 files changed, 340 insertions(+), 91 deletions(-) create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/integration/SpotiFlyerListImpl.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStore.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/Consumer.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/InstanceKeeperExt.kt delete mode 100644 common/database/src/commonMain/kotlin/com/shabinder/common/database/ReaktiveExt.kt create mode 100644 common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/FetchPlatformQueryResult.kt diff --git a/build.gradle.kts b/build.gradle.kts index b64b99d9..cd481051 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,3 +22,12 @@ buildscript { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21") } } + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check", + "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", + "-Xuse-experimental=kotlinx.coroutines.TheAnnotationYouWantToDisable" + ) + } +} \ No newline at end of file diff --git a/buildSrc/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/buildSrc/src/main/kotlin/Versions.kt index 7c161a05..7915e2c9 100644 --- a/buildSrc/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/buildSrc/src/main/kotlin/Versions.kt @@ -75,6 +75,8 @@ object MVIKotlin { const val rx = "com.arkivanov.mvikotlin:rx:$VERSION" const val mvikotlin = "com.arkivanov.mvikotlin:mvikotlin:$VERSION" const val mvikotlinMain = "com.arkivanov.mvikotlin:mvikotlin-main:$VERSION" + const val coroutines = "com.arkivanov.mvikotlin:mvikotlin-extensions-coroutines:$VERSION" + const val keepers = "com.arkivanov.mvikotlin:keepers:$VERSION" const val mvikotlinMainIosX64 = "com.arkivanov.mvikotlin:mvikotlin-main-iosx64:$VERSION" const val mvikotlinMainIosArm64 = "com.arkivanov.mvikotlin:mvikotlin-main-iosarm64:$VERSION" const val mvikotlinLogging = "com.arkivanov.mvikotlin:mvikotlin-logging:$VERSION" diff --git a/common/compose-ui/build.gradle.kts b/common/compose-ui/build.gradle.kts index b138ff54..f140db88 100644 --- a/common/compose-ui/build.gradle.kts +++ b/common/compose-ui/build.gradle.kts @@ -10,12 +10,24 @@ kotlin { implementation(project(":common:dependency-injection")) implementation(project(":common:data-models")) implementation(project(":common:database")) + //implementation(MVIKotlin.rx) + implementation(SqlDelight.coroutineExtensions) + implementation(MVIKotlin.coroutines) implementation(MVIKotlin.mvikotlin) - implementation(MVIKotlin.mvikotlinExtensionsReaktive) - implementation(Badoo.Reaktive.reaktive) + //implementation(MVIKotlin.mvikotlinExtensionsReaktive) + //implementation(Badoo.Reaktive.reaktive) implementation(Decompose.decompose) implementation(Decompose.extensionsCompose) } } } } + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xallow-jvm-ir-dependencies", "-Xskip-prerelease-check", + "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", + "-Xuse-experimental=kotlinx.coroutines.TheAnnotationYouWantToDisable" + ) + } +} \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt new file mode 100644 index 00000000..ef4598a8 --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/SpotiFlyerList.kt @@ -0,0 +1,43 @@ +package com.shabinder.common.list + +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.mvikotlin.core.store.StoreFactory +import com.shabinder.common.PlatformQueryResult +import com.shabinder.common.TrackDetails +import com.shabinder.common.list.integration.SpotiFlyerListImpl +import com.shabinder.database.Database +import kotlinx.coroutines.flow.Flow + +interface SpotiFlyerList { + + val models: Flow + + /* + * For Single Track Download -> list(that track) + * For Download All -> Model.tracks + * */ + fun onDownloadClicked(trackList:List) + + /* + * To Pop and return back to Main Screen + * */ + fun onBackPressed() + + interface Dependencies { + val storeFactory: StoreFactory + val database: Database + val link: String + fun listOutput(finished: Output.Finished) + } + sealed class Output { + object Finished : Output() + } + data class State( + val result:PlatformQueryResult? = null, + val link:String = "" + ) +} + +@Suppress("FunctionName") // Factory function +fun SpotiFlyerList(componentContext: ComponentContext, dependencies: SpotiFlyerList.Dependencies): SpotiFlyerList = + SpotiFlyerListImpl(componentContext, dependencies) diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/integration/SpotiFlyerListImpl.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/integration/SpotiFlyerListImpl.kt new file mode 100644 index 00000000..b3cf65d1 --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/integration/SpotiFlyerListImpl.kt @@ -0,0 +1,37 @@ +package com.shabinder.common.list.integration + +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.mvikotlin.extensions.coroutines.states +import com.shabinder.common.TrackDetails +import com.shabinder.common.list.SpotiFlyerList +import com.shabinder.common.list.SpotiFlyerList.Dependencies +import com.shabinder.common.list.SpotiFlyerList.State +import com.shabinder.common.list.store.SpotiFlyerListStore.Intent +import com.shabinder.common.list.store.SpotiFlyerListStoreProvider +import com.shabinder.common.utils.getStore +import kotlinx.coroutines.flow.Flow + +internal class SpotiFlyerListImpl( + componentContext: ComponentContext, + dependencies: Dependencies +): SpotiFlyerList,ComponentContext by componentContext, Dependencies by dependencies { + + private val store = + instanceKeeper.getStore { + SpotiFlyerListStoreProvider( + storeFactory = storeFactory, + database = database, + link = link + ).provide() + } + + override val models: Flow = store.states + + override fun onDownloadClicked(trackList: List) { + store.accept(Intent.StartDownload(trackList)) + } + + override fun onBackPressed(){ + listOutput(SpotiFlyerList.Output.Finished) + } +} \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStore.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStore.kt new file mode 100644 index 00000000..563a983d --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStore.kt @@ -0,0 +1,15 @@ +package com.shabinder.common.list.store + +import com.arkivanov.mvikotlin.core.store.Store +import com.shabinder.common.PlatformQueryResult +import com.shabinder.common.TrackDetails +import com.shabinder.common.list.SpotiFlyerList +import com.shabinder.common.list.SpotiFlyerList.State +import com.shabinder.common.list.store.SpotiFlyerListStore.* + +internal interface SpotiFlyerListStore: Store { + sealed class Intent { + data class StartDownload(val trackList: List): Intent() + data class SearchLink(val link: String): Intent() + } +} diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt new file mode 100644 index 00000000..6bdfb1fd --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/list/store/SpotiFlyerListStoreProvider.kt @@ -0,0 +1,57 @@ +package com.shabinder.common.list.store + +import com.arkivanov.mvikotlin.core.store.* +import com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor +import com.shabinder.common.FetchPlatformQueryResult +import com.shabinder.common.PlatformQueryResult +import com.shabinder.common.list.SpotiFlyerList.State +import com.shabinder.common.list.store.SpotiFlyerListStore.Intent +import com.shabinder.database.Database +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +internal class SpotiFlyerListStoreProvider( + private val storeFactory: StoreFactory, + private val database: Database, + private val link: String +) { + fun provide(): SpotiFlyerListStore = + object : SpotiFlyerListStore, Store by storeFactory.create( + name = "SpotiFlyerListStore", + initialState = State(), + bootstrapper = SimpleBootstrapper(Unit), + executorFactory = ::ExecutorImpl, + reducer = ReducerImpl + ) {} + + private sealed class Result { + data class ResultFetched(val result: PlatformQueryResult) : Result() + data class SearchLink(val link: String) : Result() + } + + private inner class ExecutorImpl : SuspendExecutor() { + override suspend fun executeAction(action: Unit, getState: () -> State) { + FetchPlatformQueryResult().query(link)?.let{ + dispatch(Result.ResultFetched(it)) + } + } + + override suspend fun executeIntent(intent: Intent, getState: () -> State) { + when (intent) {//TODO: Add Dispatchers where needed + is Intent.StartDownload -> {}//TODO() + is Intent.SearchLink -> FetchPlatformQueryResult().query(link)?.let{ + dispatch((Result.ResultFetched(it))) + } + } + } + } + + private object ReducerImpl : Reducer { + override fun State.reduce(result: Result): State = + when (result) { + is Result.ResultFetched -> copy(result = result.result) + is Result.SearchLink -> copy(link = result.link) + } + } +} \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt index 67cd2422..3bc9acb9 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/SpotiFlyerMain.kt @@ -1,30 +1,43 @@ package com.shabinder.common.main -import com.arkivanov.decompose.value.Value +import com.arkivanov.decompose.ComponentContext import com.arkivanov.mvikotlin.core.store.StoreFactory -import com.badoo.reaktive.base.Consumer import com.shabinder.common.DownloadRecord +import com.shabinder.common.main.integration.SpotiFlyerMainImpl +import com.shabinder.common.utils.Consumer import com.shabinder.database.Database +import kotlinx.coroutines.flow.Flow interface SpotiFlyerMain { - val models: Value + val models: Flow - fun onDownloadRecordClicked(link: String) + /* + * We Intend to Move to List Screen + * Note: Implementation in Root + * */ + fun onLinkSearch(link: String) + /* + * Update TextBox's Text + * */ fun onInputLinkChanged(link: String) interface Dependencies { + fun mainOutput(searched: Output): Consumer val storeFactory: StoreFactory val database: Database - val mainOutput: Consumer + } + sealed class Output { + data class Search(val link: String) : Output() } - data class Model( - val record: List, - val link: String + data class State( + val records: List = emptyList(), + val link: String = "" ) - sealed class Output { - data class Searched(val link: String) : Output() - } -} \ No newline at end of file +} + +@Suppress("FunctionName") // Factory function +fun SpotiFlyerMain(componentContext: ComponentContext, dependencies: SpotiFlyerMain.Dependencies): SpotiFlyerMain = + SpotiFlyerMainImpl(componentContext, dependencies) diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt index 7ebccb41..4d73340f 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/integration/SpotiFlyerMainImpl.kt @@ -1,23 +1,34 @@ package com.shabinder.common.main.integration import com.arkivanov.decompose.ComponentContext -import com.arkivanov.decompose.value.Value +import com.arkivanov.mvikotlin.extensions.coroutines.states import com.shabinder.common.main.SpotiFlyerMain -import com.shabinder.common.main.SpotiFlyerMain.Dependencies +import com.shabinder.common.main.SpotiFlyerMain.* +import com.shabinder.common.main.store.SpotiFlyerMainStore.Intent +import com.shabinder.common.main.store.SpotiFlyerMainStoreProvider +import com.shabinder.common.utils.getStore +import kotlinx.coroutines.flow.Flow internal class SpotiFlyerMainImpl( componentContext: ComponentContext, dependencies: Dependencies ): SpotiFlyerMain,ComponentContext by componentContext, Dependencies by dependencies { - override val models: Value - get() = TODO("Not yet implemented") - override fun onDownloadRecordClicked(link: String) { - TODO("Not yet implemented") + private val store = + instanceKeeper.getStore { + SpotiFlyerMainStoreProvider( + storeFactory = storeFactory, + database = database + ).provide() + } + + override val models: Flow = store.states + + override fun onLinkSearch(link: String) { + mainOutput(Output.Search(link = link)) } override fun onInputLinkChanged(link: String) { - TODO("Not yet implemented") + store.accept(Intent.SetLink(link)) } - } \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStore.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStore.kt index ee01d295..234083fb 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStore.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStore.kt @@ -2,17 +2,14 @@ package com.shabinder.common.main.store import com.arkivanov.mvikotlin.core.store.Store import com.shabinder.common.DownloadRecord +import com.shabinder.common.main.SpotiFlyerMain import com.shabinder.common.main.store.SpotiFlyerMainStore.* -internal interface SpotiFlyerMainStore: Store { +internal interface SpotiFlyerMainStore: Store { sealed class Intent { data class OpenPlatform(val platformID:String,val platformLink:String):Intent() + data class SetLink(val link:String):Intent() object GiveDonation : Intent() object ShareApp: Intent() } - - data class State( - val records: List = emptyList(), - val link: String = "" - ) -} \ No newline at end of file +} diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt index 76b3a957..37477c16 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/main/store/SpotiFlyerMainStoreProvider.kt @@ -1,52 +1,79 @@ package com.shabinder.common.main.store +import com.arkivanov.mvikotlin.core.store.Reducer +import com.arkivanov.mvikotlin.core.store.SimpleBootstrapper +import com.arkivanov.mvikotlin.core.store.Store import com.arkivanov.mvikotlin.core.store.StoreFactory -import com.arkivanov.mvikotlin.extensions.reaktive.ReaktiveExecutor -import com.badoo.reaktive.observable.Observable -import com.badoo.reaktive.observable.map -import com.badoo.reaktive.observable.mapIterable -import com.badoo.reaktive.observable.observeOn -import com.badoo.reaktive.scheduler.mainScheduler +import com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor import com.shabinder.common.DownloadRecord -import com.shabinder.common.database.asObservable +import com.shabinder.common.giveDonation +import com.shabinder.common.main.SpotiFlyerMain.State import com.shabinder.common.main.store.SpotiFlyerMainStore.Intent -import com.shabinder.common.main.store.SpotiFlyerMainStore.State +import com.shabinder.common.openPlatform +import com.shabinder.common.shareApp import com.shabinder.database.Database -import com.squareup.sqldelight.Query +import com.squareup.sqldelight.runtime.coroutines.asFlow +import com.squareup.sqldelight.runtime.coroutines.mapToList +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.map internal class SpotiFlyerMainStoreProvider( private val storeFactory: StoreFactory, - private val database: Database + database: Database ) { + + fun provide(): SpotiFlyerMainStore = + object : SpotiFlyerMainStore, Store by storeFactory.create( + name = "SpotiFlyerHomeStore", + initialState = State(), + bootstrapper = SimpleBootstrapper(Unit), + executorFactory = ::ExecutorImpl, + reducer = ReducerImpl + ) {} + + val updates: Flow> = + database.downloadRecordDatabaseQueries + .selectAll() + .asFlow() + .mapToList(Dispatchers.Default) + .map { + it.map { record -> + record.run{ + DownloadRecord(id, type, name, link, coverUrl, totalFiles) + } + } + } + + private sealed class Result { data class ItemsLoaded(val items: List) : Result() - data class TextChanged(val text: String) : Result() + data class LinkChanged(val link: String) : Result() } - private inner class ExecutorImpl : ReaktiveExecutor() { - override fun executeAction(action: Unit, getState: () -> State) { - val updates: Observable> = - database.downloadRecordDatabaseQueries - .selectAll() - .asObservable(Query::executeAsList) - .mapIterable { it.run { - DownloadRecord( - id, type, name, link, coverUrl, totalFiles - ) - } } - - - updates - .observeOn(mainScheduler) - .map(Result::ItemsLoaded) - .subscribeScoped(onNext = ::dispatch) + private inner class ExecutorImpl : SuspendExecutor() { + override suspend fun executeAction(action: Unit, getState: () -> State) { + updates.collect { + dispatch(Result.ItemsLoaded(it)) + } } - override fun executeIntent(intent: Intent, getState: () -> State) { - when (intent) {//TODO - is Intent.OpenPlatform -> {} - is Intent.GiveDonation -> {} - is Intent.ShareApp -> {} + + override suspend fun executeIntent(intent: Intent, getState: () -> State) { + when (intent) {//TODO: Add Dispatchers where needed + is Intent.OpenPlatform -> openPlatform(intent.platformID, intent.platformLink) + is Intent.GiveDonation -> giveDonation() + is Intent.ShareApp -> shareApp() + is Intent.SetLink -> dispatch(Result.LinkChanged(link = intent.link)) } } } + + private object ReducerImpl : Reducer { + override fun State.reduce(result: Result): State = + when (result) { + is Result.ItemsLoaded -> copy(records = result.items) + is Result.LinkChanged -> copy(link = result.link) + } + } } \ No newline at end of file diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/Consumer.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/Consumer.kt new file mode 100644 index 00000000..11ae96eb --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/Consumer.kt @@ -0,0 +1,16 @@ +package com.shabinder.common.utils + +/* +* Callback Utility +* */ +interface Consumer { + fun onCall(value: T) +} + +@Suppress("FunctionName") // Factory function +inline fun Consumer(crossinline block: (T) -> Unit): Consumer = + object : Consumer { + override fun onCall(value: T) { + block(value) + } + } diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/InstanceKeeperExt.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/InstanceKeeperExt.kt new file mode 100644 index 00000000..5a0488e7 --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/utils/InstanceKeeperExt.kt @@ -0,0 +1,20 @@ +package com.shabinder.common.utils + +import com.arkivanov.decompose.instancekeeper.InstanceKeeper +import com.arkivanov.decompose.instancekeeper.getOrCreate +import com.arkivanov.mvikotlin.core.store.Store + +fun > InstanceKeeper.getStore(key: Any, factory: () -> T): T = + getOrCreate(key) { StoreHolder(factory()) } + .store + +inline fun > InstanceKeeper.getStore(noinline factory: () -> T): T = + getStore(T::class, factory) + +private class StoreHolder>( + val store: T +) : InstanceKeeper.Instance { + override fun onDestroy() { + store.dispose() + } +} diff --git a/common/database/src/commonMain/kotlin/com/shabinder/common/database/ReaktiveExt.kt b/common/database/src/commonMain/kotlin/com/shabinder/common/database/ReaktiveExt.kt deleted file mode 100644 index 8a8b84ce..00000000 --- a/common/database/src/commonMain/kotlin/com/shabinder/common/database/ReaktiveExt.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.shabinder.common.database - -import com.badoo.reaktive.base.setCancellable -import com.badoo.reaktive.observable.Observable -import com.badoo.reaktive.observable.map -import com.badoo.reaktive.observable.observable -import com.badoo.reaktive.observable.observeOn -import com.badoo.reaktive.scheduler.ioScheduler -import com.squareup.sqldelight.Query - -fun Query.asObservable(execute: (Query) -> R): Observable = - asObservable() - .observeOn(ioScheduler) - .map(execute) - -fun Query.asObservable(): Observable> = - observable { emitter -> - val listener = - object : Query.Listener { - override fun queryResultsChanged() { - emitter.onNext(this@asObservable) - } - } - - emitter.onNext(this@asObservable) - addListener(listener) - emitter.setCancellable { removeListener(listener) } - } diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/PlatformImp.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/PlatformImp.kt index 601ad2e0..1eff0620 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/PlatformImp.kt +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/PlatformImp.kt @@ -2,10 +2,11 @@ package com.shabinder.common import android.content.Context import android.os.Environment +import co.touchlab.kermit.Kermit import com.shabinder.common.database.appContext import java.io.File -actual open class Dir { +actual open class Dir actual constructor(logger: Kermit) { private val context:Context get() = appContext @@ -21,4 +22,6 @@ actual open class Dir { "SpotiFlyer"+ File.separator actual fun isPresent(path: String): Boolean = File(path).exists() + actual fun createDirectory(dirPath: String) { + } } \ No newline at end of file diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Expect.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Expect.kt index 4847ac08..b92f4fe8 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Expect.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/Expect.kt @@ -3,6 +3,13 @@ package com.shabinder.common import co.touchlab.kermit.Kermit import com.shabinder.common.utils.removeIllegalChars +expect fun openPlatform(platformID:String ,platformLink:String) + +expect fun shareApp() + +expect fun giveDonation() + + expect open class Dir( logger: Kermit ) { diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/FetchPlatformQueryResult.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/FetchPlatformQueryResult.kt new file mode 100644 index 00000000..cf711413 --- /dev/null +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/FetchPlatformQueryResult.kt @@ -0,0 +1,8 @@ +package com.shabinder.common + +//TODO +class FetchPlatformQueryResult { + suspend fun query(link:String): PlatformQueryResult?{ + return null + } +} \ No newline at end of file