diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/ReactionAdapter.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/ReactionAdapter.java index a00061779..77341381e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/ReactionAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/ReactionAdapter.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView.Adapter; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Reaction; import org.nuclearfog.twidda.ui.adapter.recyclerview.holder.OnHolderClickListener; import org.nuclearfog.twidda.ui.adapter.recyclerview.holder.ReactionHolder; @@ -14,12 +15,15 @@ import java.util.List; /** + * RecyclerView adapter used by {@link org.nuclearfog.twidda.ui.adapter.recyclerview.holder.AnnouncementHolder} + * * @author nuclearfog */ public class ReactionAdapter extends Adapter implements OnHolderClickListener { private OnReactionSelected listener; private List items = new LinkedList<>(); + private Emoji[] emojis = {}; /** * @@ -38,7 +42,7 @@ public ReactionHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType @Override public void onBindViewHolder(@NonNull ReactionHolder holder, int position) { - holder.setContent(items.get(position)); + holder.setContent(items.get(position), emojis); } @@ -64,10 +68,11 @@ public boolean onPlaceholderClick(int index) { /** * add adapter items */ - public void setItems(Reaction[] reactions) { + public void setItems(Reaction[] reactions, Emoji[] emojis) { items.clear(); Arrays.sort(reactions); items.addAll(Arrays.asList(reactions)); + this.emojis = Arrays.copyOf(emojis, emojis.length); notifyDataSetChanged(); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/AnnouncementHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/AnnouncementHolder.java index e3754ac8b..bc4e8b4f3 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/AnnouncementHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/AnnouncementHolder.java @@ -15,7 +15,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder; import org.nuclearfog.twidda.R; -import org.nuclearfog.twidda.backend.async.AsyncExecutor; +import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.EmojiUtils; @@ -31,7 +31,7 @@ * * @author nuclearfog */ -public class AnnouncementHolder extends ViewHolder implements OnClickListener, OnReactionSelected { +public class AnnouncementHolder extends ViewHolder implements OnClickListener, OnReactionSelected, AsyncCallback { private TextView time, content; private View dismissButton; @@ -40,8 +40,6 @@ public class AnnouncementHolder extends ViewHolder implements OnClickListener, O private GlobalSettings settings; private TextEmojiLoader emojiLoader; private ReactionAdapter adapter; - - private AsyncExecutor.AsyncCallback textResult = this::setTextEmojis; private int iconSize; private long tagId = 0L; @@ -94,14 +92,23 @@ public void onReactionClick(int index) { } } + + @Override + public void onResult(@NonNull TextEmojiLoader.Result result) { + if (result.id == tagId && result.images != null) { + Spannable spannable = EmojiUtils.addEmojis(content.getContext(), result.spannable, result.images); + content.setText(spannable); + } + } + /** * set holder content */ public void setContent(Announcement announcement) { Spannable textSpan = Tagger.makeTextWithLinks(announcement.getMessage(), settings.getHighlightColor()); - if (announcement.getEmojis().length == 0 && settings.imagesEnabled()) { + if (announcement.getEmojis().length > 0 && settings.imagesEnabled()) { TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, announcement.getEmojis(), textSpan, iconSize); - emojiLoader.execute(param, textResult); + emojiLoader.execute(param, this); textSpan = EmojiUtils.removeTags(textSpan); } if (announcement.isDismissed()) { @@ -111,16 +118,6 @@ public void setContent(Announcement announcement) { } content.setText(textSpan); time.setText(StringUtils.formatCreationTime(time.getResources(), announcement.getTimestamp())); - adapter.setItems(announcement.getReactions()); - } - - /** - * - */ - private void setTextEmojis(@NonNull TextEmojiLoader.Result result) { - if (result.id == tagId && result.images != null) { - Spannable spannable = EmojiUtils.addEmojis(content.getContext(), result.spannable, result.images); - content.setText(spannable); - } + adapter.setItems(announcement.getReactions(), announcement.getEmojis()); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/Optionholder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/Optionholder.java index 312909bdd..235116243 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/Optionholder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/Optionholder.java @@ -17,8 +17,6 @@ import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; import org.nuclearfog.twidda.backend.async.TextEmojiLoader; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Param; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Result; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.EmojiUtils; import org.nuclearfog.twidda.backend.utils.StringUtils; @@ -32,7 +30,7 @@ * @author nuclearfog * @see org.nuclearfog.twidda.ui.adapter.recyclerview.OptionsAdapter */ -public class Optionholder extends ViewHolder implements OnClickListener, AsyncCallback { +public class Optionholder extends ViewHolder implements OnClickListener, AsyncCallback { private SeekBar voteProgress; private TextView optionName, optionVotes; @@ -82,7 +80,7 @@ public void onClick(View v) { @Override - public void onResult(@NonNull Result result) { + public void onResult(@NonNull TextEmojiLoader.Result result) { if (result.images != null && result.id == tagId) { Spannable spannable = EmojiUtils.addEmojis(optionName.getContext(), result.spannable, result.images); optionName.setText(spannable); @@ -104,7 +102,7 @@ public void setContent(PollOption option, Emoji[] emojis, boolean selected, int if (emojis.length > 0 && settings.imagesEnabled()) { tagId = option.getTitle().hashCode(); SpannableString optionSpan = new SpannableString(option.getTitle()); - Param param = new Param(tagId, emojis, optionSpan, optionName.getResources().getDimensionPixelSize(R.dimen.item_option_emoji_size)); + TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, emojis, optionSpan, optionName.getResources().getDimensionPixelSize(R.dimen.item_option_emoji_size)); optionName.setText(EmojiUtils.removeTags(optionSpan)); emojiLoader.execute(param, this); } else { diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/ReactionHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/ReactionHolder.java index b2acba02b..e113de41b 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/ReactionHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/ReactionHolder.java @@ -1,6 +1,8 @@ package org.nuclearfog.twidda.ui.adapter.recyclerview.holder; import android.graphics.PorterDuff; +import android.text.Spannable; +import android.text.SpannableStringBuilder; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -8,30 +10,48 @@ import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.ViewHolder; import com.squareup.picasso.Picasso; import org.nuclearfog.twidda.R; +import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; +import org.nuclearfog.twidda.backend.async.TextEmojiLoader; import org.nuclearfog.twidda.backend.image.PicassoBuilder; +import org.nuclearfog.twidda.backend.utils.EmojiUtils; import org.nuclearfog.twidda.config.GlobalSettings; +import org.nuclearfog.twidda.model.Emoji; import org.nuclearfog.twidda.model.Reaction; +import java.util.Random; + /** * Viewholder used by {@link org.nuclearfog.twidda.ui.adapter.recyclerview.ReactionAdapter} * * @author nuclearfog */ -public class ReactionHolder extends ViewHolder implements OnClickListener { +public class ReactionHolder extends ViewHolder implements OnClickListener, AsyncCallback { + + /** + * transparency color mask used for background + */ + private static final int TRANSPARENCY_MASK = 0xC0FFFFFF; + + private static final Random RND = new Random(); private View root; private ImageView icon; private TextView description; private OnHolderClickListener listener; + private TextEmojiLoader emojiLoader; private GlobalSettings settings; private Picasso picasso; + private int iconSize; + + private long tagId = RND.nextLong(); /** * @@ -43,6 +63,8 @@ public ReactionHolder(ViewGroup parent, OnHolderClickListener listener) { root = itemView.findViewById(R.id.item_reaction_root); picasso = PicassoBuilder.get(parent.getContext()); settings = GlobalSettings.get(parent.getContext()); + emojiLoader = new TextEmojiLoader(parent.getContext()); + iconSize = parent.getResources().getDimensionPixelSize(R.dimen.item_reaction_size_icon); this.listener = listener; description.setTextColor(settings.getTextColor()); @@ -61,24 +83,40 @@ public void onClick(View v) { } } + + @Override + public void onResult(@NonNull TextEmojiLoader.Result result) { + if (result.id == tagId && result.images != null) { + Spannable spannable = EmojiUtils.addEmojis(description.getContext(), result.spannable, result.images); + description.setText(spannable); + } + } + /** * */ - public void setContent(Reaction reaction) { + public void setContent(Reaction reaction, Emoji[] emojis) { + // set reaction text and counts + SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(""); if (!reaction.getImageUrl().isEmpty() && settings.imagesEnabled()) { icon.setVisibility(View.VISIBLE); picasso.load(reaction.getImageUrl()).into(icon); - description.setText(""); } else { icon.setVisibility(View.GONE); icon.setImageResource(0); - description.setText(reaction.getName() + " "); + spannableBuilder.append(reaction.getName()).append(" "); + } + spannableBuilder.append(Integer.toString(reaction.getCount())); + description.setText(spannableBuilder); + // load emojis + if (emojis.length > 0 && settings.imagesEnabled()) { + TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, emojis, spannableBuilder, iconSize); + emojiLoader.execute(param, this); } if (reaction.isSelected()) { - root.getBackground().setColorFilter(settings.getHighlightColor() & 0xC0FFFFFF, PorterDuff.Mode.SRC_IN); + root.getBackground().setColorFilter(settings.getHighlightColor() & TRANSPARENCY_MASK, PorterDuff.Mode.SRC_IN); } else { root.getBackground().clearColorFilter(); } - description.append(Integer.toString(reaction.getCount())); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/StatusHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/StatusHolder.java index 70f9248fc..08d4692bc 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/StatusHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/StatusHolder.java @@ -26,8 +26,6 @@ import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; import org.nuclearfog.twidda.backend.async.TextEmojiLoader; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Param; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Result; import org.nuclearfog.twidda.backend.image.PicassoBuilder; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.EmojiUtils; @@ -64,8 +62,8 @@ public class StatusHolder extends ViewHolder implements OnClickListener { private IconAdapter adapter; private OnHolderClickListener listener; - private AsyncCallback textResult = this::setTextEmojis; - private AsyncCallback usernameResult = this::setUsernameEmojis; + private AsyncCallback textResult = this::setTextEmojis; + private AsyncCallback usernameResult = this::setUsernameEmojis; private long tagId = 0L; @@ -169,7 +167,7 @@ public void setContent(Status status) { // set username and emojis if (author.getEmojis().length > 0 && !author.getUsername().trim().isEmpty() && settings.imagesEnabled()) { SpannableString usernameSpan = new SpannableString(author.getUsername()); - Param param = new Param(tagId, author.getEmojis(), usernameSpan, statusText.getResources().getDimensionPixelSize(R.dimen.item_status_icon_size)); + TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, author.getEmojis(), usernameSpan, statusText.getResources().getDimensionPixelSize(R.dimen.item_status_icon_size)); emojiLoader.execute(param, usernameResult); username.setText(EmojiUtils.removeTags(usernameSpan)); } else { @@ -179,7 +177,7 @@ public void setContent(Status status) { if (!status.getText().trim().isEmpty()) { Spannable textSpan = Tagger.makeTextWithLinks(status.getText(), settings.getHighlightColor()); if (status.getEmojis().length > 0 && settings.imagesEnabled()) { - Param param = new Param(tagId, status.getEmojis(), textSpan, statusText.getResources().getDimensionPixelSize(R.dimen.item_status_icon_size)); + TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, status.getEmojis(), textSpan, statusText.getResources().getDimensionPixelSize(R.dimen.item_status_icon_size)); emojiLoader.execute(param, textResult); textSpan = EmojiUtils.removeTags(textSpan); } @@ -305,7 +303,7 @@ public void setLabel(Notification notification) { * * @param result username with emojis */ - private void setUsernameEmojis(@NonNull Result result) { + private void setUsernameEmojis(@NonNull TextEmojiLoader.Result result) { if (result.id == tagId && result.images != null) { Spannable spannable = EmojiUtils.addEmojis(username.getContext(), result.spannable, result.images); username.setText(spannable); @@ -317,7 +315,7 @@ private void setUsernameEmojis(@NonNull Result result) { * * @param result status text with emojis */ - private void setTextEmojis(@NonNull Result result) { + private void setTextEmojis(@NonNull TextEmojiLoader.Result result) { if (result.id == tagId && result.images != null) { Spannable spannable = EmojiUtils.addEmojis(statusText.getContext(), result.spannable, result.images); statusText.setText(spannable); diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/UserHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/UserHolder.java index 30964bd9e..ea68c5b10 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/UserHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/recyclerview/holder/UserHolder.java @@ -24,8 +24,6 @@ import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.backend.async.AsyncExecutor.AsyncCallback; import org.nuclearfog.twidda.backend.async.TextEmojiLoader; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Param; -import org.nuclearfog.twidda.backend.async.TextEmojiLoader.Result; import org.nuclearfog.twidda.backend.image.PicassoBuilder; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.EmojiUtils; @@ -42,7 +40,7 @@ * @author nuclearfog * @see org.nuclearfog.twidda.ui.adapter.recyclerview.UserAdapter */ -public class UserHolder extends ViewHolder implements OnClickListener, AsyncCallback { +public class UserHolder extends ViewHolder implements OnClickListener, AsyncCallback { private static final int EMPTY_COLOR = 0x2F000000; @@ -123,7 +121,7 @@ public void onClick(View v) { @Override - public void onResult(@NonNull Result result) { + public void onResult(@NonNull TextEmojiLoader.Result result) { if (result.id == tagId && result.images != null) { Spannable spannable = EmojiUtils.addEmojis(username.getContext(), result.spannable, result.images); username.setText(spannable); @@ -152,7 +150,7 @@ public void setContent(User user) { } if (user.getEmojis().length > 0 && !user.getUsername().trim().isEmpty() && settings.imagesEnabled()) { Spannable usernameSpan = new SpannableString(user.getUsername()); - Param param = new Param(tagId, user.getEmojis(), usernameSpan, username.getResources().getDimensionPixelSize(R.dimen.item_user_icon_size)); + TextEmojiLoader.Param param = new TextEmojiLoader.Param(tagId, user.getEmojis(), usernameSpan, username.getResources().getDimensionPixelSize(R.dimen.item_user_icon_size)); emojiLoader.execute(param, this); username.setText(EmojiUtils.removeTags(usernameSpan)); } else { diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 939f5b569..9c2943f1a 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -25,7 +25,6 @@ 10dp 5dp 30sp - @dimen/fragment_list_layout_padding @dimen/toolbar_height @@ -189,9 +188,6 @@ 8sp - - 3dp - 10dp 14dp @@ -395,7 +391,7 @@ 5dp - 20dp + 14sp 14sp 5dp