From a392759ae0ac80de0311df62bd9b18e64328dde4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 21 Nov 2018 17:54:08 +0100 Subject: [PATCH] adding a few more call notification related improvements --- .../contacts/pro/activities/DialerActivity.kt | 34 ++++++++++++------- .../contacts/pro/helpers/Constants.kt | 3 +- .../pro/services/DialerCallService.kt | 31 +++++++++++++---- .../contacts/pro/services/MyCallService.kt | 4 +-- app/src/main/res/values-az/strings.xml | 2 ++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values-el/strings.xml | 2 ++ app/src/main/res/values-eu/strings.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 ++ app/src/main/res/values-hr/strings.xml | 2 ++ app/src/main/res/values-it/strings.xml | 2 ++ app/src/main/res/values-ja/strings.xml | 2 ++ app/src/main/res/values-ko-rKR/strings.xml | 2 ++ app/src/main/res/values-lt/strings.xml | 2 ++ app/src/main/res/values-pt/strings.xml | 2 ++ app/src/main/res/values-ru/strings.xml | 2 ++ app/src/main/res/values-sk/strings.xml | 2 ++ app/src/main/res/values-sv/strings.xml | 2 ++ app/src/main/res/values-tr/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 21 files changed, 83 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index f3fca781..c6d87d69 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -27,7 +27,8 @@ class DialerActivity : SimpleActivity(), SensorEventListener { private val SENSOR_SENSITIVITY = 4 private val DISCONNECT_DELAY = 3000L - private var number = "" + private var callNumber = "" + private var callStatus = Call.STATE_NEW private var isIncomingCall = false private var isCallActive = false private var callDuration = 0 @@ -43,17 +44,15 @@ class DialerActivity : SimpleActivity(), SensorEventListener { LocalBroadcastManager.getInstance(applicationContext).registerReceiver(messageReceiver, IntentFilter(DIALER_INTENT_FILTER)) if (intent.action == Intent.ACTION_CALL && intent.data != null && intent.dataString?.contains("tel:") == true) { - number = Uri.decode(intent.dataString).substringAfter("tel:") + callNumber = Uri.decode(intent.dataString).substringAfter("tel:") initViews() tryFillingOtherEndsName() - startNotificationService() - } else if (intent.action == INCOMING_CALL && intent.extras?.containsKey(CALLER_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) { + } else if (intent.action == INCOMING_CALL && intent.extras?.containsKey(CALL_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) { isIncomingCall = true - number = intent.getStringExtra(CALLER_NUMBER) + callNumber = intent.getStringExtra(CALL_NUMBER) initViews() - updateUI(intent.getIntExtra(CALL_STATUS, 0)) + updateUI(intent.getIntExtra(CALL_STATUS, Call.STATE_NEW)) tryFillingOtherEndsName() - startNotificationService() } else { toast(R.string.unknown_error_occurred) finish() @@ -69,6 +68,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener { override fun onPause() { super.onPause() sensorManager!!.unregisterListener(this) + if (!isCallActive && callStatus != Call.STATE_DISCONNECTED) { + startNotificationService() + } } override fun onDestroy() { @@ -79,7 +81,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener { private val messageReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { if (intent.extras?.containsKey(CALL_STATUS) == true) { - updateUI(intent.getIntExtra(CALL_STATUS, 0)) + updateUI(intent.getIntExtra(CALL_STATUS, Call.STATE_NEW)) } } } @@ -109,7 +111,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener { private fun startNotificationService() { Intent(this, DialerCallService::class.java).apply { - putExtra(CALLER_NUMBER, number) + putExtra(CALL_NUMBER, callNumber) + putExtra(CALL_STATUS, callStatus) + putExtra(IS_INCOMING_CALL, isIncomingCall) startService(this) } } @@ -121,13 +125,14 @@ class DialerActivity : SimpleActivity(), SensorEventListener { } private fun hangUp() { + callStatus = Call.STATE_DISCONNECTED stopNotificationService() CallManager.declineCall() finish() } private fun tryFillingOtherEndsName() { - ContactsHelper(this).getContactWithNumber(number) { + ContactsHelper(this).getContactWithNumber(callNumber) { runOnUiThread { updateOtherParticipant(it) } @@ -135,6 +140,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener { } private fun updateUI(status: Int) { + callStatus = status when (status) { Call.STATE_ACTIVE -> statusActive() Call.STATE_DISCONNECTED -> statusDisconnected() @@ -142,11 +148,12 @@ class DialerActivity : SimpleActivity(), SensorEventListener { } private fun statusActive() { + startNotificationService() isCallActive = true dialer_call_duration.beVisible() updateCallDuration() - dialer_label.text = "" + dialer_label.setText(R.string.ongoing_call) dialer_hangup_button.beVisible() dialer_incoming_accept.beGone() dialer_incoming_decline.beGone() @@ -166,6 +173,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener { stopNotificationService() timerHandler.removeCallbacksAndMessages(null) dialer_hangup_button.beGone() + dialer_label.setText(R.string.disconnected) if (isCallActive) { dialer_hangup_button.postDelayed({ finish() @@ -179,9 +187,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener { private fun updateOtherParticipant(contact: Contact?) { if (contact != null) { dialer_big_name_number.text = contact.getNameToDisplay() - dialer_number.text = number + dialer_number.text = callNumber } else { - dialer_big_name_number.text = number + dialer_big_name_number.text = callNumber dialer_number.beGone() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index fbe43487..10ce4d3e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -34,8 +34,9 @@ const val KEY_NAME = "name" // Dialer const val INCOMING_CALL = "incoming_call" -const val CALLER_NUMBER = "caller_number" +const val CALL_NUMBER = "call_number" const val CALL_STATUS = "call_status" +const val IS_INCOMING_CALL = "is_incoming_call" const val DIALER_INTENT_FILTER = "dialer_intent_filter" const val LOCATION_CONTACTS_TAB = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt index 1db8a797..d9ebd241 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/DialerCallService.kt @@ -8,21 +8,29 @@ import android.app.Service import android.content.Context import android.content.Intent import android.os.Build +import android.telecom.Call import androidx.core.app.NotificationCompat import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.DialerActivity -import com.simplemobiletools.contacts.pro.helpers.CALLER_NUMBER +import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER +import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS +import com.simplemobiletools.contacts.pro.helpers.IS_INCOMING_CALL class DialerCallService : Service() { private val CALL_NOTIFICATION_ID = 1 - private var number = "" + private var callNumber = "" + private var callStatus = Call.STATE_NEW + private var isIncomingCall = false override fun onBind(intent: Intent?) = null override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { super.onStartCommand(intent, flags, startId) - number = intent.getStringExtra(CALLER_NUMBER) + callNumber = intent.getStringExtra(CALL_NUMBER) + callStatus = intent.getIntExtra(CALL_STATUS, Call.STATE_NEW) + isIncomingCall = intent.getBooleanExtra(IS_INCOMING_CALL, false) + setupNotification() return START_STICKY } @@ -38,7 +46,7 @@ class DialerCallService : Service() { if (isOreoPlus()) { val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val name = resources.getString(R.string.app_name) - val importance = NotificationManager.IMPORTANCE_HIGH + val importance = NotificationManager.IMPORTANCE_DEFAULT NotificationChannel(channelId, name, importance).apply { enableLights(false) enableVibration(false) @@ -47,14 +55,15 @@ class DialerCallService : Service() { } val notification = NotificationCompat.Builder(applicationContext, channelId) - .setSmallIcon(R.drawable.ic_person) - .setContentTitle(number) - .setContentText(getString(R.string.calling)) + .setSmallIcon(R.drawable.ic_phone) + .setContentTitle(callNumber) + .setContentText(getCallStatusString()) .setContentIntent(getLaunchDialerIntent()) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setPriority(NotificationCompat.PRIORITY_MAX) .setOngoing(true) .setChannelId(channelId) + .setUsesChronometer(callStatus == Call.STATE_ACTIVE) startForeground(CALL_NOTIFICATION_ID, notification.build()) } @@ -65,4 +74,12 @@ class DialerCallService : Service() { intent.addCategory(Intent.CATEGORY_LAUNCHER) return PendingIntent.getActivity(this, 0, intent, 0) } + + private fun getCallStatusString(): String { + return when (callStatus) { + Call.STATE_NEW -> applicationContext.getString(if (isIncomingCall) R.string.incoming_call else R.string.calling) + Call.STATE_ACTIVE -> applicationContext.getString(R.string.ongoing_call) + else -> "" + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyCallService.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyCallService.kt index 71fa844d..dc94f9bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyCallService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/services/MyCallService.kt @@ -7,7 +7,7 @@ import android.telecom.Call import android.telecom.InCallService import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.simplemobiletools.contacts.pro.activities.DialerActivity -import com.simplemobiletools.contacts.pro.helpers.CALLER_NUMBER +import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS import com.simplemobiletools.contacts.pro.helpers.DIALER_INTENT_FILTER import com.simplemobiletools.contacts.pro.helpers.INCOMING_CALL @@ -30,7 +30,7 @@ class MyCallService : InCallService() { Intent(this, DialerActivity::class.java).apply { action = INCOMING_CALL putExtra(CALL_STATUS, call.state) - putExtra(CALLER_NUMBER, callerNumber) + putExtra(CALL_NUMBER, callerNumber) startActivity(this) } CallManager.updateCall(call) diff --git a/app/src/main/res/values-az/strings.xml b/app/src/main/res/values-az/strings.xml index 7958fd38..9b1557ed 100644 --- a/app/src/main/res/values-az/strings.xml +++ b/app/src/main/res/values-az/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Göstərmək üçün sahəni seç diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 08869b0c..edd90782 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Sichtbare Felder auswählen diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index d99f3629..24a7ff7e 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Επιλογή εμφάνισης πεδίων diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml index 49da5f48..37c847db 100644 --- a/app/src/main/res/values-eu/strings.xml +++ b/app/src/main/res/values-eu/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Hautatu erakusteko eremuak diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index dbdee9fe..916bcfd2 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Sélectionner les champs à afficher diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 96a71cdf..e3a68ed6 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Odaberi polja za prikaz diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 98ee80f9..f5538f56 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -113,6 +113,8 @@ Compositore Chiamata in corso… Incoming call from… + Ongoing call + Disconnected Seleziona i campi da mostrare diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 9a321697..f744c070 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected 表示する項目を選択 diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index c34cba44..4b92dc52 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Select fields to show diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 907d262e..ffa82445 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Pasirinkti rodomus laukelius diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index c01cfded..6955b055 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Selecione os campos a mostrar diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b673b8a9..58ed2acb 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Выберите отображаемые поля diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index bc15ab4a..3b5d5d52 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -113,6 +113,8 @@ Telefón Vytáča sa… Prichádzajúci hovor od… + Prebiehajúci hovor + Ukončený hovor Zvoľte polia na zobrazenie diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 6851d4f6..584a565c 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Välj vilka fält som ska visas diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 32ca04e4..f592c335 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Görüntülenecek alanları seç diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 08af0c67..aef6a641 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected 選擇要顯示的欄位 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa3ff8e6..0782d38f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -113,6 +113,8 @@ Dialer Calling… Incoming call from… + Ongoing call + Disconnected Select fields to show