fix a glitch with Save/Discard dialog appearing, when it shouldnt

This commit is contained in:
tibbi 2022-02-07 21:57:47 +01:00
parent d208a670c0
commit f135d347bf
2 changed files with 11 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import android.os.Bundle
import android.provider.ContactsContract.CommonDataKinds
import android.provider.ContactsContract.CommonDataKinds.*
import android.provider.MediaStore
import android.telephony.PhoneNumberUtils
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
@ -473,6 +474,7 @@ class EditContactActivity : ContactActivity() {
numberHolder!!.apply {
contact_number.setText(number.value)
contact_number.tag = number.normalizedNumber
setupPhoneNumberTypePicker(contact_number_type, number.type, number.label)
if (highlightLastPhoneNumber && index == contact!!.phoneNumbers.size - 1) {
numberViewToColor = contact_number
@ -1022,7 +1024,15 @@ class EditContactActivity : ContactActivity() {
val numberLabel = if (numberType == Phone.TYPE_CUSTOM) numberHolder.contact_number_type.value else ""
if (number.isNotEmpty()) {
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, number.normalizePhoneNumber()))
var normalizedNumber = number.normalizePhoneNumber()
// fix a glitch when onBackPressed the app thinks that a number changed because we fetched
// normalized number +421903123456, then at getting it from the input field we get 0903123456, can happen at WhatsApp contacts
val fetchedNormalizedNumber = numberHolder.contact_number.tag?.toString() ?: ""
if (PhoneNumberUtils.compare(number.normalizePhoneNumber(), fetchedNormalizedNumber)) {
normalizedNumber = fetchedNormalizedNumber
}
phoneNumbers.add(PhoneNumber(number, numberType, numberLabel, normalizedNumber))
}
}
return phoneNumbers

View File

@ -97,7 +97,6 @@ data class Contact(
private fun compareUsingIds(other: Contact): Int {
val firstId = id
val secondId = other.id
return firstId.compareTo(secondId)
}