mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: migrate from Hilt to Koin and expand KMP common modules (#4746)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
a5390a80e7
commit
875cf1cff2
440 changed files with 3738 additions and 3508 deletions
|
|
@ -18,13 +18,11 @@ package org.meshtastic.core.ble
|
|||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import no.nordicsemi.kotlin.ble.client.android.CentralManager
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
/** An Android implementation of [BleConnectionFactory]. */
|
||||
@Singleton
|
||||
class AndroidBleConnectionFactory @Inject constructor(private val centralManager: CentralManager) :
|
||||
BleConnectionFactory {
|
||||
@Single
|
||||
class AndroidBleConnectionFactory(private val centralManager: CentralManager) : BleConnectionFactory {
|
||||
override fun create(scope: CoroutineScope, tag: String): BleConnection =
|
||||
AndroidBleConnection(centralManager, scope, tag)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import kotlinx.coroutines.flow.Flow
|
|||
import kotlinx.coroutines.flow.map
|
||||
import no.nordicsemi.kotlin.ble.client.android.CentralManager
|
||||
import no.nordicsemi.kotlin.ble.client.distinctByPeripheral
|
||||
import javax.inject.Inject
|
||||
import org.koin.core.annotation.Single
|
||||
import kotlin.time.Duration
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +28,8 @@ import kotlin.time.Duration
|
|||
*
|
||||
* @param centralManager The Nordic [CentralManager] to use for scanning.
|
||||
*/
|
||||
class AndroidBleScanner @Inject constructor(private val centralManager: CentralManager) : BleScanner {
|
||||
@Single
|
||||
class AndroidBleScanner(private val centralManager: CentralManager) : BleScanner {
|
||||
|
||||
override fun scan(timeout: Duration): Flow<BleDevice> =
|
||||
centralManager.scan(timeout).distinctByPeripheral().map { AndroidBleDevice(it.peripheral) }
|
||||
|
|
|
|||
|
|
@ -29,20 +29,17 @@ import no.nordicsemi.kotlin.ble.client.RemoteServices
|
|||
import no.nordicsemi.kotlin.ble.client.android.CentralManager
|
||||
import no.nordicsemi.kotlin.ble.client.android.Peripheral
|
||||
import no.nordicsemi.kotlin.ble.core.android.AndroidEnvironment
|
||||
import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.ble.MeshtasticBleConstants.BLE_NAME_PATTERN
|
||||
import org.meshtastic.core.ble.MeshtasticBleConstants.SERVICE_UUID
|
||||
import org.meshtastic.core.di.CoroutineDispatchers
|
||||
import org.meshtastic.core.di.ProcessLifecycle
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** Android implementation of [BluetoothRepository]. */
|
||||
@Singleton
|
||||
class AndroidBluetoothRepository
|
||||
@Inject
|
||||
constructor(
|
||||
@Single
|
||||
class AndroidBluetoothRepository(
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
@ProcessLifecycle private val processLifecycle: Lifecycle,
|
||||
@Named("ProcessLifecycle") private val processLifecycle: Lifecycle,
|
||||
private val centralManager: CentralManager,
|
||||
private val androidEnvironment: AndroidEnvironment,
|
||||
) : BluetoothRepository {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.ble.di
|
||||
|
||||
import android.app.Application
|
||||
import android.location.LocationManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import no.nordicsemi.kotlin.ble.client.android.CentralManager
|
||||
import no.nordicsemi.kotlin.ble.client.android.native
|
||||
import no.nordicsemi.kotlin.ble.core.android.AndroidEnvironment
|
||||
import no.nordicsemi.kotlin.ble.environment.android.NativeAndroidEnvironment
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module
|
||||
@ComponentScan("org.meshtastic.core.ble")
|
||||
class CoreBleAndroidModule {
|
||||
@Single
|
||||
fun provideAndroidEnvironment(app: Application): AndroidEnvironment =
|
||||
NativeAndroidEnvironment.getInstance(app, isNeverForLocationFlagSet = true)
|
||||
|
||||
@Single
|
||||
fun provideCentralManager(environment: AndroidEnvironment): CentralManager = CentralManager.native(
|
||||
environment as NativeAndroidEnvironment,
|
||||
CoroutineScope(SupervisorJob() + Dispatchers.Default),
|
||||
)
|
||||
|
||||
@Single
|
||||
fun provideLocationManager(app: Application): LocationManager =
|
||||
ContextCompat.getSystemService(app, LocationManager::class.java)!!
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.meshtastic.core.ble.di
|
||||
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Module
|
||||
|
||||
@Module
|
||||
@ComponentScan("org.meshtastic.core.ble")
|
||||
class CoreBleModule
|
||||
Loading…
Add table
Add a link
Reference in a new issue