Restore debug dialog
This commit is contained in:
parent
b8012ae2af
commit
96183984ef
|
@ -2,6 +2,8 @@ package org.unifiedpush.distributor.nextpush.activities
|
|||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
@ -26,6 +28,10 @@ class MainViewModel(
|
|||
var registrationsState by mutableStateOf(registrationsState)
|
||||
private set
|
||||
|
||||
private var lastDebugClickTime by mutableLongStateOf(0L)
|
||||
|
||||
private var debugClickCount by mutableIntStateOf(0)
|
||||
|
||||
fun disableBatteryOptimization() {
|
||||
viewModelScope.launch {
|
||||
mainUiState = mainUiState.copy(requireBatteryOptimization = false)
|
||||
|
@ -90,4 +96,21 @@ class MainViewModel(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun addDebugClick() {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
if (currentTime - lastDebugClickTime < 500) {
|
||||
debugClickCount++
|
||||
if (debugClickCount == 5) {
|
||||
mainUiState = mainUiState.copy(showDebugInfo = true)
|
||||
}
|
||||
} else {
|
||||
debugClickCount = 1
|
||||
}
|
||||
lastDebugClickTime = currentTime
|
||||
}
|
||||
|
||||
fun dismissDebugInfo() {
|
||||
mainUiState = mainUiState.copy(showDebugInfo = false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi
|
|||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
|
@ -11,6 +12,8 @@ import androidx.compose.foundation.layout.Row
|
|||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
|
@ -19,6 +22,7 @@ import androidx.compose.material3.Scaffold
|
|||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
@ -32,6 +36,7 @@ import org.unifiedpush.distributor.nextpush.R
|
|||
import org.unifiedpush.distributor.nextpush.activities.AppAction
|
||||
import org.unifiedpush.distributor.nextpush.activities.MainViewModel
|
||||
import org.unifiedpush.distributor.nextpush.activities.publishAction
|
||||
import org.unifiedpush.distributor.nextpush.utils.getDebugInfo
|
||||
|
||||
@Composable
|
||||
fun MainUi(viewModel: MainViewModel) {
|
||||
|
@ -113,7 +118,13 @@ fun MainUiContent(viewModel: MainViewModel, innerPadding: PaddingValues) {
|
|||
|
||||
Text(
|
||||
text = stringResource(R.string.main_applications_title),
|
||||
style = MaterialTheme.typography.headlineMedium
|
||||
style = MaterialTheme.typography.headlineMedium,
|
||||
modifier = Modifier.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
viewModel.addDebugClick()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -184,6 +195,32 @@ fun MainUiContent(viewModel: MainViewModel, innerPadding: PaddingValues) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (viewModel.mainUiState.showDebugInfo) {
|
||||
DebugDialog {
|
||||
viewModel.dismissDebugInfo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DebugDialog(onDismissRequest: () -> Unit) {
|
||||
val text = getDebugInfo()
|
||||
AlertDialog(
|
||||
title = { Text("Debug") },
|
||||
text = {
|
||||
SelectionContainer {
|
||||
Text(text)
|
||||
}
|
||||
},
|
||||
onDismissRequest = onDismissRequest,
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = onDismissRequest
|
||||
) {
|
||||
Text(stringResource(android.R.string.ok))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
|
|
|
@ -6,7 +6,8 @@ import org.unifiedpush.distributor.nextpush.account.AccountFactory
|
|||
|
||||
data class MainUiState(
|
||||
val requireBatteryOptimization: Boolean,
|
||||
val accountName: String
|
||||
val accountName: String,
|
||||
val showDebugInfo: Boolean = false
|
||||
) {
|
||||
constructor(context: Context) : this(
|
||||
requireBatteryOptimization = !(
|
||||
|
|
Loading…
Reference in New Issue