mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Prepopulate find number with local user country code.
This commit is contained in:
committed by
Alex Hart
parent
957221e118
commit
c10c64a6a6
@@ -5,9 +5,15 @@
|
||||
|
||||
package org.thoughtcrime.securesms.recipients.ui.findby
|
||||
|
||||
import com.google.i18n.phonenumbers.NumberParseException
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||
import org.signal.core.util.orNull
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.registration.util.CountryPrefix
|
||||
|
||||
/**
|
||||
* State for driving find by number/username screen.
|
||||
*/
|
||||
data class FindByState(
|
||||
val mode: FindByMode,
|
||||
val userEntry: String = "",
|
||||
@@ -17,4 +23,21 @@ data class FindByState(
|
||||
val selectedCountryPrefix: CountryPrefix = supportedCountryPrefixes.first(),
|
||||
val countryPrefixSearchEntry: String = "",
|
||||
val isLookupInProgress: Boolean = false
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun startingState(self: Recipient, mode: FindByMode): FindByState {
|
||||
val countryCode: Int = try {
|
||||
PhoneNumberUtil.getInstance()
|
||||
.parse(self.e164.orNull(), null)
|
||||
.countryCode
|
||||
} catch (e: NumberParseException) {
|
||||
-1
|
||||
}
|
||||
|
||||
val state = FindByState(mode = mode)
|
||||
return state.copy(
|
||||
selectedCountryPrefix = state.supportedCountryPrefixes.firstOrNull { it.digits == countryCode } ?: state.supportedCountryPrefixes.first()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ class FindByViewModel(
|
||||
) : ViewModel() {
|
||||
|
||||
private val internalState = mutableStateOf(
|
||||
FindByState(
|
||||
mode = mode
|
||||
)
|
||||
FindByState.startingState(self = Recipient.self(), mode = mode)
|
||||
)
|
||||
|
||||
val state: State<FindByState> = internalState
|
||||
|
||||
Reference in New Issue
Block a user