refact: [ANDROID] classes visibility (#358)

Co-authored-by: Florent Champigny <florent@bere.al>
This commit is contained in:
Florent CHAMPIGNY 2025-10-16 22:56:47 +02:00 committed by GitHub
parent 222b39bd7b
commit dbd0da17ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 65 additions and 109 deletions

View file

@ -11,6 +11,7 @@ import kotlinx.coroutines.launch
fun initializeDatabases(context: Context) {
val dogDatabase = DogDatabase.getDatabase(context)
val foodDatabase = FoodDatabase.getDatabase(context)
GlobalScope.launch {
dogDatabase.dogDao().insertDog(
DogEntity(

View file

@ -1,14 +1,12 @@
package io.github.openflocon.flocon
import android.content.Context
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.plugins.analytics.FloconAnalyticsPlugin
import io.github.openflocon.flocon.plugins.dashboard.FloconDashboardPlugin
import io.github.openflocon.flocon.plugins.deeplinks.FloconDeeplinksPlugin
import io.github.openflocon.flocon.plugins.device.FloconDevicePlugin
import io.github.openflocon.flocon.plugins.network.FloconNetworkPlugin
import io.github.openflocon.flocon.plugins.tables.FloconTablePlugin
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
abstract class FloconApp {
@ -18,7 +16,7 @@ abstract class FloconApp {
private set
}
interface Client : FloconMessageSender {
interface Client {
@Throws(Throwable::class)
suspend fun connect(onClosed: () -> Unit)

View file

@ -1,7 +0,0 @@
package io.github.openflocon.flocon.model
data class FloconMessageFromServer(
val plugin: String,
val method: String,
val body: String,
)

View file

@ -1,7 +1,6 @@
package io.github.openflocon.flocon.plugins.analytics
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.plugins.analytics.builder.AnalyticsBuilder
import io.github.openflocon.flocon.plugins.analytics.model.AnalyticsItem
@ -12,6 +11,6 @@ fun FloconApp.analytics(analyticsName: String): AnalyticsBuilder {
)
}
interface FloconAnalyticsPlugin : FloconPlugin {
interface FloconAnalyticsPlugin {
fun registerAnalytics(analyticsItems: List<AnalyticsItem>)
}

View file

@ -1,7 +1,6 @@
package io.github.openflocon.flocon.plugins.dashboard
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.plugins.dashboard.builder.DashboardBuilder
import io.github.openflocon.flocon.plugins.dashboard.dsl.dashboardConfig
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardConfig
@ -15,6 +14,6 @@ fun FloconApp.dashboard(id: String, block: DashboardBuilder.() -> Unit) {
}
}
interface FloconDashboardPlugin : FloconPlugin {
interface FloconDashboardPlugin {
fun registerDashboard(dashboardConfig: DashboardConfig)
}

View file

@ -1,6 +1,3 @@
package io.github.openflocon.flocon.plugins.database
import io.github.openflocon.flocon.core.FloconPlugin
interface FloconDatabasePlugin : FloconPlugin
interface FloconDatabasePlugin

View file

@ -1,7 +1,6 @@
package io.github.openflocon.flocon.plugins.deeplinks
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.plugins.deeplinks.model.DeeplinkModel
class ParameterBuilder {
@ -46,6 +45,6 @@ fun FloconApp.deeplinks(deeplinksBlock: DeeplinkBuilder.() -> Unit) {
}
}
interface FloconDeeplinksPlugin : FloconPlugin {
interface FloconDeeplinksPlugin {
fun registerDeeplinks(deeplinks: List<DeeplinkModel>)
}

View file

@ -1,7 +1,5 @@
package io.github.openflocon.flocon.plugins.device
import io.github.openflocon.flocon.core.FloconPlugin
interface FloconDevicePlugin : FloconPlugin {
interface FloconDevicePlugin {
fun registerWithSerial(serial: String)
}

View file

@ -1,5 +1,3 @@
package io.github.openflocon.flocon.plugins.files
import io.github.openflocon.flocon.core.FloconPlugin
interface FloconFilesPlugin : FloconPlugin
interface FloconFilesPlugin

View file

@ -1,7 +1,6 @@
package io.github.openflocon.flocon.plugins.network
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.plugins.network.model.BadQualityConfig
import io.github.openflocon.flocon.plugins.network.model.FloconNetworkCallRequest
import io.github.openflocon.flocon.plugins.network.model.FloconNetworkCallResponse
@ -13,7 +12,7 @@ fun floconLogWebSocketEvent(event: FloconWebSocketEvent) {
FloconApp.instance?.client?.networkPlugin?.logWebSocket(event)
}
interface FloconNetworkPlugin : FloconPlugin {
interface FloconNetworkPlugin {
val mocks: Collection<MockNetworkResponse>
val badQualityConfig: BadQualityConfig?

View file

@ -1,5 +1,3 @@
package io.github.openflocon.flocon.plugins.SharedPreferences
package io.github.openflocon.flocon.plugins.sharedprefs
import io.github.openflocon.flocon.core.FloconPlugin
interface FloconSharedPreferencesPlugin : FloconPlugin
interface FloconSharedPreferencesPlugin

View file

@ -1,7 +1,6 @@
package io.github.openflocon.flocon.plugins.tables
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.plugins.tables.builder.TableBuilder
import io.github.openflocon.flocon.plugins.tables.model.TableItem
@ -12,6 +11,6 @@ fun FloconApp.table(tableName: String): TableBuilder {
)
}
interface FloconTablePlugin : FloconPlugin {
interface FloconTablePlugin {
fun registerTable(tableItem: TableItem)
}

View file

@ -8,6 +8,7 @@ import android.widget.Toast
import io.github.openflocon.flocon.FloconApp
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconFileSender
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconFileInfo
import io.github.openflocon.flocon.model.floconMessageFromServerFromJson
@ -35,7 +36,7 @@ import java.io.File
internal class FloconClientImpl(
private val appContext: Context,
) : FloconApp.Client, FloconFileSender {
) : FloconApp.Client, FloconMessageSender, FloconFileSender {
private val FLOCON_WEBSOCKET_PORT = 9023
private val FLOCON_HTTP_PORT = 9024
@ -63,9 +64,9 @@ internal class FloconClientImpl(
private val coroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
// region plugins
private val databasePlugin = FloconDatabasePluginImpl(context = appContext)
private val filesPlugin = FloconFilesPluginImpl(context = appContext, floconFileSender = this)
private val sharedPrefsPlugin = FloconSharedPreferencesPluginImpl(context = appContext)
private val databasePlugin = FloconDatabasePluginImpl(context = appContext, sender = this)
private val filesPlugin = FloconFilesPluginImpl(context = appContext, sender = this, floconFileSender = this)
private val sharedPrefsPlugin = FloconSharedPreferencesPluginImpl(context = appContext, sender = this)
override val dashboardPlugin = FloconDashboardPluginImpl(sender = this)
override val tablePlugin = FloconTablePluginImpl(sender = this)
override val deeplinksPlugin = FloconDeeplinksPluginImpl(sender = this)
@ -100,7 +101,7 @@ internal class FloconClientImpl(
onClosed = onClosed,
)
allPlugins.forEach {
it.onConnectedToServer(sender = this)
it.onConnectedToServer()
}
}
@ -115,56 +116,48 @@ internal class FloconClientImpl(
Protocol.ToDevice.Database.Plugin -> {
databasePlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Files.Plugin -> {
filesPlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.SharedPreferences.Plugin -> {
sharedPrefsPlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Device.Plugin -> {
devicePlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Dashboard.Plugin -> {
dashboardPlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Table.Plugin -> {
tablePlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Analytics.Plugin -> {
analyticsPlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
Protocol.ToDevice.Network.Plugin -> {
networkPlugin.onMessageReceived(
messageFromServer = messageFromServer,
sender = this@FloconClientImpl,
)
}
}

View file

@ -3,6 +3,6 @@ package io.github.openflocon.flocon.core
import io.github.openflocon.flocon.model.FloconFileInfo
import java.io.File
interface FloconFileSender {
internal interface FloconFileSender {
fun send(file: File, infos: FloconFileInfo)
}

View file

@ -1,10 +1,9 @@
package io.github.openflocon.flocon.core
interface FloconMessageSender {
internal interface FloconMessageSender {
fun send(
plugin: String,
method: String,
body: String,
)
}
}

View file

@ -2,13 +2,9 @@ package io.github.openflocon.flocon.core
import io.github.openflocon.flocon.model.FloconMessageFromServer
interface FloconPlugin {
internal interface FloconPlugin {
fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
)
fun onConnectedToServer(
sender: FloconMessageSender,
)
}
fun onConnectedToServer()
}

View file

@ -1,6 +1,6 @@
package io.github.openflocon.flocon.model
data class FloconFileInfo(
internal data class FloconFileInfo(
val path: String,
val requestId: String,
)

View file

@ -18,4 +18,10 @@ internal fun floconMessageFromServerFromJson(
FloconLogger.logError("parsing issue", t)
null
}
}
}
internal data class FloconMessageFromServer(
val plugin: String,
val method: String,
val body: String,
)

View file

@ -3,22 +3,22 @@ package io.github.openflocon.flocon.plugins.analytics
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.analytics.model.AnalyticsItem
import io.github.openflocon.flocon.plugins.analytics.mapper.analyticsItemsToJson
internal class FloconAnalyticsPluginImpl(
private val sender: FloconMessageSender,
) : FloconAnalyticsPlugin {
) : FloconPlugin, FloconAnalyticsPlugin {
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
// no op
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// no op
}

View file

@ -3,6 +3,7 @@ package io.github.openflocon.flocon.plugins.dashboard
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.dashboard.mapper.toJson
import io.github.openflocon.flocon.plugins.dashboard.model.DashboardCallback
@ -14,14 +15,13 @@ import java.util.concurrent.ConcurrentHashMap
internal class FloconDashboardPluginImpl(
private val sender: FloconMessageSender,
) : FloconDashboardPlugin {
) : FloconPlugin, FloconDashboardPlugin {
private val dashboards = ConcurrentHashMap<String, DashboardConfig>()
private val callbackMap: MutableMap<String, DashboardCallback> = ConcurrentHashMap()
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
when (messageFromServer.method) {
Protocol.ToDevice.Dashboard.Method.OnClick -> {
@ -56,7 +56,7 @@ internal class FloconDashboardPluginImpl(
}
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// on connected, send known dashboards
dashboards.values.takeIf { it.isNotEmpty() }?.forEach { dashboardConfig ->
registerDashboard(dashboardConfig)

View file

@ -18,14 +18,14 @@ import java.io.File
import java.util.Locale
internal class FloconDatabasePluginImpl(
private var sender: FloconMessageSender,
private val context: Context,
) : FloconDatabasePlugin {
) : FloconPlugin, FloconDatabasePlugin {
private val MAX_DEPTH = 7
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
when (messageFromServer.method) {
Protocol.ToDevice.Database.Method.GetDatabases -> {
@ -55,7 +55,7 @@ internal class FloconDatabasePluginImpl(
}
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
sendAllDatabases(sender)
}

View file

@ -3,6 +3,7 @@ package io.github.openflocon.flocon.plugins.deeplinks
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.deeplinks.model.DeeplinkModel
import org.json.JSONArray
@ -10,18 +11,17 @@ import org.json.JSONObject
internal class FloconDeeplinksPluginImpl(
private val sender: FloconMessageSender,
) : FloconDeeplinksPlugin {
) : FloconPlugin, FloconDeeplinksPlugin {
private val deeplinks = java.util.concurrent.atomic.AtomicReference<List<DeeplinkModel>?>(null)
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// on connected, send known dashboard
deeplinks.get()?.let {
registerDeeplinks(it)

View file

@ -5,13 +5,14 @@ import com.jakewharton.processphoenix.ProcessPhoenix
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.device.model.fromdevice.RegisterDeviceDataModel
internal class FloconDevicePluginImpl(
private var sender: FloconMessageSender,
private val context: Context,
) : FloconDevicePlugin {
) : FloconPlugin, FloconDevicePlugin {
override fun registerWithSerial(serial: String) {
try {
@ -27,7 +28,6 @@ internal class FloconDevicePluginImpl(
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender
) {
when (messageFromServer.method) {
Protocol.ToDevice.Device.Method.GetAppIcon -> {
@ -47,7 +47,7 @@ internal class FloconDevicePluginImpl(
}
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// no op
}
}

View file

@ -19,11 +19,11 @@ import java.io.File
internal class FloconFilesPluginImpl(
private val context: Context,
private val floconFileSender: FloconFileSender,
) : FloconFilesPlugin {
private val sender: FloconMessageSender,
) : FloconPlugin, FloconFilesPlugin {
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
when (messageFromServer.method) {
Protocol.ToDevice.Files.Method.ListFiles -> {
@ -34,7 +34,6 @@ internal class FloconFilesPluginImpl(
path = listFilesMessage.path,
isConstantPath = listFilesMessage.isConstantPath,
requestId = listFilesMessage.requestId,
sender = sender,
)
}
@ -65,7 +64,6 @@ internal class FloconFilesPluginImpl(
path = deleteFilesMessage.parentPath,
isConstantPath = deleteFilesMessage.isConstantParentPath,
requestId = deleteFilesMessage.requestId,
sender = sender,
)
}
@ -85,7 +83,6 @@ internal class FloconFilesPluginImpl(
path = deleteFolderContentMessage.path,
isConstantPath = deleteFolderContentMessage.isConstantPath,
requestId = deleteFolderContentMessage.requestId,
sender = sender,
)
}
}
@ -119,7 +116,6 @@ internal class FloconFilesPluginImpl(
path: String,
isConstantPath: Boolean,
requestId: String,
sender: FloconMessageSender
) {
val files = getFolderContent(
path = path,
@ -140,7 +136,7 @@ internal class FloconFilesPluginImpl(
}
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// no op
}

View file

@ -4,6 +4,7 @@ import android.content.Context
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.network.mapper.floconNetworkCallRequestToJson
import io.github.openflocon.flocon.plugins.network.mapper.floconNetworkCallResponseToJson
@ -38,7 +39,7 @@ internal class FloconNetworkPluginImpl(
private val context: Context,
private var sender: FloconMessageSender,
private val coroutineScope: CoroutineScope,
) : FloconNetworkPlugin {
) : FloconPlugin, FloconNetworkPlugin {
private val websocketListeners = ConcurrentHashMap<String, FloconWebSocketMockListener>()
@ -93,7 +94,6 @@ internal class FloconNetworkPluginImpl(
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender
) {
when (messageFromServer.method) {
Protocol.ToDevice.Network.Method.SetupMocks -> {
@ -118,7 +118,7 @@ internal class FloconNetworkPluginImpl(
}
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
updateWebSocketIds()
}

View file

@ -6,8 +6,8 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.SharedPreferences.FloconSharedPreferencesPlugin
import io.github.openflocon.flocon.plugins.sharedprefs.model.SharedPreferencesDescriptor
import io.github.openflocon.flocon.plugins.sharedprefs.model.fromdevice.SharedPreferenceRowDataModel
import io.github.openflocon.flocon.plugins.sharedprefs.model.fromdevice.SharedPreferenceValueResultDataModel
@ -21,9 +21,8 @@ import io.github.openflocon.flocon.plugins.sharedprefs.model.todevice.ToDeviceGe
internal class FloconSharedPreferencesPluginImpl(
private val context: Context,
) : FloconSharedPreferencesPlugin {
private var sender: FloconMessageSender? = null
private var sender: FloconMessageSender,
) : FloconPlugin, FloconSharedPreferencesPlugin {
private val mSharedPreferences: MutableMap<SharedPreferencesDescriptor, SharedPreferences> =
mutableMapOf()
@ -36,9 +35,6 @@ internal class FloconSharedPreferencesPluginImpl(
sharedPreferences: SharedPreferences,
key: String?
) {
if (sender == null) {
return
}
val descriptor: SharedPreferencesDescriptor? =
mSharedPreferencesDescriptors[sharedPreferences]
if (descriptor == null) {
@ -59,14 +55,10 @@ internal class FloconSharedPreferencesPluginImpl(
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
this.sender = sender
when (messageFromServer.method) {
Protocol.ToDevice.SharedPreferences.Method.GetSharedPreferences -> {
sendAllSharedPrefs(
sender = sender,
)
sendAllSharedPrefs()
}
Protocol.ToDevice.SharedPreferences.Method.GetSharedPreferenceValue -> {
@ -133,15 +125,11 @@ internal class FloconSharedPreferencesPluginImpl(
}
// on connected, send all shared prefs
override fun onConnectedToServer(sender: FloconMessageSender) {
sendAllSharedPrefs(
sender = sender,
)
override fun onConnectedToServer() {
sendAllSharedPrefs()
}
private fun sendAllSharedPrefs(
sender: FloconMessageSender,
) {
private fun sendAllSharedPrefs() {
val allPrefs = getAllSharedPreferences()
try {
sender.send(

View file

@ -3,22 +3,22 @@ package io.github.openflocon.flocon.plugins.tables
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.Protocol
import io.github.openflocon.flocon.core.FloconMessageSender
import io.github.openflocon.flocon.core.FloconPlugin
import io.github.openflocon.flocon.model.FloconMessageFromServer
import io.github.openflocon.flocon.plugins.tables.model.TableItem
import io.github.openflocon.flocon.plugins.tables.model.tableItemListToJson
internal class FloconTablePluginImpl(
private val sender: FloconMessageSender,
) : FloconTablePlugin {
) : FloconPlugin, FloconTablePlugin {
override fun onMessageReceived(
messageFromServer: FloconMessageFromServer,
sender: FloconMessageSender,
) {
// no op
}
override fun onConnectedToServer(sender: FloconMessageSender) {
override fun onConnectedToServer() {
// no op
}

View file

@ -3,7 +3,7 @@ package io.github.openflocon.flocon.websocket
import io.github.openflocon.flocon.model.FloconFileInfo
import java.io.File
interface FloconHttpClient {
internal interface FloconHttpClient {
suspend fun send(
file: File,
infos: FloconFileInfo,

View file

@ -8,7 +8,7 @@ import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
import java.io.File
class FloconHttpClientImpl : FloconHttpClient {
internal class FloconHttpClientImpl : FloconHttpClient {
private val client by lazy {
OkHttpClient()