Search in sources :

Example 6 with Account

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

the class AccountAdapter method removeItem.

@Nullable
public Account removeItem(int position) {
    if (position < 0 || position >= accountList.size()) {
        return null;
    }
    Account account = accountList.remove(position);
    notifyItemRemoved(position);
    return account;
}
Also used : Account(com.keylesspalace.tusky.entity.Account) Nullable(android.support.annotation.Nullable)

Example 7 with Account

use of com.keylesspalace.tusky.entity.Account 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)

Example 8 with Account

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

the class EditProfileActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(getString(R.string.title_edit_profile));
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }
    if (savedInstanceState != null) {
        priorDisplayName = savedInstanceState.getString("priorDisplayName");
        priorNote = savedInstanceState.getString("priorNote");
        isAlreadySaving = savedInstanceState.getBoolean("isAlreadySaving");
        currentlyPicking = (PickType) savedInstanceState.getSerializable("currentlyPicking");
        avatarBase64 = savedInstanceState.getString("avatarBase64");
        headerBase64 = savedInstanceState.getString("headerBase64");
    } else {
        priorDisplayName = null;
        priorNote = null;
        isAlreadySaving = false;
        currentlyPicking = PickType.NOTHING;
        avatarBase64 = null;
        headerBase64 = null;
    }
    avatarButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onMediaPick(PickType.AVATAR);
        }
    });
    headerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onMediaPick(PickType.HEADER);
        }
    });
    avatarPreview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            avatarPreview.setImageBitmap(null);
            avatarPreview.setVisibility(View.INVISIBLE);
            avatarBase64 = null;
        }
    });
    headerPreview.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            headerPreview.setImageBitmap(null);
            headerPreview.setVisibility(View.INVISIBLE);
            headerBase64 = null;
        }
    });
    mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() {

        @Override
        public void onResponse(Call<Account> call, Response<Account> response) {
            if (!response.isSuccessful()) {
                onAccountVerifyCredentialsFailed();
                return;
            }
            Account me = response.body();
            priorDisplayName = me.getDisplayName();
            priorNote = me.note.toString();
            CircularImageView avatar = (CircularImageView) findViewById(R.id.edit_profile_avatar_preview);
            ImageView header = (ImageView) findViewById(R.id.edit_profile_header_preview);
            displayNameEditText.setText(priorDisplayName);
            noteEditText.setText(priorNote);
            Picasso.with(avatar.getContext()).load(me.avatar).placeholder(R.drawable.avatar_default).error(R.drawable.avatar_error).into(avatar);
            Picasso.with(header.getContext()).load(me.header).placeholder(R.drawable.account_header_default).into(header);
        }

        @Override
        public void onFailure(Call<Account> call, Throwable t) {
            onAccountVerifyCredentialsFailed();
        }
    });
}
Also used : Account(com.keylesspalace.tusky.entity.Account) ImageView(android.widget.ImageView) CircularImageView(com.pkmmte.view.CircularImageView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) CircularImageView(com.pkmmte.view.CircularImageView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) CircularImageView(com.pkmmte.view.CircularImageView)

Aggregations

Account (com.keylesspalace.tusky.entity.Account)8 View (android.view.View)4 RecyclerView (android.support.v7.widget.RecyclerView)3 ImageView (android.widget.ImageView)2 BindView (butterknife.BindView)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Nullable (android.support.annotation.Nullable)1 TabLayout (android.support.design.widget.TabLayout)1 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 StyleSpan (android.text.style.StyleSpan)1 TextView (android.widget.TextView)1 FloatingSearchView (com.arlib.floatingsearchview.FloatingSearchView)1 SearchSuggestionsAdapter (com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter)1 SearchSuggestion (com.arlib.floatingsearchview.suggestions.model.SearchSuggestion)1 BaseActivity (com.keylesspalace.tusky.BaseActivity)1 AccountAdapter (com.keylesspalace.tusky.adapter.AccountAdapter)1 BlocksAdapter (com.keylesspalace.tusky.adapter.BlocksAdapter)1