unregister the calls callback after the call

This commit is contained in:
tibbi 2020-05-01 13:44:28 +02:00
parent cca5de0bef
commit 390c4f8b54
2 changed files with 12 additions and 4 deletions

View File

@ -15,7 +15,10 @@ import android.view.WindowManager
import android.widget.RemoteViews import android.widget.RemoteViews
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.MINUTE_SECONDS
import com.simplemobiletools.commons.helpers.isOreoMr1Plus
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.helpers.isQPlus
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
import com.simplemobiletools.contacts.pro.helpers.CallManager import com.simplemobiletools.contacts.pro.helpers.CallManager
@ -48,13 +51,14 @@ class CallActivity : SimpleActivity() {
updateOtherPersonsInfo() updateOtherPersonsInfo()
initProximitySensor() initProximitySensor()
CallManager.registerCallback(getCallCallback()) CallManager.registerCallback(callCallback)
updateCallState(CallManager.getState()) updateCallState(CallManager.getState())
} }
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
notificationManager.cancel(CALL_NOTIFICATION_ID) notificationManager.cancel(CALL_NOTIFICATION_ID)
CallManager.unregisterCallback(callCallback)
} }
private fun initButtons() { private fun initButtons() {
@ -133,7 +137,7 @@ class CallActivity : SimpleActivity() {
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
fun getCallCallback() = object : Call.Callback() { private val callCallback = object : Call.Callback() {
override fun onStateChanged(call: Call, state: Int) { override fun onStateChanged(call: Call, state: Int) {
super.onStateChanged(call, state) super.onStateChanged(call, state)
updateCallState(state) updateCallState(state)
@ -158,7 +162,7 @@ class CallActivity : SimpleActivity() {
private fun initProximitySensor() { private fun initProximitySensor() {
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "simple_contacts_proximity_wake_lock") proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "com.simplemobiletools.contacts.pro:wake_lock")
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")

View File

@ -35,6 +35,10 @@ class CallManager {
} }
} }
fun unregisterCallback(callback: Call.Callback) {
call?.unregisterCallback(callback)
}
fun getState() = if (call == null) { fun getState() = if (call == null) {
Call.STATE_DISCONNECTED Call.STATE_DISCONNECTED
} else { } else {