mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 15:45:22 +00:00
Merge pull request #147 from gsmnit/code_readiblity_improvement
1. remove unused methods in MainActivity.kt
This commit is contained in:
@@ -2,6 +2,7 @@ package com.bitchat.android
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@@ -253,7 +254,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOnboardingStatus() {
|
private fun checkOnboardingStatus() {
|
||||||
android.util.Log.d("MainActivity", "Checking onboarding status")
|
Log.d("MainActivity", "Checking onboarding status")
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// Small delay to show the checking state
|
// Small delay to show the checking state
|
||||||
@@ -268,12 +269,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Check Bluetooth status and proceed with onboarding flow
|
* Check Bluetooth status and proceed with onboarding flow
|
||||||
*/
|
*/
|
||||||
private fun checkBluetoothAndProceed() {
|
private fun checkBluetoothAndProceed() {
|
||||||
// android.util.Log.d("MainActivity", "Checking Bluetooth status")
|
// Log.d("MainActivity", "Checking Bluetooth status")
|
||||||
|
|
||||||
// For first-time users, skip Bluetooth check and go straight to permissions
|
// For first-time users, skip Bluetooth check and go straight to permissions
|
||||||
// We'll check Bluetooth after permissions are granted
|
// We'll check Bluetooth after permissions are granted
|
||||||
if (permissionManager.isFirstTimeLaunch()) {
|
if (permissionManager.isFirstTimeLaunch()) {
|
||||||
android.util.Log.d("MainActivity", "First-time launch, skipping Bluetooth check - will check after permissions")
|
Log.d("MainActivity", "First-time launch, skipping Bluetooth check - will check after permissions")
|
||||||
proceedWithPermissionCheck()
|
proceedWithPermissionCheck()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -289,7 +290,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
BluetoothStatus.DISABLED -> {
|
BluetoothStatus.DISABLED -> {
|
||||||
// Show Bluetooth enable screen (should have permissions as existing user)
|
// Show Bluetooth enable screen (should have permissions as existing user)
|
||||||
android.util.Log.d("MainActivity", "Bluetooth disabled, showing enable screen")
|
Log.d("MainActivity", "Bluetooth disabled, showing enable screen")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
||||||
mainViewModel.updateBluetoothLoading(false)
|
mainViewModel.updateBluetoothLoading(false)
|
||||||
}
|
}
|
||||||
@@ -306,20 +307,20 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Proceed with permission checking
|
* Proceed with permission checking
|
||||||
*/
|
*/
|
||||||
private fun proceedWithPermissionCheck() {
|
private fun proceedWithPermissionCheck() {
|
||||||
android.util.Log.d("MainActivity", "Proceeding with permission check")
|
Log.d("MainActivity", "Proceeding with permission check")
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
delay(200) // Small delay for smooth transition
|
delay(200) // Small delay for smooth transition
|
||||||
|
|
||||||
if (permissionManager.isFirstTimeLaunch()) {
|
if (permissionManager.isFirstTimeLaunch()) {
|
||||||
android.util.Log.d("MainActivity", "First time launch, showing permission explanation")
|
Log.d("MainActivity", "First time launch, showing permission explanation")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
||||||
} else if (permissionManager.areAllPermissionsGranted()) {
|
} else if (permissionManager.areAllPermissionsGranted()) {
|
||||||
android.util.Log.d("MainActivity", "Existing user with permissions, initializing app")
|
Log.d("MainActivity", "Existing user with permissions, initializing app")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.INITIALIZING)
|
mainViewModel.updateOnboardingState(OnboardingState.INITIALIZING)
|
||||||
initializeApp()
|
initializeApp()
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.d("MainActivity", "Existing user missing permissions, showing explanation")
|
Log.d("MainActivity", "Existing user missing permissions, showing explanation")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +330,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Handle Bluetooth enabled callback
|
* Handle Bluetooth enabled callback
|
||||||
*/
|
*/
|
||||||
private fun handleBluetoothEnabled() {
|
private fun handleBluetoothEnabled() {
|
||||||
android.util.Log.d("MainActivity", "Bluetooth enabled by user")
|
Log.d("MainActivity", "Bluetooth enabled by user")
|
||||||
mainViewModel.updateBluetoothLoading(false)
|
mainViewModel.updateBluetoothLoading(false)
|
||||||
mainViewModel.updateBluetoothStatus(BluetoothStatus.ENABLED)
|
mainViewModel.updateBluetoothStatus(BluetoothStatus.ENABLED)
|
||||||
checkLocationAndProceed()
|
checkLocationAndProceed()
|
||||||
@@ -339,12 +340,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Check Location services status and proceed with onboarding flow
|
* Check Location services status and proceed with onboarding flow
|
||||||
*/
|
*/
|
||||||
private fun checkLocationAndProceed() {
|
private fun checkLocationAndProceed() {
|
||||||
android.util.Log.d("MainActivity", "Checking location services status")
|
Log.d("MainActivity", "Checking location services status")
|
||||||
|
|
||||||
// For first-time users, skip location check and go straight to permissions
|
// For first-time users, skip location check and go straight to permissions
|
||||||
// We'll check location after permissions are granted
|
// We'll check location after permissions are granted
|
||||||
if (permissionManager.isFirstTimeLaunch()) {
|
if (permissionManager.isFirstTimeLaunch()) {
|
||||||
android.util.Log.d("MainActivity", "First-time launch, skipping location check - will check after permissions")
|
Log.d("MainActivity", "First-time launch, skipping location check - will check after permissions")
|
||||||
proceedWithPermissionCheck()
|
proceedWithPermissionCheck()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -360,13 +361,13 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
LocationStatus.DISABLED -> {
|
LocationStatus.DISABLED -> {
|
||||||
// Show location enable screen (should have permissions as existing user)
|
// Show location enable screen (should have permissions as existing user)
|
||||||
android.util.Log.d("MainActivity", "Location services disabled, showing enable screen")
|
Log.d("MainActivity", "Location services disabled, showing enable screen")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
}
|
}
|
||||||
LocationStatus.NOT_AVAILABLE -> {
|
LocationStatus.NOT_AVAILABLE -> {
|
||||||
// Device doesn't support location services (very unusual)
|
// Device doesn't support location services (very unusual)
|
||||||
android.util.Log.e("MainActivity", "Location services not available")
|
Log.e("MainActivity", "Location services not available")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
}
|
}
|
||||||
@@ -377,7 +378,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Handle Location enabled callback
|
* Handle Location enabled callback
|
||||||
*/
|
*/
|
||||||
private fun handleLocationEnabled() {
|
private fun handleLocationEnabled() {
|
||||||
android.util.Log.d("MainActivity", "Location services enabled by user")
|
Log.d("MainActivity", "Location services enabled by user")
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
mainViewModel.updateLocationStatus(LocationStatus.ENABLED)
|
mainViewModel.updateLocationStatus(LocationStatus.ENABLED)
|
||||||
checkBatteryOptimizationAndProceed()
|
checkBatteryOptimizationAndProceed()
|
||||||
@@ -387,10 +388,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Handle Location disabled callback
|
* Handle Location disabled callback
|
||||||
*/
|
*/
|
||||||
private fun handleLocationDisabled(message: String) {
|
private fun handleLocationDisabled(message: String) {
|
||||||
android.util.Log.w("MainActivity", "Location services disabled or failed: $message")
|
Log.w("MainActivity", "Location services disabled or failed: $message")
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
mainViewModel.updateLocationStatus(locationStatusManager.checkLocationStatus())
|
mainViewModel.updateLocationStatus(locationStatusManager.checkLocationStatus())
|
||||||
|
|
||||||
when {
|
when {
|
||||||
mainViewModel.locationStatus.value == LocationStatus.NOT_AVAILABLE -> {
|
mainViewModel.locationStatus.value == LocationStatus.NOT_AVAILABLE -> {
|
||||||
// Show permanent error for devices without location services
|
// Show permanent error for devices without location services
|
||||||
@@ -408,7 +409,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
* Handle Bluetooth disabled callback
|
* Handle Bluetooth disabled callback
|
||||||
*/
|
*/
|
||||||
private fun handleBluetoothDisabled(message: String) {
|
private fun handleBluetoothDisabled(message: String) {
|
||||||
android.util.Log.w("MainActivity", "Bluetooth disabled or failed: $message")
|
Log.w("MainActivity", "Bluetooth disabled or failed: $message")
|
||||||
mainViewModel.updateBluetoothLoading(false)
|
mainViewModel.updateBluetoothLoading(false)
|
||||||
mainViewModel.updateBluetoothStatus(bluetoothStatusManager.checkBluetoothStatus())
|
mainViewModel.updateBluetoothStatus(bluetoothStatusManager.checkBluetoothStatus())
|
||||||
|
|
||||||
@@ -421,12 +422,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
message.contains("Permission") && permissionManager.isFirstTimeLaunch() -> {
|
message.contains("Permission") && permissionManager.isFirstTimeLaunch() -> {
|
||||||
// During first-time onboarding, if Bluetooth enable fails due to permissions,
|
// During first-time onboarding, if Bluetooth enable fails due to permissions,
|
||||||
// proceed to permission explanation screen where user will grant permissions first
|
// proceed to permission explanation screen where user will grant permissions first
|
||||||
android.util.Log.d("MainActivity", "Bluetooth enable requires permissions, proceeding to permission explanation")
|
Log.d("MainActivity", "Bluetooth enable requires permissions, proceeding to permission explanation")
|
||||||
proceedWithPermissionCheck()
|
proceedWithPermissionCheck()
|
||||||
}
|
}
|
||||||
message.contains("Permission") -> {
|
message.contains("Permission") -> {
|
||||||
// For existing users, redirect to permission explanation to grant missing permissions
|
// For existing users, redirect to permission explanation to grant missing permissions
|
||||||
android.util.Log.d("MainActivity", "Bluetooth enable requires permissions, showing permission explanation")
|
Log.d("MainActivity", "Bluetooth enable requires permissions, showing permission explanation")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
mainViewModel.updateOnboardingState(OnboardingState.PERMISSION_EXPLANATION)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@@ -437,7 +438,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOnboardingComplete() {
|
private fun handleOnboardingComplete() {
|
||||||
android.util.Log.d("MainActivity", "Onboarding completed, checking Bluetooth, Location, and Battery Optimization before initializing app")
|
Log.d("MainActivity", "Onboarding completed, checking Bluetooth and Location before initializing app")
|
||||||
|
|
||||||
// After permissions are granted, re-check Bluetooth, Location, and Battery Optimization status
|
// After permissions are granted, re-check Bluetooth, Location, and Battery Optimization status
|
||||||
val currentBluetoothStatus = bluetoothStatusManager.checkBluetoothStatus()
|
val currentBluetoothStatus = bluetoothStatusManager.checkBluetoothStatus()
|
||||||
@@ -451,14 +452,14 @@ class MainActivity : ComponentActivity() {
|
|||||||
when {
|
when {
|
||||||
currentBluetoothStatus != BluetoothStatus.ENABLED -> {
|
currentBluetoothStatus != BluetoothStatus.ENABLED -> {
|
||||||
// Bluetooth still disabled, but now we have permissions to enable it
|
// Bluetooth still disabled, but now we have permissions to enable it
|
||||||
android.util.Log.d("MainActivity", "Permissions granted, but Bluetooth still disabled. Showing Bluetooth enable screen.")
|
Log.d("MainActivity", "Permissions granted, but Bluetooth still disabled. Showing Bluetooth enable screen.")
|
||||||
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
||||||
mainViewModel.updateBluetoothLoading(false)
|
mainViewModel.updateBluetoothLoading(false)
|
||||||
}
|
}
|
||||||
currentLocationStatus != LocationStatus.ENABLED -> {
|
currentLocationStatus != LocationStatus.ENABLED -> {
|
||||||
// Location services still disabled, but now we have permissions to enable it
|
// Location services still disabled, but now we have permissions to enable it
|
||||||
android.util.Log.d("MainActivity", "Permissions granted, but Location services still disabled. Showing Location enable screen.")
|
Log.d("MainActivity", "Permissions granted, but Location services still disabled. Showing Location enable screen.")
|
||||||
mainViewModel.updateLocationStatus(currentLocationStatus)
|
mainViewModel.updateLocationStatus(currentLocationStatus)
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
@@ -472,7 +473,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// Both are enabled, proceed to app initialization
|
// Both are enabled, proceed to app initialization
|
||||||
android.util.Log.d("MainActivity", "Both Bluetooth and Location services are enabled, proceeding to initialization")
|
Log.d("MainActivity", "Both Bluetooth and Location services are enabled, proceeding to initialization")
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.INITIALIZING)
|
mainViewModel.updateOnboardingState(OnboardingState.INITIALIZING)
|
||||||
initializeApp()
|
initializeApp()
|
||||||
}
|
}
|
||||||
@@ -480,7 +481,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleOnboardingFailed(message: String) {
|
private fun handleOnboardingFailed(message: String) {
|
||||||
android.util.Log.e("MainActivity", "Onboarding failed: $message")
|
Log.e("MainActivity", "Onboarding failed: $message")
|
||||||
mainViewModel.updateErrorMessage(message)
|
mainViewModel.updateErrorMessage(message)
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.ERROR)
|
mainViewModel.updateOnboardingState(OnboardingState.ERROR)
|
||||||
}
|
}
|
||||||
@@ -550,7 +551,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeApp() {
|
private fun initializeApp() {
|
||||||
android.util.Log.d("MainActivity", "Starting app initialization")
|
Log.d("MainActivity", "Starting app initialization")
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
@@ -558,12 +559,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
// This solves the issue where app needs restart to work on first install
|
// This solves the issue where app needs restart to work on first install
|
||||||
delay(1000) // Give the system time to process permission grants
|
delay(1000) // Give the system time to process permission grants
|
||||||
|
|
||||||
android.util.Log.d("MainActivity", "Permissions verified, initializing chat system")
|
Log.d("MainActivity", "Permissions verified, initializing chat system")
|
||||||
|
|
||||||
// Ensure all permissions are still granted (user might have revoked in settings)
|
// Ensure all permissions are still granted (user might have revoked in settings)
|
||||||
if (!permissionManager.areAllPermissionsGranted()) {
|
if (!permissionManager.areAllPermissionsGranted()) {
|
||||||
val missing = permissionManager.getMissingPermissions()
|
val missing = permissionManager.getMissingPermissions()
|
||||||
android.util.Log.w("MainActivity", "Permissions revoked during initialization: $missing")
|
Log.w("MainActivity", "Permissions revoked during initialization: $missing")
|
||||||
handleOnboardingFailed("Some permissions were revoked. Please grant all permissions to continue.")
|
handleOnboardingFailed("Some permissions were revoked. Please grant all permissions to continue.")
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
@@ -572,19 +573,17 @@ class MainActivity : ComponentActivity() {
|
|||||||
meshService.delegate = chatViewModel
|
meshService.delegate = chatViewModel
|
||||||
meshService.startServices()
|
meshService.startServices()
|
||||||
|
|
||||||
android.util.Log.d("MainActivity", "Mesh service started successfully")
|
Log.d("MainActivity", "Mesh service started successfully")
|
||||||
|
|
||||||
// Handle any notification intent
|
// Handle any notification intent
|
||||||
handleNotificationIntent(intent)
|
handleNotificationIntent(intent)
|
||||||
|
|
||||||
// Small delay to ensure mesh service is fully initialized
|
// Small delay to ensure mesh service is fully initialized
|
||||||
delay(500)
|
delay(500)
|
||||||
|
Log.d("MainActivity", "App initialization complete")
|
||||||
android.util.Log.d("MainActivity", "App initialization complete")
|
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.COMPLETE)
|
mainViewModel.updateOnboardingState(OnboardingState.COMPLETE)
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.e("MainActivity", "Failed to initialize app", e)
|
Log.e("MainActivity", "Failed to initialize app", e)
|
||||||
handleOnboardingFailed("Failed to initialize the app: ${e.message}")
|
handleOnboardingFailed("Failed to initialize the app: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,11 +604,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
// Set app foreground state
|
// Set app foreground state
|
||||||
meshService.connectionManager.setAppBackgroundState(false)
|
meshService.connectionManager.setAppBackgroundState(false)
|
||||||
chatViewModel.setAppBackgroundState(false)
|
chatViewModel.setAppBackgroundState(false)
|
||||||
|
|
||||||
// Check if Bluetooth was disabled while app was backgrounded
|
// Check if Bluetooth was disabled while app was backgrounded
|
||||||
val currentBluetoothStatus = bluetoothStatusManager.checkBluetoothStatus()
|
val currentBluetoothStatus = bluetoothStatusManager.checkBluetoothStatus()
|
||||||
if (currentBluetoothStatus != BluetoothStatus.ENABLED) {
|
if (currentBluetoothStatus != BluetoothStatus.ENABLED) {
|
||||||
android.util.Log.w("MainActivity", "Bluetooth disabled while app was backgrounded")
|
Log.w("MainActivity", "Bluetooth disabled while app was backgrounded")
|
||||||
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
mainViewModel.updateBluetoothStatus(currentBluetoothStatus)
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.BLUETOOTH_CHECK)
|
||||||
mainViewModel.updateBluetoothLoading(false)
|
mainViewModel.updateBluetoothLoading(false)
|
||||||
@@ -619,7 +618,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
// Check if location services were disabled while app was backgrounded
|
// Check if location services were disabled while app was backgrounded
|
||||||
val currentLocationStatus = locationStatusManager.checkLocationStatus()
|
val currentLocationStatus = locationStatusManager.checkLocationStatus()
|
||||||
if (currentLocationStatus != LocationStatus.ENABLED) {
|
if (currentLocationStatus != LocationStatus.ENABLED) {
|
||||||
android.util.Log.w("MainActivity", "Location services disabled while app was backgrounded")
|
Log.w("MainActivity", "Location services disabled while app was backgrounded")
|
||||||
mainViewModel.updateLocationStatus(currentLocationStatus)
|
mainViewModel.updateLocationStatus(currentLocationStatus)
|
||||||
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
mainViewModel.updateOnboardingState(OnboardingState.LOCATION_CHECK)
|
||||||
mainViewModel.updateLocationLoading(false)
|
mainViewModel.updateLocationLoading(false)
|
||||||
@@ -651,7 +650,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val senderNickname = intent.getStringExtra(com.bitchat.android.ui.NotificationManager.EXTRA_SENDER_NICKNAME)
|
val senderNickname = intent.getStringExtra(com.bitchat.android.ui.NotificationManager.EXTRA_SENDER_NICKNAME)
|
||||||
|
|
||||||
if (peerID != null) {
|
if (peerID != null) {
|
||||||
android.util.Log.d("MainActivity", "Opening private chat with $senderNickname (peerID: $peerID) from notification")
|
Log.d("MainActivity", "Opening private chat with $senderNickname (peerID: $peerID) from notification")
|
||||||
|
|
||||||
// Open the private chat with this peer
|
// Open the private chat with this peer
|
||||||
chatViewModel.startPrivateChat(peerID)
|
chatViewModel.startPrivateChat(peerID)
|
||||||
@@ -661,25 +660,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restart mesh services (for debugging/troubleshooting)
|
|
||||||
*/
|
|
||||||
fun restartMeshServices() {
|
|
||||||
if (mainViewModel.onboardingState.value == OnboardingState.COMPLETE) {
|
|
||||||
lifecycleScope.launch {
|
|
||||||
try {
|
|
||||||
android.util.Log.d("MainActivity", "Restarting mesh services")
|
|
||||||
meshService.stopServices()
|
|
||||||
delay(1000)
|
|
||||||
meshService.startServices()
|
|
||||||
android.util.Log.d("MainActivity", "Mesh services restarted successfully")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
android.util.Log.e("MainActivity", "Error restarting mesh services: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
@@ -687,18 +667,18 @@ class MainActivity : ComponentActivity() {
|
|||||||
// Cleanup location status manager
|
// Cleanup location status manager
|
||||||
try {
|
try {
|
||||||
locationStatusManager.cleanup()
|
locationStatusManager.cleanup()
|
||||||
android.util.Log.d("MainActivity", "Location status manager cleaned up successfully")
|
Log.d("MainActivity", "Location status manager cleaned up successfully")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.w("MainActivity", "Error cleaning up location status manager: ${e.message}")
|
Log.w("MainActivity", "Error cleaning up location status manager: ${e.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop mesh services if app was fully initialized
|
// Stop mesh services if app was fully initialized
|
||||||
if (mainViewModel.onboardingState.value == OnboardingState.COMPLETE) {
|
if (mainViewModel.onboardingState.value == OnboardingState.COMPLETE) {
|
||||||
try {
|
try {
|
||||||
meshService.stopServices()
|
meshService.stopServices()
|
||||||
android.util.Log.d("MainActivity", "Mesh services stopped successfully")
|
Log.d("MainActivity", "Mesh services stopped successfully")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.w("MainActivity", "Error stopping mesh services in onDestroy: ${e.message}")
|
Log.w("MainActivity", "Error stopping mesh services in onDestroy: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user