2020-11-20 15:38:08 +01:00
|
|
|
package com.cappielloantonio.play.util;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.helper.ThemeHelper;
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.model.DirectPlayCodec;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
public class PreferenceUtil {
|
2021-05-01 19:30:53 +02:00
|
|
|
private static final String TAG = "PreferenceUtil";
|
|
|
|
|
|
2020-11-20 15:38:08 +01:00
|
|
|
public static final String SERVER = "server";
|
|
|
|
|
public static final String USER = "user";
|
|
|
|
|
public static final String TOKEN = "token";
|
2020-11-24 10:52:00 +01:00
|
|
|
public static final String MUSIC_LIBRARY_ID = "music_library_id";
|
2020-12-08 20:30:21 +01:00
|
|
|
public static final String POSITION = "position";
|
|
|
|
|
public static final String PROGRESS = "progress";
|
2020-11-20 15:38:08 +01:00
|
|
|
public static final String SYNC = "sync";
|
2020-11-24 10:52:00 +01:00
|
|
|
public static final String SONG_GENRE_SYNC = "song_genre_sync";
|
2021-04-21 14:16:07 +02:00
|
|
|
public static final String SEARCH_ELEMENT_PER_CATEGORY = "search_element_per_category";
|
2020-11-20 15:38:08 +01:00
|
|
|
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
2020-12-08 20:30:21 +01:00
|
|
|
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
|
2021-04-19 14:20:00 +02:00
|
|
|
public static final String INSTANT_MIX_SONG_NUMBER = "instant_mix_song_number";
|
2021-05-01 18:29:57 +02:00
|
|
|
public static final String SIMILAR_ITEMS_NUMBER = "similar_items_number";
|
2020-12-08 11:12:44 +01:00
|
|
|
public static final String TRANSCODE_CODEC = "transcode_codec";
|
|
|
|
|
public static final String DIRECT_PLAY_CODECS = "direct_play_codecs";
|
|
|
|
|
public static final String MAXIMUM_BITRATE = "maximum_bitrate";
|
2020-12-08 20:30:21 +01:00
|
|
|
public static final String AUDIO_DUCKING = "audio_ducking";
|
2021-04-20 12:36:58 +02:00
|
|
|
public static final String SONG_NUMBER = "SONG_NUMBER";
|
2021-05-01 19:30:53 +02:00
|
|
|
|
2020-11-20 15:38:08 +01:00
|
|
|
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) {
|
2021-04-12 17:56:09 +02:00
|
|
|
sInstance = new PreferenceUtil(context);
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sInstance;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 11:01:02 +02:00
|
|
|
public String getTheme() {
|
|
|
|
|
return mPreferences.getString("themePref", ThemeHelper.DEFAULT_MODE);
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
public String getServer() {
|
|
|
|
|
return mPreferences.getString(SERVER, "https://jellyfin.org");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setServer(String server) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(SERVER, server);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUser() {
|
|
|
|
|
return mPreferences.getString(USER, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUser(String user) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(USER, user);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getToken() {
|
2020-12-05 21:31:12 +01:00
|
|
|
return mPreferences.getString(TOKEN, null);
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setToken(String token) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(TOKEN, token);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Boolean getSync() {
|
|
|
|
|
return mPreferences.getBoolean(SYNC, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSync(Boolean sync) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putBoolean(SYNC, sync);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-24 10:52:00 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 15:24:42 +02:00
|
|
|
public int getPosition() {
|
|
|
|
|
return mPreferences.getInt(POSITION, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPosition(int position) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putInt(POSITION, position);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getProgress() {
|
|
|
|
|
return mPreferences.getInt(PROGRESS, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setProgress(int progress) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putInt(PROGRESS, progress);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 15:38:08 +01:00
|
|
|
public final int getImageCacheSize() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
|
|
|
|
}
|
2020-12-08 11:12:44 +01:00
|
|
|
|
2021-04-19 14:20:00 +02:00
|
|
|
public final int getInstantMixSongNumber() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(INSTANT_MIX_SONG_NUMBER, "10"));
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 18:29:57 +02:00
|
|
|
public final int getSimilarItemsNumber() {
|
2021-05-01 19:33:11 +02:00
|
|
|
return Integer.parseInt(mPreferences.getString(SIMILAR_ITEMS_NUMBER, "5"));
|
2021-05-01 18:29:57 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-21 14:16:07 +02:00
|
|
|
public final int getSearchElementPerCategory() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(SEARCH_ELEMENT_PER_CATEGORY, "10"));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
public final String getTranscodeCodec() {
|
|
|
|
|
return mPreferences.getString(TRANSCODE_CODEC, "aac");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final String getMaximumBitrate() {
|
|
|
|
|
return mPreferences.getString(MAXIMUM_BITRATE, "10000000");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<DirectPlayCodec> getDirectPlayCodecs() {
|
|
|
|
|
DirectPlayCodec.Codec[] codecs = DirectPlayCodec.Codec.values();
|
|
|
|
|
|
|
|
|
|
Set<String> selectedCodecNames = new HashSet<>();
|
|
|
|
|
for (DirectPlayCodec.Codec codec : codecs) {
|
|
|
|
|
// this will be the default value
|
|
|
|
|
selectedCodecNames.add(codec.name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectedCodecNames = mPreferences.getStringSet(DIRECT_PLAY_CODECS, selectedCodecNames);
|
|
|
|
|
|
|
|
|
|
ArrayList<DirectPlayCodec> directPlayCodecs = new ArrayList<>();
|
|
|
|
|
for (DirectPlayCodec.Codec codec : codecs) {
|
|
|
|
|
String name = codec.name();
|
|
|
|
|
boolean selected = selectedCodecNames.contains(name);
|
|
|
|
|
directPlayCodecs.add(new DirectPlayCodec(codec, selected));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return directPlayCodecs;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 20:30:21 +01:00
|
|
|
public final int getMediaCacheSize() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final boolean getAudioDucking() {
|
|
|
|
|
return mPreferences.getBoolean(AUDIO_DUCKING, true);
|
|
|
|
|
}
|
2021-04-20 12:36:58 +02:00
|
|
|
|
2021-04-21 14:16:07 +02:00
|
|
|
/*
|
|
|
|
|
* Numero di canzoni salvate nel db
|
|
|
|
|
*/
|
2021-04-20 12:36:58 +02:00
|
|
|
public int getSongNumber() {
|
|
|
|
|
return mPreferences.getInt(SONG_NUMBER, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-21 14:16:07 +02:00
|
|
|
/*
|
|
|
|
|
* Numero di canzoni salvate nel db
|
|
|
|
|
*/
|
2021-04-20 12:36:58 +02:00
|
|
|
public void setSongNumber(int number) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putInt(SONG_NUMBER, number);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|