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;
|
|
|
|
|
|
|
|
|
|
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";
|
2021-07-24 14:47:01 +02:00
|
|
|
public static final String PASSWORD = "password";
|
2020-11-20 15:38:08 +01:00
|
|
|
public static final String TOKEN = "token";
|
2021-07-28 09:20:22 +02:00
|
|
|
public static final String SALT = "salt";
|
2021-08-08 19:21:56 +02:00
|
|
|
public static final String SERVER_ID = "server_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 IMAGE_CACHE_SIZE = "image_cache_size";
|
2021-08-31 09:58:14 +02:00
|
|
|
public static final String IMAGE_SIZE = "image_size";
|
2020-12-08 20:30:21 +01:00
|
|
|
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
|
2021-09-07 18:06:00 +02:00
|
|
|
public static final String MAX_BITRATE_WIFI = "max_bitrate_wifi";
|
|
|
|
|
public static final String MAX_BITRATE_MOBILE = "max_bitrate_mobile";
|
2021-09-12 12:14:36 +02:00
|
|
|
public static final String AUDIO_TRANSCODE_FORMAT_WIFI = "audio_transcode_format_wifi";
|
|
|
|
|
public static final String AUDIO_TRANSCODE_FORMAT_MOBILE = "audio_transcode_format_mobile";
|
2021-09-07 18:06:00 +02:00
|
|
|
public static final String WIFI_ONLY = "wifi_only";
|
2021-09-13 09:02:53 +02:00
|
|
|
public static final String DATA_SAVING_MODE = "data_saving_mode";
|
2021-09-13 11:28:48 +02:00
|
|
|
public static final String SYNC_STARRED_TRACKS_FOR_OFFLINE_USE = "sync_starred_tracks_for_offline_use";
|
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() {
|
2021-09-07 18:06:00 +02:00
|
|
|
return mPreferences.getString(SERVER, "");
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setServer(String server) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(SERVER, server);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUser() {
|
2021-07-24 14:47:01 +02:00
|
|
|
return mPreferences.getString(USER, null);
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUser(String user) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(USER, user);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
2021-07-24 14:47:01 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 09:20:22 +02:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 19:21:56 +02:00
|
|
|
public String getServerId() {
|
2021-08-09 00:23:09 +02:00
|
|
|
return mPreferences.getString(SERVER_ID, "");
|
2021-08-08 19:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setServerId(String serverId) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putString(SERVER_ID, serverId);
|
|
|
|
|
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
|
|
|
|
2020-12-08 20:30:21 +01:00
|
|
|
public final int getMediaCacheSize() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
|
|
|
|
|
}
|
2021-08-31 09:58:14 +02:00
|
|
|
|
|
|
|
|
public final int getImageSize() {
|
|
|
|
|
return Integer.parseInt(mPreferences.getString(IMAGE_SIZE, "-1"));
|
|
|
|
|
}
|
2021-09-07 18:06:00 +02:00
|
|
|
|
|
|
|
|
public final String getMaxBitrateWifi() {
|
|
|
|
|
return mPreferences.getString(MAX_BITRATE_WIFI, "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final String getMaxBitrateMobile() {
|
|
|
|
|
return mPreferences.getString(MAX_BITRATE_MOBILE, "0");
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 12:14:36 +02:00
|
|
|
public final String getAudioTranscodeFormatWifi() {
|
|
|
|
|
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_WIFI, "raw");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final String getAudioTranscodeFormatMobile() {
|
|
|
|
|
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_MOBILE, "raw");
|
2021-09-07 18:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final boolean isWifiOnly() {
|
|
|
|
|
return mPreferences.getBoolean(WIFI_ONLY, false);
|
|
|
|
|
}
|
2021-09-13 09:02:53 +02:00
|
|
|
|
|
|
|
|
public final boolean isDataSavingMode() {
|
|
|
|
|
return mPreferences.getBoolean(DATA_SAVING_MODE, false);
|
|
|
|
|
}
|
2021-09-13 09:24:58 +02:00
|
|
|
|
|
|
|
|
public void setDataSavingMode(Boolean isDataSavingModeEnabled) {
|
|
|
|
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
|
|
|
|
editor.putBoolean(DATA_SAVING_MODE, isDataSavingModeEnabled);
|
|
|
|
|
editor.apply();
|
|
|
|
|
}
|
2021-09-13 11:28:48 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|