From 625419a7db7e93cec83633cd6b0bee9e3aabf797 Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 20 Mar 2020 20:57:56 +0100 Subject: [PATCH] Detect ITEM_COUNT_* in localizeStreamCount() ITEM_COUNT_INFINITE and ITEM_COUNT_MORE_THAN_100. Use localizeStreamCount in PlaylistFragment and PlaylistItemHolder --- app/build.gradle | 2 +- .../fragments/list/playlist/PlaylistFragment.java | 13 +++---------- .../holder/PlaylistMiniInfoItemHolder.java | 4 +++- .../java/org/schabi/newpipe/util/Localization.java | 13 +++++++++++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 981a5b4f1..3357b4b31 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,7 +136,7 @@ dependencies { exclude module: 'support-annotations' }) - implementation 'com.github.XiangRongLin:NewPipeExtractor:6a23efa8d41a05f37b8f523aa08af7e0a9d6c4e1' + implementation 'com.github.XiangRongLin:NewPipeExtractor:f9a084f8f9611a87d0f8d6f309a40429304b2ac9' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.23.0' diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 7c21c073d..93df98c97 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -27,7 +27,6 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; -import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; @@ -40,6 +39,7 @@ import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ImageDisplayConstants; +import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.StreamDialogEntry; @@ -303,15 +303,8 @@ public class PlaylistFragment extends BaseListInfoFragment { IMAGE_LOADER.displayImage(result.getUploaderAvatarUrl(), headerUploaderAvatar, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); - - int streamCount = (int) result.getStreamCount(); - if (streamCount == PlaylistExtractor.MORE_THAN_100_ITEMS) { - headerStreamCount.setText(getResources().getString(R.string.playlist_more_than_100_items)); - } else if (streamCount == PlaylistExtractor.INFINITE_ITEMS) { - headerStreamCount.setText(getResources().getString(R.string.playlist_infinite_items)); - } else { - headerStreamCount.setText(getResources().getQuantityString(R.plurals.videos, streamCount, streamCount)); - } + headerStreamCount.setText(Localization + .localizeStreamCount(getContext(), result.getStreamCount())); if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, diff --git a/app/src/main/java/org/schabi/newpipe/info_list/holder/PlaylistMiniInfoItemHolder.java b/app/src/main/java/org/schabi/newpipe/info_list/holder/PlaylistMiniInfoItemHolder.java index c6e637881..2b0c2ef28 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/holder/PlaylistMiniInfoItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/holder/PlaylistMiniInfoItemHolder.java @@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.util.ImageDisplayConstants; +import org.schabi.newpipe.util.Localization; public class PlaylistMiniInfoItemHolder extends InfoItemHolder { public final ImageView itemThumbnailView; @@ -41,7 +42,8 @@ public class PlaylistMiniInfoItemHolder extends InfoItemHolder { final PlaylistInfoItem item = (PlaylistInfoItem) infoItem; itemTitleView.setText(item.getName()); - itemStreamCountView.setText(String.valueOf(item.getStreamCount())); + itemStreamCountView.setText(Localization + .localizeStreamCount(itemStreamCountView.getContext(), item.getStreamCount())); itemUploaderView.setText(item.getUploaderName()); itemBuilder.getImageLoader() 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 0b81df07d..c7d10438f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -6,6 +6,8 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.preference.PreferenceManager; + +import org.schabi.newpipe.extractor.ListExtractor; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -151,8 +153,15 @@ public final class Localization { } public static String localizeStreamCount(final Context context, final long streamCount) { - return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, - localizeNumber(context, streamCount)); + switch ((int) streamCount) { + case (int) ListExtractor.ITEM_COUNT_MORE_THAN_100: + return context.getResources().getString(R.string.playlist_more_than_100_items); + case (int) ListExtractor.ITEM_COUNT_INFINITE: + return context.getResources().getString(R.string.playlist_infinite_items); + default: + return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, + localizeNumber(context, streamCount)); + } } public static String localizeWatchingCount(final Context context, final long watchingCount) {