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