Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YouTube Music search stuff #3240

Merged
merged 8 commits into from
Apr 10, 2020
Merged
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:a5155fb'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:a5155fb562ca99ca4a9c8caa2fd60f2f0a305eb0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -302,8 +303,8 @@ public void handleResult(@NonNull final PlaylistInfo result) {

IMAGE_LOADER.displayImage(result.getUploaderAvatarUrl(), headerUploaderAvatar,
ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS);
headerStreamCount.setText(getResources().getQuantityString(R.plurals.videos,
(int) result.getStreamCount(), (int) result.getStreamCount()));
headerStreamCount.setText(Localization
.localizeStreamCount(getContext(), result.getStreamCount()));

if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_PLAYLIST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
boolean isFirstItem = true;
final Context c = getContext();
for (String filter : service.getSearchQHFactory().getAvailableContentFilter()) {
if (filter.equals("music_songs")) {
MenuItem musicItem = menu.add(2,
itemId++,
0,
"YouTube Music");
musicItem.setEnabled(false);
}
Comment on lines +419 to +425
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, adding a disabled item as a header title is bad...

Though I don't know if something like that can even be implemented in a native way (closest thing would be a sub-menu), and I'm not sure if it's worth it to add custom components when this option will be improved in the near future.

Will we just leave it like this until that day?

Copy link
Contributor Author

@wb9688 wb9688 Mar 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this couldn't be implemented in a native way other than submenus. I told Tobias that I didn't really like using a disabled item for that, but he seems to be fine with it until we improve the whole search filter thing some day.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, adding a disabled item as a header title is bad...

Yes. I hope that we will get proper search filter soon.

menuItemToFilterName.put(itemId, filter);
MenuItem item = menu.add(1,
itemId++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -41,7 +42,8 @@ public void updateFromItem(final InfoItem infoItem,
final PlaylistInfoItem item = (PlaylistInfoItem) infoItem;

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

itemBuilder.getImageLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.schabi.newpipe.local.LocalItemBuilder;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.Localization;

import java.text.DateFormat;

Expand All @@ -31,7 +32,8 @@ public void updateFromItem(final LocalItem localItem,
final PlaylistMetadataEntry item = (PlaylistMetadataEntry) localItem;

itemTitleView.setText(item.name);
itemStreamCountView.setText(String.valueOf(item.streamCount));
itemStreamCountView.setText(Localization.localizeStreamCountMini(
itemStreamCountView.getContext(), item.streamCount));
itemUploaderView.setVisibility(View.INVISIBLE);

itemBuilder.displayImage(item.thumbnailUrl, itemThumbnailView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void updateFromItem(final LocalItem localItem,
final PlaylistRemoteEntity item = (PlaylistRemoteEntity) localItem;

itemTitleView.setText(item.getName());
itemStreamCountView.setText(String.valueOf(item.getStreamCount()));
itemStreamCountView.setText(Localization.localizeStreamCountMini(
itemStreamCountView.getContext(), item.getStreamCount()));
// Here is where the uploader name is set in the bookmarked playlists library
if (!TextUtils.isEmpty(item.getUploader())) {
itemUploaderView.setText(Localization.concatenateStrings(item.getUploader(),
Expand Down
27 changes: 25 additions & 2 deletions app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.units.Decade;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.localization.ContentCountry;

import java.math.BigDecimal;
Expand Down Expand Up @@ -151,8 +152,30 @@ public static String localizeViewCount(final Context context, final long viewCou
}

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_UNKNOWN:
return "";
case (int) ListExtractor.ITEM_COUNT_INFINITE:
return context.getResources().getString(R.string.infinite_videos);
case (int) ListExtractor.ITEM_COUNT_MORE_THAN_100:
return context.getResources().getString(R.string.more_than_100_videos);
default:
return getQuantity(context, R.plurals.videos, R.string.no_videos, streamCount,
localizeNumber(context, streamCount));
}
}

public static String localizeStreamCountMini(final Context context, final long streamCount) {
switch ((int) streamCount) {
case (int) ListExtractor.ITEM_COUNT_UNKNOWN:
return "";
case (int) ListExtractor.ITEM_COUNT_INFINITE:
return context.getResources().getString(R.string.infinite_videos_mini);
case (int) ListExtractor.ITEM_COUNT_MORE_THAN_100:
return context.getResources().getString(R.string.more_than_100_videos_mini);
default:
return String.valueOf(streamCount);
}
}

public static String localizeWatchingCount(final Context context, final long watchingCount) {
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/ServiceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public static String getTranslatedFilterString(final String filter, final Contex
case "all":
return c.getString(R.string.all);
case "videos":
case "music_videos":
return c.getString(R.string.videos_string);
case "channels":
return c.getString(R.string.channels);
case "playlists":
case "music_playlists":
return c.getString(R.string.playlists);
case "tracks":
return c.getString(R.string.tracks);
Expand All @@ -61,6 +63,12 @@ public static String getTranslatedFilterString(final String filter, final Contex
return c.getString(R.string.conferences);
case "events":
return c.getString(R.string.events);
case "music_songs":
return c.getString(R.string.songs);
case "music_albums":
return c.getString(R.string.albums);
case "music_artists":
return c.getString(R.string.artists);
default:
return filter;
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,7 @@
<string name="drawer_header_description">Toggle service, momenteel geselecteerd:</string>
<string name="most_liked">Meest geliked</string>
<string name="error_postprocessing_stopped">NewPipe werd gesloten terwijl het bezig was met het bestand</string>
</resources>
<string name="songs">Nummers</string>
<string name="albums">Albums</string>
<string name="artists">Artiesten</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
<string name="tracks">Tracks</string>
<string name="users">Users</string>
<string name="events">Events</string>
<string name="songs">Songs</string>
<string name="albums">Albums</string>
<string name="artists">Artists</string>
<string name="yes">Yes</string>
<string name="later">Later</string>
<string name="disabled">Disabled</string>
Expand Down Expand Up @@ -284,6 +287,10 @@
<item quantity="other">%s listeners</item>
</plurals>
<string name="no_videos">No videos</string>
<string name="more_than_100_videos">100+ videos</string>
<string name="infinite_videos">∞ videos</string>
<string name="more_than_100_videos_mini" translatable="false">100+</string>
<string name="infinite_videos_mini" translatable="false">∞</string>
<plurals name="videos">
<item quantity="one">%s video</item>
<item quantity="other">%s videos</item>
Expand Down