diff --git a/app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java b/app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java index f83b5bd81..03241246b 100644 --- a/app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java +++ b/app/src/org/commcare/fragments/connectId/ConnectIDSignupFragment.java @@ -107,6 +107,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, } ); + binding.countryCode.setText(PhoneNumberHelper.setDefaultCountryCode(getContext())); binding.connectPrimaryPhoneInput.setOnFocusChangeListener(listener); binding.countryCode.setOnFocusChangeListener(listener); diff --git a/app/src/org/commcare/utils/PhoneNumberHelper.java b/app/src/org/commcare/utils/PhoneNumberHelper.java index 7888ac184..81e2ba405 100644 --- a/app/src/org/commcare/utils/PhoneNumberHelper.java +++ b/app/src/org/commcare/utils/PhoneNumberHelper.java @@ -1,11 +1,8 @@ package org.commcare.utils; import android.app.Activity; -import android.app.PendingIntent; import android.content.Context; import android.content.Intent; -import android.content.IntentSender; -import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.IntentSenderRequest; @@ -14,18 +11,9 @@ import com.google.android.gms.auth.api.identity.Identity; import com.google.android.gms.auth.api.identity.SignInClient; import com.google.android.gms.common.api.ApiException; -import com.google.android.gms.tasks.OnSuccessListener; -import org.commcare.android.database.connect.models.ConnectUserRecord; import org.commcare.connect.ConnectConstants; -import org.commcare.connect.ConnectManager; -import org.commcare.connect.network.ApiConnectId; -import org.commcare.connect.network.IApiCallback; -import org.commcare.dalvik.R; -import org.javarosa.core.services.Logger; - -import java.io.IOException; -import java.io.InputStream; + import java.util.Locale; import io.michaelrocks.libphonenumber.android.NumberParseException; @@ -95,6 +83,23 @@ public static int getCountryCode(Context context) { return util.getCountryCodeForRegion(locale.getCountry()); } + public static String setDefaultCountryCode(Context context) { + Locale locale = context.getResources().getConfiguration().locale; + PhoneNumberUtil util = getUtil(context); + + int code = util.getCountryCodeForRegion(locale.getCountry()); + + String codeText = ""; + if (code > 0) { + codeText = String.format(Locale.getDefault(), "%d", code); + if (!codeText.startsWith("+")) { + codeText = "+" + codeText; + } + } + + return codeText; + } + public static void requestPhoneNumberHint(Activity activity) { GetPhoneNumberHintIntentRequest hintRequest = GetPhoneNumberHintIntentRequest.builder().build(); Identity.getSignInClient(activity).getPhoneNumberHintIntent(hintRequest) @@ -102,13 +107,13 @@ public static void requestPhoneNumberHint(Activity activity) { try { IntentSenderRequest intentSenderRequest = new IntentSenderRequest.Builder(pendingIntent).build(); phoneNumberHintLauncher.launch(intentSenderRequest); - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } }); } - public static String handlePhoneNumberPickerResult(int requestCode, int resultCode, Intent intent, Activity activity){ + public static String handlePhoneNumberPickerResult(int requestCode, int resultCode, Intent intent, Activity activity) { if (requestCode == ConnectConstants.CREDENTIAL_PICKER_REQUEST && resultCode == Activity.RESULT_OK) { SignInClient signInClient = Identity.getSignInClient(activity);