IOS project WIP

This commit is contained in:
shabinder 2021-04-30 01:44:51 +05:30
parent ff7acc9558
commit 7949fcd7ed
11 changed files with 165 additions and 37 deletions

View File

@ -0,0 +1,4 @@
package com.shabinder.common.models
actual interface PlatformActions {
}

View File

@ -7,7 +7,7 @@ import org.koin.dsl.module
import com.squareup.sqldelight.drivers.native.NativeSqliteDriver import com.squareup.sqldelight.drivers.native.NativeSqliteDriver
@Suppress("RedundantNullableReturnType") @Suppress("RedundantNullableReturnType")
actual fun databaseModule(): Module { actual fun databaseModule() = module {
single { single {
val driver = NativeSqliteDriver(Database.Schema, "Database.db") val driver = NativeSqliteDriver(Database.Schema, "Database.db")
SpotiFlyerDatabase(Database(driver)) SpotiFlyerDatabase(Database(driver))

View File

@ -29,18 +29,19 @@ kotlin {
cocoapods { cocoapods {
// Configure fields required by CocoaPods. // Configure fields required by CocoaPods.
summary = "SpotiFlyer Native Module" summary = "SpotiFlyer-DI Native Module"
homepage = "https://github.com/Shabinder/SpotiFlyer" homepage = "https://github.com/Shabinder/SpotiFlyer"
authors = "Shabinder Singh" authors = "Shabinder Singh"
// You can change the name of the produced framework. // You can change the name of the produced framework.
// By default, it is the name of the Gradle project. // By default, it is the name of the Gradle project.
frameworkName = "SpotiFlyer" frameworkName = "SpotiFlyer-DI"
ios.deploymentTarget = "13.5" ios.deploymentTarget = "9.0"
// Dependencies // Dependencies
pod("TagLibIOS") { pod("TagLibIOS") {
version = "~> 0.3" version = "~> 0.3"
} }
//podfile = project.file("spotiflyer-ios/Podfile")
} }
sourceSets { sourceSets {

View File

@ -5,14 +5,14 @@ Pod::Spec.new do |spec|
spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" } spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
spec.authors = 'Shabinder Singh' spec.authors = 'Shabinder Singh'
spec.license = '' spec.license = ''
spec.summary = 'SpotiFlyer Native Module' spec.summary = 'SpotiFlyer-DI Native Module'
spec.static_framework = true spec.static_framework = true
spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer.framework" spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer-DI.framework"
spec.libraries = "c++" spec.libraries = "c++"
spec.module_name = "#{spec.name}_umbrella" spec.module_name = "#{spec.name}_umbrella"
spec.ios.deployment_target = '13.5' spec.ios.deployment_target = '9.0'
spec.dependency 'TagLibIOS', '~> 0.3' spec.dependency 'TagLibIOS', '~> 0.3'

View File

@ -27,7 +27,10 @@ import com.shabinder.common.database.SpotiFlyerDatabase
import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.TrackDetails
import com.shabinder.common.models.methods import com.shabinder.common.models.methods
import com.shabinder.database.Database import com.shabinder.database.Database
import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.IOException import java.io.IOException

View File

@ -1,25 +1,6 @@
package com.shabinder.common.di package com.shabinder.common.di
import com.shabinder.common.models.AllPlatforms
import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.TrackDetails
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
actual fun queryActiveTracks() {}
actual fun openPlatform(packageID: String, platformLink: String) {}
actual fun shareApp() {}
actual fun giveDonation() {}
actual val dispatcherIO: CoroutineDispatcher = Dispatchers.Default
actual val isInternetAvailable: Boolean
get() = runBlocking { isInternetAccessible() }
actual val currentPlatform: AllPlatforms = AllPlatforms.Native
actual suspend fun downloadTracks( actual suspend fun downloadTracks(
list: List<TrackDetails>, list: List<TrackDetails>,

View File

@ -1,14 +1,25 @@
package com.shabinder.common.di package com.shabinder.common.di
import co.touchlab.kermit.Kermit import co.touchlab.kermit.Kermit
import cocoapods.TagLibIOS.TLAudio
import com.shabinder.common.database.SpotiFlyerDatabase
import com.shabinder.common.models.TrackDetails import com.shabinder.common.models.TrackDetails
import com.shabinder.database.Database import com.shabinder.database.Database
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import platform.Foundation.* import platform.Foundation.NSCachesDirectory
import platform.Foundation.NSDirectoryEnumerationSkipsHiddenFiles
import platform.Foundation.NSFileManager
import platform.Foundation.NSMusicDirectory
import platform.Foundation.NSURL
import platform.Foundation.NSURLConnection
import platform.Foundation.NSURLRequest
import platform.Foundation.NSUserDomainMask
import platform.Foundation.URLByAppendingPathComponent
import platform.Foundation.sendSynchronousRequest
import platform.Foundation.writeToFile
import platform.UIKit.UIImage import platform.UIKit.UIImage
import platform.UIKit.UIImageJPEGRepresentation import platform.UIKit.UIImageJPEGRepresentation
import cocoapods.TagLibIOS.TLAudio
actual class Dir actual constructor( actual class Dir actual constructor(
private val logger: Kermit, private val logger: Kermit,
@ -87,7 +98,7 @@ actual class Dir actual constructor(
private suspend fun loadFreshImage(url: String):UIImage? { private suspend fun loadFreshImage(url: String):UIImage? {
return try { return try {
val nsURL = NSURL(url) val nsURL = NSURL(string = url)
val data = NSURLConnection.sendSynchronousRequest(NSURLRequest.requestWithURL(nsURL),null,null) val data = NSURLConnection.sendSynchronousRequest(NSURLRequest.requestWithURL(nsURL),null,null)
if (data != null) { if (data != null) {
UIImage.imageWithData(data)?.also { UIImage.imageWithData(data)?.also {

View File

@ -18,9 +18,69 @@ plugins {
id("multiplatform-setup") id("multiplatform-setup")
id("android-setup") id("android-setup")
id("kotlin-parcelize") id("kotlin-parcelize")
//kotlin("native.cocoapods")
} }
// Required be cocoapods
version = "1.0"
kotlin { kotlin {
/*IOS Target Can be only built on Mac*/
if(HostOS.isMac){
val sdkName: String? = System.getenv("SDK_NAME")
val isiOSDevice = sdkName.orEmpty().startsWith("iphoneos")
if (isiOSDevice) {
iosArm64("ios"){
binaries {
framework {
baseName = "SpotiFlyer"
linkerOpts.add("-lsqlite3")
export(project(":common:database"))
export(project(":common:main"))
export(project(":common:list"))
export(project(":common:dependency-injection"))
export(project(":common:data-models"))
export(Decompose.decompose)
export(MVIKotlin.mvikotlin)
}
}
}
} else {
iosX64("ios"){
binaries {
framework {
baseName = "SpotiFlyer"
linkerOpts.add("-lsqlite3")
export(project(":common:database"))
export(project(":common:main"))
export(project(":common:list"))
export(project(":common:dependency-injection"))
export(project(":common:data-models"))
export(Decompose.decompose)
export(MVIKotlin.mvikotlin)
}
}
}
}
}
/*cocoapods {
// Configure fields required by CocoaPods.
summary = "SpotiFlyer Native Module"
homepage = "https://github.com/Shabinder/SpotiFlyer"
authors = "Shabinder Singh"
// You can change the name of the produced framework.
// By default, it is the name of the Gradle project.
frameworkName = "SpotiFlyer"
ios.deploymentTarget = "11.0"
*//*pod("dependency_injection"){
version = "1.0"
source = path(rootProject.file("common/dependency-injection"))
}*//*
}*/
sourceSets { sourceSets {
commonMain { commonMain {
dependencies { dependencies {
@ -36,4 +96,29 @@ kotlin {
} }
} }
} }
sourceSets {
named("iosMain") {
dependencies {
api(project(":common:dependency-injection"))
api(project(":common:data-models"))
api(project(":common:database"))
api(project(":common:list"))
api(project(":common:main"))
api(Decompose.decompose)
api(MVIKotlin.mvikotlin)
}
}
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val targetName = "ios"
val framework = kotlin.targets.getByName<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from(framework.outputDirectory)
into(targetDir)
} }

46
common/root/root.podspec Normal file
View File

@ -0,0 +1,46 @@
Pod::Spec.new do |spec|
spec.name = 'root'
spec.version = '1.0'
spec.homepage = 'https://github.com/Shabinder/SpotiFlyer'
spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
spec.authors = 'Shabinder Singh'
spec.license = ''
spec.summary = 'SpotiFlyer Native Module'
spec.static_framework = true
spec.vendored_frameworks = "build/cocoapods/framework/SpotiFlyer.framework"
spec.libraries = "c++"
spec.module_name = "#{spec.name}_umbrella"
spec.ios.deployment_target = '11.0'
spec.pod_target_xcconfig = {
'KOTLIN_TARGET[sdk=iphonesimulator*]' => 'ios_x64',
'KOTLIN_TARGET[sdk=iphoneos*]' => 'ios_arm',
'KOTLIN_TARGET[sdk=watchsimulator*]' => 'watchos_x64',
'KOTLIN_TARGET[sdk=watchos*]' => 'watchos_arm',
'KOTLIN_TARGET[sdk=appletvsimulator*]' => 'tvos_x64',
'KOTLIN_TARGET[sdk=appletvos*]' => 'tvos_arm64',
'KOTLIN_TARGET[sdk=macosx*]' => 'macos_x64'
}
spec.script_phases = [
{
:name => 'Build root',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
set -ev
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../../gradlew" -p "$REPO_ROOT" :common:root:syncFramework \
-Pkotlin.native.cocoapods.target=$KOTLIN_TARGET \
-Pkotlin.native.cocoapods.configuration=$CONFIGURATION \
-Pkotlin.native.cocoapods.cflags="$OTHER_CFLAGS" \
-Pkotlin.native.cocoapods.paths.headers="$HEADER_SEARCH_PATHS" \
-Pkotlin.native.cocoapods.paths.frameworks="$FRAMEWORK_SEARCH_PATHS"
SCRIPT
}
]
end

View File

@ -42,8 +42,7 @@ import com.shabinder.common.uikit.colorOffWhite
import com.shabinder.common.uikit.showToast import com.shabinder.common.uikit.showToast
import com.shabinder.database.Database import com.shabinder.database.Database
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
private val koin = initKoin(enableNetworkLogs = true).koin private val koin = initKoin(enableNetworkLogs = true).koin
@ -96,11 +95,8 @@ private fun spotiFlyerRoot(componentContext: ComponentContext): SpotiFlyerRoot =
override val dispatcherIO = Dispatchers.IO override val dispatcherIO = Dispatchers.IO
override val isInternetAvailable: Boolean override val isInternetAvailable: Boolean
get() { get() = runBlocking {
var result = false isInternetAccessible()
val job = GlobalScope.launch { result = isInternetAccessible() }
while (job.isActive) {/*TODO Better Way*/}
return result
} }
override val currentPlatform = AllPlatforms.Jvm override val currentPlatform = AllPlatforms.Jvm

View File

@ -41,4 +41,5 @@ kotlin.native.disableCompilerDaemon=true
kotlin.mpp.stability.nowarn=true kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false kotlin.native.enableDependencyPropagation=false
kotlin.native.cacheKind=none
#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 #org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8