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,7 +18,7 @@
|
|||
plugins {
|
||||
alias(libs.plugins.meshtastic.kmp.library)
|
||||
alias(libs.plugins.meshtastic.kotlinx.serialization)
|
||||
alias(libs.plugins.devtools.ksp)
|
||||
id("meshtastic.koin")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
|
@ -35,7 +35,6 @@ kotlin {
|
|||
implementation(projects.core.model)
|
||||
implementation(projects.core.proto)
|
||||
|
||||
api(libs.javax.inject)
|
||||
implementation(libs.okio)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.ktor.client.core)
|
||||
|
|
@ -43,8 +42,8 @@ kotlin {
|
|||
implementation(libs.ktor.serialization.kotlinx.json)
|
||||
implementation(libs.kermit)
|
||||
}
|
||||
|
||||
androidMain.dependencies {
|
||||
implementation(libs.hilt.android)
|
||||
implementation(libs.org.eclipse.paho.client.mqttv3)
|
||||
implementation(libs.coil.network.okhttp)
|
||||
implementation(libs.coil.svg)
|
||||
|
|
@ -61,5 +60,3 @@ configurations.all {
|
|||
attributes.attribute(marketplaceAttr, "fdroid")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies { add("kspAndroid", libs.hilt.compiler) }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.network.di
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module
|
||||
@ComponentScan("org.meshtastic.core.network")
|
||||
class CoreNetworkAndroidModule {
|
||||
@Single
|
||||
fun provideHttpClient(json: Json): HttpClient = HttpClient(OkHttp) { install(ContentNegotiation) { json(json) } }
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ import org.eclipse.paho.client.mqttv3.MqttCallbackExtended
|
|||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.common.util.ignoreException
|
||||
import org.meshtastic.core.model.util.subscribeList
|
||||
import org.meshtastic.core.repository.NodeRepository
|
||||
|
|
@ -37,14 +38,11 @@ import org.meshtastic.core.repository.RadioConfigRepository
|
|||
import org.meshtastic.proto.MqttClientProxyMessage
|
||||
import java.net.URI
|
||||
import java.security.SecureRandom
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import javax.net.ssl.SSLContext
|
||||
import javax.net.ssl.TrustManager
|
||||
|
||||
@Singleton
|
||||
@Single
|
||||
class MQTTRepositoryImpl
|
||||
@Inject
|
||||
constructor(
|
||||
private val radioConfigRepository: RadioConfigRepository,
|
||||
private val nodeRepository: NodeRepository,
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@
|
|||
package org.meshtastic.core.network
|
||||
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.di.CoroutineDispatchers
|
||||
import org.meshtastic.core.model.NetworkDeviceHardware
|
||||
import org.meshtastic.core.network.service.ApiService
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeviceHardwareRemoteDataSource
|
||||
@Inject
|
||||
constructor(
|
||||
@Single
|
||||
class DeviceHardwareRemoteDataSource(
|
||||
private val apiService: ApiService,
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@
|
|||
package org.meshtastic.core.network
|
||||
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.di.CoroutineDispatchers
|
||||
import org.meshtastic.core.model.NetworkFirmwareReleases
|
||||
import org.meshtastic.core.network.service.ApiService
|
||||
import javax.inject.Inject
|
||||
|
||||
class FirmwareReleaseRemoteDataSource
|
||||
@Inject
|
||||
constructor(
|
||||
@Single
|
||||
class FirmwareReleaseRemoteDataSource(
|
||||
private val apiService: ApiService,
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.network.di
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
|
||||
@Module
|
||||
@ComponentScan("org.meshtastic.core.network")
|
||||
class CoreNetworkModule {
|
||||
@Single
|
||||
fun provideJson(): Json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
coerceInputValues = true
|
||||
}
|
||||
}
|
||||
|
|
@ -19,9 +19,9 @@ package org.meshtastic.core.network.service
|
|||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.model.NetworkDeviceHardware
|
||||
import org.meshtastic.core.model.NetworkFirmwareReleases
|
||||
import javax.inject.Inject
|
||||
|
||||
interface ApiService {
|
||||
suspend fun getDeviceHardware(): List<NetworkDeviceHardware>
|
||||
|
|
@ -29,7 +29,8 @@ interface ApiService {
|
|||
suspend fun getFirmwareReleases(): NetworkFirmwareReleases
|
||||
}
|
||||
|
||||
class ApiServiceImpl @Inject constructor(private val client: HttpClient) : ApiService {
|
||||
@Single
|
||||
class ApiServiceImpl(private val client: HttpClient) : ApiService {
|
||||
override suspend fun getDeviceHardware(): List<NetworkDeviceHardware> =
|
||||
client.get("https://api.meshtastic.org/resource/deviceHardware").body()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue