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 {
|
|
|
|
|
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-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";
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
public static final String HOST_URL = "host";
|
|
|
|
|
public static final String IMAGE_CACHE_SIZE = "image_cache_size";
|
|
|
|
|
|
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-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) {
|
|
|
|
|
sInstance = new PreferenceUtil(context.getApplicationContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTheme() { return mPreferences.getString("themePref", ThemeHelper.DEFAULT_MODE ); }
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 15:38:08 +01:00
|
|
|
public final String getHostUrl() {
|
|
|
|
|
return mPreferences.getString(HOST_URL, "undefined");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final int getImageCacheSize() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDirectPlayCodecs(List<DirectPlayCodec> directPlayCodecs) {
|
|
|
|
|
Set<String> codecNames = new HashSet<>();
|
|
|
|
|
for (DirectPlayCodec directPlayCodec : directPlayCodecs) {
|
|
|
|
|
if (directPlayCodec.selected) {
|
|
|
|
|
codecNames.add(directPlayCodec.codec.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putStringSet(DIRECT_PLAY_CODECS, codecNames);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|