From 8f4cd032b76412f8f05ee2800021162fc89e9795 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Apr 2023 10:47:40 +0200 Subject: [PATCH 01/19] Remove mini variant and move upload date to top in comments --- .../newpipe/info_list/InfoItemBuilder.java | 6 +- .../newpipe/info_list/InfoListAdapter.java | 12 ++-- ...Holder.java => CommentInfoItemHolder.java} | 45 ++++++------ .../holder/CommentsInfoItemHolder.java | 63 ----------------- app/src/main/res/layout/fragment_comments.xml | 2 +- ...omments_item.xml => list_comment_item.xml} | 14 +--- .../res/layout/list_comments_mini_item.xml | 69 ------------------- 7 files changed, 31 insertions(+), 180 deletions(-) rename app/src/main/java/org/schabi/newpipe/info_list/holder/{CommentsMiniInfoItemHolder.java => CommentInfoItemHolder.java} (90%) delete mode 100644 app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsInfoItemHolder.java rename app/src/main/res/layout/{list_comments_item.xml => list_comment_item.xml} (89%) delete mode 100644 app/src/main/res/layout/list_comments_mini_item.xml diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java index 68f19ee97..d959c6327 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoItemBuilder.java @@ -13,8 +13,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder; -import org.schabi.newpipe.info_list.holder.CommentsInfoItemHolder; -import org.schabi.newpipe.info_list.holder.CommentsMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.CommentInfoItemHolder; import org.schabi.newpipe.info_list.holder.InfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistInfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistMiniInfoItemHolder; @@ -87,8 +86,7 @@ public class InfoItemBuilder { return useMiniVariant ? new PlaylistMiniInfoItemHolder(this, parent) : new PlaylistInfoItemHolder(this, parent); case COMMENT: - return useMiniVariant ? new CommentsMiniInfoItemHolder(this, parent) - : new CommentsInfoItemHolder(this, parent); + return new CommentInfoItemHolder(this, parent); default: throw new RuntimeException("InfoType not expected = " + infoType.name()); } diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index a13f0e5aa..575568c00 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -21,8 +21,7 @@ import org.schabi.newpipe.info_list.holder.ChannelCardInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelGridInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder; -import org.schabi.newpipe.info_list.holder.CommentsInfoItemHolder; -import org.schabi.newpipe.info_list.holder.CommentsMiniInfoItemHolder; +import org.schabi.newpipe.info_list.holder.CommentInfoItemHolder; import org.schabi.newpipe.info_list.holder.InfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistCardInfoItemHolder; import org.schabi.newpipe.info_list.holder.PlaylistGridInfoItemHolder; @@ -79,8 +78,7 @@ public class InfoListAdapter extends RecyclerView.Adapter openCommentAuthor(item)); + final String uploadDate; + if (item.getUploadDate() != null) { + uploadDate = Localization.relativeTime(item.getUploadDate().offsetDateTime()); + } else { + uploadDate = item.getTextualUploadDate(); + } + itemTitleView.setText(Localization.concatenateStrings(item.getUploaderName(), uploadDate)); + + itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE); + itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE); + try { streamService = NewPipe.getService(item.getServiceId()); } catch (final ExtractionException e) { @@ -136,12 +144,6 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { itemLikesCountView.setText("-"); } - if (item.getUploadDate() != null) { - itemPublishedTime.setText(Localization.relativeTime(item.getUploadDate() - .offsetDateTime())); - } else { - itemPublishedTime.setText(item.getTextualUploadDate()); - } itemView.setOnClickListener(view -> { toggleEllipsize(); @@ -150,7 +152,6 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { } }); - itemView.setOnLongClickListener(view -> { if (DeviceUtils.isTv(itemBuilder.getContext())) { openCommentAuthor(item); diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsInfoItemHolder.java deleted file mode 100644 index 4fc2d9f84..000000000 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsInfoItemHolder.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.schabi.newpipe.info_list.holder; - -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - -import org.schabi.newpipe.R; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.comments.CommentsInfoItem; -import org.schabi.newpipe.info_list.InfoItemBuilder; -import org.schabi.newpipe.local.history.HistoryRecordManager; - -/* - * Created by Christian Schabesberger on 12.02.17. - * - * Copyright (C) Christian Schabesberger 2016 - * ChannelInfoItemHolder .java is part of NewPipe. - * - * NewPipe is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NewPipe is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NewPipe. If not, see . - */ - -public class CommentsInfoItemHolder extends CommentsMiniInfoItemHolder { - public final TextView itemTitleView; - private final ImageView itemHeartView; - private final ImageView itemPinnedView; - - public CommentsInfoItemHolder(final InfoItemBuilder infoItemBuilder, final ViewGroup parent) { - super(infoItemBuilder, R.layout.list_comments_item, parent); - - itemTitleView = itemView.findViewById(R.id.itemTitleView); - itemHeartView = itemView.findViewById(R.id.detail_heart_image_view); - itemPinnedView = itemView.findViewById(R.id.detail_pinned_view); - } - - @Override - public void updateFromItem(final InfoItem infoItem, - final HistoryRecordManager historyRecordManager) { - super.updateFromItem(infoItem, historyRecordManager); - - if (!(infoItem instanceof CommentsInfoItem)) { - return; - } - final CommentsInfoItem item = (CommentsInfoItem) infoItem; - - itemTitleView.setText(item.getUploaderName()); - - itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE); - - itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE); - } -} diff --git a/app/src/main/res/layout/fragment_comments.xml b/app/src/main/res/layout/fragment_comments.xml index b1b644d8c..2a8c747cd 100644 --- a/app/src/main/res/layout/fragment_comments.xml +++ b/app/src/main/res/layout/fragment_comments.xml @@ -9,7 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" - tools:listitem="@layout/list_comments_item" /> + tools:listitem="@layout/list_comment_item" /> + tools:text="Author Name, Lorem ipsum · 5 months ago" /> - - diff --git a/app/src/main/res/layout/list_comments_mini_item.xml b/app/src/main/res/layout/list_comments_mini_item.xml deleted file mode 100644 index 606a237c5..000000000 --- a/app/src/main/res/layout/list_comments_mini_item.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - From 4c709b2c4d1aaa6c8568e5f7845f314072fef643 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Apr 2023 10:58:32 +0200 Subject: [PATCH 02/19] Use start/end instead of left/right in comment layout --- app/src/main/res/layout/list_comment_item.xml | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/layout/list_comment_item.xml b/app/src/main/res/layout/list_comment_item.xml index 26fcc9727..3e0cce2e7 100644 --- a/app/src/main/res/layout/list_comment_item.xml +++ b/app/src/main/res/layout/list_comment_item.xml @@ -15,10 +15,9 @@ android:layout_width="42dp" android:layout_height="42dp" android:layout_alignParentStart="true" - android:layout_alignParentLeft="true" android:layout_alignParentTop="true" - android:layout_marginLeft="3dp" - android:layout_marginRight="@dimen/comment_item_avatar_right_margin" + android:layout_marginStart="3dp" + android:layout_marginEnd="@dimen/comment_item_avatar_right_margin" android:focusable="false" android:src="@drawable/placeholder_person" app:shapeAppearance="@style/CircularImageView" @@ -29,7 +28,7 @@ android:layout_width="@dimen/video_item_detail_pinned_image_width" android:layout_height="@dimen/video_item_detail_pinned_image_height" android:layout_alignParentTop="true" - android:layout_marginRight="@dimen/video_item_detail_pinned_right_margin" + android:layout_marginEnd="@dimen/video_item_detail_pinned_right_margin" android:layout_toEndOf="@+id/itemThumbnailView" android:contentDescription="@string/detail_pinned_comment_view_description" android:src="@drawable/ic_pin" @@ -56,18 +55,16 @@ android:layout_below="@id/itemTitleView" android:layout_marginBottom="@dimen/channel_item_description_to_details_margin" android:layout_toEndOf="@+id/itemThumbnailView" - android:layout_toRightOf="@+id/itemThumbnailView" android:textAppearance="?android:attr/textAppearanceLarge" android:textSize="@dimen/comment_item_content_text_size" tools:text="Comment Content, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tristique vitae sem vitae blanditLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tristique vitae sem vitae blanditLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tristique vitae sem vitae blandit" /> - @@ -76,8 +73,8 @@ android:layout_width="wrap_content" android:layout_height="@dimen/video_item_detail_like_image_height" android:layout_below="@id/itemCommentContentView" - android:layout_marginLeft="@dimen/video_item_detail_like_margin" - android:layout_toRightOf="@id/detail_thumbs_up_img_view" + android:layout_marginStart="@dimen/video_item_detail_like_margin" + android:layout_toEndOf="@id/detail_thumbs_up_img_view" android:lines="1" android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="@dimen/video_item_detail_likes_text_size" @@ -89,8 +86,8 @@ android:layout_width="@dimen/video_item_detail_heart_image_size" android:layout_height="@dimen/video_item_detail_heart_image_size" android:layout_below="@id/itemCommentContentView" - android:layout_marginLeft="@dimen/video_item_detail_heart_margin" - android:layout_toRightOf="@+id/detail_thumbs_up_count_view" + android:layout_marginStart="@dimen/video_item_detail_heart_margin" + android:layout_toEndOf="@+id/detail_thumbs_up_count_view" android:contentDescription="@string/detail_heart_img_view_description" android:src="@drawable/ic_heart" android:visibility="gone" From 059db6fb31880b279ea30bc45c5048d7941cc30a Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Apr 2023 14:56:04 +0200 Subject: [PATCH 03/19] Add replies button to comments --- .../holder/CommentInfoItemHolder.java | 56 ++++++++++++++----- .../org/schabi/newpipe/util/Localization.java | 5 ++ app/src/main/res/layout/list_comment_item.xml | 38 ++++++++----- app/src/main/res/values/strings.xml | 4 ++ 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java index afe641c18..f1ac72e89 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java @@ -9,6 +9,7 @@ import android.text.style.URLSpan; import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; @@ -57,15 +58,20 @@ public class CommentInfoItemHolder extends InfoItemHolder { private final RelativeLayout itemRoot; private final ImageView itemThumbnailView; private final TextView itemContentView; + private final ImageView itemThumbsUpView; private final TextView itemLikesCountView; private final TextView itemTitleView; private final ImageView itemHeartView; private final ImageView itemPinnedView; + private final Button repliesButton; private final CompositeDisposable disposables = new CompositeDisposable(); - @Nullable private Description commentText; - @Nullable private StreamingService streamService; - @Nullable private String streamUrl; + @Nullable + private Description commentText; + @Nullable + private StreamingService streamService; + @Nullable + private String streamUrl; public CommentInfoItemHolder(final InfoItemBuilder infoItemBuilder, final ViewGroup parent) { @@ -74,10 +80,12 @@ public class CommentInfoItemHolder extends InfoItemHolder { itemRoot = itemView.findViewById(R.id.itemRoot); itemThumbnailView = itemView.findViewById(R.id.itemThumbnailView); itemContentView = itemView.findViewById(R.id.itemCommentContentView); + itemThumbsUpView = itemView.findViewById(R.id.detail_thumbs_up_img_view); itemLikesCountView = itemView.findViewById(R.id.detail_thumbs_up_count_view); itemTitleView = itemView.findViewById(R.id.itemTitleView); itemHeartView = itemView.findViewById(R.id.detail_heart_image_view); itemPinnedView = itemView.findViewById(R.id.detail_pinned_view); + repliesButton = itemView.findViewById(R.id.replies_button); commentHorizontalPadding = (int) infoItemBuilder.getContext() .getResources().getDimension(R.dimen.comments_horizontal_padding); @@ -97,6 +105,8 @@ public class CommentInfoItemHolder extends InfoItemHolder { } final CommentsInfoItem item = (CommentsInfoItem) infoItem; + + // load the author avatar PicassoHelper.loadAvatar(item.getUploaderAvatars()).into(itemThumbnailView); if (ImageStrategy.shouldLoadImages()) { itemThumbnailView.setVisibility(View.VISIBLE); @@ -109,6 +119,10 @@ public class CommentInfoItemHolder extends InfoItemHolder { } itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item)); + + // setup the top row, with pinned icon, author name and comment date + itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE); + final String uploadDate; if (item.getUploadDate() != null) { uploadDate = Localization.relativeTime(item.getUploadDate().offsetDateTime()); @@ -117,9 +131,29 @@ public class CommentInfoItemHolder extends InfoItemHolder { } itemTitleView.setText(Localization.concatenateStrings(item.getUploaderName(), uploadDate)); - itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE); + + // setup bottom row, with likes, heart and replies button + if (item.getLikeCount() >= 0) { + itemLikesCountView.setText( + Localization.shortCount( + itemBuilder.getContext(), + item.getLikeCount())); + } else { + itemLikesCountView.setText("-"); + } + itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE); + final boolean hasReplies = item.getReplies() != null; + repliesButton.setOnClickListener(hasReplies ? (v) -> openRepliesFragment() : null); + repliesButton.setVisibility(hasReplies ? View.VISIBLE : View.GONE); + repliesButton.setText(hasReplies + ? Localization.replyCount(itemBuilder.getContext(), item.getReplyCount()) : ""); + ((RelativeLayout.LayoutParams) itemThumbsUpView.getLayoutParams()).topMargin = + hasReplies ? 0 : DeviceUtils.dpToPx(6, itemBuilder.getContext()); + + + // setup comment content and click listeners to expand/ellipsize it try { streamService = NewPipe.getService(item.getServiceId()); } catch (final ExtractionException e) { @@ -135,16 +169,6 @@ public class CommentInfoItemHolder extends InfoItemHolder { //noinspection ClickableViewAccessibility itemContentView.setOnTouchListener(CommentTextOnTouchListener.INSTANCE); - if (item.getLikeCount() >= 0) { - itemLikesCountView.setText( - Localization.shortCount( - itemBuilder.getContext(), - item.getLikeCount())); - } else { - itemLikesCountView.setText("-"); - } - - itemView.setOnClickListener(view -> { toggleEllipsize(); if (itemBuilder.getOnCommentsSelectedListener() != null) { @@ -278,4 +302,8 @@ public class CommentInfoItemHolder extends InfoItemHolder { onCompletion); } } + + private void openRepliesFragment() { + // TODO + } } diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index c4034252d..20d21d76b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -209,6 +209,11 @@ public final class Localization { deletedCount, shortCount(context, deletedCount)); } + public static String replyCount(final Context context, final int replyCount) { + return getQuantity(context, R.plurals.replies, 0, replyCount, + String.valueOf(replyCount)); + } + public static String getDurationString(final long duration) { final String output; diff --git a/app/src/main/res/layout/list_comment_item.xml b/app/src/main/res/layout/list_comment_item.xml index 3e0cce2e7..631ab204b 100644 --- a/app/src/main/res/layout/list_comment_item.xml +++ b/app/src/main/res/layout/list_comment_item.xml @@ -16,7 +16,6 @@ android:layout_height="42dp" android:layout_alignParentStart="true" android:layout_alignParentTop="true" - android:layout_marginStart="3dp" android:layout_marginEnd="@dimen/comment_item_avatar_right_margin" android:focusable="false" android:src="@drawable/placeholder_person" @@ -31,39 +30,37 @@ android:layout_marginEnd="@dimen/video_item_detail_pinned_right_margin" android:layout_toEndOf="@+id/itemThumbnailView" android:contentDescription="@string/detail_pinned_comment_view_description" - android:src="@drawable/ic_pin" - android:visibility="gone" - tools:visibility="visible" /> + android:src="@drawable/ic_pin" /> + tools:text="Author Name, Lorem ipsum • 5 months ago" /> + tools:text="@tools:sample/lorem/random[1]" /> @@ -71,26 +68,37 @@ + android:src="@drawable/ic_heart" /> + +