mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
adding a couple additional call screen related improvements
This commit is contained in:
@ -12,10 +12,7 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.helpers.*
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
@ -26,6 +23,8 @@ import kotlinx.android.synthetic.main.activity_dialer.*
|
||||
// incoming call handling inspired by https://github.com/mbarrben/android_dialer_replacement
|
||||
class DialerActivity : SimpleActivity(), SensorEventListener {
|
||||
private val SENSOR_SENSITIVITY = 4
|
||||
private val DISCONNECT_DELAY = 3000L
|
||||
|
||||
private var number = ""
|
||||
private var isIncomingCall = false
|
||||
private var sensorManager: SensorManager? = null
|
||||
@ -41,16 +40,13 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
|
||||
if (intent.action == Intent.ACTION_CALL && intent.data != null && intent.dataString?.contains("tel:") == true) {
|
||||
number = Uri.decode(intent.dataString).substringAfter("tel:")
|
||||
initViews()
|
||||
ContactsHelper(this).getContactWithNumber(number) {
|
||||
runOnUiThread {
|
||||
updateCallee(it)
|
||||
}
|
||||
}
|
||||
tryFillingOtherEndsName()
|
||||
} else if (intent.action == INCOMING_CALL && intent.extras?.containsKey(CALLER_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) {
|
||||
isIncomingCall = true
|
||||
number = intent.getStringExtra(CALLER_NUMBER)
|
||||
initViews()
|
||||
updateUI(intent.getSerializableExtra(CALL_STATUS) as GsmCall.Status)
|
||||
tryFillingOtherEndsName()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
finish()
|
||||
@ -88,28 +84,63 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
dialer_hangup_button.setOnClickListener { CallManager.declineCall() }
|
||||
dialer_incoming_accept.setOnClickListener { CallManager.acceptCall() }
|
||||
dialer_incoming_decline.setOnClickListener { CallManager.declineCall() }
|
||||
dialer_hangup_button.setOnClickListener {
|
||||
CallManager.declineCall()
|
||||
finish()
|
||||
}
|
||||
|
||||
dialer_incoming_accept.setOnClickListener {
|
||||
CallManager.acceptCall()
|
||||
}
|
||||
|
||||
dialer_incoming_decline.setOnClickListener {
|
||||
CallManager.declineCall()
|
||||
finish()
|
||||
}
|
||||
|
||||
dialer_hangup_button.beVisibleIf(!isIncomingCall)
|
||||
dialer_incoming_decline.beVisibleIf(isIncomingCall)
|
||||
dialer_incoming_accept.beVisibleIf(isIncomingCall)
|
||||
|
||||
calling_label.setText(if (isIncomingCall) R.string.incoming_call else R.string.calling)
|
||||
dialer_label.setText(if (isIncomingCall) R.string.incoming_call else R.string.calling)
|
||||
}
|
||||
|
||||
private fun tryFillingOtherEndsName() {
|
||||
ContactsHelper(this).getContactWithNumber(number) {
|
||||
runOnUiThread {
|
||||
updateOtherParticipant(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUI(status: GsmCall.Status) {
|
||||
|
||||
when (status) {
|
||||
GsmCall.Status.ACTIVE -> statusActive()
|
||||
GsmCall.Status.DISCONNECTED -> statusDisconnected()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCallee(contact: Contact?) {
|
||||
private fun statusActive() {
|
||||
dialer_label.text = ""
|
||||
dialer_hangup_button.beVisible()
|
||||
dialer_incoming_accept.beGone()
|
||||
dialer_incoming_decline.beGone()
|
||||
}
|
||||
|
||||
private fun statusDisconnected() {
|
||||
dialer_hangup_button.beGone()
|
||||
dialer_hangup_button.postDelayed({
|
||||
finish()
|
||||
}, DISCONNECT_DELAY)
|
||||
}
|
||||
|
||||
private fun updateOtherParticipant(contact: Contact?) {
|
||||
if (contact != null) {
|
||||
callee_big_name_number.text = contact.getNameToDisplay()
|
||||
callee_number.text = number
|
||||
dialer_big_name_number.text = contact.getNameToDisplay()
|
||||
dialer_number.text = number
|
||||
} else {
|
||||
callee_big_name_number.text = number
|
||||
callee_number.beGone()
|
||||
dialer_big_name_number.text = number
|
||||
dialer_number.beGone()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user