Skip to content

Commit

Permalink
Remove Koin from library
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylwester Zieliński committed Jan 11, 2024
1 parent 226ca60 commit 33afe6a
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 35 deletions.
3 changes: 1 addition & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ kotlin {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.koin.core)
implementation(libs.koin.compose)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
Expand All @@ -107,6 +105,7 @@ kotlin {
implementation(libs.nordic.blek.server)
implementation(libs.nordic.permissions.ble)
implementation(libs.nordic.permissions.internet)
implementation(libs.androidx.startup)
}
}
val iosX64Main by getting
Expand Down
20 changes: 17 additions & 3 deletions lib/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2023, Nordic Semiconductor
~ All rights reserved.
~
Expand Down Expand Up @@ -30,4 +29,19 @@
~ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<manifest />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">

<meta-data
android:name="setup.BleInitializer"
android:value="androidx.startup" />
</provider>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package scanner

import advertisement.IOSServer
import advertisement.IOSServerWrapper
import advertisement.Advertiser
import client.IOSClient
import client.IOSClientWrapper
import client.Client
import org.koin.core.module.Module
import org.koin.dsl.module
import scanner.Scanner
import server.Server
import server.NotificationsRecords
import setup.applicationContext

actual object BleFactory {
actual fun provideScanner(): Scanner {
return Scanner(applicationContext)
}

actual fun provideAdvertiser(): Advertiser {
return Advertiser(applicationContext)
}

actual fun provideClient(): Client {
return Client(applicationContext)
}

actual val ScannerModule: Module = module {
single { IOSClientWrapper(IOSClient()) }
single { Scanner(get()) }
single { Client(get()) }
single { NotificationsRecords() }
single { IOSServerWrapper(IOSServer(get())) }
single { Server(get()) }
single { Advertiser(get()) }
actual fun provideServer(): Server {
return Server(applicationContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package scanner
package setup

import org.koin.core.module.Module
import android.content.Context

expect val ScannerModule: Module
internal lateinit var applicationContext: Context
47 changes: 47 additions & 0 deletions lib/src/androidMain/kotlin/setup/BleInitializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2023, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package setup

import android.content.Context
import androidx.startup.Initializer

object Nordic

class BleInitializer : Initializer<Nordic> {

override fun create(context: Context): Nordic {
applicationContext = context.applicationContext
return Nordic
}

override fun dependencies(): List<Class<out Initializer<*>>> = emptyList()
}
46 changes: 46 additions & 0 deletions lib/src/commonMain/kotlin/BleFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import advertisement.Advertiser
import client.Client
import scanner.Scanner
import server.Server

/*
* Copyright (c) 2023, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

expect object BleFactory {

fun provideScanner(): Scanner

fun provideAdvertiser(): Advertiser

fun provideClient(): Client

fun provideServer(): Server
}
71 changes: 71 additions & 0 deletions lib/src/iosMain/kotlin/BleFactory.ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2023, Nordic Semiconductor
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import advertisement.Advertiser
import advertisement.IOSServer
import advertisement.IOSServerWrapper
import client.Client
import client.IOSClient
import client.IOSClientWrapper
import scanner.Scanner
import server.NotificationsRecords
import server.Server

//TODO: check if something needs to be a singletone
actual object BleFactory {
actual fun provideScanner(): Scanner {
return Scanner(provideIOSClientWrapper())
}

actual fun provideAdvertiser(): Advertiser {
return Advertiser(provideIOSServerWrapper())
}

actual fun provideClient(): Client {
return Client(provideIOSClientWrapper())
}

actual fun provideServer(): Server {
return Server(provideIOSServerWrapper())
}

private fun provideNotificationRecords(): NotificationsRecords {
return NotificationsRecords()
}

private fun provideIOSServerWrapper(): IOSServerWrapper {
return IOSServerWrapper(IOSServer(provideNotificationRecords()))
}

private fun provideIOSClientWrapper(): IOSClientWrapper {
return IOSClientWrapper(IOSClient())
}
}
4 changes: 1 addition & 3 deletions lib/src/iosMain/kotlin/advertisement/Advertiser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@

package advertisement

import org.koin.core.component.KoinComponent

actual class Advertiser(private val server: IOSServerWrapper) : KoinComponent {
actual class Advertiser(private val server: IOSServerWrapper) {

actual suspend fun advertise(settings: AdvertisementSettings) {
server.value.advertise(settings)
Expand Down
1 change: 0 additions & 1 deletion shared/src/commonMain/kotlin/di/CommonModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ package di

import org.koin.core.context.startKoin
import org.koin.dsl.KoinAppDeclaration
import scanner.ScannerModule

fun initKoin(appDeclaration: KoinAppDeclaration) = startKoin {
appDeclaration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package scanner
package di

import BleFactory
import advertisement.Advertiser
import client.Client
import org.koin.core.module.Module
import org.koin.dsl.module
import server.Server

actual val ScannerModule: Module = module {
single { Scanner(get()) }
single { Client(get()) }
single { Server(get()) }
single { Advertiser(get()) }
internal val ScannerModule: Module = module {
single { BleFactory.provideScanner() }
single { BleFactory.provideClient() }
single { BleFactory.provideAdvertiser() }
single { BleFactory.provideServer() }
}

0 comments on commit 33afe6a

Please sign in to comment.