From d37a386291c89e3740a762dbc99fe621fb8faac3 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 9 Nov 2020 12:27:21 +0800 Subject: Shrink icon size in flair and award tags. --- app/src/main/AndroidManifest.xml | 1 + .../Adapter/CommentAndPostRecyclerViewAdapter.java | 27 ++++------------------ .../CommentsListingRecyclerViewAdapter.java | 4 ++-- .../Adapter/PostRecyclerViewAdapter.java | 4 ++-- .../Adapter/UserFlairRecyclerViewAdapter.java | 2 +- .../infinityforreddit/Utils/GlideImageGetter.java | 6 +++-- .../infinityforreddit/Utils/Utils.java | 4 ++-- 7 files changed, 17 insertions(+), 31 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b174ee0e..b2b2dcb1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ + diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index f9268870..66c4ba8e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -11,8 +11,6 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.text.Html; -import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; @@ -113,7 +111,6 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.Utils.APIUtils; -import ml.docilealligator.infinityforreddit.Utils.GlideImageGetter; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.VoteThing; @@ -767,7 +764,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.N) { - flairHTML = (Spannable) Html.fromHtml(mPost.getFlair(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); - } else { - flairHTML = (Spannable) Html.fromHtml(mPost.getFlair(), glideImageGetter, null); - } - ((PostDetailBaseViewHolder) holder).mFlairTextView.setText(flairHTML); + Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mFlairTextView, mPost.getFlair(), false); } if (mPost.getAwards() != null && !mPost.getAwards().equals("")) { ((PostDetailBaseViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE); - Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards()); + Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards(), true); } if (mPost.isNSFW()) { @@ -1030,7 +1020,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.N) { - awardsHTML = (Spannable) Html.fromHtml(comment.getAwards(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); - } else { - awardsHTML = (Spannable) Html.fromHtml(comment.getAwards(), glideImageGetter, null); - } - ((CommentViewHolder) holder).awardsTextView.setText(awardsHTML); + Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true); } mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java index 508d22aa..147a13d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -251,7 +251,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter 0) { @@ -837,7 +837,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter 0) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserFlairRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserFlairRecyclerViewAdapter.java index e0669959..a9ae4687 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserFlairRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/UserFlairRecyclerViewAdapter.java @@ -47,7 +47,7 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter container; private boolean matchParentWidth; + private boolean enlargeImage; private HtmlImagesHandler imagesHandler; private float density = 1.0f; private float textSize; - public GlideImageGetter(TextView textView) { + public GlideImageGetter(TextView textView, boolean enlargeImage) { this(textView, false, false, null); + this.enlargeImage = enlargeImage; } public GlideImageGetter(TextView textView, boolean matchParentWidth, HtmlImagesHandler imagesHandler) { @@ -88,7 +90,7 @@ public class GlideImageGetter implements Html.ImageGetter { int drawableWidth = (int) (drawable.getIntrinsicWidth() * density); int drawableHeight = (int) (drawable.getIntrinsicHeight() * density); float ratio = (float) drawableWidth / (float) drawableHeight; - drawableHeight = (int) (textSize * 1.5); + drawableHeight = enlargeImage ? (int) (textSize * 1.5) : (int) textSize; drawableWidth = (int) (drawableHeight * ratio); int maxWidth = container.get().getMeasuredWidth(); if ((maxWidth > 0 && (drawableWidth > maxWidth)) || matchParentWidth) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index f3d32e5d..d277e8df 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -134,9 +134,9 @@ public class Utils { } } - public static void setHTMLWithImageToTextView(TextView textView, String content) { + public static void setHTMLWithImageToTextView(TextView textView, String content, boolean enlargeImage) { Spannable html; - GlideImageGetter glideImageGetter = new GlideImageGetter(textView); + GlideImageGetter glideImageGetter = new GlideImageGetter(textView, enlargeImage); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { html = (Spannable) Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); } else { -- cgit v1.2.3