mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-30 07:31:34 +03:00
Cleanup a bunch of preference setters and getters by using the new utility class
This commit is contained in:
parent
f0c02f5551
commit
2d9a212b5c
@ -26,7 +26,6 @@ import org.moire.ultrasonic.R;
|
|||||||
import org.moire.ultrasonic.featureflags.Feature;
|
import org.moire.ultrasonic.featureflags.Feature;
|
||||||
import org.moire.ultrasonic.featureflags.FeatureStorage;
|
import org.moire.ultrasonic.featureflags.FeatureStorage;
|
||||||
import org.moire.ultrasonic.filepicker.FilePickerDialog;
|
import org.moire.ultrasonic.filepicker.FilePickerDialog;
|
||||||
import org.moire.ultrasonic.filepicker.OnFileSelectedListener;
|
|
||||||
import org.moire.ultrasonic.log.FileLoggerTree;
|
import org.moire.ultrasonic.log.FileLoggerTree;
|
||||||
import org.moire.ultrasonic.provider.SearchSuggestionProvider;
|
import org.moire.ultrasonic.provider.SearchSuggestionProvider;
|
||||||
import org.moire.ultrasonic.service.Consumer;
|
import org.moire.ultrasonic.service.Consumer;
|
||||||
@ -233,15 +232,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
FilePickerDialog filePickerDialog = FilePickerDialog.Companion.createFilePickerDialog(getContext());
|
FilePickerDialog filePickerDialog = FilePickerDialog.Companion.createFilePickerDialog(getContext());
|
||||||
filePickerDialog.setDefaultDirectory(FileUtil.getDefaultMusicDirectory().getPath());
|
filePickerDialog.setDefaultDirectory(FileUtil.getDefaultMusicDirectory().getPath());
|
||||||
filePickerDialog.setInitialDirectory(cacheLocation.getSummary().toString());
|
filePickerDialog.setInitialDirectory(cacheLocation.getSummary().toString());
|
||||||
filePickerDialog.setOnFileSelectedListener(new OnFileSelectedListener() {
|
filePickerDialog.setOnFileSelectedListener((file, path) -> {
|
||||||
@Override
|
Settings.setCacheLocation(path);
|
||||||
public void onFileSelected(File file, String path) {
|
setCacheLocation(path);
|
||||||
SharedPreferences.Editor editor = cacheLocation.getSharedPreferences().edit();
|
|
||||||
editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, path);
|
|
||||||
editor.apply();
|
|
||||||
|
|
||||||
setCacheLocation(path);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
filePickerDialog.show();
|
filePickerDialog.show();
|
||||||
}
|
}
|
||||||
@ -287,9 +280,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
new Consumer<Integer>() {
|
new Consumer<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(Integer choice) {
|
public void accept(Integer choice) {
|
||||||
SharedPreferences.Editor editor = pauseOnBluetoothDevice.getSharedPreferences().edit();
|
Settings.setPauseOnBluetoothDevice(choice);
|
||||||
editor.putInt(Constants.PREFERENCES_KEY_PAUSE_ON_BLUETOOTH_DEVICE, choice);
|
|
||||||
editor.apply();
|
|
||||||
pauseOnBluetoothDevice.setSummary(bluetoothDevicePreferenceToString(choice));
|
pauseOnBluetoothDevice.setSummary(bluetoothDevicePreferenceToString(choice));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -442,13 +433,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
File dir = new File(path);
|
File dir = new File(path);
|
||||||
|
|
||||||
if (!FileUtil.ensureDirectoryExistsAndIsReadWritable(dir)) {
|
if (!FileUtil.ensureDirectoryExistsAndIsReadWritable(dir)) {
|
||||||
permissionUtil.getValue().handlePermissionFailed(new PermissionUtil.PermissionRequestFinishedCallback() {
|
permissionUtil.getValue().handlePermissionFailed(hasPermission -> {
|
||||||
@Override
|
String currentPath = Settings.getCacheLocation();
|
||||||
public void onPermissionRequestFinished(boolean hasPermission) {
|
cacheLocation.setSummary(currentPath);
|
||||||
String currentPath = settings.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION,
|
|
||||||
FileUtil.getDefaultMusicDirectory().getPath());
|
|
||||||
cacheLocation.setSummary(currentPath);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -193,8 +193,7 @@ class ActiveServerProvider(
|
|||||||
* Queries the Id of the Active Server
|
* Queries the Id of the Active Server
|
||||||
*/
|
*/
|
||||||
fun getActiveServerId(): Int {
|
fun getActiveServerId(): Int {
|
||||||
val preferences = Settings.preferences
|
return Settings.activeServer
|
||||||
return preferences.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, -1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,11 +202,7 @@ class ActiveServerProvider(
|
|||||||
fun setActiveServerId(serverId: Int) {
|
fun setActiveServerId(serverId: Int) {
|
||||||
resetMusicService()
|
resetMusicService()
|
||||||
|
|
||||||
val preferences = Settings.preferences
|
Settings.activeServer = serverId
|
||||||
val editor = preferences.edit()
|
|
||||||
editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, serverId)
|
|
||||||
editor.apply()
|
|
||||||
|
|
||||||
liveActiveServerId.postValue(serverId)
|
liveActiveServerId.postValue(serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,8 +224,7 @@ class ActiveServerProvider(
|
|||||||
if (isOffline()) {
|
if (isOffline()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val preferences = Settings.preferences
|
return Settings.serverScaling
|
||||||
return preferences.getBoolean(Constants.PREFERENCES_KEY_SERVER_SCALING, false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import androidx.media.AudioFocusRequestCompat
|
|||||||
import androidx.media.AudioManagerCompat
|
import androidx.media.AudioManagerCompat
|
||||||
import org.koin.java.KoinJavaComponent.inject
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
import org.moire.ultrasonic.domain.PlayerState
|
import org.moire.ultrasonic.domain.PlayerState
|
||||||
import org.moire.ultrasonic.util.Constants
|
|
||||||
import org.moire.ultrasonic.util.Settings
|
import org.moire.ultrasonic.util.Settings
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@ -25,12 +24,8 @@ class AudioFocusHandler(private val context: Context) {
|
|||||||
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
}
|
}
|
||||||
|
|
||||||
private val preferences by lazy {
|
|
||||||
Settings.preferences
|
|
||||||
}
|
|
||||||
|
|
||||||
private val lossPref: Int
|
private val lossPref: Int
|
||||||
get() = preferences.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1")!!.toInt()
|
get() = Settings.tempLoss
|
||||||
|
|
||||||
private val audioAttributesCompat by lazy {
|
private val audioAttributesCompat by lazy {
|
||||||
AudioAttributesCompat.Builder()
|
AudioAttributesCompat.Builder()
|
||||||
|
@ -185,6 +185,15 @@ object Settings {
|
|||||||
var shouldUseId3Tags
|
var shouldUseId3Tags
|
||||||
by BooleanSetting(Constants.PREFERENCES_KEY_ID3_TAGS, false)
|
by BooleanSetting(Constants.PREFERENCES_KEY_ID3_TAGS, false)
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
var tempLoss by StringIntSetting(Constants.PREFERENCES_KEY_TEMP_LOSS, "1")
|
||||||
|
|
||||||
|
var activeServer by IntSetting(Constants.PREFERENCES_KEY_SERVER_INSTANCE, -1)
|
||||||
|
|
||||||
|
var serverScaling by BooleanSetting(Constants.PREFERENCES_KEY_SERVER_SCALING, false)
|
||||||
|
|
||||||
|
var firstRunExecuted by BooleanSetting(Constants.PREFERENCES_KEY_FIRST_RUN_EXECUTED, false)
|
||||||
|
|
||||||
val shouldShowArtistPicture: Boolean
|
val shouldShowArtistPicture: Boolean
|
||||||
get() {
|
get() {
|
||||||
val preferences = preferences
|
val preferences = preferences
|
||||||
|
@ -95,21 +95,18 @@ object Util {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun applyTheme(context: Context?) {
|
fun applyTheme(context: Context?) {
|
||||||
val theme = Settings.theme
|
when (Settings.theme.lowercase()) {
|
||||||
if (Constants.PREFERENCES_KEY_THEME_DARK.equals(
|
Constants.PREFERENCES_KEY_THEME_DARK,
|
||||||
theme,
|
"fullscreen" -> {
|
||||||
ignoreCase = true
|
context!!.setTheme(R.style.UltrasonicTheme)
|
||||||
) || "fullscreen".equals(theme, ignoreCase = true)
|
}
|
||||||
) {
|
Constants.PREFERENCES_KEY_THEME_BLACK -> {
|
||||||
context!!.setTheme(R.style.UltrasonicTheme)
|
context!!.setTheme(R.style.UltrasonicTheme_Black)
|
||||||
} else if (Constants.PREFERENCES_KEY_THEME_BLACK.equals(theme, ignoreCase = true)) {
|
}
|
||||||
context!!.setTheme(R.style.UltrasonicTheme_Black)
|
Constants.PREFERENCES_KEY_THEME_LIGHT,
|
||||||
} else if (Constants.PREFERENCES_KEY_THEME_LIGHT.equals(
|
"fullscreenlight" -> {
|
||||||
theme,
|
context!!.setTheme(R.style.UltrasonicTheme_Light)
|
||||||
ignoreCase = true
|
}
|
||||||
) || "fullscreenlight".equals(theme, ignoreCase = true)
|
|
||||||
) {
|
|
||||||
context!!.setTheme(R.style.UltrasonicTheme_Light)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,13 +791,9 @@ object Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isFirstRun(): Boolean {
|
fun isFirstRun(): Boolean {
|
||||||
val preferences = Settings.preferences
|
if (Settings.firstRunExecuted) return false
|
||||||
val firstExecuted =
|
|
||||||
preferences.getBoolean(Constants.PREFERENCES_KEY_FIRST_RUN_EXECUTED, false)
|
Settings.firstRunExecuted = true
|
||||||
if (firstExecuted) return false
|
|
||||||
val editor = preferences.edit()
|
|
||||||
editor.putBoolean(Constants.PREFERENCES_KEY_FIRST_RUN_EXECUTED, true)
|
|
||||||
editor.apply()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,7 +918,7 @@ object Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getConnectivityManager(): ConnectivityManager {
|
fun getConnectivityManager(): ConnectivityManager {
|
||||||
val context = Util.appContext()
|
val context = appContext()
|
||||||
return context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
return context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user