Enabled OnBackInvokedCallback in all activities
This commit is contained in:
@ -45,7 +45,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:largeHeap="true"
|
||||
android:enableOnBackInvokedCallback="false"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:theme="@style/Theme.Material3.DayNight.NoActionBar"
|
||||
tools:remove="android:appComponentFactory"
|
||||
tools:targetApi="33">
|
||||
@ -55,7 +55,6 @@
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:windowSoftInputMode="adjustResize" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@ -77,6 +76,14 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AboutActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:label="@string/about_title"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:parentActivityName=".MainActivity" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AccountsActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
@ -171,14 +178,6 @@
|
||||
android:label="@string/chat" >
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AboutActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:label="@string/about_title"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:parentActivityName=".MainActivity" >
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".BaresipService"
|
||||
android:enabled="true"
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -34,6 +37,10 @@ import androidx.compose.ui.unit.dp
|
||||
|
||||
class AboutActivity : ComponentActivity() {
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -46,6 +53,14 @@ class AboutActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
Utils.addActivity("about")
|
||||
|
||||
val aboutTitle = String.format(getString(R.string.about_title))
|
||||
@ -62,9 +77,6 @@ class AboutActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -114,6 +126,15 @@ class AboutActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("about")
|
||||
setResult(RESULT_CANCELED, Intent())
|
||||
|
||||
@ -2,7 +2,10 @@ package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -133,6 +136,10 @@ class AccountActivity : ComponentActivity() {
|
||||
private val showAlert = mutableStateOf(false)
|
||||
private val showStun = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -145,6 +152,14 @@ class AccountActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
|
||||
Utils.addActivity("account,$aor")
|
||||
@ -207,10 +222,6 @@ class AccountActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
// Api.account_debug(acc.accp)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -1619,6 +1630,15 @@ class AccountActivity : ComponentActivity() {
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun returnResult(code: Int) {
|
||||
val i = Intent()
|
||||
if (code == RESULT_OK)
|
||||
|
||||
@ -2,8 +2,11 @@ package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -82,6 +85,10 @@ class AccountsActivity : ComponentActivity() {
|
||||
private val alertMessage = mutableStateOf("")
|
||||
private val showAlert = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -94,6 +101,14 @@ class AccountsActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title = String.format(getString(R.string.accounts))
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
@ -114,9 +129,6 @@ class AccountsActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -468,6 +480,15 @@ class AccountsActivity : ComponentActivity() {
|
||||
showAccounts.value = true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun saveAccounts() {
|
||||
|
||||
@ -4,7 +4,10 @@ import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -61,6 +64,10 @@ class AndroidContactActivity : ComponentActivity() {
|
||||
|
||||
private var color = 0
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -73,6 +80,14 @@ class AndroidContactActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
name = intent.getStringExtra("name")!!
|
||||
|
||||
@ -84,6 +99,8 @@ class AndroidContactActivity : ComponentActivity() {
|
||||
goBack()
|
||||
}
|
||||
|
||||
Utils.addActivity("android contact, $name")
|
||||
|
||||
setContent {
|
||||
AppTheme {
|
||||
Surface(
|
||||
@ -94,10 +111,6 @@ class AndroidContactActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Utils.addActivity("android contact, $name")
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -268,6 +281,15 @@ class AndroidContactActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("android contact,$name")
|
||||
setResult(RESULT_CANCELED, Intent(this, MainActivity::class.java))
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -77,6 +80,10 @@ class AudioActivity : ComponentActivity() {
|
||||
private val alertMessage = mutableStateOf("")
|
||||
private val showAlert = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -89,6 +96,14 @@ class AudioActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title = String.format(getString(R.string.configuration))
|
||||
|
||||
Utils.addActivity("audio")
|
||||
@ -106,8 +121,6 @@ class AudioActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -642,6 +655,15 @@ class AudioActivity : ComponentActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("audio")
|
||||
finish()
|
||||
|
||||
@ -9,10 +9,13 @@ import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Matrix
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.ContactsContract.CommonDataKinds
|
||||
import android.provider.ContactsContract.Contacts.Data
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
@ -105,6 +108,10 @@ class BaresipContactActivity : ComponentActivity() {
|
||||
private val textAvatarColor = mutableIntStateOf(0)
|
||||
private val imageAvatarUri = mutableStateOf("")
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -117,6 +124,14 @@ class BaresipContactActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title: String
|
||||
|
||||
new = intent.getBooleanExtra("new", false)
|
||||
@ -150,6 +165,8 @@ class BaresipContactActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
Utils.addActivity("baresip contact,$new,$uriOrName")
|
||||
|
||||
setContent {
|
||||
AppTheme {
|
||||
Surface(
|
||||
@ -160,10 +177,6 @@ class BaresipContactActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Utils.addActivity("baresip contact,$new,$uriOrName")
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -687,6 +700,15 @@ class BaresipContactActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("baresip contact,$new,$uriOrName")
|
||||
setResult(RESULT_CANCELED, Intent(this, MainActivity::class.java))
|
||||
|
||||
@ -3,8 +3,11 @@ package com.tutpro.baresip
|
||||
import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.MediaPlayer
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -67,6 +70,10 @@ class CallDetailsActivity : ComponentActivity() {
|
||||
private val encPlayer = MediaPlayer()
|
||||
private var position = 0
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -79,6 +86,14 @@ class CallDetailsActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
account = Account.ofAor(aor)!!
|
||||
peer = intent.getStringExtra("peer")!!
|
||||
@ -98,8 +113,6 @@ class CallDetailsActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -362,6 +375,15 @@ class CallDetailsActivity : ComponentActivity() {
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("call_details,$aor,$peer,$position")
|
||||
decPlayer.stop()
|
||||
|
||||
@ -4,7 +4,10 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -70,6 +73,10 @@ class CallsActivity : ComponentActivity() {
|
||||
|
||||
private var aor = ""
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -82,6 +89,14 @@ class CallsActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title = String.format(getString(R.string.call_history))
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
@ -103,9 +118,6 @@ class CallsActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
account.missedCalls = false
|
||||
invalidateOptionsMenu()
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -439,14 +451,23 @@ class CallsActivity : ComponentActivity() {
|
||||
returnResult()
|
||||
}
|
||||
|
||||
private fun returnResult() {
|
||||
setResult(RESULT_CANCELED, Intent())
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
MainActivity.activityAor = aor
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
private fun returnResult() {
|
||||
setResult(RESULT_CANCELED, Intent())
|
||||
finish()
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun aorGenerateHistory(aor: String) {
|
||||
|
||||
@ -2,11 +2,14 @@ package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -98,6 +101,10 @@ class ChatActivity : ComponentActivity() {
|
||||
private var unsentMessage = ""
|
||||
private var keyboardController: SoftwareKeyboardController? = null
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -110,6 +117,14 @@ class ChatActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
peerUri = intent.getStringExtra("peer")!!
|
||||
account = UserAgent.ofAor(aor)!!.account
|
||||
@ -156,8 +171,6 @@ class ChatActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -622,6 +635,15 @@ class ChatActivity : ComponentActivity() {
|
||||
MainActivity.activityAor = aor
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
var save = false
|
||||
for (m in chatMessages) {
|
||||
|
||||
@ -3,8 +3,11 @@ package com.tutpro.baresip
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -99,6 +102,10 @@ class ChatsActivity: ComponentActivity() {
|
||||
private val alertMessage = mutableStateOf("")
|
||||
private val showAlert = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -111,6 +118,14 @@ class ChatsActivity: ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.extras!!.getString("aor")!!
|
||||
Utils.addActivity("chats,$aor")
|
||||
account = UserAgent.ofAor(aor)!!.account
|
||||
@ -135,9 +150,6 @@ class ChatsActivity: ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -670,6 +682,15 @@ class ChatsActivity: ComponentActivity() {
|
||||
_uaMessages.value = uaMessages(aor)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("chats,$aor")
|
||||
returnResult()
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -65,6 +68,10 @@ class CodecsActivity : ComponentActivity() {
|
||||
private val alertMessage = mutableStateOf("")
|
||||
private val showAlert = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -77,6 +84,14 @@ class CodecsActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
media = intent.getStringExtra("media")!!
|
||||
|
||||
@ -114,8 +129,6 @@ class CodecsActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -353,4 +366,12 @@ class CodecsActivity : ComponentActivity() {
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -129,6 +131,10 @@ class ConfigActivity : ComponentActivity() {
|
||||
private val onNegativeClicked = mutableStateOf({})
|
||||
private val showDialog = mutableStateOf(false)
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -201,6 +207,14 @@ class ConfigActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title = String.format(getString(R.string.configuration))
|
||||
|
||||
Utils.addActivity("config")
|
||||
@ -291,8 +305,6 @@ class ConfigActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -1279,6 +1291,12 @@ class ConfigActivity : ComponentActivity() {
|
||||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (managingOverlayPermission) {
|
||||
@ -1287,10 +1305,13 @@ class ConfigActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
requestPermissionLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun isAppearOnTopPermissionGranted(ctx: Context): Boolean {
|
||||
|
||||
@ -4,9 +4,12 @@ import android.app.Activity
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.provider.ContactsContract
|
||||
import android.window.OnBackInvokedCallback
|
||||
import android.window.OnBackInvokedDispatcher
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -71,6 +74,10 @@ class ContactsActivity : ComponentActivity() {
|
||||
private var newAndroidName: String? = null
|
||||
private var lastClick: Long = 0
|
||||
|
||||
private val backInvokedCallback = OnBackInvokedCallback {
|
||||
goBack()
|
||||
}
|
||||
|
||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
goBack()
|
||||
@ -91,6 +98,14 @@ class ContactsActivity : ComponentActivity() {
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 33)
|
||||
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||
backInvokedCallback
|
||||
)
|
||||
else
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
|
||||
val title = String.format(getString(R.string.contacts))
|
||||
|
||||
aor = intent.getStringExtra("aor")!!
|
||||
@ -126,8 +141,6 @@ class ContactsActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@ -419,6 +432,15 @@ class ContactsActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||
} else {
|
||||
onBackPressedCallback.remove()
|
||||
}
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
BaresipService.activities.remove("contacts,$aor")
|
||||
setResult(RESULT_OK, Intent())
|
||||
|
||||
Reference in New Issue
Block a user