mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-07-13 06:42:23 -04:00
refactor(di): drop the F-Droid ApiService stub, use the real API client in both flavors (#6226)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.app.di
|
||||
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.model.EventFirmwareResponse
|
||||
import org.meshtastic.core.model.NetworkDeviceHardware
|
||||
import org.meshtastic.core.model.NetworkDeviceLinksResponse
|
||||
import org.meshtastic.core.model.NetworkFirmwareReleases
|
||||
import org.meshtastic.core.network.service.ApiService
|
||||
|
||||
@Module
|
||||
class FDroidNetworkModule {
|
||||
|
||||
/**
|
||||
* F-Droid builds intentionally avoid network calls to the Meshtastic API.
|
||||
*
|
||||
* We throw [UnsupportedOperationException] (an [Exception], not an [Error]) so that `safeCatching {}` in the
|
||||
* repositories captures the failure and falls back to the bundled JSON assets instead of crashing the app.
|
||||
*/
|
||||
@Single
|
||||
fun provideApiService(): ApiService = object : ApiService {
|
||||
override suspend fun getDeviceHardware(): List<NetworkDeviceHardware> =
|
||||
throw UnsupportedOperationException("getDeviceHardware is not supported on F-Droid builds.")
|
||||
|
||||
override suspend fun getDeviceLinks(): NetworkDeviceLinksResponse =
|
||||
throw UnsupportedOperationException("getDeviceLinks is not supported on F-Droid builds.")
|
||||
|
||||
override suspend fun getFirmwareReleases(): NetworkFirmwareReleases =
|
||||
throw UnsupportedOperationException("getFirmwareReleases is not supported on F-Droid builds.")
|
||||
|
||||
override suspend fun getEventFirmware(): EventFirmwareResponse =
|
||||
throw UnsupportedOperationException("getEventFirmware is not supported on F-Droid builds.")
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import org.koin.core.annotation.Named
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.ui.theme.EventFontResolver
|
||||
|
||||
@Module(includes = [FDroidNetworkModule::class, FdroidAiModule::class])
|
||||
@Module(includes = [FdroidAiModule::class])
|
||||
class FlavorModule {
|
||||
@Single
|
||||
@Named("googleServicesAvailable")
|
||||
|
||||
@@ -26,14 +26,7 @@ import org.meshtastic.core.ui.theme.EventFontResolver
|
||||
import org.meshtastic.feature.car.di.FeatureCarModule
|
||||
|
||||
@Module(
|
||||
includes =
|
||||
[
|
||||
GoogleNetworkModule::class,
|
||||
GoogleMapsKoinModule::class,
|
||||
GoogleAiModule::class,
|
||||
AppFunctionsModule::class,
|
||||
FeatureCarModule::class,
|
||||
],
|
||||
includes = [GoogleMapsKoinModule::class, GoogleAiModule::class, AppFunctionsModule::class, FeatureCarModule::class],
|
||||
)
|
||||
class FlavorModule {
|
||||
/** Downloadable Google Fonts for event branding — Google flavor only. */
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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.app.di
|
||||
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Single
|
||||
import org.meshtastic.core.network.service.ApiService
|
||||
import org.meshtastic.core.network.service.ApiServiceImpl
|
||||
|
||||
@Module
|
||||
class GoogleNetworkModule {
|
||||
|
||||
@Single fun bindApiService(apiServiceImpl: ApiServiceImpl): ApiService = apiServiceImpl
|
||||
}
|
||||
@@ -49,6 +49,8 @@ import org.meshtastic.core.common.BuildConfigProvider
|
||||
import org.meshtastic.core.network.HttpClientDefaults
|
||||
import org.meshtastic.core.network.KermitHttpLogger
|
||||
import org.meshtastic.core.network.configureDefaultRetry
|
||||
import org.meshtastic.core.network.service.ApiService
|
||||
import org.meshtastic.core.network.service.ApiServiceImpl
|
||||
|
||||
private const val DISK_CACHE_PERCENT = 0.02
|
||||
private const val MEMORY_CACHE_PERCENT = 0.25
|
||||
@@ -57,6 +59,8 @@ private const val MEMORY_CACHE_BACKGROUND_PERCENT = 0.1
|
||||
@Module
|
||||
class NetworkModule {
|
||||
|
||||
@Single fun bindApiService(apiServiceImpl: ApiServiceImpl): ApiService = apiServiceImpl
|
||||
|
||||
@Single
|
||||
fun provideConnectivityManager(application: Application): ConnectivityManager =
|
||||
application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
Reference in New Issue
Block a user