Skip to content
Merged
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
31 changes: 16 additions & 15 deletions app/src/org/commcare/connect/network/ApiPersonalId.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static void resetPassword(Context context, String phoneNumber, String rec
params.put("phone", phoneNumber);
params.put("secret_key", recoverySecret);
params.put("password", newPassword);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.resetPassword(params);
callApi(context, call, callback);
}
Expand All @@ -266,7 +266,7 @@ public static void checkPin(Context context, String phone, String secret,
params.put("secret_key", secret);
params.put("recovery_pin", pin);

ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.confirmPIN(params);
callApi(context, call, callback);
}
Expand All @@ -280,15 +280,15 @@ public static void setBackupCode(Context context, String username, String passwo
HashMap<String, String> params = new HashMap<>();
params.put("recovery_pin", pin);

ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.changePIN(token, params);
callApi(context, call, callback);
}

public static void startConfiguration(Context context, String phone, IApiCallback callback) {
HashMap<String, String> params = new HashMap<>();
params.put("phone_number", phone);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.startConfiguration(params);
callApi(context, call, callback);
}
Expand All @@ -307,13 +307,13 @@ public static void updateUserProfile(Context context, String username,
if (displayName != null) {
params.put("name", displayName);
}
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.updateProfile(token, params);
callApi(context, call, callback);
}

public static void setPhotoAndName(Context context, String userId, String password, String userName,
String photoAsBase64, IApiCallback callback) {
public static void setPhotoAndCompleteProfile(Context context, String userId, String password, String userName,
String photoAsBase64, String pin, IApiCallback callback) {
Objects.requireNonNull(photoAsBase64);
Objects.requireNonNull(userName);
AuthInfo authInfo = new AuthInfo.ProvidedAuth(userId, password, false);
Expand All @@ -323,9 +323,10 @@ public static void setPhotoAndName(Context context, String userId, String passwo
HashMap<String, String> params = new HashMap<>();
params.put("photo", photoAsBase64);
params.put("name", userName);
params.put("recovery_pin", pin);

ApiService apiService = ApiClient.getClient().create(ApiService.class);
Call<ResponseBody> call = apiService.setProfile(token, params);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.completeProfile(token, params);
callApi(context, call, callback);
}

Expand All @@ -334,15 +335,15 @@ public static void requestRegistrationOtpPrimary(Context context, String usernam
AuthInfo authInfo = new AuthInfo.ProvidedAuth(username, password, false);
String token = HttpUtils.getCredential(authInfo);
HashMap<String, String> params = new HashMap<>();
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.validatePhone(token, params);
callApi(context, call, callback);
}

public static void requestRecoveryOtpPrimary(Context context, String phone, IApiCallback callback) {
HashMap<String, String> params = new HashMap<>();
params.put("phone", phone);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.requestOTPPrimary(params);
callApi(context, call, callback);
}
Expand All @@ -354,7 +355,7 @@ public static void confirmRegistrationOtpPrimary(Context context, String usernam
HashMap<String, String> params = new HashMap<>();
params.put("token", token);

ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.confirmOTP(basicToken, params);
callApi(context, call, callback);
}
Expand All @@ -365,7 +366,7 @@ public static void confirmRecoveryOtpPrimary(Context context, String phone, Stri
params.put("phone", phone);
params.put("secret_key", secret);
params.put("token", token);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.recoverConfirmOTP(params);
callApi(context, call, callback);
}
Expand All @@ -374,7 +375,7 @@ public static void requestInitiateAccountDeactivation(Context context, String ph
HashMap<String, String> params = new HashMap<>();
params.put("secret_key", secretKey);
params.put("phone_number", phone);
ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.accountDeactivation(params);
callApi(context, call, callback);
}
Expand All @@ -386,7 +387,7 @@ public static void confirmUserDeactivation(Context context, String phone, String
params.put("secret_key", secret);
params.put("token", token);

ApiService apiService = ApiClient.getClient().create(ApiService.class);
ApiService apiService = ApiClient.getClientApi();
Call<ResponseBody> call = apiService.confirmDeactivation(params);
callApi(context, call, callback);
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/org/commcare/connect/network/connectId/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
public class ApiClient {
public static final String BASE_URL = "https://connectid.dimagi.com"; // Replace with actual base URL
private static final String API_VERSION = "1.0"; // Replace with actual version value
private static volatile Retrofit retrofit;
private static volatile ApiService apiService;

private ApiClient() {
}

public static Retrofit getClient() {
if (retrofit == null) {
public static ApiService getClientApi() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay, thanks for getting this in.

if (apiService == null) {
synchronized (ApiClient.class) { // Double-checked locking
if (retrofit == null) {
retrofit = buildRetrofitClient();
if (apiService == null) {
apiService = buildRetrofitClient().create(ApiService.class);
}
}
}
return retrofit;
return apiService;
}

private static Retrofit buildRetrofitClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ApiEndPoints {
public static final String phoneAvailable = "/users/phone_available";
public static final String changePhoneNo = "/users/change_phone";
public static final String updateProfile = "/users/update_profile";
public static final String setProfile = "/users/set_profile";
public static final String completeProfile = "/users/complete_profile";
public static final String validatePhone = "/users/validate_phone";
public static final String recoverOTPPrimary = "/users/recover";
public static final String recoverOTPSecondary = "/users/validate_secondary_phone";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Call<ResponseBody> changePhoneNo(@Header("Authorization") String token,
Call<ResponseBody> updateProfile(@Header("Authorization") String token,
@Body Map<String, String> updateProfile);

@POST(ApiEndPoints.setProfile)
Call<ResponseBody> setProfile(@Header("Authorization") String token,
@Body Map<String, String> body);
@POST(ApiEndPoints.completeProfile)
Call<ResponseBody> completeProfile(@Header("Authorization") String token,
@Body Map<String, String> body);

@POST(ApiEndPoints.validatePhone)
Call<ResponseBody> validatePhone(@Header("Authorization") String token, @Body Map<String, String> requestOTP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void initTakePhotoLauncher() {
private void setUpUi() {
viewBinding.title.setText(getString(R.string.connectid_photo_capture_title, getUserName()));
viewBinding.takePhotoButton.setOnClickListener(v -> executeTakePhoto());
viewBinding.savePhotoButton.setOnClickListener(v -> uploadImage());
viewBinding.savePhotoButton.setOnClickListener(v -> uploadImageAndCompleteProfile());
}

private String getUserName() {
Expand All @@ -82,7 +82,7 @@ private String getUserName() {
return "";
}

private void uploadImage() {
private void uploadImageAndCompleteProfile() {
IApiCallback networkResponseCallback = new IApiCallback() {
@Override
public void processSuccess(int responseCode, InputStream responseData) {
Expand Down Expand Up @@ -115,8 +115,8 @@ public void processOldApiError() {
onPhotoUploadFailure(requireContext().getString(R.string.recovery_network_outdated), false);
}
};
ApiPersonalId.setPhotoAndName(requireContext(), connectUserRecord.getUserId(), connectUserRecord.getPassword(),
connectUserRecord.getName(), photoAsBase64, networkResponseCallback);
ApiPersonalId.setPhotoAndCompleteProfile(requireContext(), connectUserRecord.getUserId(), connectUserRecord.getPassword(),
connectUserRecord.getName(), photoAsBase64,connectUserRecord.getPin() ,networkResponseCallback);
}

private void onPhotoUploadFailure(String error, boolean allowRetry) {
Expand Down
Loading