Skip to content

Commit

Permalink
Merge pull request #4350 from 4D17Y4/commenter
Browse files Browse the repository at this point in the history
Disabled commenter image view on LoadThumbnail set to false
  • Loading branch information
TobiGr authored Oct 1, 2020
2 parents 4e76329 + 87ae26e commit b1ea7d6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,11 +75,20 @@ public String transformUrl(final Matcher match, final String url) {
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,
Expand All @@ -85,11 +104,24 @@ public void updateFromItem(final InfoItem infoItem,
}
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();
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/list_comments_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/itemThumbnailView"
Expand All @@ -30,7 +30,6 @@
android:layout_alignParentTop="true"
android:layout_marginBottom="@dimen/video_item_search_image_right_margin"
android:layout_toEndOf="@+id/itemThumbnailView"
android:layout_toRightOf="@+id/itemThumbnailView"
android:ellipsize="end"
android:lines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<dimen name="video_item_detail_description_to_details_margin">4dp</dimen>
<dimen name="software_component_item_padding">8dp</dimen>
<dimen name="channel_item_grid_padding">12dp</dimen>
<dimen name="comments_horizontal_padding">16dp</dimen>
<dimen name="comments_vertical_padding">12dp</dimen>

<!-- Players padding & sizes -->
<dimen name="player_main_controls_padding">16dp</dimen>
Expand Down

0 comments on commit b1ea7d6

Please sign in to comment.