Enabled OnBackInvokedCallback for MainActivity
If suggestions are shown, clear icon makes them not shown
This commit is contained in:
@@ -45,14 +45,17 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:largeHeap="true"
|
android:largeHeap="true"
|
||||||
|
android:enableOnBackInvokedCallback="false"
|
||||||
android:theme="@style/Theme.Material3.DayNight.NoActionBar"
|
android:theme="@style/Theme.Material3.DayNight.NoActionBar"
|
||||||
tools:remove="android:appComponentFactory" >
|
tools:remove="android:appComponentFactory"
|
||||||
|
tools:targetApi="33">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:windowSoftInputMode="adjustResize" >
|
android:windowSoftInputMode="adjustResize" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -569,8 +569,10 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable {
|
.clickable {
|
||||||
newPeer = ""
|
if (showSuggestions)
|
||||||
showSuggestions = false
|
showSuggestions = false
|
||||||
|
else
|
||||||
|
newPeer = ""
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import android.view.WindowManager
|
|||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Chronometer
|
import android.widget.Chronometer
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import android.window.OnBackInvokedCallback
|
||||||
|
import android.window.OnBackInvokedDispatcher
|
||||||
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
|
||||||
@@ -66,8 +68,6 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
@@ -80,17 +80,14 @@ import androidx.compose.material.icons.filled.KeyboardArrowDown
|
|||||||
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
||||||
import androidx.compose.material.icons.filled.Menu
|
import androidx.compose.material.icons.filled.Menu
|
||||||
import androidx.compose.material.icons.outlined.Clear
|
import androidx.compose.material.icons.outlined.Clear
|
||||||
import androidx.compose.material3.AlertDialogDefaults
|
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
import androidx.compose.material3.ButtonColors
|
import androidx.compose.material3.ButtonColors
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ExposedDropdownMenuDefaults.outlinedTextFieldColors
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||||
@@ -99,8 +96,6 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextField
|
||||||
import androidx.compose.material3.TextFieldColors
|
|
||||||
import androidx.compose.material3.TextFieldDefaults
|
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -244,6 +239,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
val items = mutableStateOf(listOf<String>())
|
val items = mutableStateOf(listOf<String>())
|
||||||
val itemAction = mutableStateOf<(Int) -> Unit>({ index -> {} })
|
val itemAction = mutableStateOf<(Int) -> Unit>({ index -> {} })
|
||||||
|
|
||||||
|
private val backInvokedCallback = OnBackInvokedCallback {
|
||||||
|
moveTaskToBack(true)
|
||||||
|
}
|
||||||
|
|
||||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||||
override fun handleOnBackPressed() {
|
override fun handleOnBackPressed() {
|
||||||
moveTaskToBack(true)
|
moveTaskToBack(true)
|
||||||
@@ -257,7 +256,13 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
if (Build.VERSION.SDK_INT >= 33)
|
||||||
|
onBackInvokedDispatcher.registerOnBackInvokedCallback(
|
||||||
|
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
|
||||||
|
backInvokedCallback
|
||||||
|
)
|
||||||
|
else
|
||||||
|
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
|
||||||
|
|
||||||
val extraAction = intent.getStringExtra("action")
|
val extraAction = intent.getStringExtra("action")
|
||||||
Log.d(TAG, "Main onCreate ${intent.action}/${intent.data}/$extraAction")
|
Log.d(TAG, "Main onCreate ${intent.action}/${intent.data}/$extraAction")
|
||||||
@@ -986,8 +991,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable {
|
.clickable {
|
||||||
callUri.value = ""
|
if (showSuggestions.value)
|
||||||
showSuggestions.value = false
|
showSuggestions.value = false
|
||||||
|
else
|
||||||
|
callUri.value = ""
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -2017,14 +2024,24 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
|
||||||
Log.d(TAG, "Main onDestroy")
|
Log.d(TAG, "Main onDestroy")
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 33) {
|
||||||
|
onBackInvokedDispatcher.unregisterOnBackInvokedCallback(backInvokedCallback)
|
||||||
|
} else {
|
||||||
|
onBackPressedCallback.remove()
|
||||||
|
}
|
||||||
|
|
||||||
this.unregisterReceiver(screenEventReceiver)
|
this.unregisterReceiver(screenEventReceiver)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 31)
|
if (Build.VERSION.SDK_INT >= 31)
|
||||||
am.removeOnCommunicationDeviceChangedListener(comDevChangedListener)
|
am.removeOnCommunicationDeviceChangedListener(comDevChangedListener)
|
||||||
|
|
||||||
BaresipService.serviceEvent.removeObserver(serviceEventObserver)
|
BaresipService.serviceEvent.removeObserver(serviceEventObserver)
|
||||||
BaresipService.serviceEvents.clear()
|
BaresipService.serviceEvents.clear()
|
||||||
BaresipService.activities.clear()
|
BaresipService.activities.clear()
|
||||||
|
|
||||||
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
|||||||
Reference in New Issue
Block a user