CountryCodePickerProject icon indicating copy to clipboard operation
CountryCodePickerProject copied to clipboard

Add support for Preference API

Open yankarinRG opened this issue 6 years ago • 4 comments

It would be very nice if CountryCodePicker could be a custom preference supported by the Preference API. More info here: Settings | Android Developers

yankarinRG avatar Feb 26 '19 00:02 yankarinRG

Hello @yankarinRG, this sounds interesting. Can you brief a little what exactly you want to see in term of feature.

hbb20 avatar Feb 28 '19 01:02 hbb20

Basically it would be a DialogPreference with the custom CountryCodePicker view (country code/prefix + phone number). In the preference layout file (with PreferenceScreen as root) then you would add something like <in.hbb20.CountryCodePickerPreference>, then in onDisplayPreferenceDialog (of class PreferenceFragmentCompat) you check if the preference which wants to show a dialog (because the preference item on the preference screen is different than the dialog) is instanceof CountryCodePickerPreference, then create a new instance of CountryCodePickerPreferenceDialogFragment and show it. Some useful source code here: (I take EditTextPreference as an example)

This way you can have a persistent preference of a phone number!

yankarinRG avatar Feb 28 '19 18:02 yankarinRG

@hbb20 really it'll be consistent to have support for android preferences,because choosing a country /language... is something we do at registration and also when changing settings . thank you

@yankarinRG did you make it yourself? or any workaround please?

aymenhs avatar Aug 12 '19 00:08 aymenhs

At the end I simply used an EditTextPreference and guessed/validated the phone number using libphonenumber. Of course, it would've been a lot more elegant if there was a CountryCodePickerPreference.

yankarinRG avatar Aug 12 '19 09:08 yankarinRG