mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-18 03:48:52 +01:00
Stricter check for phone number equality
This commit is contained in:
+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