mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 12:57:12 +01:00
Shrink icon size in flair and award tags.
This commit is contained in:
parent
252412d8ce
commit
d37a386291
@ -9,6 +9,7 @@
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
|
||||
|
@ -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<Recy
|
||||
|
||||
if (mPost.getAuthorFlairHTML() != null && !mPost.getAuthorFlairHTML().equals("")) {
|
||||
((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAuthorFlairTextView, mPost.getAuthorFlairHTML());
|
||||
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAuthorFlairTextView, mPost.getAuthorFlairHTML(), true);
|
||||
} else if (mPost.getAuthorFlair() != null && !mPost.getAuthorFlair().equals("")) {
|
||||
((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setVisibility(View.VISIBLE);
|
||||
((PostDetailBaseViewHolder) holder).mAuthorFlairTextView.setText(mPost.getAuthorFlair());
|
||||
@ -825,19 +822,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
|
||||
if (mPost.getFlair() != null && !mPost.getFlair().equals("")) {
|
||||
((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE);
|
||||
Spannable flairHTML;
|
||||
GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailBaseViewHolder) holder).mFlairTextView);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 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<Recy
|
||||
|
||||
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
|
||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML());
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
|
||||
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
|
||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
|
||||
@ -1065,14 +1055,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
|
||||
if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
||||
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
||||
Spannable awardsHTML;
|
||||
GlideImageGetter glideImageGetter = new GlideImageGetter(((CommentViewHolder) holder).awardsTextView);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 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());
|
||||
|
@ -251,7 +251,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
|
||||
if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
|
||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML());
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).authorFlairTextView, comment.getAuthorFlairHTML(), true);
|
||||
} else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) {
|
||||
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
|
||||
((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair());
|
||||
@ -266,7 +266,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
|
||||
if (comment.getAwards() != null && !comment.getAwards().equals("")) {
|
||||
((CommentViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards());
|
||||
Utils.setHTMLWithImageToTextView(((CommentViewHolder) holder).awardsTextView, comment.getAwards(), true);
|
||||
}
|
||||
|
||||
mMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
|
||||
|
@ -523,7 +523,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
|
||||
if (flair != null && !flair.equals("")) {
|
||||
((PostBaseViewHolder) holder).flairTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((PostBaseViewHolder) holder).flairTextView, flair);
|
||||
Utils.setHTMLWithImageToTextView(((PostBaseViewHolder) holder).flairTextView, flair, false);
|
||||
}
|
||||
|
||||
if (nAwards > 0) {
|
||||
@ -837,7 +837,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
|
||||
if (flair != null && !flair.equals("")) {
|
||||
((PostCompactBaseViewHolder) holder).flairTextView.setVisibility(View.VISIBLE);
|
||||
Utils.setHTMLWithImageToTextView(((PostCompactBaseViewHolder) holder).flairTextView, flair);
|
||||
Utils.setHTMLWithImageToTextView(((PostCompactBaseViewHolder) holder).flairTextView, flair, false);
|
||||
}
|
||||
|
||||
if (nAwards > 0) {
|
||||
|
@ -47,7 +47,7 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV
|
||||
if (userFlair.getHtmlText() == null || userFlair.getHtmlText().equals("")) {
|
||||
((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(userFlair.getText());
|
||||
} else {
|
||||
Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).userFlairHtmlTextView, userFlair.getHtmlText());
|
||||
Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).userFlairHtmlTextView, userFlair.getHtmlText(), true);
|
||||
}
|
||||
if (userFlair.isEditable()) {
|
||||
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.VISIBLE);
|
||||
|
@ -25,12 +25,14 @@ public class GlideImageGetter implements Html.ImageGetter {
|
||||
|
||||
private WeakReference<TextView> 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) {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user