Added setting for call overlay notification in app

This commit is contained in:
Sylvain Berfini 2021-04-27 13:46:54 +02:00
parent 336f006a2e
commit fc8d00e982
17 changed files with 61 additions and 45 deletions

View file

@ -49,7 +49,7 @@ This version is a full rewrite of the app in kotlin, using modern Android compon
### Removed
- "back-to-call" button from dialer & chat views, use notification or overlay (see call settings)
- "back-to-call" button from dialer & chat views, use notification or overlay (see call settings for in-app/system-wide overlay)
- Don't ask for "Do not disturb settings" permission anymore
- Previous translations, starting again from scratch using Weblate instead of Transifex

View file

@ -50,7 +50,7 @@ class CallSettingsFragment : GenericFragment<SettingsCallFragmentBinding>() {
binding.setBackClickListener { findNavController().popBackStack() }
binding.back.visibility = if (resources.getBoolean(R.bool.isTablet)) View.INVISIBLE else View.VISIBLE
viewModel.overlayEnabledEvent.observe(viewLifecycleOwner, {
viewModel.systemWideOverlayEnabledEvent.observe(viewLifecycleOwner, {
it.consume {
if (!Compatibility.canDrawOverlay(requireContext())) {
val intent = Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION", Uri.parse("package:${requireContext().packageName}"))
@ -81,7 +81,7 @@ class CallSettingsFragment : GenericFragment<SettingsCallFragmentBinding>() {
super.onActivityResult(requestCode, resultCode, data)
if (!Compatibility.canDrawOverlay(requireContext())) {
viewModel.overlayListener.onBoolValueChanged(false)
viewModel.systemWideOverlayListener.onBoolValueChanged(false)
}
}
}

View file

@ -68,14 +68,21 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
val overlayListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
if (newValue) overlayEnabledEvent.value = Event(true)
}
prefs.showCallOverlay = newValue
}
}
val overlay = MutableLiveData<Boolean>()
val overlayEnabledEvent = MutableLiveData<Event<Boolean>>()
val systemWideOverlayListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
if (newValue) systemWideOverlayEnabledEvent.value = Event(true)
}
prefs.systemWideCallOverlay = newValue
}
}
val systemWideOverlay = MutableLiveData<Boolean>()
val systemWideOverlayEnabledEvent = MutableLiveData<Event<Boolean>>()
val sipInfoDtmfListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
@ -162,6 +169,7 @@ class CallSettingsViewModel : GenericSettingsViewModel() {
fullScreen.value = prefs.fullScreenCallUI
overlay.value = prefs.showCallOverlay
systemWideOverlay.value = prefs.systemWideCallOverlay
sipInfoDtmf.value = core.useInfoForDtmf
rfc2833Dtmf.value = core.useRfc2833ForDtmf
autoStart.value = prefs.callRightAway

View file

@ -48,7 +48,9 @@ class CallOverlayViewModel : ViewModel() {
}
init {
displayCallOverlay.value = coreContext.core.callsNb > 0
displayCallOverlay.value = corePreferences.showCallOverlay &&
!corePreferences.systemWideCallOverlay &&
coreContext.core.callsNb > 0
coreContext.core.addListener(listener)
}
@ -60,8 +62,8 @@ class CallOverlayViewModel : ViewModel() {
}
private fun createCallOverlay() {
// If system-wide call overlay is enabled or if already visible, abort
if (corePreferences.showCallOverlay) {
// If overlay is disabled or if system-wide call overlay is enabled, abort
if (!corePreferences.showCallOverlay || corePreferences.systemWideCallOverlay) {
return
}

View file

@ -517,7 +517,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
fun createCallOverlay() {
if (!corePreferences.showCallOverlay || callOverlay != null) {
if (!corePreferences.showCallOverlay || !corePreferences.systemWideCallOverlay || callOverlay != null) {
return
}

View file

@ -239,12 +239,20 @@ class CorePreferences constructor(private val context: Context) {
config.setInt("app", "auto_answer_delay", value)
}
// Show overlay inside of application
var showCallOverlay: Boolean
get() = config.getBool("app", "call_overlay", false)
get() = config.getBool("app", "call_overlay", true)
set(value) {
config.setBool("app", "call_overlay", value)
}
// Show overlay even when app is in background, requires permission
var systemWideCallOverlay: Boolean
get() = config.getBool("app", "system_wide_call_overlay", false)
set(value) {
config.setBool("app", "system_wide_call_overlay", value)
}
var callRightAway: Boolean
get() = config.getBool("app", "call_right_away", false)
set(value) {

View file

@ -3,12 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="callOverlayViewModel"
type="org.linphone.activities.main.viewmodels.CallOverlayViewModel" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -34,11 +28,6 @@
app:navGraph="@navigation/main_nav_graph"
tools:layout="@layout/dialer_fragment" />
<include
android:id="@+id/call_overlay"
layout="@layout/call_overlay"
tools:visibility="@{callOverlayViewModel.displayCallOverlay}"/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -9,13 +9,13 @@
</data>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="@dimen/call_overlay_size"
android:layout_height="@dimen/call_overlay_size"
android:visibility="@{visibility ? View.VISIBLE : View.GONE}">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_round_primary_color"
android:contentDescription="@string/content_description_go_back_to_call"
android:adjustViewBounds="true"

View file

@ -37,8 +37,7 @@
<include
android:id="@+id/content"
layout="@layout/main_activity_content"
tools:callOverlayViewModel="@{callOverlayViewModel}"/>
layout="@layout/main_activity_content"/>
<!-- Side Menu -->
<RelativeLayout
@ -58,6 +57,15 @@
</androidx.drawerlayout.widget.DrawerLayout>
<include
android:id="@+id/call_overlay"
layout="@layout/call_overlay"
android:layout_width="@dimen/call_overlay_size"
android:layout_height="@dimen/call_overlay_size"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
tools:visibility="@{callOverlayViewModel.displayCallOverlay}"/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -3,12 +3,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="callOverlayViewModel"
type="org.linphone.activities.main.viewmodels.CallOverlayViewModel" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -34,11 +28,6 @@
app:navGraph="@navigation/main_nav_graph"
tools:layout="@layout/dialer_fragment" />
<include
android:id="@+id/call_overlay"
layout="@layout/call_overlay"
tools:visibility="@{callOverlayViewModel.displayCallOverlay}" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -109,6 +109,14 @@
linphone:listener="@{viewModel.overlayListener}"
linphone:checked="@={viewModel.overlay}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/call_settings_system_wide_overlay_title}"
linphone:subtitle="@{@string/call_settings_system_wide_overlay_summary}"
linphone:listener="@{viewModel.systemWideOverlayListener}"
linphone:checked="@={viewModel.systemWideOverlay}"
linphone:enabled="@{viewModel.overlay}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/call_settings_sipinfo_dtmf_title}"

View file

@ -460,7 +460,7 @@
<string name="call_settings_media_encryption_dtls">DTLS</string>
<string name="call_settings_encryption_mandatory_title">La encriptación de los medios es obligatoria</string>
<string name="call_settings_overlay_title">Notificación de llamada superpuesta</string>
<string name="call_settings_overlay_summary">Se le pedirá que conceda el permiso de superposición</string>
<string name="call_settings_system_wide_overlay_summary">Se le pedirá que conceda el permiso de superposición</string>
<string name="call_settings_rfc2833_dtmf_title">Enviar DTMF en banda (RFC 2833)</string>
<string name="call_settings_auto_start_title">Comienza la llamada inmediatamente</string>
<string name="call_settings_auto_answer_title">Respuesta automática a las llamadas entrantes</string>

View file

@ -554,7 +554,7 @@
<string name="chat_message_notification_hidden_content">&lt;Censuré&gt;</string>
<string name="content_description_enable_speaker">Envoyer le son vers le haut-parleur</string>
<string name="call_settings_overlay_title">Notification d\'appel flottante</string>
<string name="call_settings_overlay_summary">Une autorisation explicite est requise</string>
<string name="call_settings_system_wide_overlay_summary">Une autorisation explicite est requise</string>
<string name="chat_settings_mark_as_read_notif_dismissal_title">Marquer comme lu lorsque la notification est supprimée</string>
<string name="chat_settings_launcher_shortcuts_summary">Seront remplacés par les raccourcis de contacts si activés</string>
<string name="account_settings_transport_title">Transport</string>
@ -586,4 +586,5 @@
<string name="advanced_settings_reset_debug_logs_summary"></string>
<string name="advanced_settings_debug_title">Paramètres de deboggage</string>
<string name="advanced_settings_other_title">Autres paramètres</string>
<string name="call_settings_system_wide_overlay_title">Afficher la notification flottante en dehors de l\'app</string>
</resources>

View file

@ -71,7 +71,7 @@
<string name="video_settings_preferred_fps_title">每秒帧数FPS偏好设置</string>
<string name="call_settings_encryption_title">媒体加密</string>
<string name="call_settings_overlay_title">重叠来电通知</string>
<string name="call_settings_overlay_summary">系统将要求您授予重叠权限</string>
<string name="call_settings_system_wide_overlay_summary">系统将要求您授予重叠权限</string>
<string name="call_settings_sipinfo_dtmf_title">发送带外DTMFsSIP INFO</string>
<string name="call_settings_rfc2833_dtmf_title">发送带内DTMFsRFC 2833</string>
<string name="call_settings_auto_answer_delay_summary">毫秒</string>

View file

@ -293,7 +293,7 @@
<string name="call_settings_media_encryption_srtp">SRTP 安全實時傳輸協議</string>
<string name="call_settings_media_encryption_zrtp">ZRTP 密鑰</string>
<string name="call_settings_media_encryption_dtls">DTLS 數據包傳輸層安全性協議</string>
<string name="call_settings_overlay_summary">系統將要求您授予重疊權限</string>
<string name="call_settings_system_wide_overlay_summary">系統將要求您授予重疊權限</string>
<string name="call_settings_rfc2833_dtmf_title">發送帶内DTMFsRFC 2833</string>
<string name="call_settings_auto_start_title">立即開始通話</string>
<string name="call_settings_auto_start_summary">如果從其他應用程序開始,則通話將自動開始</string>

View file

@ -20,4 +20,5 @@
<dimen name="call_audio_routes_menu_translate_y">240dp</dimen>
<dimen name="field_button_size">20dp</dimen>
<dimen name="field_shape_margin">3dp</dimen>
<dimen name="call_overlay_size">60dp</dimen>
</resources>

View file

@ -399,7 +399,9 @@
<string name="call_settings_full_screen_title">Full screen app while in call</string>
<string name="call_settings_full_screen_summary">Hides status and navigation bars</string>
<string name="call_settings_overlay_title">Overlay call notification</string>
<string name="call_settings_overlay_summary">You will be asked to grant overlay permission</string>
<string name="call_settings_overlay_summary"></string>
<string name="call_settings_system_wide_overlay_title">Show overlay outside of app</string>
<string name="call_settings_system_wide_overlay_summary">You will be asked to grant overlay permission</string>
<string name="call_settings_sipinfo_dtmf_title">Send out-band DTMFs (SIP INFO)</string>
<string name="call_settings_sipinfo_dtmf_summary"></string>
<string name="call_settings_rfc2833_dtmf_title">Send in-band DTMFs (RFC 2833)</string>