Detect ITEM_COUNT_* in localizeStreamCount()

ITEM_COUNT_INFINITE and ITEM_COUNT_MORE_THAN_100.
Use localizeStreamCount in PlaylistFragment and PlaylistItemHolder
This commit is contained in:
Stypox 2020-03-20 20:57:56 +01:00 committed by wb9688
parent 2710d9de5b
commit 625419a7db
4 changed files with 18 additions and 14 deletions

View File

@ -136,7 +136,7 @@ dependencies {
exclude module: 'support-annotations' exclude module: 'support-annotations'
}) })
implementation 'com.github.XiangRongLin:NewPipeExtractor:6a23efa8d41a05f37b8f523aa08af7e0a9d6c4e1' implementation 'com.github.XiangRongLin:NewPipeExtractor:f9a084f8f9611a87d0f8d6f309a40429304b2ac9'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0' testImplementation 'org.mockito:mockito-core:2.23.0'

View File

@ -27,7 +27,6 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; 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.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamType; 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.report.UserAction;
import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants; import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ShareUtils;
import org.schabi.newpipe.util.StreamDialogEntry; import org.schabi.newpipe.util.StreamDialogEntry;
@ -303,15 +303,8 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
IMAGE_LOADER.displayImage(result.getUploaderAvatarUrl(), headerUploaderAvatar, IMAGE_LOADER.displayImage(result.getUploaderAvatarUrl(), headerUploaderAvatar,
ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS);
headerStreamCount.setText(Localization
int streamCount = (int) result.getStreamCount(); .localizeStreamCount(getContext(), 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));
}
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST, showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST,

View File

@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.info_list.InfoItemBuilder; import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager; import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.ImageDisplayConstants; import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;
public class PlaylistMiniInfoItemHolder extends InfoItemHolder { public class PlaylistMiniInfoItemHolder extends InfoItemHolder {
public final ImageView itemThumbnailView; public final ImageView itemThumbnailView;
@ -41,7 +42,8 @@ public class PlaylistMiniInfoItemHolder extends InfoItemHolder {
final PlaylistInfoItem item = (PlaylistInfoItem) infoItem; final PlaylistInfoItem item = (PlaylistInfoItem) infoItem;
itemTitleView.setText(item.getName()); itemTitleView.setText(item.getName());
itemStreamCountView.setText(String.valueOf(item.getStreamCount())); itemStreamCountView.setText(Localization
.localizeStreamCount(itemStreamCountView.getContext(), item.getStreamCount()));
itemUploaderView.setText(item.getUploaderName()); itemUploaderView.setText(item.getUploaderName());
itemBuilder.getImageLoader() itemBuilder.getImageLoader()

View File

@ -6,6 +6,8 @@ import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.schabi.newpipe.extractor.ListExtractor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -151,8 +153,15 @@ public final class Localization {
} }
public static String localizeStreamCount(final Context context, final long streamCount) { public static String localizeStreamCount(final Context context, final long streamCount) {
return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount, switch ((int) streamCount) {
localizeNumber(context, 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) { public static String localizeWatchingCount(final Context context, final long watchingCount) {