mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
Add song/genre sync
This commit is contained in:
parent
b2c269a051
commit
76037e487b
47 changed files with 703 additions and 89 deletions
|
|
@ -11,8 +11,10 @@ public class PreferenceUtil {
|
|||
public static final String SERVER = "server";
|
||||
public static final String USER = "user";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String MUSIC_LIBRARY_ID = "music_library_id";
|
||||
|
||||
public static final String SYNC = "sync";
|
||||
public static final String SONG_GENRE_SYNC = "song_genre_sync";
|
||||
|
||||
public static final String HOST_URL = "host";
|
||||
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
||||
|
|
@ -75,6 +77,26 @@ public class PreferenceUtil {
|
|||
editor.apply();
|
||||
}
|
||||
|
||||
public Boolean getSongGenreSync() {
|
||||
return mPreferences.getBoolean(SONG_GENRE_SYNC, false);
|
||||
}
|
||||
|
||||
public void setSongGenreSync(Boolean sync) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(SONG_GENRE_SYNC, sync);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getMusicLibraryID() {
|
||||
return mPreferences.getString(MUSIC_LIBRARY_ID, "");
|
||||
}
|
||||
|
||||
public void setMusicLibraryID(String musicLibraryID) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(MUSIC_LIBRARY_ID, musicLibraryID);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final String getHostUrl() {
|
||||
return mPreferences.getString(HOST_URL, "undefined");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.cappielloantonio.play.model.Artist;
|
|||
import com.cappielloantonio.play.model.Genre;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.model.SongGenreCross;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
|
@ -23,8 +24,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
public class SyncUtil {
|
||||
public static BaseItemDto musicLibrary;
|
||||
|
||||
public static void getLibraries(Context context, MediaCallback callback) {
|
||||
String id = App.getApiClientInstance(context).getCurrentUserId();
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ public class SyncUtil {
|
|||
query.setFields(new ItemFields[]{ItemFields.MediaSources});
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(musicLibrary.getId());
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
|
||||
App.getApiClientInstance(context).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
|
|
@ -78,7 +77,7 @@ public class SyncUtil {
|
|||
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(musicLibrary.getId());
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
|
||||
App.getApiClientInstance(context).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
|
|
@ -104,7 +103,7 @@ public class SyncUtil {
|
|||
query.setFields(new ItemFields[]{ItemFields.Genres});
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(musicLibrary.getId());
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
|
||||
App.getApiClientInstance(context).GetAlbumArtistsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
|
|
@ -130,7 +129,7 @@ public class SyncUtil {
|
|||
query.setIncludeItemTypes(new String[]{"Playlist"});
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(musicLibrary.getId());
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
|
||||
App.getApiClientInstance(context).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
|
|
@ -155,7 +154,7 @@ public class SyncUtil {
|
|||
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(musicLibrary.getId());
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
|
||||
App.getApiClientInstance(context).GetGenresAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
|
|
@ -174,4 +173,33 @@ public class SyncUtil {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void getSongsPerGenre(Context context, MediaCallback callback, String genreId) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
|
||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
||||
query.setFields(new ItemFields[]{ItemFields.MediaSources});
|
||||
query.setUserId(App.getApiClientInstance(context).getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID());
|
||||
query.setGenreIds(new String[]{genreId});
|
||||
|
||||
App.getApiClientInstance(context).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
ArrayList<SongGenreCross> crosses = new ArrayList<>();
|
||||
|
||||
for (BaseItemDto itemDto : result.getItems()) {
|
||||
crosses.add(new SongGenreCross(itemDto.getId(), genreId));
|
||||
}
|
||||
|
||||
callback.onLoadMedia(crosses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
callback.onError(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue