From 87ae26ede3d622818aa95881823ff41e843e42a0 Mon Sep 17 00:00:00 2001 From: Aditya Srivastava Date: Tue, 29 Sep 2020 21:17:39 +0530 Subject: [PATCH] Disabled commenter image view on LoadThumbnail set to false --- .../holder/CommentsMiniInfoItemHolder.java | 32 +++++++++++++++++++ .../main/res/layout/list_comments_item.xml | 3 +- app/src/main/res/values/dimens.xml | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java index 944b578f5..878b7af7d 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java @@ -1,13 +1,18 @@ package org.schabi.newpipe.info_list.holder; +import android.content.SharedPreferences; import android.text.TextUtils; import android.text.method.LinkMovementMethod; import android.text.style.URLSpan; import android.text.util.Linkify; +import android.view.View; import android.view.ViewGroup; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceManager; + import org.schabi.newpipe.R; import org.schabi.newpipe.extractor.InfoItem; @@ -31,7 +36,12 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { private static final int COMMENT_DEFAULT_LINES = 2; private static final int COMMENT_EXPANDED_LINES = 1000; private static final Pattern PATTERN = Pattern.compile("(\\d+:)?(\\d+)?:(\\d+)"); + private final String downloadThumbnailKey; + private final int commentHorizontalPadding; + private final int commentVerticalPadding; + private SharedPreferences preferences = null; + private final RelativeLayout itemRoot; public final CircleImageView itemThumbnailView; private final TextView itemContentView; private final TextView itemLikesCountView; @@ -65,11 +75,20 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { final ViewGroup parent) { super(infoItemBuilder, layoutId, parent); + itemRoot = itemView.findViewById(R.id.itemRoot); itemThumbnailView = itemView.findViewById(R.id.itemThumbnailView); itemLikesCountView = itemView.findViewById(R.id.detail_thumbs_up_count_view); itemDislikesCountView = itemView.findViewById(R.id.detail_thumbs_down_count_view); itemPublishedTime = itemView.findViewById(R.id.itemPublishedTime); itemContentView = itemView.findViewById(R.id.itemCommentContentView); + + downloadThumbnailKey = infoItemBuilder.getContext(). + getString(R.string.download_thumbnail_key); + + commentHorizontalPadding = (int) infoItemBuilder.getContext() + .getResources().getDimension(R.dimen.comments_horizontal_padding); + commentVerticalPadding = (int) infoItemBuilder.getContext() + .getResources().getDimension(R.dimen.comments_vertical_padding); } public CommentsMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder, @@ -85,11 +104,24 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { } final CommentsInfoItem item = (CommentsInfoItem) infoItem; + preferences = PreferenceManager.getDefaultSharedPreferences(itemBuilder.getContext()); + itemBuilder.getImageLoader() .displayImage(item.getUploaderAvatarUrl(), itemThumbnailView, ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS); + if (preferences.getBoolean(downloadThumbnailKey, true)) { + itemThumbnailView.setVisibility(View.VISIBLE); + itemRoot.setPadding(commentVerticalPadding, commentVerticalPadding, + commentVerticalPadding, commentVerticalPadding); + } else { + itemThumbnailView.setVisibility(View.GONE); + itemRoot.setPadding(commentHorizontalPadding, commentVerticalPadding, + commentHorizontalPadding, commentVerticalPadding); + } + + itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item)); streamUrl = item.getUrl(); diff --git a/app/src/main/res/layout/list_comments_item.xml b/app/src/main/res/layout/list_comments_item.xml index 1cbafdb6b..02af7e98a 100644 --- a/app/src/main/res/layout/list_comments_item.xml +++ b/app/src/main/res/layout/list_comments_item.xml @@ -8,7 +8,7 @@ android:background="?attr/selectableItemBackground" android:clickable="true" android:focusable="true" - android:padding="@dimen/video_item_search_padding"> + android:padding="@dimen/comments_vertical_padding"> 4dp 8dp 12dp + 16dp + 12dp 16dp