diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipContactScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipContactScreen.kt index 359c2900..3f7681a4 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipContactScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipContactScreen.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt index 14dbe34b..90eab376 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsScreen.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatScreen.kt index 194663e7..479e4f3b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatScreen.kt @@ -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)) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatsScreen.kt index e0971ffa..fc7866eb 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatsScreen.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index d5276445..5c08d95a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -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() 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() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt index e5438deb..ee05e15d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactScreen.kt @@ -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 + } } } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt index 9c02dd62..b6dda2dd 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactsScreen.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt index 18e7139f..a4710abd 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainScreen.kt @@ -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() diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 43bea4cb..ef322315 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bc02cf09..0c991c4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -464,6 +464,8 @@ on top of contacts list. Invalid contact name \'%1$s\' Contact \'%1$s\' already exists. + Contact \'%1$s\' has no SIP or TEL URI + Contact \'%1$s\' has no TEL URI If checked, this contact is added to Android contacts. Profile image @@ -595,6 +597,7 @@ You are not able to use this application without \"Notifications\" permission. + Airplane mode is ON. Turn it OFF to use mobile account. baresip needs \"Microphone\" permission for voice calls. Grant \"Camera\" permission to make or answer video calls. You are not able create backup without \"Storage\" permission.