mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-19 15:34:26 +01:00
Add analytics to UART profile
This commit is contained in:
@@ -33,3 +33,18 @@ const val PROFILE_PARAM_KEY = "PROFILE_NAME"
|
|||||||
private fun createBundle(name: String): Bundle {
|
private fun createBundle(name: String): Bundle {
|
||||||
return Bundle().apply { putString(PROFILE_PARAM_KEY, name) }
|
return Bundle().apply { putString(PROFILE_PARAM_KEY, name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class UARTAnalyticsEvent(eventName: String, params: Bundle?) : FirebaseEvent(eventName, params)
|
||||||
|
|
||||||
|
class UARTSendAnalyticsEvent(mode: UARTMode) : UARTAnalyticsEvent("UART_SEND_EVENT", createParams(mode)) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun createParams(mode: UARTMode) = Bundle().apply {
|
||||||
|
putString("MODE", mode.displayName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UARTCreateConfiguration : UARTAnalyticsEvent("UART_CREATE_CONF", null)
|
||||||
|
|
||||||
|
class UARTChangeConfiguration : UARTAnalyticsEvent("UART_CHANGE_CONF", null)
|
||||||
|
|||||||
@@ -16,3 +16,8 @@ enum class Link(val displayName: String) {
|
|||||||
DFU("DFU"),
|
DFU("DFU"),
|
||||||
LOGGER("LOGGER");
|
LOGGER("LOGGER");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class UARTMode(val displayName: String) {
|
||||||
|
MACRO("MACRO"),
|
||||||
|
TEXT("TEXT")
|
||||||
|
}
|
||||||
@@ -6,16 +6,12 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import no.nordicsemi.android.analytics.AppAnalytics
|
import no.nordicsemi.android.analytics.*
|
||||||
import no.nordicsemi.android.analytics.Profile
|
|
||||||
import no.nordicsemi.android.analytics.ProfileConnectedEvent
|
|
||||||
import no.nordicsemi.android.navigation.*
|
import no.nordicsemi.android.navigation.*
|
||||||
import no.nordicsemi.android.service.IdleResult
|
import no.nordicsemi.android.service.IdleResult
|
||||||
import no.nordicsemi.android.service.SuccessResult
|
import no.nordicsemi.android.service.SuccessResult
|
||||||
import no.nordicsemi.android.uart.data.UARTConfiguration
|
import no.nordicsemi.android.uart.data.*
|
||||||
import no.nordicsemi.android.uart.data.UARTMacro
|
|
||||||
import no.nordicsemi.android.uart.data.UARTPersistentDataSource
|
import no.nordicsemi.android.uart.data.UARTPersistentDataSource
|
||||||
import no.nordicsemi.android.uart.data.UART_SERVICE_UUID
|
|
||||||
import no.nordicsemi.android.uart.repository.UARTRepository
|
import no.nordicsemi.android.uart.repository.UARTRepository
|
||||||
import no.nordicsemi.android.uart.view.*
|
import no.nordicsemi.android.uart.view.*
|
||||||
import no.nordicsemi.android.utils.exhaustive
|
import no.nordicsemi.android.utils.exhaustive
|
||||||
@@ -85,7 +81,7 @@ internal class UARTViewModel @Inject constructor(
|
|||||||
is OnCreateMacro -> addNewMacro(event.macro)
|
is OnCreateMacro -> addNewMacro(event.macro)
|
||||||
OnDeleteMacro -> deleteMacro()
|
OnDeleteMacro -> deleteMacro()
|
||||||
DisconnectEvent -> disconnect()
|
DisconnectEvent -> disconnect()
|
||||||
is OnRunMacro -> repository.runMacro(event.macro)
|
is OnRunMacro -> runMacro(event.macro)
|
||||||
NavigateUp -> navigationManager.navigateUp()
|
NavigateUp -> navigationManager.navigateUp()
|
||||||
is OnEditMacro -> onEditMacro(event)
|
is OnEditMacro -> onEditMacro(event)
|
||||||
OnEditFinish -> onEditFinish()
|
OnEditFinish -> onEditFinish()
|
||||||
@@ -95,11 +91,21 @@ internal class UARTViewModel @Inject constructor(
|
|||||||
OnEditConfiguration -> onEditConfiguration()
|
OnEditConfiguration -> onEditConfiguration()
|
||||||
ClearOutputItems -> repository.clearItems()
|
ClearOutputItems -> repository.clearItems()
|
||||||
OpenLogger -> repository.openLogger()
|
OpenLogger -> repository.openLogger()
|
||||||
is OnRunInput -> repository.sendText(event.text, event.newLineChar)
|
is OnRunInput -> sendText(event.text, event.newLineChar)
|
||||||
MacroInputSwitchClick -> onMacroInputSwitch()
|
MacroInputSwitchClick -> onMacroInputSwitch()
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun runMacro(macro: UARTMacro) {
|
||||||
|
repository.runMacro(macro)
|
||||||
|
analytics.logEvent(UARTSendAnalyticsEvent(UARTMode.MACRO))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendText(text: String, newLineChar: MacroEol) {
|
||||||
|
repository.sendText(text, newLineChar)
|
||||||
|
analytics.logEvent(UARTSendAnalyticsEvent(UARTMode.TEXT))
|
||||||
|
}
|
||||||
|
|
||||||
private fun onMacroInputSwitch() {
|
private fun onMacroInputSwitch() {
|
||||||
_state.value = _state.value.copy(isInputVisible = !state.value.isInputVisible)
|
_state.value = _state.value.copy(isInputVisible = !state.value.isInputVisible)
|
||||||
}
|
}
|
||||||
@@ -115,6 +121,7 @@ internal class UARTViewModel @Inject constructor(
|
|||||||
_state.value = _state.value.copy(selectedConfigurationName = event.name)
|
_state.value = _state.value.copy(selectedConfigurationName = event.name)
|
||||||
}
|
}
|
||||||
saveLastConfigurationName(event.name)
|
saveLastConfigurationName(event.name)
|
||||||
|
analytics.logEvent(UARTCreateConfiguration())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onEditMacro(event: OnEditMacro) {
|
private fun onEditMacro(event: OnEditMacro) {
|
||||||
@@ -127,6 +134,7 @@ internal class UARTViewModel @Inject constructor(
|
|||||||
|
|
||||||
private fun onConfigurationSelected(event: OnConfigurationSelected) {
|
private fun onConfigurationSelected(event: OnConfigurationSelected) {
|
||||||
saveLastConfigurationName(event.configuration.name)
|
saveLastConfigurationName(event.configuration.name)
|
||||||
|
analytics.logEvent(UARTChangeConfiguration())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveLastConfigurationName(name: String) {
|
private fun saveLastConfigurationName(name: String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user