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

Added random songs as requested in #1111 #1120

Open
wants to merge 4 commits into
base: edge
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ protected List<Entry> cacheInBackground() throws Exception {
result = service.getAlbumList(type, extra, size, offset, false, context, null);
} else if("genres".equals(type) || "genres-songs".equals(type)) {
result = service.getSongsByGenre(extra, size, offset, context, null);
} else if (type.equals("randomsongs")) {
result = service.getRandomTracks(size, context, null);
}else if(type.indexOf(MainFragment.SONGS_LIST_PREFIX) != -1) {
result = service.getSongList(type, size, offset, context, null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ public SectionAdapter getAdapter(List objs) {
sections.add(albums);
headers.add("albums");

List<Integer> songs = new ArrayList<>();

if(ServerInfo.isMadsonic6(context)) {
List<Integer> songs = new ArrayList<>();

songs.add(R.string.main_songs_newest);
if(ServerInfo.checkServerVersion(context, "2.0.1")) {
Expand All @@ -143,10 +144,15 @@ public SectionAdapter getAdapter(List objs) {
songs.add(R.string.main_songs_frequent);
}

sections.add(songs);
headers.add("songs");
}

if(ServerInfo.checkServerVersion(context, "1.2.0")) {
songs.add(R.string.main_songs_random);
}

sections.add(songs);
headers.add("songs");

if(ServerInfo.checkServerVersion(context, "1.8")) {
List<Integer> videos = Arrays.asList(R.string.main_videos);
sections.add(videos);
Expand Down Expand Up @@ -403,6 +409,8 @@ public void onItemClicked(UpdateView<Integer> updateView, Integer item) {
showAlbumList("newest");
} else if (item == R.string.main_albums_random) {
showAlbumList("random");
} else if (item == R.string.main_songs_random) {
showAlbumList("randomsongs");
} else if (item == R.string.main_albums_highest) {
showAlbumList("highest");
} else if (item == R.string.main_albums_recent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ private void getAlbumList(final String albumListType, final int size, final bool
setTitle(R.string.main_albums_newest);
} else if ("random".equals(albumListType)) {
setTitle(R.string.main_albums_random);
} else if ("randomsongs".equals(albumListType)) {
setTitle(R.string.main_songs_random);
} else if ("highest".equals(albumListType)) {
setTitle(R.string.main_albums_highest);
} else if ("recent".equals(albumListType)) {
Expand Down Expand Up @@ -576,7 +578,9 @@ protected MusicDirectory load(MusicService service) throws Exception {
}
} else if("genres".equals(albumListType) || "genres-songs".equals(albumListType)) {
result = service.getSongsByGenre(albumListExtra, size, 0, context, this);
} else if(albumListType.indexOf(MainFragment.SONGS_LIST_PREFIX) != -1) {
} else if("randomsongs".equals(albumListType)) {
result = service.getRandomTracks(size,context, this);
} else if(albumListType.indexOf(MainFragment.SONGS_LIST_PREFIX) != -1) {
result = service.getSongList(albumListType, size, 0, context, this);
} else {
result = service.getAlbumList(albumListType, size, 0, refresh, context, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,11 @@ public MusicDirectory getRandomSongs(int size, String artistId, Context context,
return musicService.getRandomSongs(size, artistId, context, progressListener);
}

@Override
public MusicDirectory getRandomTracks(int size, Context context, ProgressListener progressListener) throws Exception {
return musicService.getRandomTracks(size, context, progressListener);
}

@Override
public MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public interface MusicService {

MusicDirectory getRandomSongs(int size, String artistId, Context context, ProgressListener progressListener) throws Exception;
MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception;
MusicDirectory getRandomTracks(int size, Context context, ProgressListener progressListener) throws Exception;

String getCoverArtUrl(Context context, MusicDirectory.Entry entry) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ public MusicDirectory getRandomSongs(int size, String artistId, Context context,
throw new OfflineException(ERRORMSG);
}

@Override
public MusicDirectory getRandomTracks(int size, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException(ERRORMSG);
}

@Override
public String getVideoUrl(int maxBitrate, Context context, String id) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,17 +734,32 @@ public MusicDirectory getStarredList(Context context, ProgressListener progressL
}

@Override
public MusicDirectory getRandomSongs(int size, String musicFolderId, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception {
public MusicDirectory getRandomTracks(int size, Context context, ProgressListener progressListener) throws Exception {
List<String> names = new ArrayList<String>();
List<Object> values = new ArrayList<Object>();

names.add("size");
values.add(size);

if (musicFolderId != null && !"".equals(musicFolderId) && !Util.isTagBrowsing(context, getInstance(context))) {
names.add("musicFolderId");
values.add(musicFolderId);
Reader reader = getReader(context, progressListener, "getRandomSongs", names, values);
try {
return new RandomSongsParser(context, getInstance(context)).parse(reader, progressListener);
} finally {
Util.close(reader);
}
}
@Override
public MusicDirectory getRandomSongs(int size, String musicFolderId, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception {
List<String> names = new ArrayList<String>();
List<Object> values = new ArrayList<Object>();

names.add("size");
values.add(size);

if (musicFolderId != null && !"".equals(musicFolderId) && !Util.isTagBrowsing(context, getInstance(context))) {
names.add("musicFolderId");
values.add(musicFolderId);
}
if(genre != null && !"".equals(genre)) {
names.add("genre");
values.add(genre);
Expand Down Expand Up @@ -774,13 +789,13 @@ public MusicDirectory getRandomSongs(int size, String musicFolderId, String genr
values.add(endYear);
}

Reader reader = getReader(context, progressListener, "getRandomSongs", names, values);
try {
return new RandomSongsParser(context, getInstance(context)).parse(reader, progressListener);
} finally {
Util.close(reader);
}
}
Reader reader = getReader(context, progressListener, "getRandomSongs", names, values);
try {
return new RandomSongsParser(context, getInstance(context)).parse(reader, progressListener);
} finally {
Util.close(reader);
}
}

private void checkServerVersion(Context context, String version, String text) throws ServerTooOldException {
Version serverVersion = ServerInfo.getServerVersion(context);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<string name="main.albums_year">Decades</string>
<string name="main.albums_alphabetical">Alphabetically</string>
<string name="main.videos">Videos</string>
<string name="main.songs_random">Random</string>
<string name="main.songs_genres">@string/main.albums_genres</string>
<string name="main.songs_newest">@string/main.albums_newest</string>
<string name="main.songs_top_played">Top Played</string>
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:7.4.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -22,6 +22,7 @@ allprojects {
jcenter()
maven {
url 'http://4thline.org/m2'
allowInsecureProtocol = true
}
google()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists