Search in sources :

Example 11 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 12 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)

Example 13 with Account

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

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 14 with Account

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

the class MentionAutoCompleteAdapter method getView.

@Override
@NonNull
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    Context context = getContext();
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // noinspection ConstantConditions
        view = layoutInflater.inflate(layoutId, parent, false);
    }
    Account account = getItem(position);
    if (account != null) {
        TextView username = view.findViewById(R.id.username);
        TextView displayName = view.findViewById(R.id.display_name);
        ImageView avatar = view.findViewById(R.id.avatar);
        String format = getContext().getString(R.string.status_username_format);
        String formattedUsername = String.format(format, account.getUsername());
        username.setText(formattedUsername);
        displayName.setText(account.getName());
        if (!account.getAvatar().isEmpty()) {
            Picasso.with(context).load(account.getAvatar()).placeholder(R.drawable.avatar_default).transform(new RoundedTransformation(25)).into(avatar);
        }
    }
    return view;
}
Also used : Context(android.content.Context) Account(com.keylesspalace.tusky.entity.Account) LayoutInflater(android.view.LayoutInflater) RoundedTransformation(com.keylesspalace.tusky.view.RoundedTransformation) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) NonNull(android.support.annotation.NonNull)

Aggregations

Account (com.keylesspalace.tusky.entity.Account)14 View (android.view.View)8 RecyclerView (android.support.v7.widget.RecyclerView)5 Context (android.content.Context)4 Nullable (android.support.annotation.Nullable)4 ImageView (android.widget.ImageView)4 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 LayoutInflater (android.view.LayoutInflater)3 TextView (android.widget.TextView)3 BaseActivity (com.keylesspalace.tusky.BaseActivity)3 AccountAdapter (com.keylesspalace.tusky.adapter.AccountAdapter)3 BlocksAdapter (com.keylesspalace.tusky.adapter.BlocksAdapter)3 MutesAdapter (com.keylesspalace.tusky.adapter.MutesAdapter)3 EndlessOnScrollListener (com.keylesspalace.tusky.view.EndlessOnScrollListener)3 Call (retrofit2.Call)3 Callback (retrofit2.Callback)3 Response (retrofit2.Response)3 Drawable (android.graphics.drawable.Drawable)2 Bundle (android.os.Bundle)2