From 02e6ef3a47894bd5248f012cb879dd2097f79919 Mon Sep 17 00:00:00 2001 From: shabinder Date: Wed, 10 Feb 2021 22:55:36 +0530 Subject: [PATCH] Android Intents & Callbacks --- .../com/shabinder/android/MainActivity.kt | 73 ++++++++++++++++-- .../shabinder/android/utils/UtilFunctions.kt | 49 ++++++++++++ common/compose-ui/build.gradle.kts | 11 --- .../main/store/SpotiFlyerMainStoreProvider.kt | 2 +- .../shabinder/common/root/SpotiFlyerRoot.kt | 4 + .../shabinder/common/root/SpotiFlyerRootUi.kt | 4 +- .../root/callbacks/SpotiFlyerRootCallBacks.kt | 5 ++ .../root/integration/SpotiFlyerRootImpl.kt | 7 +- .../src/main/res/drawable/ic_arrow.xml | 0 .../main/res/drawable/ic_download_arrow.xml | 0 .../src/main/res/drawable/ic_error.xml | 0 .../src/main/res/drawable/ic_gaana.xml | 0 .../src/main/res/drawable/ic_github.xml | 0 .../src/main/res/drawable/ic_heart.xml | 0 .../main/res/drawable/ic_spotiflyer_logo.xml | 0 .../src/main/res/drawable/ic_spotify_logo.xml | 0 .../src/main/res/drawable/ic_tick.xml | 0 .../src/main/res/drawable/ic_youtube.xml | 0 .../res/drawable/ic_youtube_music_logo.xml | 0 .../src/main/res/drawable/music.xml | 0 .../src/main/res/font/montserrat_light.ttf | Bin .../src/main/res/font/montserrat_medium.ttf | Bin .../src/main/res/font/montserrat_regular.ttf | Bin .../src/main/res/font/montserrat_semibold.ttf | Bin .../src/main/res/font/pristine_script.ttf | Bin .../com/shabinder/common/database/TokenDB.sq | 2 +- .../com/shabinder/common/di/AndroidActual.kt | 34 ++++++++ .../kotlin/com/shabinder/common/di/Expect.kt | 2 +- .../kotlin/com/shabinder/common/di/Actual.kt | 19 ----- .../com/shabinder/common/di/DesktopActual.kt} | 2 +- desktop/build.gradle.kts | 4 + desktop/src/jvmMain/kotlin/Main.kt | 50 ++++++++++++ desktop/src/jvmMain/kotlin/main.kt | 12 --- 33 files changed, 225 insertions(+), 55 deletions(-) create mode 100644 android/src/main/java/com/shabinder/android/utils/UtilFunctions.kt create mode 100644 common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/callbacks/SpotiFlyerRootCallBacks.kt rename common/{data-models => compose-ui}/src/main/res/drawable/ic_arrow.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_download_arrow.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_error.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_gaana.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_github.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_heart.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_spotiflyer_logo.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_spotify_logo.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_tick.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_youtube.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/ic_youtube_music_logo.xml (100%) rename common/{data-models => compose-ui}/src/main/res/drawable/music.xml (100%) rename common/{data-models => compose-ui}/src/main/res/font/montserrat_light.ttf (100%) rename common/{data-models => compose-ui}/src/main/res/font/montserrat_medium.ttf (100%) rename common/{data-models => compose-ui}/src/main/res/font/montserrat_regular.ttf (100%) rename common/{data-models => compose-ui}/src/main/res/font/montserrat_semibold.ttf (100%) rename common/{data-models => compose-ui}/src/main/res/font/pristine_script.ttf (100%) create mode 100644 common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidActual.kt delete mode 100644 common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/Actual.kt rename common/dependency-injection/src/{androidMain/kotlin/com/shabinder/common/di/Actual.kt => desktopMain/kotlin/com/shabinder/common/di/DesktopActual.kt} (78%) create mode 100644 desktop/src/jvmMain/kotlin/Main.kt delete mode 100644 desktop/src/jvmMain/kotlin/main.kt diff --git a/android/src/main/java/com/shabinder/android/MainActivity.kt b/android/src/main/java/com/shabinder/android/MainActivity.kt index b44d46f8..feddfa53 100644 --- a/android/src/main/java/com/shabinder/android/MainActivity.kt +++ b/android/src/main/java/com/shabinder/android/MainActivity.kt @@ -1,37 +1,58 @@ package com.shabinder.android +import android.annotation.SuppressLint +import android.content.Context +import android.content.Intent +import android.os.Build import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity +import android.os.PowerManager +import androidx.activity.ComponentActivity import com.arkivanov.decompose.ComponentContext import androidx.compose.ui.platform.setContent import com.arkivanov.decompose.extensions.compose.jetbrains.rootComponent import com.arkivanov.mvikotlin.logging.store.LoggingStoreFactory import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory +import com.shabinder.android.utils.checkIfLatestVersion +import com.shabinder.android.utils.disableDozeMode +import com.shabinder.android.utils.requestStoragePermission import com.shabinder.common.di.Dir import com.shabinder.common.di.FetchPlatformQueryResult import com.shabinder.common.di.createDirectories import com.shabinder.common.root.SpotiFlyerRoot import com.shabinder.common.root.SpotiFlyerRootContent +import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.common.ui.SpotiFlyerTheme import com.shabinder.database.Database +import kotlinx.coroutines.* import org.koin.android.ext.android.inject -class MainActivity : AppCompatActivity() { +const val disableDozeCode = 1223 - val database: Database by inject() - val fetcher: FetchPlatformQueryResult by inject() - val dir: Dir by inject() +class MainActivity : ComponentActivity() { + + private val database: Database by inject() + private val fetcher: FetchPlatformQueryResult by inject() + private val dir: Dir by inject() + private lateinit var root: SpotiFlyerRoot + private val callBacks: SpotiFlyerRootCallBacks + get() = root.callBacks override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { SpotiFlyerTheme { - SpotiFlyerRootContent(rootComponent(::spotiFlyerRoot)) + root = SpotiFlyerRootContent(rootComponent(::spotiFlyerRoot)) } } - dir.createDirectories() + initialise() } + private fun initialise() { + checkIfLatestVersion() + requestStoragePermission() + disableDozeMode(disableDozeCode) + dir.createDirectories() + } private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = SpotiFlyerRoot( @@ -43,4 +64,42 @@ class MainActivity : AppCompatActivity() { override val directories: Dir = this@MainActivity.dir } ) + + + @SuppressLint("ObsoleteSdkInt") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == disableDozeCode) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val pm = + getSystemService(Context.POWER_SERVICE) as PowerManager + val isIgnoringBatteryOptimizations = + pm.isIgnoringBatteryOptimizations(packageName) + if (isIgnoringBatteryOptimizations) { + // Ignoring battery optimization + } else { + disableDozeMode(disableDozeCode)//Again Ask For Permission!! + } + } + } + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + handleIntentFromExternalActivity(intent) + } + + private fun handleIntentFromExternalActivity(intent: Intent? = getIntent()) { + if (intent?.action == Intent.ACTION_SEND) { + if ("text/plain" == intent.type) { + intent.getStringExtra(Intent.EXTRA_TEXT)?.let { + val filterLinkRegex = """http.+\w""".toRegex() + val string = it.replace("\n".toRegex(), " ") + val link = filterLinkRegex.find(string)?.value.toString() + callBacks.searchLink(link) + } + } + } + } + } diff --git a/android/src/main/java/com/shabinder/android/utils/UtilFunctions.kt b/android/src/main/java/com/shabinder/android/utils/UtilFunctions.kt new file mode 100644 index 00000000..d71c9fe1 --- /dev/null +++ b/android/src/main/java/com/shabinder/android/utils/UtilFunctions.kt @@ -0,0 +1,49 @@ +package com.shabinder.android.utils + +import android.Manifest +import android.annotation.SuppressLint +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import android.os.PowerManager +import android.provider.Settings +import com.github.javiersantos.appupdater.AppUpdater +import com.github.javiersantos.appupdater.enums.Display +import com.github.javiersantos.appupdater.enums.UpdateFrom + +fun Activity.checkIfLatestVersion() { + AppUpdater(this,0).run { + setDisplay(Display.NOTIFICATION) + showAppUpdated(false)//true:Show App is Updated Dialog + setUpdateFrom(UpdateFrom.XML) + setUpdateXML("https://raw.githubusercontent.com/Shabinder/SpotiFlyer/Compose/app/src/main/res/xml/app_update.xml") + setCancelable(false) + start() + } +} +@SuppressLint("BatteryLife", "ObsoleteSdkInt") +fun Activity.disableDozeMode(requestCode:Int) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val pm = + this.getSystemService(Context.POWER_SERVICE) as PowerManager + val isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(packageName) + if (!isIgnoringBatteryOptimizations) { + val intent = Intent().apply{ + action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS + data = Uri.parse("package:$packageName") + } + startActivityForResult(intent, requestCode) + } + } +} +@SuppressLint("ObsoleteSdkInt") +fun Activity.requestStoragePermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + this.requestPermissions( + arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), + 786 + ) + } +} \ No newline at end of file diff --git a/common/compose-ui/build.gradle.kts b/common/compose-ui/build.gradle.kts index 6b731cd2..4e543cbf 100644 --- a/common/compose-ui/build.gradle.kts +++ b/common/compose-ui/build.gradle.kts @@ -31,14 +31,3 @@ kotlin { } } } -/* -tasks.withType { - kotlinOptions { - //useIR = true - freeCompilerArgs = listOf("-Xallow-jvm-ir-dependencies", - "-Xallow-unstable-dependencies","-Xskip-prerelease-check", - "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi", - "-Xuse-experimental=kotlinx.coroutines.TheAnnotationYouWantToDisable" - ) - } -}*/ 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 449a870e..60d40ecb 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 @@ -62,7 +62,7 @@ internal class SpotiFlyerMainStoreProvider( } override suspend fun executeIntent(intent: Intent, getState: () -> State) { - when (intent) {//TODO: Add Dispatchers where needed + when (intent) { is Intent.OpenPlatform -> openPlatform(intent.platformID, intent.platformLink) is Intent.GiveDonation -> giveDonation() is Intent.ShareApp -> shareApp() diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt index eb7ff17e..b1bbe96f 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRoot.kt @@ -9,13 +9,17 @@ import com.shabinder.common.di.FetchPlatformQueryResult import com.shabinder.common.list.SpotiFlyerList import com.shabinder.common.main.SpotiFlyerMain import com.shabinder.common.root.SpotiFlyerRoot.Dependencies +import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.database.Database import com.shabinder.common.root.integration.SpotiFlyerRootImpl +import com.shabinder.common.utils.Consumer interface SpotiFlyerRoot { val routerState: Value> + val callBacks: SpotiFlyerRootCallBacks + sealed class Child { data class Main(val component: SpotiFlyerMain) : Child() data class List(val component: SpotiFlyerList) : Child() diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRootUi.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRootUi.kt index fd0e2dc6..074419b4 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRootUi.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/SpotiFlyerRootUi.kt @@ -18,7 +18,8 @@ import com.shabinder.common.ui.SpotiFlyerLogo import com.shabinder.common.ui.appNameStyle @Composable -fun SpotiFlyerRootContent(component: SpotiFlyerRoot) { +fun SpotiFlyerRootContent(component: SpotiFlyerRoot):SpotiFlyerRoot { + val appBarColor = MaterialTheme.colors.surface Column( modifier = Modifier.fillMaxSize() @@ -43,6 +44,7 @@ fun SpotiFlyerRootContent(component: SpotiFlyerRoot) { } } } + return component } @Composable diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/callbacks/SpotiFlyerRootCallBacks.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/callbacks/SpotiFlyerRootCallBacks.kt new file mode 100644 index 00000000..db0250b3 --- /dev/null +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/callbacks/SpotiFlyerRootCallBacks.kt @@ -0,0 +1,5 @@ +package com.shabinder.common.root.callbacks + +interface SpotiFlyerRootCallBacks { + fun searchLink(link:String) +} diff --git a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt index aaa39081..4fd45c7e 100644 --- a/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt +++ b/common/compose-ui/src/commonMain/kotlin/com/shabinder/common/root/integration/SpotiFlyerRootImpl.kt @@ -14,11 +14,12 @@ import com.shabinder.common.main.SpotiFlyerMain import com.shabinder.common.root.SpotiFlyerRoot import com.shabinder.common.root.SpotiFlyerRoot.Child import com.shabinder.common.root.SpotiFlyerRoot.Dependencies +import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.common.utils.Consumer internal class SpotiFlyerRootImpl( componentContext: ComponentContext, - dependencies: Dependencies + dependencies: Dependencies, ) : SpotiFlyerRoot, ComponentContext by componentContext, Dependencies by dependencies { private val router = @@ -30,6 +31,10 @@ internal class SpotiFlyerRootImpl( override val routerState: Value> = router.state + override val callBacks = object : SpotiFlyerRootCallBacks{ + override fun searchLink(link: String) = onMainOutput(SpotiFlyerMain.Output.Search(link)) + } + private fun createChild(configuration: Configuration, componentContext: ComponentContext): Child = when (configuration) { is Configuration.Main -> Child.Main(spotiFlyerMain(componentContext)) diff --git a/common/data-models/src/main/res/drawable/ic_arrow.xml b/common/compose-ui/src/main/res/drawable/ic_arrow.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_arrow.xml rename to common/compose-ui/src/main/res/drawable/ic_arrow.xml diff --git a/common/data-models/src/main/res/drawable/ic_download_arrow.xml b/common/compose-ui/src/main/res/drawable/ic_download_arrow.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_download_arrow.xml rename to common/compose-ui/src/main/res/drawable/ic_download_arrow.xml diff --git a/common/data-models/src/main/res/drawable/ic_error.xml b/common/compose-ui/src/main/res/drawable/ic_error.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_error.xml rename to common/compose-ui/src/main/res/drawable/ic_error.xml diff --git a/common/data-models/src/main/res/drawable/ic_gaana.xml b/common/compose-ui/src/main/res/drawable/ic_gaana.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_gaana.xml rename to common/compose-ui/src/main/res/drawable/ic_gaana.xml diff --git a/common/data-models/src/main/res/drawable/ic_github.xml b/common/compose-ui/src/main/res/drawable/ic_github.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_github.xml rename to common/compose-ui/src/main/res/drawable/ic_github.xml diff --git a/common/data-models/src/main/res/drawable/ic_heart.xml b/common/compose-ui/src/main/res/drawable/ic_heart.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_heart.xml rename to common/compose-ui/src/main/res/drawable/ic_heart.xml diff --git a/common/data-models/src/main/res/drawable/ic_spotiflyer_logo.xml b/common/compose-ui/src/main/res/drawable/ic_spotiflyer_logo.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_spotiflyer_logo.xml rename to common/compose-ui/src/main/res/drawable/ic_spotiflyer_logo.xml diff --git a/common/data-models/src/main/res/drawable/ic_spotify_logo.xml b/common/compose-ui/src/main/res/drawable/ic_spotify_logo.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_spotify_logo.xml rename to common/compose-ui/src/main/res/drawable/ic_spotify_logo.xml diff --git a/common/data-models/src/main/res/drawable/ic_tick.xml b/common/compose-ui/src/main/res/drawable/ic_tick.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_tick.xml rename to common/compose-ui/src/main/res/drawable/ic_tick.xml diff --git a/common/data-models/src/main/res/drawable/ic_youtube.xml b/common/compose-ui/src/main/res/drawable/ic_youtube.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_youtube.xml rename to common/compose-ui/src/main/res/drawable/ic_youtube.xml diff --git a/common/data-models/src/main/res/drawable/ic_youtube_music_logo.xml b/common/compose-ui/src/main/res/drawable/ic_youtube_music_logo.xml similarity index 100% rename from common/data-models/src/main/res/drawable/ic_youtube_music_logo.xml rename to common/compose-ui/src/main/res/drawable/ic_youtube_music_logo.xml diff --git a/common/data-models/src/main/res/drawable/music.xml b/common/compose-ui/src/main/res/drawable/music.xml similarity index 100% rename from common/data-models/src/main/res/drawable/music.xml rename to common/compose-ui/src/main/res/drawable/music.xml diff --git a/common/data-models/src/main/res/font/montserrat_light.ttf b/common/compose-ui/src/main/res/font/montserrat_light.ttf similarity index 100% rename from common/data-models/src/main/res/font/montserrat_light.ttf rename to common/compose-ui/src/main/res/font/montserrat_light.ttf diff --git a/common/data-models/src/main/res/font/montserrat_medium.ttf b/common/compose-ui/src/main/res/font/montserrat_medium.ttf similarity index 100% rename from common/data-models/src/main/res/font/montserrat_medium.ttf rename to common/compose-ui/src/main/res/font/montserrat_medium.ttf diff --git a/common/data-models/src/main/res/font/montserrat_regular.ttf b/common/compose-ui/src/main/res/font/montserrat_regular.ttf similarity index 100% rename from common/data-models/src/main/res/font/montserrat_regular.ttf rename to common/compose-ui/src/main/res/font/montserrat_regular.ttf diff --git a/common/data-models/src/main/res/font/montserrat_semibold.ttf b/common/compose-ui/src/main/res/font/montserrat_semibold.ttf similarity index 100% rename from common/data-models/src/main/res/font/montserrat_semibold.ttf rename to common/compose-ui/src/main/res/font/montserrat_semibold.ttf diff --git a/common/data-models/src/main/res/font/pristine_script.ttf b/common/compose-ui/src/main/res/font/pristine_script.ttf similarity index 100% rename from common/data-models/src/main/res/font/pristine_script.ttf rename to common/compose-ui/src/main/res/font/pristine_script.ttf diff --git a/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq b/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq index 7af88657..04cb78c2 100644 --- a/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq +++ b/common/database/src/commonMain/sqldelight/com/shabinder/common/database/TokenDB.sq @@ -1,4 +1,4 @@ -CREATE TABLE Token ( +CREATE TABLE IF NOT EXISTS Token ( tokenIndex INTEGER NOT NULL DEFAULT 0 PRIMARY KEY ON CONFLICT REPLACE, accessToken TEXT NOT NULL, expiry INTEGER NOT NULL diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidActual.kt b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidActual.kt new file mode 100644 index 00000000..8ef07e77 --- /dev/null +++ b/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/AndroidActual.kt @@ -0,0 +1,34 @@ +package com.shabinder.common.di + +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import com.shabinder.common.database.appContext +import com.shabinder.common.models.TrackDetails + +actual fun openPlatform(packageID:String, platformLink:String){ + val manager: PackageManager = appContext.packageManager + try { + val intent = manager.getLaunchIntentForPackage(packageID) + ?: throw PackageManager.NameNotFoundException() + intent.addCategory(Intent.CATEGORY_LAUNCHER) + appContext.startActivity(intent) + } catch (e: PackageManager.NameNotFoundException) { + val uri: Uri = + Uri.parse(platformLink) + val intent = Intent(Intent.ACTION_VIEW, uri) + appContext.startActivity(intent) + } +} + +actual fun shareApp(){ + //TODO +} + +actual fun giveDonation(){ + //TODO +} + +actual fun downloadTracks(list: List){ + //TODO +} \ No newline at end of file diff --git a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt index 9ee3d8fc..b738fb65 100644 --- a/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt +++ b/common/dependency-injection/src/commonMain/kotlin/com/shabinder/common/di/Expect.kt @@ -2,7 +2,7 @@ package com.shabinder.common.di import com.shabinder.common.models.TrackDetails -expect fun openPlatform(platformID:String ,platformLink:String) +expect fun openPlatform(packageID:String, platformLink:String) expect fun shareApp() diff --git a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/Actual.kt b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/Actual.kt deleted file mode 100644 index 9bcaff1b..00000000 --- a/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/Actual.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.shabinder.common.di - -import com.shabinder.common.models.TrackDetails - -actual fun openPlatform(platformID:String ,platformLink:String){ - //TODO -} - -actual fun shareApp(){ - //TODO -} - -actual fun giveDonation(){ - //TODO -} - -actual fun downloadTracks(list: List){ - //TODO -} \ No newline at end of file diff --git a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/Actual.kt b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopActual.kt similarity index 78% rename from common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/Actual.kt rename to common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopActual.kt index 9bcaff1b..8b6efa5e 100644 --- a/common/dependency-injection/src/androidMain/kotlin/com/shabinder/common/di/Actual.kt +++ b/common/dependency-injection/src/desktopMain/kotlin/com/shabinder/common/di/DesktopActual.kt @@ -2,7 +2,7 @@ package com.shabinder.common.di import com.shabinder.common.models.TrackDetails -actual fun openPlatform(platformID:String ,platformLink:String){ +actual fun openPlatform(packageID:String, platformLink:String){ //TODO } diff --git a/desktop/build.gradle.kts b/desktop/build.gradle.kts index a652a55f..a3175128 100644 --- a/desktop/build.gradle.kts +++ b/desktop/build.gradle.kts @@ -22,6 +22,10 @@ kotlin { implementation(project(":common:database")) implementation(project(":common:dependency-injection")) implementation(project(":common:compose-ui")) + implementation(Decompose.decompose) + implementation(Decompose.extensionsCompose) + implementation(MVIKotlin.mvikotlin) + implementation(MVIKotlin.mvikotlinMain) } } val jvmTest by getting diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt new file mode 100644 index 00000000..6eb5d30c --- /dev/null +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -0,0 +1,50 @@ +import androidx.compose.desktop.DesktopMaterialTheme +import androidx.compose.desktop.Window +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Surface +import androidx.compose.ui.Modifier +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.decompose.extensions.compose.jetbrains.rootComponent +import com.arkivanov.mvikotlin.core.lifecycle.LifecycleRegistry +import com.arkivanov.mvikotlin.core.lifecycle.resume +import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory +import com.shabinder.common.di.Dir +import com.shabinder.common.di.FetchPlatformQueryResult +import com.shabinder.common.di.initKoin +import com.shabinder.common.root.SpotiFlyerRoot +import com.shabinder.common.root.SpotiFlyerRootContent +import com.shabinder.common.ui.SpotiFlyerColors +import com.shabinder.common.ui.SpotiFlyerShapes +import com.shabinder.common.ui.SpotiFlyerTypography +import com.shabinder.database.Database + +private val koin = initKoin(enableNetworkLogs = true).koin + +fun main(){ + + val lifecycle = LifecycleRegistry() + lifecycle.resume() + + Window("SpotiFlyer") { + Surface(modifier = Modifier.fillMaxSize()) { + DesktopMaterialTheme( +// colors = SpotiFlyerColors, +// typography = SpotiFlyerTypography, +// shapes = SpotiFlyerShapes + ) { + SpotiFlyerRootContent(rootComponent(factory = ::spotiFlyerRoot)) + } + } + } +} + +private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot = + SpotiFlyerRoot( + componentContext = componentContext, + dependencies = object : SpotiFlyerRoot.Dependencies { + override val storeFactory = DefaultStoreFactory + override val database: Database = koin.get() + override val fetchPlatformQueryResult: FetchPlatformQueryResult = koin.get() + override val directories: Dir = koin.get() + } + ) \ No newline at end of file diff --git a/desktop/src/jvmMain/kotlin/main.kt b/desktop/src/jvmMain/kotlin/main.kt deleted file mode 100644 index 50ecf53c..00000000 --- a/desktop/src/jvmMain/kotlin/main.kt +++ /dev/null @@ -1,12 +0,0 @@ -import androidx.compose.desktop.Window -import androidx.compose.foundation.layout.Column -import androidx.compose.material.Text -import com.shabinder.common.di.initKoin - -private val koin = initKoin(enableNetworkLogs = true).koin - -fun main() = Window { - Column{ - Text("Hello World") - } -} \ No newline at end of file