mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
- Removed middle layer of abstraction for subsonic classes
- Used kotlin for classes
This commit is contained in:
parent
917c0839de
commit
ca15f51c85
168 changed files with 2026 additions and 6588 deletions
|
|
@ -0,0 +1,5 @@
|
|||
package com.cappielloantonio.play.util
|
||||
|
||||
object Constants {
|
||||
const val SHARED_PREF_KEY = "play-shared-preferences"
|
||||
}
|
||||
|
|
@ -12,142 +12,25 @@ import androidx.media3.common.util.UnstableApi;
|
|||
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Chronology;
|
||||
import com.cappielloantonio.play.model.Download;
|
||||
import com.cappielloantonio.play.model.Media;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.PodcastChannel;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumInfo;
|
||||
import com.cappielloantonio.play.subsonic.models.AlbumWithSongsID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistInfo2;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||
import com.cappielloantonio.play.subsonic.models.Child;
|
||||
import com.cappielloantonio.play.subsonic.models.Genre;
|
||||
import com.cappielloantonio.play.subsonic.models.SimilarArtistID3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MappingUtil {
|
||||
public static ArrayList<Media> mapSong(List<Child> children) {
|
||||
ArrayList<Media> songs = new ArrayList();
|
||||
|
||||
for (Child child : children) {
|
||||
songs.add(new Media(child));
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static Media mapSong(Child child) {
|
||||
return new Media(child);
|
||||
}
|
||||
|
||||
public static ArrayList<Album> mapAlbum(List<AlbumID3> albumID3List) {
|
||||
ArrayList<Album> albums = new ArrayList();
|
||||
|
||||
for (AlbumID3 albumID3 : albumID3List) {
|
||||
albums.add(new Album(albumID3));
|
||||
}
|
||||
|
||||
return albums;
|
||||
}
|
||||
|
||||
public static Album mapAlbum(AlbumWithSongsID3 albumWithSongsID3) {
|
||||
return new Album(albumWithSongsID3);
|
||||
}
|
||||
|
||||
public static ArrayList<Artist> mapArtist(List<ArtistID3> artistID3List) {
|
||||
ArrayList<Artist> artists = new ArrayList();
|
||||
|
||||
for (ArtistID3 artistID3 : artistID3List) {
|
||||
artists.add(new Artist(artistID3));
|
||||
}
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
public static Artist mapArtist(ArtistInfo2 artistInfo2) {
|
||||
return new Artist(artistInfo2);
|
||||
}
|
||||
|
||||
public static Artist mapArtist(ArtistWithAlbumsID3 artistWithAlbumsID3) {
|
||||
return new Artist(artistWithAlbumsID3);
|
||||
}
|
||||
|
||||
public static Artist mapArtistWithAlbum(ArtistWithAlbumsID3 artistWithAlbumsID3) {
|
||||
return new Artist(artistWithAlbumsID3);
|
||||
}
|
||||
|
||||
public static ArrayList<Artist> mapSimilarArtist(List<SimilarArtistID3> similarArtistID3s) {
|
||||
ArrayList<Artist> artists = new ArrayList();
|
||||
|
||||
for (SimilarArtistID3 similarArtistID3 : similarArtistID3s) {
|
||||
artists.add(new Artist(similarArtistID3));
|
||||
}
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
public static ArrayList<Media> mapQueue(List<Queue> queueList) {
|
||||
ArrayList<Media> media = new ArrayList();
|
||||
|
||||
for (Queue item : queueList) {
|
||||
media.add(new Media(item));
|
||||
}
|
||||
|
||||
return media;
|
||||
}
|
||||
|
||||
public static Queue mapMediaToQueue(Media media, int trackOrder) {
|
||||
return new Queue(trackOrder, media.getId(), media.getTitle(), media.getAlbumId(), media.getAlbumName(), media.getArtistId(), media.getArtistName(), media.getCoverArtId(), media.getDuration(), 0, 0, media.getStreamId(), media.getChannelId(), media.getPublishDate(), media.getContainer(), media.getBitrate(), media.getExtension(), media.getType());
|
||||
}
|
||||
|
||||
public static List<Queue> mapMediaToQueue(List<Media> media) {
|
||||
List<Queue> queue = new ArrayList<>();
|
||||
|
||||
for (int counter = 0; counter < media.size(); counter++) {
|
||||
queue.add(mapMediaToQueue(media.get(counter), counter));
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
public static ArrayList<Playlist> mapPlaylist(List<com.cappielloantonio.play.subsonic.models.Playlist> playlists) {
|
||||
ArrayList<Playlist> playlist = new ArrayList();
|
||||
|
||||
for (com.cappielloantonio.play.subsonic.models.Playlist item : playlists) {
|
||||
playlist.add(new Playlist(item));
|
||||
}
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public static ArrayList<Media> mapDownloadToMedia(List<Download> downloads) {
|
||||
ArrayList<Media> media = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
Media item = new Media(download);
|
||||
if (!media.contains(item)) {
|
||||
media.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return media;
|
||||
}
|
||||
|
||||
public static ArrayList<Album> mapDownloadToAlbum(List<Download> downloads) {
|
||||
ArrayList<Album> albums = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
// TODO
|
||||
/* for (Download download : downloads) {
|
||||
Album album = new Album(download);
|
||||
if (!albums.contains(album)) {
|
||||
albums.add(album);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
return albums;
|
||||
}
|
||||
|
|
@ -155,12 +38,13 @@ public class MappingUtil {
|
|||
public static ArrayList<Artist> mapDownloadToArtist(List<Download> downloads) {
|
||||
ArrayList<Artist> artists = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
// TODO
|
||||
/* for (Download download : downloads) {
|
||||
Artist artist = new Artist(download);
|
||||
if (!artists.contains(artist)) {
|
||||
artists.add(artist);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
|
@ -168,63 +52,53 @@ public class MappingUtil {
|
|||
public static ArrayList<Playlist> mapDownloadToPlaylist(List<Download> downloads) {
|
||||
ArrayList<Playlist> playlists = new ArrayList();
|
||||
|
||||
for (Download download : downloads) {
|
||||
// TODO
|
||||
/*for (Download download : downloads) {
|
||||
playlists.add(new Playlist(download.getPlaylistId(), download.getPlaylistName(), null, 0, 0, null));
|
||||
}
|
||||
}*/
|
||||
|
||||
return playlists;
|
||||
}
|
||||
|
||||
public static ArrayList<Download> mapDownload(List<Media> media, String playlistId, String playlistName) {
|
||||
public static ArrayList<Download> mapDownload(List<Child> media, String playlistId, String playlistName) {
|
||||
ArrayList<Download> downloads = new ArrayList();
|
||||
|
||||
for (Media item : media) {
|
||||
downloads.add(new Download(item, playlistId, playlistName));
|
||||
}
|
||||
// TODO
|
||||
/* for (Child item : media) {
|
||||
Download download = (Download) item;
|
||||
download.setMediaID();
|
||||
download.setServer();
|
||||
download.setPlaylistId();
|
||||
downloads.add(download);
|
||||
} */
|
||||
|
||||
return downloads;
|
||||
}
|
||||
|
||||
public static Download mapDownload(Media media, String playlistId, String playlistName) {
|
||||
return new Download(media, playlistId, playlistName);
|
||||
}
|
||||
public static Download mapDownload(Child media, String playlistId, String playlistName) {
|
||||
// TODO
|
||||
//return new Download(media, playlistId, playlistName);
|
||||
|
||||
public static ArrayList<com.cappielloantonio.play.model.Genre> mapGenre(List<Genre> genreList) {
|
||||
ArrayList<com.cappielloantonio.play.model.Genre> genres = new ArrayList();
|
||||
|
||||
for (Genre genre : genreList) {
|
||||
genres.add(new com.cappielloantonio.play.model.Genre(genre));
|
||||
}
|
||||
|
||||
return genres;
|
||||
return null;
|
||||
}
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
public static MediaItem mapMediaItem(Context context, Media media, boolean stream) {
|
||||
public static MediaItem mapMediaItem(Context context, Child media, boolean stream) {
|
||||
boolean isDownloaded = DownloadUtil.getDownloadTracker(context).isDownloaded(MusicUtil.getDownloadUri(media.getId()));
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("id", media.getId());
|
||||
bundle.putString("albumId", media.getAlbumId());
|
||||
bundle.putString("artistId", media.getArtistId());
|
||||
bundle.putString("coverArtId", media.getCoverArtId());
|
||||
bundle.putString("mediaType", media.getType());
|
||||
bundle.putLong("duration", media.getDuration());
|
||||
bundle.putString("container", media.getContainer());
|
||||
bundle.putInt("bitrate", media.getBitrate());
|
||||
bundle.putString("extension", media.getExtension());
|
||||
bundle.putString("server", PreferenceUtil.getInstance(context).getServerId());
|
||||
bundle.putParcelable("child", media);
|
||||
|
||||
return new MediaItem.Builder()
|
||||
.setMediaId(media.getId())
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder()
|
||||
.setTitle(MusicUtil.getReadableString(media.getTitle()))
|
||||
.setTrackNumber(media.getTrackNumber())
|
||||
.setTrackNumber(media.getTrack())
|
||||
.setDiscNumber(media.getDiscNumber())
|
||||
.setReleaseYear(media.getYear())
|
||||
.setAlbumTitle(MusicUtil.getReadableString(media.getAlbumName()))
|
||||
.setArtist(MusicUtil.getReadableString(media.getArtistName()))
|
||||
.setAlbumTitle(MusicUtil.getReadableString(media.getAlbum()))
|
||||
.setArtist(MusicUtil.getReadableString(media.getArtist()))
|
||||
.setExtras(bundle)
|
||||
.build()
|
||||
)
|
||||
|
|
@ -239,7 +113,7 @@ public class MappingUtil {
|
|||
.build();
|
||||
}
|
||||
|
||||
private static Uri getUri(Context context, Media media, boolean stream) {
|
||||
private static Uri getUri(Context context, Child media, boolean stream) {
|
||||
switch (media.getType()) {
|
||||
case Media.MEDIA_TYPE_MUSIC:
|
||||
if (stream) {
|
||||
|
|
@ -249,16 +123,18 @@ public class MappingUtil {
|
|||
}
|
||||
case Media.MEDIA_TYPE_PODCAST:
|
||||
if (stream) {
|
||||
return MusicUtil.getStreamUri(context, media.getStreamId());
|
||||
// TODO
|
||||
// return MusicUtil.getStreamUri(context, media.getStreamId());
|
||||
} else {
|
||||
return MusicUtil.getDownloadUri(media.getStreamId());
|
||||
// TODO
|
||||
// return MusicUtil.getDownloadUri(media.getStreamId());
|
||||
}
|
||||
default:
|
||||
return MusicUtil.getStreamUri(context, media.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<MediaItem> mapMediaItems(Context context, List<Media> items, boolean stream) {
|
||||
public static ArrayList<MediaItem> mapMediaItems(Context context, List<Child> items, boolean stream) {
|
||||
ArrayList<MediaItem> mediaItems = new ArrayList();
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
|
|
@ -267,63 +143,4 @@ public class MappingUtil {
|
|||
|
||||
return mediaItems;
|
||||
}
|
||||
|
||||
public static Chronology mapChronology(MediaItem item) {
|
||||
return new Chronology(
|
||||
item.mediaId,
|
||||
item.mediaMetadata.title.toString(),
|
||||
item.mediaMetadata.extras.get("albumId").toString(),
|
||||
item.mediaMetadata.albumTitle.toString(),
|
||||
item.mediaMetadata.extras.get("artistId").toString(),
|
||||
item.mediaMetadata.artist.toString(),
|
||||
item.mediaMetadata.extras.get("coverArtId").toString(),
|
||||
(long) item.mediaMetadata.extras.get("duration"),
|
||||
item.mediaMetadata.extras.get("container").toString(),
|
||||
(int) item.mediaMetadata.extras.get("bitrate"),
|
||||
item.mediaMetadata.extras.get("extension").toString(),
|
||||
item.mediaMetadata.extras.get("server").toString()
|
||||
);
|
||||
}
|
||||
|
||||
public static ArrayList<Media> mapChronology(List<Chronology> items) {
|
||||
ArrayList<Media> songs = new ArrayList();
|
||||
|
||||
for (Chronology item : items) {
|
||||
songs.add(mapSong(item));
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
public static Media mapSong(Chronology item) {
|
||||
return new Media(item);
|
||||
}
|
||||
|
||||
public static ArrayList<PodcastChannel> mapPodcastChannel(List<com.cappielloantonio.play.subsonic.models.PodcastChannel> subsonicPodcastChannels) {
|
||||
ArrayList<PodcastChannel> podcastChannels = new ArrayList();
|
||||
|
||||
for (com.cappielloantonio.play.subsonic.models.PodcastChannel subsonicPodcastChannel : subsonicPodcastChannels) {
|
||||
podcastChannels.add(mapPodcastChannel(subsonicPodcastChannel));
|
||||
}
|
||||
|
||||
return podcastChannels;
|
||||
}
|
||||
|
||||
public static PodcastChannel mapPodcastChannel(com.cappielloantonio.play.subsonic.models.PodcastChannel subsonicPodcastChannel) {
|
||||
return new PodcastChannel(subsonicPodcastChannel);
|
||||
}
|
||||
|
||||
public static ArrayList<Media> mapPodcastEpisode(List<com.cappielloantonio.play.subsonic.models.PodcastEpisode> subsonicPodcastEpisodes) {
|
||||
ArrayList<Media> podcastEpisodes = new ArrayList();
|
||||
|
||||
for (com.cappielloantonio.play.subsonic.models.PodcastEpisode subsonicPodcastEpisode : subsonicPodcastEpisodes) {
|
||||
podcastEpisodes.add(mapPodcastEpisode(subsonicPodcastEpisode));
|
||||
}
|
||||
|
||||
return podcastEpisodes;
|
||||
}
|
||||
|
||||
public static Media mapPodcastEpisode(com.cappielloantonio.play.subsonic.models.PodcastEpisode subsonicPodcastEpisode) {
|
||||
return new Media(subsonicPodcastEpisode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,11 +201,11 @@ public class MusicUtil {
|
|||
return "0";
|
||||
|
||||
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateWifi();
|
||||
return Preferences.getMaxBitrateWifi();
|
||||
} else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateMobile();
|
||||
return Preferences.getMaxBitrateMobile();
|
||||
} else {
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateWifi();
|
||||
return Preferences.getMaxBitrateWifi();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -216,11 +216,11 @@ public class MusicUtil {
|
|||
if (network == null || networkCapabilities == null) return "raw";
|
||||
|
||||
if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatWifi();
|
||||
return Preferences.getAudioTranscodeFormatWifi();
|
||||
} else if (networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatMobile();
|
||||
return Preferences.getAudioTranscodeFormatMobile();
|
||||
} else {
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatWifi();
|
||||
return Preferences.getAudioTranscodeFormatWifi();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,194 +0,0 @@
|
|||
package com.cappielloantonio.play.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.cappielloantonio.play.helper.ThemeHelper;
|
||||
|
||||
public class PreferenceUtil {
|
||||
private static final String TAG = "PreferenceUtil";
|
||||
|
||||
public static final String SERVER = "server";
|
||||
public static final String THEME = "theme";
|
||||
public static final String USER = "user";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String SALT = "salt";
|
||||
public static final String LOW_SECURITY = "low_security";
|
||||
public static final String SERVER_ID = "server_id";
|
||||
public static final String PLAYBACK_SPEED = "playback_speed";
|
||||
public static final String SKIP_SILENCE = "skip_silence";
|
||||
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
||||
public static final String IMAGE_SIZE = "image_size";
|
||||
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
|
||||
public static final String MAX_BITRATE_WIFI = "max_bitrate_wifi";
|
||||
public static final String MAX_BITRATE_MOBILE = "max_bitrate_mobile";
|
||||
public static final String AUDIO_TRANSCODE_FORMAT_WIFI = "audio_transcode_format_wifi";
|
||||
public static final String AUDIO_TRANSCODE_FORMAT_MOBILE = "audio_transcode_format_mobile";
|
||||
public static final String WIFI_ONLY = "wifi_only";
|
||||
public static final String DATA_SAVING_MODE = "data_saving_mode";
|
||||
public static final String SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use";
|
||||
|
||||
private static PreferenceUtil sInstance;
|
||||
private final SharedPreferences mPreferences;
|
||||
|
||||
private PreferenceUtil(final Context context) {
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public static PreferenceUtil getInstance(final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PreferenceUtil(context);
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
return mPreferences.getString(THEME, ThemeHelper.DEFAULT_MODE);
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return mPreferences.getString(SERVER, "");
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(SERVER, server);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return mPreferences.getString(USER, null);
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(USER, user);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return mPreferences.getString(PASSWORD, null);
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(PASSWORD, password);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return mPreferences.getString(TOKEN, null);
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(TOKEN, token);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getSalt() {
|
||||
return mPreferences.getString(SALT, null);
|
||||
}
|
||||
|
||||
public void setSalt(String salt) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(SALT, salt);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public boolean isLowScurity() {
|
||||
return mPreferences.getBoolean(LOW_SECURITY, false);
|
||||
}
|
||||
|
||||
public void setLowSecurity(boolean isLowSecurity) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(LOW_SECURITY, isLowSecurity);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getServerId() {
|
||||
return mPreferences.getString(SERVER_ID, "");
|
||||
}
|
||||
|
||||
public void setServerId(String serverId) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(SERVER_ID, serverId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public float getPlaybackSpeed() {
|
||||
return mPreferences.getFloat(PLAYBACK_SPEED, 1f);
|
||||
}
|
||||
|
||||
public void setPlaybackSpeed(float playbackSpeed) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putFloat(PLAYBACK_SPEED, playbackSpeed);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final boolean isSkipSilenceMode() {
|
||||
return mPreferences.getBoolean(SKIP_SILENCE, false);
|
||||
}
|
||||
|
||||
public void setSkipSilenceMode(Boolean isSkipSilenceMode) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(SKIP_SILENCE, isSkipSilenceMode);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final int getImageCacheSize() {
|
||||
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
||||
}
|
||||
|
||||
public final int getMediaCacheSize() {
|
||||
return Integer.parseInt(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
|
||||
}
|
||||
|
||||
public final int getImageSize() {
|
||||
return Integer.parseInt(mPreferences.getString(IMAGE_SIZE, "-1"));
|
||||
}
|
||||
|
||||
public final String getMaxBitrateWifi() {
|
||||
return mPreferences.getString(MAX_BITRATE_WIFI, "0");
|
||||
}
|
||||
|
||||
public final String getMaxBitrateMobile() {
|
||||
return mPreferences.getString(MAX_BITRATE_MOBILE, "0");
|
||||
}
|
||||
|
||||
public final String getAudioTranscodeFormatWifi() {
|
||||
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_WIFI, "raw");
|
||||
}
|
||||
|
||||
public final String getAudioTranscodeFormatMobile() {
|
||||
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_MOBILE, "raw");
|
||||
}
|
||||
|
||||
public final boolean isWifiOnly() {
|
||||
return mPreferences.getBoolean(WIFI_ONLY, false);
|
||||
}
|
||||
|
||||
public final boolean isDataSavingMode() {
|
||||
return mPreferences.getBoolean(DATA_SAVING_MODE, false);
|
||||
}
|
||||
|
||||
public void setDataSavingMode(Boolean isDataSavingModeEnabled) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public final boolean isStarredSyncEnabled() {
|
||||
return mPreferences.getBoolean(SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, false);
|
||||
}
|
||||
|
||||
public void setStarredSyncEnabled(Boolean isStarredSyncEnabled) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, isStarredSyncEnabled);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
189
app/src/main/java/com/cappielloantonio/play/util/Preferences.kt
Normal file
189
app/src/main/java/com/cappielloantonio/play/util/Preferences.kt
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
package com.cappielloantonio.play.util
|
||||
|
||||
import com.cappielloantonio.play.App
|
||||
import com.cappielloantonio.play.helper.ThemeHelper
|
||||
|
||||
object Preferences {
|
||||
const val THEME = "theme"
|
||||
private const val SERVER = "server"
|
||||
private const val USER = "user"
|
||||
private const val PASSWORD = "password"
|
||||
private const val TOKEN = "token"
|
||||
private const val SALT = "salt"
|
||||
private const val LOW_SECURITY = "low_security"
|
||||
private const val SERVER_ID = "server_id"
|
||||
private const val PLAYBACK_SPEED = "playback_speed"
|
||||
private const val SKIP_SILENCE = "skip_silence"
|
||||
private const val IMAGE_CACHE_SIZE = "image_cache_size"
|
||||
private const val IMAGE_SIZE = "image_size"
|
||||
private const val MEDIA_CACHE_SIZE = "media_cache_size"
|
||||
private const val MAX_BITRATE_WIFI = "max_bitrate_wifi"
|
||||
private const val MAX_BITRATE_MOBILE = "max_bitrate_mobile"
|
||||
private const val AUDIO_TRANSCODE_FORMAT_WIFI = "audio_transcode_format_wifi"
|
||||
private const val AUDIO_TRANSCODE_FORMAT_MOBILE = "audio_transcode_format_mobile"
|
||||
private const val WIFI_ONLY = "wifi_only"
|
||||
private const val DATA_SAVING_MODE = "data_saving_mode"
|
||||
private const val SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use"
|
||||
|
||||
@JvmStatic
|
||||
fun getTheme(): String? {
|
||||
return App.getInstance().preferences.getString(THEME, ThemeHelper.DEFAULT_MODE)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getServer(): String? {
|
||||
return App.getInstance().preferences.getString(SERVER, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setServer(server: String?) {
|
||||
App.getInstance().preferences.edit().putString(SERVER, server).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getUser(): String? {
|
||||
return App.getInstance().preferences.getString(USER, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setUser(user: String?) {
|
||||
App.getInstance().preferences.edit().putString(USER, user).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getPassword(): String? {
|
||||
return App.getInstance().preferences.getString(PASSWORD, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setPassword(password: String?) {
|
||||
App.getInstance().preferences.edit().putString(PASSWORD, password).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getToken(): String? {
|
||||
return App.getInstance().preferences.getString(TOKEN, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setToken(token: String?) {
|
||||
App.getInstance().preferences.edit().putString(TOKEN, token).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getSalt(): String? {
|
||||
return App.getInstance().preferences.getString(SALT, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setSalt(salt: String?) {
|
||||
App.getInstance().preferences.edit().putString(SALT, salt).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isLowScurity(): Boolean {
|
||||
return App.getInstance().preferences.getBoolean(LOW_SECURITY, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setLowSecurity(isLowSecurity: Boolean) {
|
||||
App.getInstance().preferences.edit().putBoolean(LOW_SECURITY, isLowSecurity).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getServerId(): String? {
|
||||
return App.getInstance().preferences.getString(SERVER_ID, null)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setServerId(serverId: String?) {
|
||||
App.getInstance().preferences.edit().putString(SERVER_ID, serverId).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getPlaybackSpeed(): Float {
|
||||
return App.getInstance().preferences.getFloat(PLAYBACK_SPEED, 1f)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setPlaybackSpeed(playbackSpeed: Float) {
|
||||
App.getInstance().preferences.edit().putFloat(PLAYBACK_SPEED, playbackSpeed).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isSkipSilenceMode(): Boolean {
|
||||
return App.getInstance().preferences.getBoolean(SKIP_SILENCE, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setSkipSilenceMode(isSkipSilenceMode: Boolean) {
|
||||
App.getInstance().preferences.edit().putBoolean(SKIP_SILENCE, isSkipSilenceMode)
|
||||
.apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getImageCacheSize(): Int {
|
||||
return App.getInstance().preferences.getString(IMAGE_CACHE_SIZE, "400000000")!!
|
||||
.toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMediaCacheSize(): Int {
|
||||
return App.getInstance().preferences.getString(MEDIA_CACHE_SIZE, "400000000")!!
|
||||
.toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getImageSize(): Int {
|
||||
return App.getInstance().preferences.getString(IMAGE_SIZE, "-1")!!.toInt()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMaxBitrateWifi(): String {
|
||||
return App.getInstance().preferences.getString(MAX_BITRATE_WIFI, "0")!!
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getMaxBitrateMobile(): String {
|
||||
return App.getInstance().preferences.getString(MAX_BITRATE_MOBILE, "0")!!
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getAudioTranscodeFormatWifi(): String {
|
||||
return App.getInstance().preferences.getString(AUDIO_TRANSCODE_FORMAT_WIFI, "raw")!!
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getAudioTranscodeFormatMobile(): String {
|
||||
return App.getInstance().preferences.getString(AUDIO_TRANSCODE_FORMAT_MOBILE, "raw")!!
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isWifiOnly(): Boolean {
|
||||
return App.getInstance().preferences.getBoolean(WIFI_ONLY, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isDataSavingMode(): Boolean {
|
||||
return App.getInstance().preferences.getBoolean(DATA_SAVING_MODE, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setDataSavingMode(isDataSavingModeEnabled: Boolean) {
|
||||
App.getInstance().preferences.edit()
|
||||
.putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isStarredSyncEnabled(): Boolean {
|
||||
return App.getInstance().preferences
|
||||
.getBoolean(SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setStarredSyncEnabled(isStarredSyncEnabled: Boolean) {
|
||||
App.getInstance().preferences.edit().putBoolean(
|
||||
SYNC_STARRED_TRACKS_FOR_OFFLINE_USE, isStarredSyncEnabled
|
||||
).apply()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue