mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-08-15 06:56:30 +00:00
* update permissions screen design * battery optimization screen * remove init screen * skip init screen on load * skip on load only * location sheet design wip * denser location sheet * location sheet layout fix
397 lines
14 KiB
Kotlin
397 lines
14 KiB
Kotlin
package com.bitchat.android.onboarding
|
|
|
|
import androidx.compose.animation.core.*
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.rememberScrollState
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.foundation.verticalScroll
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.*
|
|
import androidx.compose.material.icons.outlined.*
|
|
import androidx.compose.material3.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.rotate
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.text.font.FontFamily
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import com.bitchat.android.R
|
|
|
|
/**
|
|
* Screen shown when checking battery optimization status or requesting battery optimization disable
|
|
*/
|
|
|
|
@Composable
|
|
fun BatteryOptimizationScreen(
|
|
modifier: Modifier,
|
|
status: BatteryOptimizationStatus,
|
|
onDisableBatteryOptimization: () -> Unit,
|
|
onRetry: () -> Unit,
|
|
onSkip: () -> Unit,
|
|
isLoading: Boolean = false
|
|
) {
|
|
val context = LocalContext.current
|
|
val colorScheme = MaterialTheme.colorScheme
|
|
|
|
// Initialize preference manager
|
|
LaunchedEffect(Unit) {
|
|
BatteryOptimizationPreferenceManager.init(context)
|
|
}
|
|
|
|
Box(
|
|
modifier = modifier.padding(24.dp),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
when (status) {
|
|
BatteryOptimizationStatus.ENABLED -> {
|
|
BatteryOptimizationEnabledContent(
|
|
onDisableBatteryOptimization = onDisableBatteryOptimization,
|
|
onRetry = onRetry,
|
|
onSkip = onSkip,
|
|
colorScheme = colorScheme,
|
|
isLoading = isLoading
|
|
)
|
|
}
|
|
|
|
BatteryOptimizationStatus.DISABLED -> {
|
|
BatteryOptimizationCheckingContent(
|
|
colorScheme = colorScheme
|
|
)
|
|
}
|
|
|
|
BatteryOptimizationStatus.NOT_SUPPORTED -> {
|
|
BatteryOptimizationNotSupportedContent(
|
|
onRetry = onRetry,
|
|
colorScheme = colorScheme
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun BatteryOptimizationEnabledContent(
|
|
onDisableBatteryOptimization: () -> Unit,
|
|
onRetry: () -> Unit,
|
|
onSkip: () -> Unit,
|
|
colorScheme: ColorScheme,
|
|
isLoading: Boolean
|
|
) {
|
|
val context = LocalContext.current
|
|
|
|
Column(
|
|
modifier = Modifier.fillMaxSize()
|
|
) {
|
|
// Scrollable content area
|
|
Column(
|
|
modifier = Modifier
|
|
.weight(1f)
|
|
.verticalScroll(rememberScrollState())
|
|
.padding(bottom = 16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
) {
|
|
// Header Section - matching AboutSheet style
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(bottom = 16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
Text(
|
|
text = "bitchat",
|
|
style = MaterialTheme.typography.headlineLarge.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
fontWeight = FontWeight.Bold,
|
|
fontSize = 32.sp
|
|
),
|
|
color = colorScheme.onBackground
|
|
)
|
|
|
|
Text(
|
|
text = "battery optimization detected",
|
|
fontSize = 12.sp,
|
|
fontFamily = FontFamily.Monospace,
|
|
color = colorScheme.onBackground.copy(alpha = 0.7f)
|
|
)
|
|
}
|
|
|
|
// Battery optimization info section
|
|
Surface(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
color = colorScheme.surfaceVariant.copy(alpha = 0.25f),
|
|
shape = RoundedCornerShape(12.dp)
|
|
) {
|
|
Column(
|
|
modifier = Modifier.padding(16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
Row(
|
|
verticalAlignment = Alignment.Top,
|
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Filled.Power,
|
|
contentDescription = "Battery Optimization",
|
|
tint = colorScheme.primary,
|
|
modifier = Modifier
|
|
.padding(top = 2.dp)
|
|
.size(20.dp)
|
|
)
|
|
Column {
|
|
Text(
|
|
text = "Battery Optimization Enabled",
|
|
style = MaterialTheme.typography.titleMedium,
|
|
fontWeight = FontWeight.Medium,
|
|
color = colorScheme.onBackground
|
|
)
|
|
Spacer(modifier = Modifier.height(4.dp))
|
|
Text(
|
|
text = "bitchat needs to run in the background to maintain mesh connections. battery optimization can interrupt these connections.",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = colorScheme.onBackground.copy(alpha = 0.8f)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Benefits section
|
|
Surface(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
color = colorScheme.surfaceVariant.copy(alpha = 0.25f),
|
|
shape = RoundedCornerShape(12.dp)
|
|
) {
|
|
Column(
|
|
modifier = Modifier.padding(16.dp),
|
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
) {
|
|
Row(
|
|
verticalAlignment = Alignment.Top,
|
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Filled.CheckCircle,
|
|
contentDescription = "Benefits",
|
|
tint = colorScheme.primary,
|
|
modifier = Modifier
|
|
.padding(top = 2.dp)
|
|
.size(20.dp)
|
|
)
|
|
Column {
|
|
Text(
|
|
text = "Benefits of Disabling",
|
|
style = MaterialTheme.typography.titleMedium,
|
|
fontWeight = FontWeight.Medium,
|
|
color = colorScheme.onBackground
|
|
)
|
|
Spacer(modifier = Modifier.height(4.dp))
|
|
Text(
|
|
text = "• reliable message delivery\n• maintains mesh connectivity\n• prevents connection drops",
|
|
style = MaterialTheme.typography.bodySmall,
|
|
color = colorScheme.onBackground.copy(alpha = 0.8f)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fixed buttons at the bottom
|
|
Column(
|
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
Button(
|
|
onClick = onDisableBatteryOptimization,
|
|
modifier = Modifier.fillMaxWidth(),
|
|
enabled = !isLoading,
|
|
colors = ButtonDefaults.buttonColors(
|
|
containerColor = colorScheme.primary
|
|
)
|
|
) {
|
|
if (isLoading) {
|
|
CircularProgressIndicator(
|
|
modifier = Modifier.size(16.dp),
|
|
strokeWidth = 2.dp,
|
|
color = colorScheme.onPrimary
|
|
)
|
|
Spacer(modifier = Modifier.width(8.dp))
|
|
}
|
|
Text(
|
|
text = "Disable Battery Optimization",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
)
|
|
}
|
|
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
) {
|
|
OutlinedButton(
|
|
onClick = onRetry,
|
|
modifier = Modifier.weight(1f),
|
|
enabled = !isLoading
|
|
) {
|
|
Text(
|
|
text = "Check Again",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace
|
|
)
|
|
)
|
|
}
|
|
|
|
TextButton(
|
|
onClick = {
|
|
BatteryOptimizationPreferenceManager.setSkipped(context, true)
|
|
onSkip()
|
|
},
|
|
modifier = Modifier.weight(1f),
|
|
enabled = !isLoading
|
|
) {
|
|
Text(
|
|
text = "Skip for Now",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun BatteryOptimizationCheckingContent(
|
|
colorScheme: ColorScheme
|
|
) {
|
|
Column(
|
|
verticalArrangement = Arrangement.spacedBy(24.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
// Header Section - matching AboutSheet style
|
|
Column(
|
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
Text(
|
|
text = "bitchat",
|
|
style = MaterialTheme.typography.headlineLarge.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
fontWeight = FontWeight.Bold,
|
|
fontSize = 32.sp
|
|
),
|
|
color = colorScheme.onBackground
|
|
)
|
|
|
|
Text(
|
|
text = "battery optimization disabled",
|
|
fontSize = 12.sp,
|
|
fontFamily = FontFamily.Monospace,
|
|
color = colorScheme.onBackground.copy(alpha = 0.7f)
|
|
)
|
|
}
|
|
|
|
val infiniteTransition = rememberInfiniteTransition(label = "rotation")
|
|
val rotation by infiniteTransition.animateFloat(
|
|
initialValue = 0f,
|
|
targetValue = 360f,
|
|
animationSpec = infiniteRepeatable(
|
|
animation = tween(2000, easing = LinearEasing),
|
|
repeatMode = RepeatMode.Restart
|
|
),
|
|
label = "rotation"
|
|
)
|
|
|
|
Icon(
|
|
imageVector = Icons.Filled.BatteryStd,
|
|
contentDescription = "Checking Battery Optimization",
|
|
modifier = Modifier
|
|
.size(64.dp)
|
|
.rotate(rotation),
|
|
tint = colorScheme.primary
|
|
)
|
|
|
|
Text(
|
|
text = "bitchat can run reliably in the background",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
color = colorScheme.onBackground.copy(alpha = 0.8f)
|
|
),
|
|
textAlign = TextAlign.Center
|
|
)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun BatteryOptimizationNotSupportedContent(
|
|
onRetry: () -> Unit,
|
|
colorScheme: ColorScheme
|
|
) {
|
|
Column(
|
|
verticalArrangement = Arrangement.spacedBy(24.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
// Header Section - matching AboutSheet style
|
|
Column(
|
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
) {
|
|
Text(
|
|
text = "bitchat",
|
|
style = MaterialTheme.typography.headlineLarge.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
fontWeight = FontWeight.Bold,
|
|
fontSize = 32.sp
|
|
),
|
|
color = colorScheme.onBackground
|
|
)
|
|
|
|
Text(
|
|
text = "battery optimization not required",
|
|
fontSize = 12.sp,
|
|
fontFamily = FontFamily.Monospace,
|
|
color = colorScheme.onBackground.copy(alpha = 0.7f)
|
|
)
|
|
}
|
|
|
|
Icon(
|
|
imageVector = Icons.Filled.CheckCircle,
|
|
contentDescription = "Battery Optimization Not Supported",
|
|
modifier = Modifier.size(64.dp),
|
|
tint = colorScheme.primary
|
|
)
|
|
|
|
Text(
|
|
text = "your device doesn't require battery optimization settings. bitchat will run normally.",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
color = colorScheme.onBackground.copy(alpha = 0.8f)
|
|
),
|
|
textAlign = TextAlign.Center
|
|
)
|
|
|
|
Button(
|
|
onClick = onRetry,
|
|
modifier = Modifier.fillMaxWidth(),
|
|
colors = ButtonDefaults.buttonColors(
|
|
containerColor = colorScheme.primary
|
|
)
|
|
) {
|
|
Text(
|
|
text = "Continue",
|
|
style = MaterialTheme.typography.bodyMedium.copy(
|
|
fontFamily = FontFamily.Monospace,
|
|
fontWeight = FontWeight.Bold
|
|
)
|
|
)
|
|
}
|
|
}
|
|
} |