mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 12:05:20 +00:00
Wifi aware skip bluetooth (#538)
* unify connection tracker for ble and wifi * bluetooth optional
This commit is contained in:
@@ -266,6 +266,10 @@ class MainActivity : OrientationAwareActivity() {
|
||||
onRetry = {
|
||||
checkBluetoothAndProceed()
|
||||
},
|
||||
onSkip = {
|
||||
mainViewModel.skipBluetoothCheck()
|
||||
checkLocationAndProceed()
|
||||
},
|
||||
isLoading = isBluetoothLoading
|
||||
)
|
||||
}
|
||||
@@ -384,6 +388,13 @@ class MainActivity : OrientationAwareActivity() {
|
||||
private fun checkBluetoothAndProceed() {
|
||||
// Log.d("MainActivity", "Checking Bluetooth status")
|
||||
|
||||
// Check if user has skipped Bluetooth check for this session
|
||||
if (mainViewModel.isBluetoothCheckSkipped.value) {
|
||||
Log.d("MainActivity", "Bluetooth check skipped by user, proceeding to location check")
|
||||
checkLocationAndProceed()
|
||||
return
|
||||
}
|
||||
|
||||
// For first-time users, skip Bluetooth check and go straight to permissions
|
||||
// We'll check Bluetooth after permissions are granted
|
||||
if (permissionManager.isFirstTimeLaunch()) {
|
||||
@@ -754,7 +765,7 @@ class MainActivity : OrientationAwareActivity() {
|
||||
|
||||
// Check if Bluetooth was disabled while app was backgrounded
|
||||
val currentBluetoothStatus = bluetoothStatusManager.checkBluetoothStatus()
|
||||
if (currentBluetoothStatus != BluetoothStatus.ENABLED) {
|
||||
if (currentBluetoothStatus != BluetoothStatus.ENABLED && !mainViewModel.isBluetoothCheckSkipped.value) {
|
||||
Log.w("MainActivity", "Bluetooth disabled while app was backgrounded")
|
||||
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
||||
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
||||
|
||||
@@ -35,6 +35,9 @@ class MainViewModel : ViewModel() {
|
||||
private val _isBatteryOptimizationLoading = MutableStateFlow(false)
|
||||
val isBatteryOptimizationLoading: StateFlow<Boolean> = _isBatteryOptimizationLoading.asStateFlow()
|
||||
|
||||
private val _isBluetoothCheckSkipped = MutableStateFlow(false)
|
||||
val isBluetoothCheckSkipped: StateFlow<Boolean> = _isBluetoothCheckSkipped.asStateFlow()
|
||||
|
||||
// Public update functions for MainActivity
|
||||
fun updateOnboardingState(state: OnboardingState) {
|
||||
_onboardingState.value = state
|
||||
@@ -67,4 +70,8 @@ class MainViewModel : ViewModel() {
|
||||
fun updateBatteryOptimizationLoading(loading: Boolean) {
|
||||
_isBatteryOptimizationLoading.value = loading
|
||||
}
|
||||
|
||||
fun skipBluetoothCheck() {
|
||||
_isBluetoothCheckSkipped.value = true
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ fun BluetoothCheckScreen(
|
||||
status: BluetoothStatus,
|
||||
onEnableBluetooth: () -> Unit,
|
||||
onRetry: () -> Unit,
|
||||
onSkip: () -> Unit,
|
||||
isLoading: Boolean = false
|
||||
) {
|
||||
val colorScheme = MaterialTheme.colorScheme
|
||||
@@ -39,13 +40,15 @@ fun BluetoothCheckScreen(
|
||||
BluetoothDisabledContent(
|
||||
onEnableBluetooth = onEnableBluetooth,
|
||||
onRetry = onRetry,
|
||||
onSkip = onSkip,
|
||||
colorScheme = colorScheme,
|
||||
isLoading = isLoading
|
||||
)
|
||||
}
|
||||
BluetoothStatus.NOT_SUPPORTED -> {
|
||||
BluetoothNotSupportedContent(
|
||||
colorScheme = colorScheme
|
||||
colorScheme = colorScheme,
|
||||
onSkip = onSkip
|
||||
)
|
||||
}
|
||||
BluetoothStatus.ENABLED -> {
|
||||
@@ -61,6 +64,7 @@ fun BluetoothCheckScreen(
|
||||
private fun BluetoothDisabledContent(
|
||||
onEnableBluetooth: () -> Unit,
|
||||
onRetry: () -> Unit,
|
||||
onSkip: () -> Unit,
|
||||
colorScheme: ColorScheme,
|
||||
isLoading: Boolean
|
||||
) {
|
||||
@@ -77,7 +81,7 @@ private fun BluetoothDisabledContent(
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.bluetooth_required),
|
||||
text = stringResource(R.string.bluetooth_recommended),
|
||||
style = MaterialTheme.typography.headlineSmall.copy(
|
||||
fontFamily = FontFamily.Monospace,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@@ -141,20 +145,17 @@ private fun BluetoothDisabledContent(
|
||||
)
|
||||
}
|
||||
|
||||
//Since we are automatically checking bluetooth state -- commented
|
||||
|
||||
// OutlinedButton(
|
||||
// onClick = onRetry,
|
||||
// modifier = Modifier.fillMaxWidth()
|
||||
// ) {
|
||||
// Text(
|
||||
// text = "Check Again",
|
||||
// style = MaterialTheme.typography.bodyMedium.copy(
|
||||
// fontFamily = FontFamily.Monospace
|
||||
// ),
|
||||
// modifier = Modifier.padding(vertical = 4.dp)
|
||||
// )
|
||||
// }
|
||||
TextButton(
|
||||
onClick = onSkip,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.skip),
|
||||
style = MaterialTheme.typography.labelLarge.copy(
|
||||
color = colorScheme.onSurface.copy(alpha = 0.7f)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,7 +163,8 @@ private fun BluetoothDisabledContent(
|
||||
|
||||
@Composable
|
||||
private fun BluetoothNotSupportedContent(
|
||||
colorScheme: ColorScheme
|
||||
colorScheme: ColorScheme,
|
||||
onSkip: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp),
|
||||
@@ -209,6 +211,16 @@ private fun BluetoothNotSupportedContent(
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onSkip,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = colorScheme.secondary
|
||||
)
|
||||
) {
|
||||
Text(text = stringResource(R.string.continue_btn))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user