diff options
Diffstat (limited to 'app/src/main/java')
5 files changed, 45 insertions, 12 deletions
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 7b89c940..8a67a44f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -555,9 +555,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((PostDetailViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE); } - if (mPost.getFlair() != null) { + if (mPost.getFlair() != null && !mPost.getFlair().equals("")) { ((PostDetailViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE); - ((PostDetailViewHolder) holder).mFlairTextView.setText(mPost.getFlair()); + Spannable flairHTML; + GlideImageGetter glideImageGetter = new GlideImageGetter(((PostDetailViewHolder) 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); + } + ((PostDetailViewHolder) holder).mFlairTextView.setText(flairHTML); } if (mPost.isNSFW()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index a5504f4a..55fbac6f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -7,6 +7,8 @@ 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.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -66,6 +68,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.User.UserDao; +import ml.docilealligator.infinityforreddit.Utils.GlideImageGetter; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.Utils; @@ -446,9 +449,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE); } - if (flair != null) { + if (flair != null && !flair.equals("")) { ((PostViewHolder) holder).flairTextView.setVisibility(View.VISIBLE); - ((PostViewHolder) holder).flairTextView.setText(flair); + Spannable flairHTML; + GlideImageGetter glideImageGetter = new GlideImageGetter(((PostViewHolder) holder).flairTextView); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + flairHTML = (Spannable) Html.fromHtml(flair, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); + } else { + flairHTML = (Spannable) Html.fromHtml(flair, glideImageGetter, null); + } + ((PostViewHolder) holder).flairTextView.setText(flairHTML); } switch (voteType) { @@ -1001,9 +1011,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE); } - if (flair != null) { + if (flair != null && !flair.equals("")) { ((PostCompactViewHolder) holder).flairTextView.setVisibility(View.VISIBLE); - ((PostCompactViewHolder) holder).flairTextView.setText(flair); + Spannable flairHTML; + GlideImageGetter glideImageGetter = new GlideImageGetter(((PostCompactViewHolder) holder).flairTextView); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + flairHTML = (Spannable) Html.fromHtml(flair, Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); + } else { + flairHTML = (Spannable) Html.fromHtml(flair, glideImageGetter, null); + } + ((PostCompactViewHolder) holder).flairTextView.setText(flairHTML); } switch (voteType) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index 1d2e2e6f..0974cbdf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -50,10 +50,20 @@ public class ParsePost { boolean archived = data.getBoolean(JSONUtils.ARCHIVED_KEY); boolean locked = data.getBoolean(JSONUtils.LOCKEC_KEY); boolean saved = data.getBoolean(JSONUtils.SAVED_KEY); - String flair = null; - if (!data.isNull(JSONUtils.LINK_FLAIR_TEXT_KEY)) { - flair = data.getString(JSONUtils.LINK_FLAIR_TEXT_KEY); + StringBuilder postFlairHTMLBuilder = new StringBuilder(); + if (data.has(JSONUtils.LINK_FLAIR_RICHTEXT_KEY)) { + JSONArray flairArray = data.getJSONArray(JSONUtils.LINK_FLAIR_RICHTEXT_KEY); + for (int i = 0; i < flairArray.length(); i++) { + JSONObject flairObject = flairArray.getJSONObject(i); + String e = flairObject.getString(JSONUtils.E_KEY); + if (e.equals("text")) { + postFlairHTMLBuilder.append(flairObject.getString(JSONUtils.T_KEY)); + } else if (e.equals("emoji")) { + postFlairHTMLBuilder.append("<img src=\"").append(flairObject.getString(JSONUtils.U_KEY)).append("\">"); + } + } } + String flair = postFlairHTMLBuilder.toString(); if (data.isNull(JSONUtils.LIKES_KEY)) { voteType = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java index b38f5b52..8e018449 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java @@ -82,7 +82,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 + 10; + drawableHeight = (int) textSize; drawableWidth = (int) (drawableHeight * ratio); int maxWidth = container.get().getMeasuredWidth(); if ((drawableWidth > maxWidth) || matchParentWidth) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index 577b16e0..2d7d7919 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -16,13 +16,12 @@ public class JSONUtils { public static final String SELFTEXT_KEY = "selftext"; public static final String SELFTEXT_HTML_KEY = "selftext_html"; public static final String AUTHOR_KEY = "author"; - public static final String AUTHOR_FLAIR_TEXT_KEY = "author_flair_text"; public static final String AUTHOR_FLAIR_RICHTEXT_KEY = "author_flair_richtext"; public static final String E_KEY = "e"; public static final String T_KEY = "t"; public static final String U_KEY = "u"; public static final String LINK_AUTHOR_KEY = "link_author"; - public static final String LINK_FLAIR_TEXT_KEY = "link_flair_text"; + public static final String LINK_FLAIR_RICHTEXT_KEY = "link_flair_richtext"; public static final String SCORE_KEY = "score"; public static final String LIKES_KEY = "likes"; public static final String NSFW_KEY = "over_18"; |