Search in sources :

Example 1 with Emoji

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

the class ComposeAutoCompleteAdapter method getView.

@Override
@NonNull
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    final Context context = parent.getContext();
    switch(getItemViewType(position)) {
        case ACCOUNT_VIEW_TYPE:
            AccountViewHolder accountViewHolder;
            if (convertView == null) {
                view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_autocomplete_account, parent, false);
            }
            if (view.getTag() == null) {
                view.setTag(new AccountViewHolder(view));
            }
            accountViewHolder = (AccountViewHolder) view.getTag();
            AccountResult accountResult = ((AccountResult) getItem(position));
            if (accountResult != null) {
                Account account = accountResult.account;
                String formattedUsername = context.getString(R.string.status_username_format, account.getUsername());
                accountViewHolder.username.setText(formattedUsername);
                CharSequence emojifiedName = CustomEmojiHelper.emojify(account.getName(), account.getEmojis(), accountViewHolder.displayName, animateEmojis);
                accountViewHolder.displayName.setText(emojifiedName);
                int avatarRadius = accountViewHolder.avatar.getContext().getResources().getDimensionPixelSize(R.dimen.avatar_radius_42dp);
                ImageLoadingHelper.loadAvatar(account.getAvatar(), accountViewHolder.avatar, avatarRadius, animateAvatar);
            }
            break;
        case HASHTAG_VIEW_TYPE:
            if (convertView == null) {
                view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_autocomplete_hashtag, parent, false);
            }
            HashtagResult result = (HashtagResult) getItem(position);
            if (result != null) {
                ((TextView) view).setText(formatHashtag(result));
            }
            break;
        case EMOJI_VIEW_TYPE:
            EmojiViewHolder emojiViewHolder;
            if (convertView == null) {
                view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_autocomplete_emoji, parent, false);
            }
            if (view.getTag() == null) {
                view.setTag(new EmojiViewHolder(view));
            }
            emojiViewHolder = (EmojiViewHolder) view.getTag();
            EmojiResult emojiResult = ((EmojiResult) getItem(position));
            if (emojiResult != null) {
                Emoji emoji = emojiResult.emoji;
                String formattedShortcode = context.getString(R.string.emoji_shortcode_format, emoji.getShortcode());
                emojiViewHolder.shortcode.setText(formattedShortcode);
                Glide.with(emojiViewHolder.preview).load(emoji.getUrl()).into(emojiViewHolder.preview);
            }
            break;
        case SEPARATOR_VIEW_TYPE:
            if (convertView == null) {
                view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.item_autocomplete_divider, parent, false);
            }
            break;
        default:
            throw new AssertionError("unknown view type");
    }
    return view;
}
Also used : Context(android.content.Context) Account(com.keylesspalace.tusky.entity.Account) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Emoji(com.keylesspalace.tusky.entity.Emoji) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull)

Example 2 with Emoji

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

the class StatusBaseViewHolder method setupPoll.

private void setupPoll(PollViewData poll, List<Emoji> emojis, StatusDisplayOptions statusDisplayOptions, StatusActionListener listener) {
    long timestamp = System.currentTimeMillis();
    boolean expired = poll.getExpired() || (poll.getExpiresAt() != null && timestamp > poll.getExpiresAt().getTime());
    Context context = pollDescription.getContext();
    pollOptions.setVisibility(View.VISIBLE);
    if (expired || poll.getVoted()) {
        // no voting possible
        View.OnClickListener viewThreadListener = v -> {
            int position = getBindingAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                listener.onViewThread(position);
            }
        };
        pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, PollAdapter.RESULT, viewThreadListener, statusDisplayOptions.animateEmojis());
        pollButton.setVisibility(View.GONE);
    } else {
        // voting possible
        pollAdapter.setup(poll.getOptions(), poll.getVotesCount(), poll.getVotersCount(), emojis, poll.getMultiple() ? PollAdapter.MULTIPLE : PollAdapter.SINGLE, null, statusDisplayOptions.animateEmojis());
        pollButton.setVisibility(View.VISIBLE);
        pollButton.setOnClickListener(v -> {
            int position = getBindingAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                List<Integer> pollResult = pollAdapter.getSelected();
                if (!pollResult.isEmpty()) {
                    listener.onVoteInPoll(position, pollResult);
                }
            }
        });
    }
    pollDescription.setVisibility(View.VISIBLE);
    pollDescription.setText(getPollInfoText(timestamp, poll, statusDisplayOptions, context));
}
Also used : Context(android.content.Context) ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) DateUtils(android.text.format.DateUtils) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) RequestBuilder(com.bumptech.glide.RequestBuilder) Utils(at.connyduck.sparkbutton.helpers.Utils) ColorDrawable(android.graphics.drawable.ColorDrawable) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) Card(com.keylesspalace.tusky.entity.Card) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) MetaData(com.keylesspalace.tusky.entity.Attachment.MetaData) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewMediaActivity(com.keylesspalace.tusky.ViewMediaActivity) SparkButton(at.connyduck.sparkbutton.SparkButton) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) Focus(com.keylesspalace.tusky.entity.Attachment.Focus) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) HtmlCompat(androidx.core.text.HtmlCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Attachment(com.keylesspalace.tusky.entity.Attachment) PollOptionViewData(com.keylesspalace.tusky.viewdata.PollOptionViewData) CollectionsKt(kotlin.collections.CollectionsKt) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TimestampUtils(com.keylesspalace.tusky.util.TimestampUtils) PollViewDataKt(com.keylesspalace.tusky.viewdata.PollViewDataKt) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) PollViewData(com.keylesspalace.tusky.viewdata.PollViewData) Status(com.keylesspalace.tusky.entity.Status) SimpleDateFormat(java.text.SimpleDateFormat) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) NumberFormat(java.text.NumberFormat) MaterialButton(com.google.android.material.button.MaterialButton) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) CustomEmojiHelper(com.keylesspalace.tusky.util.CustomEmojiHelper) Toast(android.widget.Toast) PollViewDataKt.buildDescription(com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) Emoji(com.keylesspalace.tusky.entity.Emoji) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) TextUtils(android.text.TextUtils) Glide(com.bumptech.glide.Glide) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) ImageLoadingHelper(com.keylesspalace.tusky.util.ImageLoadingHelper) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView)

Aggregations

Context (android.content.Context)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Emoji (com.keylesspalace.tusky.entity.Emoji)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Spanned (android.text.Spanned)1 TextUtils (android.text.TextUtils)1 DateUtils (android.text.format.DateUtils)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 LinearLayout (android.widget.LinearLayout)1 Toast (android.widget.Toast)1 DrawableRes (androidx.annotation.DrawableRes)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1