Search in sources :

Example 6 with ProfileItem

use of ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileItem in project Saiy-PS by brandall76.

the class SaiyAccountHelper method updateEnrollmentStatus.

/**
 * Update the enrollment status of a profile
 *
 * @param ctx             the application context
 * @param operationStatus the {@link OperationStatus} object
 * @param profileId       of the user
 * @return true if the profile was successfully updated, false otherwise
 */
public static boolean updateEnrollmentStatus(@NonNull final Context ctx, @Nullable final OperationStatus operationStatus, @NonNull final String profileId) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "updateEnrollmentStatus");
    }
    if (operationStatus == null || operationStatus.getProcessingResult() == null) {
        return false;
    }
    if (haveAccounts(ctx)) {
        boolean save = false;
        final SaiyAccountList accountList = getAccountList(ctx);
        for (final SaiyAccount account : accountList.getSaiyAccountList()) {
            if (account.getProfileItem() != null) {
                final ProfileItem item = account.getProfileItem();
                final String id = item.getId();
                if (UtilsString.notNaked(id)) {
                    if (id.matches(Pattern.quote(profileId))) {
                        if (DEBUG) {
                            MyLog.i(CLS_NAME, "updateEnrollmentStatus: have match");
                        }
                        item.setCreated(operationStatus.getCreated());
                        item.setLastAction(operationStatus.getLastAction());
                        item.setRemainingSpeechTime(operationStatus.getProcessingResult().getRemainingSpeechTime());
                        item.setSpeechTime(operationStatus.getProcessingResult().getSpeechTime());
                        item.setStatus(operationStatus.getStatus());
                        save = true;
                        break;
                    }
                } else {
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "updateEnrollmentStatus: id naked");
                    }
                }
            } else {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "updateEnrollmentStatus: getProfileItem null");
                }
            }
        }
        if (save) {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "updateEnrollmentStatus: saving");
            }
            saveSaiyAccountList(ctx, accountList);
            if (DEBUG) {
                debugAccountList(ctx);
            }
            return true;
        }
    } else {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "updateEnrollmentStatus: no account");
        }
    }
    return false;
}
Also used : ProfileItem(ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileItem) UtilsString(ai.saiy.android.utils.UtilsString)

Aggregations

ProfileItem (ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileItem)6 UtilsString (ai.saiy.android.utils.UtilsString)3 Pair (android.util.Pair)2 DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)2 NetworkResponse (com.android.volley.NetworkResponse)2 RequestQueue (com.android.volley.RequestQueue)2 Response (com.android.volley.Response)2 VolleyError (com.android.volley.VolleyError)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Speaker (ai.saiy.android.cognitive.identity.provider.microsoft.Speaker)1 ProfileList (ai.saiy.android.cognitive.identity.provider.microsoft.containers.ProfileList)1 Outcome (ai.saiy.android.processing.Outcome)1 Qubit (ai.saiy.android.processing.Qubit)1 SaiyAccount (ai.saiy.android.user.SaiyAccount)1 SaiyAccountList (ai.saiy.android.user.SaiyAccountList)1 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)1