Search in sources :

Example 1 with AccountDataUpdatedCallback

use of org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback in project edx-app-android by edx.

the class EditUserProfileFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    setHasOptionsMenu(true);
    EventBus.getDefault().register(this);
    final Activity activity = getActivity();
    final TaskMessageCallback mCallback = activity instanceof TaskMessageCallback ? (TaskMessageCallback) activity : null;
    getAccountCall = userService.getAccount(username);
    getAccountCall.enqueue(new AccountDataUpdatedCallback(activity, username, // Disable default loading indicator, we have our own
    null, mCallback, CallTrigger.LOADING_CACHED));
    getProfileFormDescriptionTask = new GetProfileFormDescriptionTask(activity) {

        @Override
        protected void onSuccess(@NonNull FormDescription formDescription) throws Exception {
            EditUserProfileFragment.this.formDescription = formDescription;
            if (null != viewHolder) {
                setData(account, formDescription);
            }
        }
    };
    getProfileFormDescriptionTask.setTaskProcessCallback(null);
    getProfileFormDescriptionTask.execute();
}
Also used : AccountDataUpdatedCallback(org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback) Activity(android.app.Activity) GetProfileFormDescriptionTask(org.edx.mobile.user.GetProfileFormDescriptionTask) FormDescription(org.edx.mobile.user.FormDescription) InvalidLocaleException(org.edx.mobile.util.InvalidLocaleException) TaskMessageCallback(org.edx.mobile.view.common.TaskMessageCallback)

Example 2 with AccountDataUpdatedCallback

use of org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback in project edx-app-android by edx.

the class EditUserProfileFragment method executeUpdate.

private void executeUpdate(FormField field, String fieldValue) {
    final Object valueObject;
    if (field.getDataType() == DataType.LANGUAGE) {
        if (TextUtils.isEmpty(fieldValue)) {
            valueObject = Collections.emptyList();
        } else {
            valueObject = Collections.singletonList(new LanguageProficiency(fieldValue));
        }
    } else {
        valueObject = fieldValue;
    }
    userService.updateAccount(username, Collections.singletonMap(field.getName(), valueObject)).enqueue(new AccountDataUpdatedCallback(getActivity(), username, new DialogErrorNotification(this)) {

        @Override
        protected void onResponse(@NonNull final Account account) {
            super.onResponse(account);
            EditUserProfileFragment.this.account = account;
            setData(account, formDescription);
        }
    });
}
Also used : LanguageProficiency(org.edx.mobile.user.LanguageProficiency) AccountDataUpdatedCallback(org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback) Account(org.edx.mobile.user.Account) JsonObject(com.google.gson.JsonObject) DialogErrorNotification(org.edx.mobile.http.notifications.DialogErrorNotification)

Aggregations

AccountDataUpdatedCallback (org.edx.mobile.user.UserAPI.AccountDataUpdatedCallback)2 Activity (android.app.Activity)1 JsonObject (com.google.gson.JsonObject)1 DialogErrorNotification (org.edx.mobile.http.notifications.DialogErrorNotification)1 Account (org.edx.mobile.user.Account)1 FormDescription (org.edx.mobile.user.FormDescription)1 GetProfileFormDescriptionTask (org.edx.mobile.user.GetProfileFormDescriptionTask)1 LanguageProficiency (org.edx.mobile.user.LanguageProficiency)1 InvalidLocaleException (org.edx.mobile.util.InvalidLocaleException)1 TaskMessageCallback (org.edx.mobile.view.common.TaskMessageCallback)1