Code styling improvements
This commit is contained in:
@ -90,10 +90,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
recreate()
|
recreate()
|
||||||
else {
|
else {
|
||||||
if (first.event == "stopped") {
|
if (first.event == "stopped") {
|
||||||
Log.d(
|
Log.d(TAG, "Handling service event 'stopped' with start error '${first.params[0]}'")
|
||||||
TAG,
|
|
||||||
"Handling service event 'stopped' with start error '${first.params[0]}'"
|
|
||||||
)
|
|
||||||
if (first.params[0] != "")
|
if (first.params[0] != "")
|
||||||
handleDialog(
|
handleDialog(
|
||||||
ctx = applicationContext,
|
ctx = applicationContext,
|
||||||
@ -127,15 +124,12 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.registerReceiver(screenEventReceiver, IntentFilter().apply {
|
this.registerReceiver(screenEventReceiver, IntentFilter().apply { addAction(Intent.ACTION_SCREEN_ON) })
|
||||||
addAction(Intent.ACTION_SCREEN_ON)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
comDevChangedListener = AudioManager.OnCommunicationDeviceChangedListener { device ->
|
comDevChangedListener = AudioManager.OnCommunicationDeviceChangedListener { device ->
|
||||||
if (device != null) {
|
if (device != null)
|
||||||
Log.d(TAG, "Com device changed to type ${device.type} in mode ${am.mode}")
|
Log.d(TAG, "Com device changed to type ${device.type} in mode ${am.mode}")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
||||||
}
|
}
|
||||||
@ -150,28 +144,29 @@ class MainActivity : ComponentActivity() {
|
|||||||
restart = true
|
restart = true
|
||||||
baresipService.action = "Stop"
|
baresipService.action = "Stop"
|
||||||
ContextCompat.startForegroundService(this, baresipService)
|
ContextCompat.startForegroundService(this, baresipService)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
val pm = applicationContext.packageManager
|
val pm = applicationContext.packageManager
|
||||||
val intent = pm.getLaunchIntentForPackage(applicationContext.packageName)
|
val intent = pm.getLaunchIntentForPackage(applicationContext.packageName)
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
applicationContext.startActivity(intent)
|
applicationContext.startActivity(intent)
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Failed to restart: Launch intent is null")
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Log.e(TAG, "Failed to restart: Launch intent is null")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val quitApp = {
|
val quitApp = {
|
||||||
Log.i(TAG, "Quiting baresip")
|
Log.i(TAG, "Quiting baresip")
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
|
||||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
|
|
||||||
if (BaresipService.isServiceRunning) {
|
if (BaresipService.isServiceRunning) {
|
||||||
restart = false
|
restart = false
|
||||||
baresipService.action = "Stop"
|
baresipService.action = "Stop"
|
||||||
ContextCompat.startForegroundService(this, baresipService)
|
ContextCompat.startForegroundService(this, baresipService)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
}
|
}
|
||||||
@ -184,21 +179,27 @@ class MainActivity : ComponentActivity() {
|
|||||||
when (intent?.action) {
|
when (intent?.action) {
|
||||||
ACTION_DIAL, ACTION_CALL, ACTION_VIEW ->
|
ACTION_DIAL, ACTION_CALL, ACTION_VIEW ->
|
||||||
if (BaresipService.isServiceRunning)
|
if (BaresipService.isServiceRunning)
|
||||||
callAction(applicationContext, viewModel, intent.data, if (intent?.action == ACTION_CALL) "call" else "dial")
|
callAction(
|
||||||
|
applicationContext,
|
||||||
|
viewModel,
|
||||||
|
intent.data,
|
||||||
|
if (intent?.action == ACTION_CALL) "call" else "dial"
|
||||||
|
)
|
||||||
else
|
else
|
||||||
BaresipService.callActionUri = intent.data.toString().replace("%2B", "+")
|
BaresipService.callActionUri = intent.data
|
||||||
.replace("%20", "").filterNot{setOf('-', ' ', '(', ')').contains(it)}
|
.toString().replace("%2B", "+")
|
||||||
|
.replace("%20", "")
|
||||||
|
.filterNot{setOf('-', ' ', '(', ')').contains(it)}
|
||||||
}
|
}
|
||||||
|
|
||||||
val permissions = if (Build.VERSION.SDK_INT >= 33)
|
val permissions = if (Build.VERSION.SDK_INT >= 33)
|
||||||
arrayOf(POST_NOTIFICATIONS, RECORD_AUDIO, BLUETOOTH_CONNECT)
|
arrayOf(POST_NOTIFICATIONS, RECORD_AUDIO, BLUETOOTH_CONNECT)
|
||||||
else if (Build.VERSION.SDK_INT >= 31)
|
else if (Build.VERSION.SDK_INT >= 31)
|
||||||
arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT)
|
arrayOf(RECORD_AUDIO, BLUETOOTH_CONNECT)
|
||||||
|
else if (Build.VERSION.SDK_INT < 29)
|
||||||
|
arrayOf(RECORD_AUDIO, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
|
||||||
else
|
else
|
||||||
if (Build.VERSION.SDK_INT < 29)
|
arrayOf(RECORD_AUDIO)
|
||||||
arrayOf(RECORD_AUDIO, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
|
|
||||||
else
|
|
||||||
arrayOf(RECORD_AUDIO)
|
|
||||||
|
|
||||||
requestPermissionLauncher =
|
requestPermissionLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
|
||||||
@ -216,30 +217,24 @@ class MainActivity : ComponentActivity() {
|
|||||||
shouldShow.add(permission.key)
|
shouldShow.add(permission.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (denied.contains(POST_NOTIFICATIONS) && !shouldShow.contains(POST_NOTIFICATIONS)) {
|
if (denied.contains(POST_NOTIFICATIONS) && !shouldShow.contains(POST_NOTIFICATIONS))
|
||||||
handleDialog(
|
handleDialog(
|
||||||
ctx = applicationContext,
|
ctx = applicationContext,
|
||||||
title = getString(R.string.notice),
|
title = getString(R.string.notice),
|
||||||
message = getString(R.string.no_notifications),
|
message = getString(R.string.no_notifications),
|
||||||
action = { quitRestart(false) }
|
action = { quitRestart(false) }
|
||||||
)
|
)
|
||||||
} else {
|
else if (shouldShow.isNotEmpty())
|
||||||
if (shouldShow.isNotEmpty()) {
|
handleDialog(
|
||||||
handleDialog(
|
ctx = applicationContext,
|
||||||
ctx = applicationContext,
|
title = getString(R.string.permissions_rationale),
|
||||||
title = getString(R.string.permissions_rationale),
|
message = getString(R.string.audio_permissions),
|
||||||
message = getString(R.string.audio_permissions),
|
action = { requestPermissionsLauncher.launch(permissions) }
|
||||||
action = { requestPermissionsLauncher.launch(permissions) }
|
)
|
||||||
)
|
else if (!BaresipService.isStartReceived) {
|
||||||
}
|
baresipService.action = "Start"
|
||||||
else {
|
ContextCompat.startForegroundService(this, baresipService)
|
||||||
if (!BaresipService.isStartReceived) {
|
if (atStartup) moveTaskToBack(true)
|
||||||
baresipService.action = "Start"
|
|
||||||
ContextCompat.startForegroundService(this, baresipService)
|
|
||||||
if (atStartup)
|
|
||||||
moveTaskToBack(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,11 +256,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
val route = "calls/${command.aor}"
|
val route = "calls/${command.aor}"
|
||||||
navController.navigate(route)
|
navController.navigate(route)
|
||||||
}
|
}
|
||||||
is NavigationCommand.NavigateToHome -> {
|
is NavigationCommand.NavigateToHome ->
|
||||||
navController.navigate("main") {
|
navController.navigate("main") {
|
||||||
popUpTo("main") { inclusive = true }
|
popUpTo("main") { inclusive = true }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,7 +390,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
restart = reStart
|
restart = reStart
|
||||||
baresipService.action = "Stop"
|
baresipService.action = "Stop"
|
||||||
ContextCompat.startForegroundService(this, baresipService)
|
ContextCompat.startForegroundService(this, baresipService)
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
if (reStart)
|
if (reStart)
|
||||||
quitRestart(true)
|
quitRestart(true)
|
||||||
|
|||||||
@ -29,12 +29,11 @@ fun AppTheme(
|
|||||||
val isDark = useDarkTheme || isSystemInDarkTheme()
|
val isDark = useDarkTheme || isSystemInDarkTheme()
|
||||||
|
|
||||||
val colorScheme = when {
|
val colorScheme = when {
|
||||||
useActualDynamicColors -> {
|
useActualDynamicColors ->
|
||||||
if (isDark)
|
if (isDark)
|
||||||
dynamicDarkColorScheme(context)
|
dynamicDarkColorScheme(context)
|
||||||
else
|
else
|
||||||
dynamicLightColorScheme(context)
|
dynamicLightColorScheme(context)
|
||||||
}
|
|
||||||
isDark -> darkColorScheme(
|
isDark -> darkColorScheme(
|
||||||
primary = PrimaryDark,
|
primary = PrimaryDark,
|
||||||
onPrimary = OnPrimaryDark,
|
onPrimary = OnPrimaryDark,
|
||||||
|
|||||||
Reference in New Issue
Block a user