Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion app/src/main/java/com/spop/poverlay/ConfigurationPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ fun ConfigurationPage(viewModel: ConfigurationViewModel) {
viewModel.bleFtmsDeviceName.collectAsStateWithLifecycle(
initialValue = "Grupetto FTMS"
)
val showOverlay by
viewModel.showOverlay.collectAsStateWithLifecycle(initialValue = true)
StartServicePage(
timerShownWhenMinimized,
viewModel::onShowTimerWhenMinimizedClicked,
bleTxEnabled,
viewModel::onBleTxEnabledClicked,
bleFtmsDeviceName,
showOverlay,
viewModel::onShowOverlayClicked,
viewModel::onStartServiceClicked,
viewModel::onRestartClicked,
viewModel::onClickedRelease,
Expand All @@ -69,6 +73,8 @@ private fun StartServicePage(
bleTxEnabled: Boolean,
onBleTxEnabledToggled: (Boolean) -> Unit,
bleFtmsDeviceName: String,
showOverlay: Boolean,
onShowOverlayToggled: (Boolean) -> Unit,
onClickedStartOverlay: () -> Unit,
onClickedRestartApp: () -> Unit,
onClickedRelease: (Release) -> Unit,
Expand All @@ -90,7 +96,7 @@ private fun StartServicePage(
onClick = onClickedStartOverlay,
) {
Text(
text = "Click here to start the overlay",
text = if (showOverlay) "Click here to start the overlay" else "Start service (BLE only)",
fontSize = 30.sp,
fontFamily = LatoFontFamily,
fontWeight = FontWeight.Bold,
Expand All @@ -104,6 +110,13 @@ private fun StartServicePage(
onCheckedChange = onTimerShownWhenMinimizedToggled
)
}
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = "Show overlay on screen?", fontSize = 20.sp)
Checkbox(
checked = showOverlay,
onCheckedChange = onShowOverlayToggled
)
}
// BLE FTMS Settings
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
Expand All @@ -125,6 +138,15 @@ private fun StartServicePage(
fontSize = 14.sp
)
}

if (!showOverlay) {
Spacer(modifier = Modifier.height(4.dp))
Text(
text = "ℹ️ BLE transmission is active without overlay display",
fontSize = 14.sp,
color = Color.Blue
)
}
} else {
Spacer(modifier = Modifier.height(8.dp))

Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/com/spop/poverlay/ConfigurationRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class ConfigurationRepository(context: Context, lifecycleOwner: LifecycleOwner)
enum class Preferences(val key: String) {
ShowTimerWhenMinimized("showTimerWhenMinimized"),
BleTxEnabled("bleTxEnabled"),
BleFtmsDeviceName("bleFtmsDeviceName"),
SerialNumber("serialNumber")
BleFtmsDeviceName("bleFtmsDeviceName"),
SerialNumber("serialNumber"),
ShowOverlay("showOverlay")
}

companion object {
Expand All @@ -28,11 +29,13 @@ class ConfigurationRepository(context: Context, lifecycleOwner: LifecycleOwner)
private val mutableBleTxEnabled = MutableStateFlow(true)
private val mutableBleFtmsDeviceName = MutableStateFlow("Grupetto FTMS")
private val mutableSerialNumber = MutableStateFlow("")
private val mutableShowOverlay = MutableStateFlow(true)

val showTimerWhenMinimized = mutableShowTimerWhenMinimized
val bleTxEnabled = mutableBleTxEnabled
val bleFtmsDeviceName = mutableBleFtmsDeviceName
val serialNumber = mutableSerialNumber
val showOverlay = mutableShowOverlay

private val sharedPreferences: SharedPreferences

Expand Down Expand Up @@ -87,6 +90,13 @@ class ConfigurationRepository(context: Context, lifecycleOwner: LifecycleOwner)
}
}

fun setShowOverlay(show: Boolean) {
mutableShowOverlay.value = show
sharedPreferences.edit {
putBoolean(Preferences.ShowOverlay.key, show)
}
}

private fun generateSerialHex(): String {
val value = kotlin.random.Random.nextInt(0x10000)
return value.toString(16).padStart(4, '0').uppercase()
Expand All @@ -105,6 +115,10 @@ class ConfigurationRepository(context: Context, lifecycleOwner: LifecycleOwner)
sharedPreferences
.getString(Preferences.BleFtmsDeviceName.key, "Grupetto FTMS") ?: "Grupetto FTMS"

mutableShowOverlay.value =
sharedPreferences
.getBoolean(Preferences.ShowOverlay.key, true)

// Ensure a serial number exists and keep it in memory
val existingSerial = sharedPreferences.getString(Preferences.SerialNumber.key, null)
val ensuredSerial = if (existingSerial.isNullOrEmpty()) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/spop/poverlay/ConfigurationViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ConfigurationViewModel(
val bleFtmsDeviceName
get() = configurationRepository.bleFtmsDeviceName

val showOverlay
get() = configurationRepository.showOverlay

private val bleServer = (application as GrupettoApplication).bleServer

init {
Expand All @@ -63,6 +66,10 @@ class ConfigurationViewModel(
configurationRepository.setShowTimerWhenMinimized(isChecked)
}

fun onShowOverlayClicked(isChecked: Boolean) {
configurationRepository.setShowOverlay(isChecked)
}

fun onBleTxEnabledClicked(isChecked: Boolean) {
configurationRepository.setBleTxEnabled(isChecked)
if (isChecked) {
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/spop/poverlay/overlay/OverlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ class OverlayService : LifecycleEnabledService() {
}

private fun buildDialog() {
val configurationRepository = ConfigurationRepository(applicationContext, this)

// Check if overlay should be shown
if (!configurationRepository.showOverlay.value) {
// Skip overlay creation when disabled - BLE is handled by the application
return
}

val wm = getSystemService(WINDOW_SERVICE) as WindowManager
val screenSize = Size(
resources.displayMetrics.widthPixels.toFloat(),
Expand Down Expand Up @@ -123,7 +131,7 @@ class OverlayService : LifecycleEnabledService() {

val timerViewModel = OverlayTimerViewModel(
application,
ConfigurationRepository(applicationContext, this)
configurationRepository
)
val dialogViewModel = OverlayDialogViewModel(screenSize, sensorViewModel.isMinimized)

Expand Down