Show alert if contact does not have suitable URI
Show alert if calling or messaging is tried on mobile account when device is in airplane mode
This commit is contained in:
@ -618,7 +618,7 @@ private fun checkOnClick(
|
||||
newUris.add(u)
|
||||
}
|
||||
|
||||
if (newUris.isEmpty()) {
|
||||
if (newUris.isEmpty() && currentState.email.trim().isEmpty()) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = ctx.getString(R.string.sip_or_tel_uri)
|
||||
showAlert.value = true
|
||||
|
||||
@ -359,16 +359,26 @@ private fun Calls(
|
||||
)
|
||||
secondButtonText.value = ctx.getString(R.string.call)
|
||||
secondAction.value = {
|
||||
handleIntent(ctx, viewModel, intent, "call")
|
||||
navController.navigate("main") {
|
||||
popUpTo("main")
|
||||
launchSingleTop = true
|
||||
if (ua.account.isMobile && Utils.isAirplaneModeOn(ctx)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = ctx.getString(R.string.no_airplane_mode)
|
||||
showAlert.value = true
|
||||
} else {
|
||||
handleIntent(ctx, viewModel, intent, "call")
|
||||
navController.navigate("main") {
|
||||
popUpTo("main")
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
thirdButtonText.value = ctx.getString(R.string.send_message)
|
||||
thirdAction.value = {
|
||||
if (ua.account.isMobile) {
|
||||
if (!Utils.isDefaultSmsApp(ctx)) {
|
||||
if (Utils.isAirplaneModeOn(ctx)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = ctx.getString(R.string.no_airplane_mode)
|
||||
showAlert.value = true
|
||||
} else if (!Utils.isDefaultSmsApp(ctx)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = ctx.getString(R.string.enable_default_messaging)
|
||||
showAlert.value = true
|
||||
|
||||
@ -582,19 +582,24 @@ private fun NewMessage(
|
||||
var msgUri = ""
|
||||
addMessage(msg)
|
||||
if (ua.account.isMobile) {
|
||||
val destination = Utils.uriUserPart(peerUri)
|
||||
if (Utils.sendSms(ctx, destination, msgText)) {
|
||||
msg.direction = MESSAGE_UP
|
||||
newMessage.value = TextFieldValue("")
|
||||
viewModel.updateAorPeerMessage(aor, peerUri, "")
|
||||
keyboardController?.hide()
|
||||
if (Utils.isAirplaneModeOn(ctx)) {
|
||||
dialogMessage.value = ctx.getString(R.string.no_airplane_mode)
|
||||
showDialog.value = true
|
||||
} else {
|
||||
Toast.makeText(
|
||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
msg.direction = MESSAGE_UP_FAIL
|
||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
||||
val destination = Utils.uriUserPart(peerUri)
|
||||
if (Utils.sendSms(ctx, destination, msgText)) {
|
||||
msg.direction = MESSAGE_UP
|
||||
newMessage.value = TextFieldValue("")
|
||||
viewModel.updateAorPeerMessage(aor, peerUri, "")
|
||||
keyboardController?.hide()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
msg.direction = MESSAGE_UP_FAIL
|
||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Utils.isTelUri(peerUri))
|
||||
|
||||
@ -594,9 +594,18 @@ private fun NewChatPeer(ctx: Context, navController: NavController, account: Acc
|
||||
val peerText = newPeer.trim()
|
||||
if (peerText.isNotEmpty()) {
|
||||
val uris = Contact.contactUris(peerText, account.isMobile)
|
||||
if (uris.isEmpty())
|
||||
makeChat(ctx, navController, account, peerText)
|
||||
else if (uris.size == 1)
|
||||
if (uris.isEmpty()) {
|
||||
if (Contact.nameExists(peerText, BaresipService.contacts, true)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = if (account.isMobile)
|
||||
String.format(ctx.getString(R.string.contact_no_tel_uri), peerText)
|
||||
else
|
||||
String.format(ctx.getString(R.string.contact_no_sip_or_tel_uri), peerText)
|
||||
showAlert.value = true
|
||||
} else {
|
||||
makeChat(ctx, navController, account, peerText)
|
||||
}
|
||||
} else if (uris.size == 1)
|
||||
makeChat(ctx, navController, account, uris[0])
|
||||
else {
|
||||
items.value = uris
|
||||
|
||||
@ -106,8 +106,11 @@ sealed class Contact {
|
||||
}
|
||||
is AndroidContact -> {
|
||||
if (c.name == name) {
|
||||
for (u in c.uris)
|
||||
for (u in c.uris) {
|
||||
if (tel && !u.startsWith("tel:"))
|
||||
continue
|
||||
uris.add(u)
|
||||
}
|
||||
return uris
|
||||
}
|
||||
}
|
||||
@ -207,7 +210,7 @@ sealed class Contact {
|
||||
cur?.close()
|
||||
val newList = mutableListOf<AndroidContact>()
|
||||
for ((_, value) in contacts)
|
||||
if (value.name != "" && value.uris.isNotEmpty())
|
||||
if (value.name != "" && (value.uris.isNotEmpty() || value.email != ""))
|
||||
newList.add(value)
|
||||
BaresipService.androidContacts.value = newList.toList()
|
||||
}
|
||||
|
||||
@ -290,7 +290,10 @@ private fun Uris(
|
||||
if (ua == null)
|
||||
Log.w(TAG, "Message clickable did not find AoR $aor")
|
||||
else {
|
||||
if (ua.account.isMobile && !Utils.isDefaultSmsApp(ctx)) {
|
||||
if (ua.account.isMobile && Utils.isAirplaneModeOn(ctx)) {
|
||||
handleDialog(ctx, ctx.getString(R.string.notice),
|
||||
ctx.getString(R.string.no_airplane_mode))
|
||||
} else if (ua.account.isMobile && !Utils.isDefaultSmsApp(ctx)) {
|
||||
handleDialog(ctx, ctx.getString(R.string.notice),
|
||||
ctx.getString(R.string.enable_default_messaging))
|
||||
} else {
|
||||
@ -321,13 +324,18 @@ private fun Uris(
|
||||
if (ua == null)
|
||||
Log.w(TAG, "Call clickable did not find AoR $aor")
|
||||
else {
|
||||
val intent = Intent(ctx, MainActivity::class.java)
|
||||
intent.putExtra("uap", ua.uap)
|
||||
intent.putExtra("peer", uri)
|
||||
handleIntent(ctx, viewModel, intent, "call")
|
||||
navController.navigate("main") {
|
||||
popUpTo("main") { inclusive = false }
|
||||
launchSingleTop = true
|
||||
if (ua.account.isMobile && Utils.isAirplaneModeOn(ctx)) {
|
||||
handleDialog(ctx, ctx.getString(R.string.notice),
|
||||
ctx.getString(R.string.no_airplane_mode))
|
||||
} else {
|
||||
val intent = Intent(ctx, MainActivity::class.java)
|
||||
intent.putExtra("uap", ua.uap)
|
||||
intent.putExtra("peer", uri)
|
||||
handleIntent(ctx, viewModel, intent, "call")
|
||||
navController.navigate("main") {
|
||||
popUpTo("main") { inclusive = false }
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ private fun ContactsScreen(navController: NavController) {
|
||||
}
|
||||
}
|
||||
line.startsWith("END:VCARD", ignoreCase = true) -> {
|
||||
if (name.isNotEmpty() && uris.isNotEmpty()) {
|
||||
if (name.isNotEmpty() && (uris.isNotEmpty() || email.isNotEmpty())) {
|
||||
val existingContact = Contact.baresipContact(name)
|
||||
if (existingContact != null) {
|
||||
var updated = false
|
||||
|
||||
@ -2046,14 +2046,26 @@ private fun callClick(ctx: Context, viewModel: ViewModel, dialerState: ViewModel
|
||||
val uriText = dialerState.callUri.value.trim()
|
||||
if (uriText.isNotEmpty()) {
|
||||
if (Utils.checkPermissions(ctx, arrayOf(RECORD_AUDIO))) {
|
||||
val uris = Contact.contactUris(uriText)
|
||||
if (uris.isEmpty())
|
||||
makeCall(
|
||||
ctx,
|
||||
viewModel,
|
||||
uriText,
|
||||
dialerState
|
||||
)
|
||||
val aor = viewModel.selectedAor.value
|
||||
val ua = UserAgent.ofAor(aor)
|
||||
val uris = Contact.contactUris(uriText, ua?.account?.isMobile ?: false)
|
||||
if (uris.isEmpty()) {
|
||||
if (Contact.nameExists(uriText, BaresipService.contacts, true)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = if (ua?.account?.isMobile == true)
|
||||
String.format(ctx.getString(R.string.contact_no_tel_uri), uriText)
|
||||
else
|
||||
String.format(ctx.getString(R.string.contact_no_sip_or_tel_uri), uriText)
|
||||
showAlert.value = true
|
||||
} else {
|
||||
makeCall(
|
||||
ctx,
|
||||
viewModel,
|
||||
uriText,
|
||||
dialerState
|
||||
)
|
||||
}
|
||||
}
|
||||
else if (uris.size == 1)
|
||||
makeCall(
|
||||
ctx,
|
||||
@ -2120,6 +2132,12 @@ private fun makeCall(ctx: Context, viewModel: ViewModel, uriText: String,
|
||||
showAlert.value = true
|
||||
return
|
||||
}
|
||||
else if (ua.account.isMobile && Utils.isAirplaneModeOn(ctx)) {
|
||||
alertTitle.value = ctx.getString(R.string.notice)
|
||||
alertMessage.value = ctx.getString(R.string.no_airplane_mode)
|
||||
showAlert.value = true
|
||||
return
|
||||
}
|
||||
else if (Utils.isAudioMode(ctx,AudioManager.MODE_IN_CALL) &&
|
||||
!Call.calls().any { it.ua.account.aor == ua.account.aor })
|
||||
Toast.makeText(ctx, R.string.call_already_active, Toast.LENGTH_SHORT).show()
|
||||
|
||||
@ -873,6 +873,13 @@ object Utils {
|
||||
Configuration.UI_MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
fun isAirplaneModeOn(ctx: Context): Boolean {
|
||||
return android.provider.Settings.Global.getInt(
|
||||
ctx.contentResolver,
|
||||
android.provider.Settings.Global.AIRPLANE_MODE_ON, 0
|
||||
) != 0
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun isPSTNCallActive(ctx: Context): Boolean {
|
||||
val tm = ctx.getSystemService(Context.TELECOM_SERVICE) as? TelecomManager ?: return false
|
||||
|
||||
@ -464,6 +464,8 @@
|
||||
on top of contacts list.</string>
|
||||
<string name="invalid_contact">Invalid contact name \'%1$s\'</string>
|
||||
<string name="contact_already_exists">Contact \'%1$s\' already exists.</string>
|
||||
<string name="contact_no_sip_or_tel_uri">Contact \'%1$s\' has no SIP or TEL URI</string>
|
||||
<string name="contact_no_tel_uri">Contact \'%1$s\' has no TEL URI</string>
|
||||
<string name="android_contact_help">If checked, this contact is added to Android contacts.</string>
|
||||
<string name="avatar_image">Profile image</string>
|
||||
<!-- Contacts Activity -->
|
||||
@ -595,6 +597,7 @@
|
||||
</string>
|
||||
<string name="no_notifications">You are not able to use this application without \"Notifications\"
|
||||
permission.</string>
|
||||
<string name="no_airplane_mode">Airplane mode is ON. Turn it OFF to use mobile account.</string>
|
||||
<string name="no_calls">baresip needs \"Microphone\" permission for voice calls.</string>
|
||||
<string name="no_video_calls">Grant \"Camera\" permission to make or answer video calls.</string>
|
||||
<string name="no_backup">You are not able create backup without \"Storage\" permission.</string>
|
||||
|
||||
Reference in New Issue
Block a user