Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCCT-627 || Country Code Issue #2926

Open
wants to merge 1 commit into
base: connect_qa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 20 additions & 15 deletions app/src/org/commcare/utils/PhoneNumberHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -95,20 +83,37 @@ 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)
.addOnSuccessListener(pendingIntent -> {
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);
Expand Down