forked from upstream-mirrors/quik
Stricter check for phone number equality
This commit is contained in:
@@ -29,14 +29,12 @@ import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.app.Person
|
||||
import androidx.core.app.RemoteInput
|
||||
import androidx.core.app.TaskStackBuilder
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import androidx.core.graphics.get
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.extensions.isImage
|
||||
@@ -48,10 +46,10 @@ import com.moez.QKSMS.receiver.DeleteMessagesReceiver
|
||||
import com.moez.QKSMS.receiver.MarkReadReceiver
|
||||
import com.moez.QKSMS.receiver.MarkSeenReceiver
|
||||
import com.moez.QKSMS.receiver.RemoteMessagingReceiver
|
||||
import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
@@ -64,7 +62,8 @@ class NotificationManagerImpl @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val prefs: Preferences,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val permissions: PermissionManager
|
||||
private val permissions: PermissionManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : com.moez.QKSMS.manager.NotificationManager {
|
||||
|
||||
companion object {
|
||||
@@ -151,14 +150,14 @@ class NotificationManagerImpl @Inject constructor(
|
||||
|
||||
if (!message.isMe()) {
|
||||
val recipient = conversation.recipients
|
||||
.firstOrNull { PhoneNumberUtils.compare(it.address, message.address) }
|
||||
.firstOrNull { phoneNumberUtils.compare(it.address, message.address) }
|
||||
|
||||
person.setName(recipient?.getDisplayName() ?: message.address)
|
||||
|
||||
person.setIcon(GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.circleCrop()
|
||||
.load(PhoneNumberUtils.stripSeparators(message.address))
|
||||
.load(message.address)
|
||||
.submit(64.dpToPx(context), 64.dpToPx(context))
|
||||
.let { futureGet -> tryOrNull(false) { futureGet.get() } }
|
||||
?.let(IconCompat::createWithBitmap))
|
||||
@@ -183,7 +182,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.circleCrop()
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.load(address)
|
||||
.submit(64.dpToPx(context), 64.dpToPx(context))
|
||||
}
|
||||
?.let { futureGet -> tryOrNull(false) { futureGet.get() } }
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.service.chooser.ChooserTarget
|
||||
import android.service.chooser.ChooserTargetService
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.os.bundleOf
|
||||
import com.moez.QKSMS.R
|
||||
@@ -59,7 +58,7 @@ class QkChooserTargetService : ChooserTargetService() {
|
||||
val request = GlideApp.with(this)
|
||||
.asBitmap()
|
||||
.circleCrop()
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.load(address)
|
||||
.submit()
|
||||
val bitmap = tryOrNull(false) { request.get() }
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.feature.compose.ComposeActivity
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
@@ -66,7 +65,7 @@ class ShortcutManagerImpl @Inject constructor(
|
||||
val request = GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.circleCrop()
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.load(address)
|
||||
.submit(shortcutManager.iconMaxWidth, shortcutManager.iconMaxHeight)
|
||||
val bitmap = tryOrNull(false) { request.get() }
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
@@ -127,7 +126,7 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
||||
photo.setImageDrawable(null)
|
||||
address?.let { address ->
|
||||
GlideApp.with(photo)
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.load(address)
|
||||
.signature(ObjectKey(lastUpdated ?: 0L))
|
||||
.into(photo)
|
||||
}
|
||||
|
||||
+6
-6
@@ -18,14 +18,15 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.blocking.numbers
|
||||
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.widget.EditText
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
|
||||
class BlockedNumberTextWatcher(private val editText: EditText) : TextWatcher {
|
||||
class BlockedNumberTextWatcher(
|
||||
private val editText: EditText,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : TextWatcher {
|
||||
|
||||
init {
|
||||
editText.addTextChangedListener(this)
|
||||
@@ -36,8 +37,7 @@ class BlockedNumberTextWatcher(private val editText: EditText) : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
val formatted = PhoneNumberUtils.formatNumber(s?.toString(), Locale.getDefault().country)
|
||||
Timber.v("onTextChanged=$s, formatted=$formatted")
|
||||
val formatted = s?.let(phoneNumberUtils::formatNumber)
|
||||
if (s?.toString() != formatted && formatted != null) {
|
||||
editText.setText(formatted)
|
||||
editText.setSelection(formatted.length)
|
||||
|
||||
+3
-1
@@ -28,6 +28,7 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
@@ -40,6 +41,7 @@ class BlockedNumbersController : QkController<BlockedNumbersView, BlockedNumbers
|
||||
|
||||
@Inject override lateinit var presenter: BlockedNumbersPresenter
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var phoneNumberUtils: PhoneNumberUtils
|
||||
|
||||
private val adapter = BlockedNumbersAdapter()
|
||||
private val saveAddressSubject: Subject<String> = PublishSubject.create()
|
||||
@@ -75,7 +77,7 @@ class BlockedNumbersController : QkController<BlockedNumbersView, BlockedNumbers
|
||||
|
||||
override fun showAddDialog() {
|
||||
val layout = LayoutInflater.from(activity).inflate(R.layout.blocked_numbers_add_dialog, null)
|
||||
val textWatcher = BlockedNumberTextWatcher(layout.input)
|
||||
val textWatcher = BlockedNumberTextWatcher(layout.input, phoneNumberUtils)
|
||||
val dialog = AlertDialog.Builder(activity!!)
|
||||
.setView(layout)
|
||||
.setPositiveButton(R.string.blocked_numbers_dialog_block) { _, _ ->
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.moez.QKSMS.feature.compose
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SmsMessage
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import com.moez.QKSMS.R
|
||||
@@ -57,6 +56,7 @@ import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.util.ActiveSubscriptionObservable
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -96,6 +96,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences,
|
||||
private val retrySending: RetrySending,
|
||||
private val sendMessage: SendMessage,
|
||||
@@ -260,10 +261,9 @@ class ComposeViewModel @Inject constructor(
|
||||
.filter { contact -> contactFilter.filter(contact, normalizedQuery) }
|
||||
|
||||
// If the entry is a valid destination, allow it as a recipient
|
||||
if (PhoneNumberUtils.isWellFormedSmsAddress(query.toString())) {
|
||||
val newAddress = PhoneNumberUtils.formatNumber(query.toString(), Locale.getDefault().country)
|
||||
val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress
|
||||
?: query.toString())))
|
||||
if (phoneNumberUtils.isPossibleNumber(query.toString())) {
|
||||
val newAddress = phoneNumberUtils.formatNumber(query)
|
||||
val newContact = Contact(numbers = RealmList(PhoneNumber(address = newAddress)))
|
||||
filteredContacts = listOf(newContact) + filteredContacts
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
@@ -57,6 +56,7 @@ import com.moez.QKSMS.feature.compose.part.PartsAdapter
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
@@ -72,6 +72,7 @@ class MessagesAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences,
|
||||
private val textViewStyler: TextViewStyler
|
||||
) : QkRealmAdapter<Message>() {
|
||||
@@ -322,7 +323,7 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
override fun get(key: String): Recipient? {
|
||||
if (super.get(key)?.isValid != true) {
|
||||
set(key, conversation?.recipients?.firstOrNull { PhoneNumberUtils.compare(it.address, key) })
|
||||
set(key, conversation?.recipients?.firstOrNull { phoneNumberUtils.compare(it.address, key) })
|
||||
}
|
||||
|
||||
return super.get(key)?.takeIf { it.isValid }
|
||||
|
||||
+4
-3
@@ -19,7 +19,6 @@
|
||||
package com.moez.QKSMS.feature.scheduled
|
||||
|
||||
import android.net.Uri
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
@@ -32,6 +31,7 @@ import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.model.ScheduledMessage
|
||||
import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.scheduled_message_list_item.view.*
|
||||
@@ -39,7 +39,8 @@ import javax.inject.Inject
|
||||
|
||||
class ScheduledMessageAdapter @Inject constructor(
|
||||
private val contactRepo: ContactRepository,
|
||||
private val dateFormatter: DateFormatter
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : QkRealmAdapter<ScheduledMessage>() {
|
||||
|
||||
private val contacts by lazy { contactRepo.getContacts() }
|
||||
@@ -91,7 +92,7 @@ class ScheduledMessageAdapter @Inject constructor(
|
||||
if (super.get(key)?.isValid != true) {
|
||||
set(key, contacts.firstOrNull { contact ->
|
||||
contact.numbers.any {
|
||||
PhoneNumberUtils.compare(it.address, key)
|
||||
phoneNumberUtils.compare(it.address, key)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.StyleSpan
|
||||
@@ -133,7 +132,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
contact?.numbers?.firstOrNull()?.address?.let { address ->
|
||||
val futureGet = GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.load(address)
|
||||
.submit(48.dpToPx(context), 48.dpToPx(context))
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user