Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-i18n:1.0.0'
implementation 'androidx.documentfile:documentfile:1.0.1'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:${androidxLifecycleVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public List<String> getTags() {
@Override
protected void setupMetadata(final LayoutInflater inflater,
final LinearLayout layout) {
if (streamInfo != null && streamInfo.getUploadDate() != null) {
binding.detailUploadDateView.setText(Localization
.localizeUploadDate(activity, streamInfo.getUploadDate().offsetDateTime()));
final var date = streamInfo != null ? streamInfo.getUploadDate() : null;
if (date != null) {
binding.detailUploadDateView.setText(Localization.formatDate(date.offsetDateTime()));
} else {
binding.detailUploadDateView.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,14 +1514,14 @@ public void handleResult(@NonNull final StreamInfo info) {

if (info.getViewCount() >= 0) {
if (info.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) {
binding.detailViewCountView.setText(Localization.listeningCount(activity,
binding.detailViewCountView.setText(Localization.formatListeningCount(activity,
info.getViewCount()));
} else if (info.getStreamType().equals(StreamType.LIVE_STREAM)) {
binding.detailViewCountView.setText(Localization
.localizeWatchingCount(activity, info.getViewCount()));
.formatWatchingCount(activity, info.getViewCount()));
} else {
binding.detailViewCountView.setText(Localization
.localizeViewCount(activity, info.getViewCount()));
.formatViewCount(activity, info.getViewCount()));
}
binding.detailViewCountView.setVisibility(View.VISIBLE);
} else {
Expand All @@ -1538,7 +1538,7 @@ public void handleResult(@NonNull final StreamInfo info) {
} else {
if (info.getDislikeCount() >= 0) {
binding.detailThumbsDownCountView.setText(Localization
.shortCount(activity, info.getDislikeCount()));
.getShortCount(activity, info.getDislikeCount()));
binding.detailThumbsDownCountView.setVisibility(View.VISIBLE);
binding.detailThumbsDownImgView.setVisibility(View.VISIBLE);
} else {
Expand All @@ -1547,7 +1547,7 @@ public void handleResult(@NonNull final StreamInfo info) {
}

if (info.getLikeCount() >= 0) {
binding.detailThumbsUpCountView.setText(Localization.shortCount(activity,
binding.detailThumbsUpCountView.setText(Localization.getShortCount(activity,
info.getLikeCount()));
binding.detailThumbsUpCountView.setVisibility(View.VISIBLE);
binding.detailThumbsUpImgView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -1622,8 +1622,8 @@ private void displayUploaderAsSubChannel(final StreamInfo info) {
binding.detailSubChannelTextView.setSelected(true);

if (info.getUploaderSubscriberCount() > -1) {
binding.detailUploaderTextView.setText(
Localization.shortSubscriberCount(activity, info.getUploaderSubscriberCount()));
binding.detailUploaderTextView.setText(Localization.formatSubscriberCount(activity,
info.getUploaderSubscriberCount()));
binding.detailUploaderTextView.setVisibility(View.VISIBLE);
} else {
binding.detailUploaderTextView.setVisibility(View.GONE);
Expand All @@ -1642,18 +1642,17 @@ private void displayBothUploaderAndSubChannel(final StreamInfo info) {

final StringBuilder subText = new StringBuilder();
if (!isEmpty(info.getUploaderName())) {
subText.append(
String.format(getString(R.string.video_detail_by), info.getUploaderName()));
subText.append(getString(R.string.video_detail_by, info.getUploaderName()));
}
if (info.getUploaderSubscriberCount() > -1) {
if (subText.length() > 0) {
if (!isEmpty(subText)) {
subText.append(Localization.DOT_SEPARATOR);
}
subText.append(
Localization.shortSubscriberCount(activity, info.getUploaderSubscriberCount()));
subText.append(Localization.formatSubscriberCount(activity,
info.getUploaderSubscriberCount()));
}

if (subText.length() > 0) {
if (!isEmpty(subText)) {
binding.detailUploaderTextView.setText(subText);
binding.detailUploaderTextView.setVisibility(View.VISIBLE);
binding.detailUploaderTextView.setSelected(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,12 @@ public void handleResult(@NonNull final ChannelInfo result) {

binding.channelTitleView.setText(result.getName());
binding.channelSubscriberView.setVisibility(View.VISIBLE);
if (result.getSubscriberCount() >= 0) {
binding.channelSubscriberView.setText(Localization
.shortSubscriberCount(activity, result.getSubscriberCount()));
} else {
binding.channelSubscriberView.setText(R.string.subscribers_count_not_available);
}
binding.channelSubscriberView.setText(Localization.formatSubscriberCount(activity,
result.getSubscriberCount()));

if (!TextUtils.isEmpty(currentInfo.getParentChannelName())) {
binding.subChannelTitleView.setText(String.format(
getString(R.string.channel_created_by),
currentInfo.getParentChannelName())
);
binding.subChannelTitleView.setText(getString(R.string.channel_created_by,
currentInfo.getParentChannelName()));
binding.subChannelTitleView.setVisibility(View.VISIBLE);
binding.subChannelAvatarView.setVisibility(View.VISIBLE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected Supplier<View> getListHeaderSupplier() {

// setup like count, hearted and pinned
binding.thumbsUpCount.setText(
Localization.likeCount(requireContext(), item.getLikeCount()));
Localization.formatLikeCount(requireContext(), item.getLikeCount()));
// for heartImage goneMarginEnd was used, but there is no way to tell ConstraintLayout
// not to use a different margin only when both the next two views are gone
((ConstraintLayout.LayoutParams) binding.thumbsUpCount.getLayoutParams())
Expand Down Expand Up @@ -142,7 +142,7 @@ public void readFrom(@NonNull final Queue<Object> savedObjects) throws Exception
protected Single<CommentRepliesInfo> loadResult(final boolean forceLoad) {
return Single.fromCallable(() -> new CommentRepliesInfo(commentsInfoItem,
// the reply count string will be shown as the activity title
Localization.replyCount(requireContext(), commentsInfoItem.getReplyCount())));
Localization.formatReplyCount(requireContext(), commentsInfoItem.getReplyCount())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private void setStreamCountAndOverallDuration(final List<StreamInfoItem> list,
.sum();
headerBinding.playlistStreamCount.setText(
Localization.concatenateStrings(
Localization.localizeStreamCount(activity, streamCount),
Localization.formatStreamCount(activity, streamCount),
Localization.getDurationString(playlistOverallDurationSeconds,
isDurationComplete, true))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ protected int getDescriptionMaxLineCount(@Nullable final String content) {
private String getDetailLine(final ChannelInfoItem item) {
if (item.getStreamCount() >= 0 && item.getSubscriberCount() >= 0) {
return Localization.concatenateStrings(
Localization.shortSubscriberCount(itemBuilder.getContext(),
Localization.formatSubscriberCount(itemBuilder.getContext(),
item.getSubscriberCount()),
Localization.localizeStreamCount(itemBuilder.getContext(),
Localization.formatStreamCount(itemBuilder.getContext(),
item.getStreamCount()));
} else if (item.getStreamCount() >= 0) {
return Localization.localizeStreamCount(itemBuilder.getContext(),
return Localization.formatStreamCount(itemBuilder.getContext(),
item.getStreamCount());
} else if (item.getSubscriberCount() >= 0) {
return Localization.shortSubscriberCount(itemBuilder.getContext(),
return Localization.formatSubscriberCount(itemBuilder.getContext(),
item.getSubscriberCount());
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@ public void updateFromItem(final InfoItem infoItem,

// setup bottom row, with likes, heart and replies button
itemLikesCountView.setText(
Localization.likeCount(itemBuilder.getContext(), item.getLikeCount()));
Localization.formatLikeCount(itemBuilder.getContext(), item.getLikeCount()));

itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE);

final boolean hasReplies = item.getReplies() != null;
repliesButton.setOnClickListener(hasReplies ? v -> openCommentReplies(item) : 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());

? Localization.formatReplyCount(itemBuilder.getContext(), item.getReplyCount())
: "");
final var params = (RelativeLayout.LayoutParams) itemThumbsUpView.getLayoutParams();
params.topMargin = hasReplies ? 0 : DeviceUtils.dpToPx(6, itemBuilder.getContext());
itemThumbsUpView.setLayoutParams(params);

// setup comment content and click listeners to expand/ellipsize it
textEllipsizer.setStreamingService(getServiceById(item.getServiceId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public PlaylistMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder,
@Override
public void updateFromItem(final InfoItem infoItem,
final HistoryRecordManager historyRecordManager) {
if (!(infoItem instanceof PlaylistInfoItem)) {
if (!(infoItem instanceof PlaylistInfoItem item)) {
return;
}
final PlaylistInfoItem item = (PlaylistInfoItem) infoItem;

itemTitleView.setText(item.getName());
itemStreamCountView.setText(Localization
.localizeStreamCountMini(itemStreamCountView.getContext(), item.getStreamCount()));
.formatStreamCountMini(itemStreamCountView.getContext(), item.getStreamCount()));
itemUploaderView.setText(item.getUploaderName());

PicassoHelper.loadPlaylistThumbnail(item.getThumbnails()).into(itemThumbnailView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.Localization;
Expand Down Expand Up @@ -54,40 +53,35 @@ public void updateFromItem(final InfoItem infoItem,
final HistoryRecordManager historyRecordManager) {
super.updateFromItem(infoItem, historyRecordManager);

if (!(infoItem instanceof StreamInfoItem)) {
return;
if (infoItem instanceof StreamInfoItem item) {
itemAdditionalDetails.setText(getStreamInfoDetailLine(item));
}
final StreamInfoItem item = (StreamInfoItem) infoItem;

itemAdditionalDetails.setText(getStreamInfoDetailLine(item));
}

private String getStreamInfoDetailLine(final StreamInfoItem infoItem) {
String viewsAndDate = "";
if (infoItem.getViewCount() >= 0) {
if (infoItem.getStreamType().equals(StreamType.AUDIO_LIVE_STREAM)) {
viewsAndDate = Localization
.listeningCount(itemBuilder.getContext(), infoItem.getViewCount());
} else if (infoItem.getStreamType().equals(StreamType.LIVE_STREAM)) {
viewsAndDate = Localization
.shortWatchingCount(itemBuilder.getContext(), infoItem.getViewCount());
} else {
viewsAndDate = Localization
.shortViewCount(itemBuilder.getContext(), infoItem.getViewCount());
}
final var context = itemBuilder.getContext();
final long count = infoItem.getViewCount();
final String views;
if (count >= 0) {
views = switch (infoItem.getStreamType()) {
case LIVE_STREAM -> Localization.formatWatchingCount(context, count);
case AUDIO_LIVE_STREAM -> Localization.formatListeningCount(context, count);
default -> Localization.formatViewCount(context, count);
};
} else {
views = "";
}

final String uploadDate = Localization.relativeTimeOrTextual(itemBuilder.getContext(),
infoItem.getUploadDate(),
final var uploadDate = Localization.relativeTimeOrTextual(context, infoItem.getUploadDate(),
infoItem.getTextualUploadDate());
if (!TextUtils.isEmpty(uploadDate)) {
if (viewsAndDate.isEmpty()) {
if (views.isEmpty()) {
return uploadDate;
}

return Localization.concatenateStrings(viewsAndDate, uploadDate);
return Localization.concatenateStrings(views, uploadDate);
}

return viewsAndDate;
return views;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
import org.schabi.newpipe.local.holder.RemotePlaylistGridItemHolder;
import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder;
import org.schabi.newpipe.util.FallbackViewHolder;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.OnClickGesture;

import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -85,7 +82,6 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
private final LocalItemBuilder localItemBuilder;
private final ArrayList<LocalItem> localItems;
private final HistoryRecordManager recordManager;
private final DateTimeFormatter dateTimeFormatter;

private boolean showFooter = false;
private View header = null;
Expand All @@ -97,8 +93,6 @@ public LocalItemListAdapter(final Context context) {
recordManager = new HistoryRecordManager(context);
localItemBuilder = new LocalItemBuilder(context);
localItems = new ArrayList<>();
dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(Localization.getPreferredLocale(context));
}

public void setSelectedListener(final OnClickGesture<LocalItem> listener) {
Expand Down Expand Up @@ -364,19 +358,19 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
+ "position = [" + position + "]");
}

if (holder instanceof LocalItemHolder) {
if (holder instanceof LocalItemHolder localItemHolder) {
// If header isn't null, offset the items by -1
if (header != null) {
position--;
}

((LocalItemHolder) holder)
.updateFromItem(localItems.get(position), recordManager, dateTimeFormatter);
} else if (holder instanceof HeaderFooterHolder && position == 0 && header != null) {
((HeaderFooterHolder) holder).view = header;
} else if (holder instanceof HeaderFooterHolder && position == sizeConsideringHeader()
&& footer != null && showFooter) {
((HeaderFooterHolder) holder).view = footer;
localItemHolder.updateFromItem(localItems.get(position), recordManager);
} else if (holder instanceof HeaderFooterHolder headerFooterHolder) {
if (position == 0 && header != null) {
headerFooterHolder.view = header;
} else if (footer != null && showFooter) {
headerFooterHolder.view = footer;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.schabi.newpipe.local.feed.item

import android.content.Context
import android.text.TextUtils
import android.view.View
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -121,15 +120,15 @@ data class StreamItem(
val viewCount = stream.viewCount
if (viewCount != null && viewCount >= 0) {
viewsAndDate = when (stream.streamType) {
AUDIO_LIVE_STREAM -> Localization.listeningCount(context, viewCount)
LIVE_STREAM -> Localization.shortWatchingCount(context, viewCount)
else -> Localization.shortViewCount(context, viewCount)
AUDIO_LIVE_STREAM -> Localization.formatListeningCount(context, viewCount)
LIVE_STREAM -> Localization.formatWatchingCount(context, viewCount)
else -> Localization.formatViewCount(context, viewCount)
}
}
val uploadDate = getFormattedRelativeUploadDate(context)
return when {
!TextUtils.isEmpty(uploadDate) -> when {
viewsAndDate.isEmpty() -> uploadDate!!
!uploadDate.isNullOrEmpty() -> when {
viewsAndDate.isEmpty() -> uploadDate
else -> Localization.concatenateStrings(viewsAndDate, uploadDate)
}
else -> viewsAndDate
Expand Down
Loading