CountryCodePickerProject icon indicating copy to clipboard operation
CountryCodePickerProject copied to clipboard

set country to null or blank

Open Avramo opened this issue 3 years ago • 4 comments

I get the User's data from the DB, and sometimes for whatever reason the User has "" (empty string) saved as their country. I use this Picker to edit their country, and if the User does not change his country then I get India "IN" as the selectedCCPCountry since the defaultCCPCountry automatically returns India if no country was set. How can I set the selectedCCPCountry or some other flag to null or "" so that in this case I can know not to change the User's data?

Thanks!

Avramo avatar Jun 28 '21 13:06 Avramo

It seems like your primary use case is to select country without phone number validation, did I get that right? if so, you should try Android Country Picker (https://github.com/hbb20/AndroidCountryPicker). It has out of box support for non selection and much more. Please let me know if that works for you.

On Mon, Jun 28, 2021 at 07:34 Avramo @.***> wrote:

I get the User's data from the DB, and sometimes for whatever reason the User has "" (empty string) saved as their country. I use this Picker to edit their country, and if the User does not change his country then I get India "IN" as the selectedCCPCountry since the defaultCCPCountry automatically returns India if no country was set. How can I set the selectedCCPCountry or some other flag to null or "" so that in this case I can know not to change the User's data?

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hbb20/CountryCodePickerProject/issues/496, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFQ32HVJCLTKPM72SRFT3TTVB26FANCNFSM47N7QP5Q .

hbb20 avatar Jun 28 '21 13:06 hbb20

Thanks for the quick response!

As I don't want to undo all the code I have already, I made a temporary workaround.
mCountryChangedByUser is false and turns true only when a country is selected inside the CountryCodePicker.

    mCountryCCP.setOnCountryChangeListener(new CountryCodePicker.OnCountryChangeListener() {
        @Override
        public void onCountrySelected() {
            mCountryChangedByUser = true;
            mCountryTextTV.setText(mCountryCCP.getSelectedCountryName());
            mUser.setCountry(mCountryCCP.getSelectedCountryNameCode());
        }
    });

If the user did not change his country then just return the original country in my saveUser() function.

if (mCountryChangedByUser) {  

        userUpdate.setCountry(mCountryCCP.getSelectedCountryNameCode() );  

    } else {  
        userUpdate.setCountry(mUser.getCountry());  
    }

Maybe next time I'll use the AndroidCountryPicker.

Thanks!

Avramo avatar Jun 28 '21 16:06 Avramo

Glad that workaround worked for you. Sorry for the inconvenience.

On Mon, Jun 28, 2021 at 10:02 Avramo @.***> wrote:

Thanks for the quick response!

As I don't want to undo all the code I have already, I made a temporary workaround.

if (mCountryChangedByUser) { userUpdate.setCountry(mCountryCCP.getSelectedCountryNameCode() ); } else { userUpdate.setCountry(mUser.getCountry()); }

Maybe next time I'll use the AndroidCountryPicker.

Thanks!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/hbb20/CountryCodePickerProject/issues/496#issuecomment-869808145, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFQ32DCAYT44H7SYQ65BITTVCMHXANCNFSM47N7QP5Q .

hbb20 avatar Jun 28 '21 16:06 hbb20

No problem at all! Keep up the great coding!

Thanks!

Avramo avatar Jun 28 '21 16:06 Avramo