Search in sources :

Example 1 with Profile

use of com.keylesspalace.tusky.entity.Profile in project Tusky by Vavassor.

the class EditProfileActivity method save.

private void save() {
    if (isAlreadySaving || currentlyPicking != PickType.NOTHING) {
        return;
    }
    String newDisplayName = displayNameEditText.getText().toString();
    if (newDisplayName.isEmpty()) {
        displayNameEditText.setError(getString(R.string.error_empty));
        return;
    }
    if (priorDisplayName != null && priorDisplayName.equals(newDisplayName)) {
        // If it's not any different, don't patch it.
        newDisplayName = null;
    }
    String newNote = noteEditText.getText().toString();
    if (newNote.isEmpty()) {
        noteEditText.setError(getString(R.string.error_empty));
        return;
    }
    if (priorNote != null && priorNote.equals(newNote)) {
        // If it's not any different, don't patch it.
        newNote = null;
    }
    if (newDisplayName == null && newNote == null && avatarBase64 == null && headerBase64 == null) {
        // If nothing is changed, then there's nothing to save.
        return;
    }
    saveProgress.setVisibility(View.VISIBLE);
    isAlreadySaving = true;
    Profile profile = new Profile();
    profile.displayName = newDisplayName;
    profile.note = newNote;
    profile.avatar = avatarBase64;
    profile.header = headerBase64;
    mastodonAPI.accountUpdateCredentials(profile).enqueue(new Callback<Account>() {

        @Override
        public void onResponse(Call<Account> call, Response<Account> response) {
            if (!response.isSuccessful()) {
                onSaveFailure();
                return;
            }
            getPrivatePreferences().edit().putBoolean("refreshProfileHeader", true).apply();
            finish();
        }

        @Override
        public void onFailure(Call<Account> call, Throwable t) {
            onSaveFailure();
        }
    });
}
Also used : Account(com.keylesspalace.tusky.entity.Account) Profile(com.keylesspalace.tusky.entity.Profile)

Aggregations

Account (com.keylesspalace.tusky.entity.Account)1 Profile (com.keylesspalace.tusky.entity.Profile)1