From 824a385b11e5043c21caf715e875b29dd95407f5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 1 May 2020 10:22:51 +0200 Subject: [PATCH] handle accepting call --- .../contacts/pro/activities/CallActivity.kt | 22 ++++++++++++++----- .../contacts/pro/helpers/CallManager.kt | 5 +++++ .../pro/receivers/CallActionReceiver.kt | 2 ++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt index 06af301e..3327a40b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt @@ -10,9 +10,7 @@ import android.os.Bundle import android.telecom.Call import android.widget.RemoteViews import androidx.core.app.NotificationCompat -import com.simplemobiletools.commons.extensions.notificationManager -import com.simplemobiletools.commons.extensions.setText -import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL @@ -49,7 +47,9 @@ class CallActivity : SimpleActivity() { endCall() } - call_accept.setOnClickListener { } + call_accept.setOnClickListener { + acceptCall() + } call_toggle_microphone.setOnClickListener { toggleMicrophone() @@ -60,7 +60,9 @@ class CallActivity : SimpleActivity() { } call_dialpad.setOnClickListener { } - call_end.setOnClickListener { } + call_end.setOnClickListener { + endCall() + } } private fun toggleSpeaker() { @@ -77,10 +79,20 @@ class CallActivity : SimpleActivity() { private fun updateCallState(state: Int) { when (state) { + Call.STATE_ACTIVE -> callStarted() Call.STATE_DISCONNECTED -> endCall() } } + private fun acceptCall() { + CallManager.accept() + } + + private fun callStarted() { + incoming_call_holder.beGone() + ongoing_call_holder.beVisible() + } + private fun endCall() { CallManager.reject() finish() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt index d85c3ca8..a1b70832 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.helpers import android.annotation.SuppressLint import android.telecom.Call +import android.telecom.VideoProfile // inspired by https://github.com/Chooloo/call_manage @SuppressLint("NewApi") @@ -9,6 +10,10 @@ class CallManager { companion object { var call: Call? = null + fun accept() { + call?.answer(VideoProfile.STATE_AUDIO_ONLY) + } + fun reject() { if (call != null) { if (call!!.state == Call.STATE_RINGING) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/receivers/CallActionReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/receivers/CallActionReceiver.kt index 60fe5cc2..9ae27eb3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/receivers/CallActionReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/receivers/CallActionReceiver.kt @@ -3,12 +3,14 @@ package com.simplemobiletools.contacts.pro.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL import com.simplemobiletools.contacts.pro.helpers.CallManager import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL class CallActionReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { when (intent.action) { + ACCEPT_CALL -> CallManager.accept() DECLINE_CALL -> CallManager.reject() } }