Make all preference operations context-free

(use the application context for them)
This commit is contained in:
tzugen 2021-05-09 08:35:15 +02:00
parent 21282b4c17
commit 9ec92c6cf3
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
38 changed files with 230 additions and 234 deletions

View File

@ -202,7 +202,7 @@ public class ChatFragment extends Fragment {
private void timerMethod()
{
int refreshInterval = Util.getChatRefreshInterval(getContext());
int refreshInterval = Util.getChatRefreshInterval();
if (refreshInterval > 0)
{

View File

@ -65,7 +65,7 @@ public class MainFragment extends Fragment {
super.onResume();
boolean shouldRestart = false;
boolean id3 = Util.getShouldUseId3Tags(MainFragment.this.getContext());
boolean id3 = Util.getShouldUseId3Tags();
String currentActiveServerProperties = getActiveServerProperties();
if (id3 != shouldUseId3)
@ -126,7 +126,7 @@ public class MainFragment extends Fragment {
adapter.addViews(asList(randomSongsButton, songsStarredButton), true);
adapter.addView(albumsTitle, false);
if (Util.getShouldUseId3Tags(MainFragment.this.getContext()))
if (Util.getShouldUseId3Tags())
{
shouldUseId3 = true;
adapter.addViews(asList(albumsNewestButton, albumsRecentButton, albumsFrequentButton, albumsRandomButton, albumsStarredButton, albumsAlphaByNameButton, albumsAlphaByArtistButton), true);
@ -224,7 +224,7 @@ public class MainFragment extends Fragment {
Bundle bundle = new Bundle();
bundle.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, title);
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxAlbums(getContext()));
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxAlbums());
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
Navigation.findNavController(getView()).navigate(R.id.mainToSelectAlbum, bundle);
}
@ -240,7 +240,7 @@ public class MainFragment extends Fragment {
{
Bundle bundle = new Bundle();
bundle.putInt(Constants.INTENT_EXTRA_NAME_RANDOM, 1);
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs(getContext()));
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs());
Navigation.findNavController(getView()).navigate(R.id.mainToSelectAlbum, bundle);
}

View File

@ -115,7 +115,7 @@ public class NowPlayingFragment extends Fragment {
nowPlayingAlbumArtImage.setOnClickListener(v -> {
Bundle bundle = new Bundle();
if (Util.getShouldUseId3Tags(getContext())) {
if (Util.getShouldUseId3Tags()) {
bundle.putBoolean(Constants.INTENT_EXTRA_NAME_IS_ALBUM, true);
bundle.putString(Constants.INTENT_EXTRA_NAME_ID, song.getAlbumId());
} else {

View File

@ -287,7 +287,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
@Override
public void run()
{
int incrementTime = Util.getIncrementTime(getActivity());
int incrementTime = Util.getIncrementTime();
changeProgress(-incrementTime);
}
});
@ -326,7 +326,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
@Override
public void run()
{
int incrementTime = Util.getIncrementTime(getActivity());
int incrementTime = Util.getIncrementTime();
changeProgress(incrementTime);
}
});
@ -834,7 +834,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
}
}
if (ActiveServerProvider.Companion.isOffline(getContext()) || !Util.getShouldUseId3Tags(getContext()))
if (ActiveServerProvider.Companion.isOffline(getContext()) || !Util.getShouldUseId3Tags())
{
MenuItem menuItem = menu.findItem(R.id.menu_show_artist);
@ -891,7 +891,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
return false;
}
if (Util.getShouldUseId3Tags(getContext())) {
if (Util.getShouldUseId3Tags()) {
bundle = new Bundle();
bundle.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getArtistId());
bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getArtist());
@ -906,7 +906,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
return false;
}
String albumId = Util.getShouldUseId3Tags(getContext()) ? entry.getAlbumId() : entry.getParent();
String albumId = Util.getShouldUseId3Tags() ? entry.getAlbumId() : entry.getParent();
bundle = new Bundle();
bundle.putString(Constants.INTENT_EXTRA_NAME_ID, albumId);
bundle.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getAlbum());

View File

@ -113,9 +113,9 @@ public class SearchFragment extends Fragment {
FragmentTitle.Companion.setTitle(this, R.string.search_title);
setHasOptionsMenu(true);
DEFAULT_ARTISTS = Util.getDefaultArtists(getContext());
DEFAULT_ALBUMS = Util.getDefaultAlbums(getContext());
DEFAULT_SONGS = Util.getDefaultSongs(getContext());
DEFAULT_ARTISTS = Util.getDefaultArtists();
DEFAULT_ALBUMS = Util.getDefaultAlbums();
DEFAULT_SONGS = Util.getDefaultSongs();
View buttons = LayoutInflater.from(getContext()).inflate(R.layout.search_buttons, list, false);
@ -410,9 +410,9 @@ public class SearchFragment extends Fragment {
private void search(final String query, final boolean autoplay)
{
final int maxArtists = Util.getMaxArtists(getContext());
final int maxAlbums = Util.getMaxAlbums(getContext());
final int maxSongs = Util.getMaxSongs(getContext());
final int maxArtists = Util.getMaxArtists();
final int maxAlbums = Util.getMaxAlbums();
final int maxSongs = Util.getMaxSongs();
BackgroundTask<SearchResult> task = new FragmentBackgroundTask<SearchResult>(getActivity(), true, searchRefresh, cancellationToken)
{

View File

@ -75,7 +75,7 @@ public class SelectGenreFragment extends Fragment {
{
Bundle bundle = new Bundle();
bundle.putString(Constants.INTENT_EXTRA_NAME_GENRE_NAME, genre.getName());
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs(getContext()));
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, Util.getMaxSongs());
bundle.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
Navigation.findNavController(view).navigate(R.id.selectAlbumFragment, bundle);
}

View File

@ -166,14 +166,14 @@ public class SettingsFragment extends PreferenceFragmentCompat
@Override
public void onResume() {
super.onResume();
SharedPreferences preferences = Util.getPreferences(getActivity());
SharedPreferences preferences = Util.getPreferences();
preferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
super.onPause();
SharedPreferences prefs = Util.getPreferences(getActivity());
SharedPreferences prefs = Util.getPreferences();
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@ -257,8 +257,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
}
private void setupBluetoothDevicePreferences() {
final int resumeSetting = Util.getResumeOnBluetoothDevice(getActivity());
final int pauseSetting = Util.getPauseOnBluetoothDevice(getActivity());
final int resumeSetting = Util.getResumeOnBluetoothDevice();
final int pauseSetting = Util.getPauseOnBluetoothDevice();
resumeOnBluetoothDevice.setSummary(bluetoothDevicePreferenceToString(resumeSetting));
pauseOnBluetoothDevice.setSummary(bluetoothDevicePreferenceToString(pauseSetting));
@ -268,7 +268,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
public boolean onPreferenceClick(Preference preference) {
showBluetoothDevicePreferenceDialog(
R.string.settings_playback_resume_on_bluetooth_device,
Util.getResumeOnBluetoothDevice(getActivity()),
Util.getResumeOnBluetoothDevice(),
new Consumer<Integer>() {
@Override
public void accept(Integer choice) {
@ -287,7 +287,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
public boolean onPreferenceClick(Preference preference) {
showBluetoothDevicePreferenceDialog(
R.string.settings_playback_pause_on_bluetooth_device,
Util.getPauseOnBluetoothDevice(getActivity()),
Util.getPauseOnBluetoothDevice(),
new Consumer<Integer>() {
@Override
public void accept(Integer choice) {
@ -467,7 +467,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
debugLogToFile.setSummary("");
}
showArtistPicture.setEnabled(Util.getShouldUseId3Tags(getActivity()));
showArtistPicture.setEnabled(Util.getShouldUseId3Tags());
}
private void setImageLoaderConcurrency(int concurrency) {

View File

@ -66,7 +66,7 @@ public class BluetoothIntentReceiver extends BroadcastReceiver
boolean resume = false;
boolean pause = false;
switch (Util.getResumeOnBluetoothDevice(context))
switch (Util.getResumeOnBluetoothDevice())
{
case Constants.PREFERENCE_VALUE_ALL: resume = actionA2dpConnected || actionBluetoothDeviceConnected;
break;
@ -74,7 +74,7 @@ public class BluetoothIntentReceiver extends BroadcastReceiver
break;
}
switch (Util.getPauseOnBluetoothDevice(context))
switch (Util.getPauseOnBluetoothDevice())
{
case Constants.PREFERENCE_VALUE_ALL: pause = actionA2dpDisconnected || actionBluetoothDeviceDisconnected;
break;

View File

@ -46,8 +46,8 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver
String intentAction = intent.getAction();
// If media button are turned off and we received a media button, exit
if (!Util.getMediaButtonsEnabled(context) &&
Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) return;
if (!Util.getMediaButtonsEnabled() && Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
return;
// Only process media buttons and CMD_PROCESS_KEYCODE, which is received from the widgets
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction) &&

View File

@ -36,7 +36,6 @@ import org.moire.ultrasonic.domain.SearchCriteria;
import org.moire.ultrasonic.domain.SearchResult;
import org.moire.ultrasonic.domain.Share;
import org.moire.ultrasonic.domain.UserInfo;
import org.moire.ultrasonic.util.CancellableTask;
import org.moire.ultrasonic.util.Constants;
import org.moire.ultrasonic.util.LRUCache;
import org.moire.ultrasonic.util.TimeLimitedCache;
@ -171,7 +170,7 @@ public class CachedMusicService implements MusicService
if (dir == null)
{
dir = musicService.getMusicDirectory(id, name, refresh, context);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(context), TimeUnit.SECONDS);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(), TimeUnit.SECONDS);
cache.set(dir);
cachedMusicDirectories.put(id, cache);
}
@ -187,7 +186,7 @@ public class CachedMusicService implements MusicService
if (dir == null)
{
dir = musicService.getArtist(id, name, refresh, context);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(context), TimeUnit.SECONDS);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(), TimeUnit.SECONDS);
cache.set(dir);
cachedArtist.put(id, cache);
}
@ -203,7 +202,7 @@ public class CachedMusicService implements MusicService
if (dir == null)
{
dir = musicService.getAlbum(id, name, refresh, context);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(context), TimeUnit.SECONDS);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(), TimeUnit.SECONDS);
cache.set(dir);
cachedAlbum.put(id, cache);
}
@ -487,7 +486,7 @@ public class CachedMusicService implements MusicService
if (dir == null)
{
dir = musicService.getVideos(refresh, context);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(context), TimeUnit.SECONDS);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(), TimeUnit.SECONDS);
cache.set(dir);
cachedMusicDirectories.put(Constants.INTENT_EXTRA_NAME_VIDEOS, cache);
}
@ -507,7 +506,7 @@ public class CachedMusicService implements MusicService
if (userInfo == null)
{
userInfo = musicService.getUser(username, context);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(context), TimeUnit.SECONDS);
cache = new TimeLimitedCache<>(Util.getDirectoryCacheTime(), TimeUnit.SECONDS);
cache.set(userInfo);
cachedUserInfo.put(username, cache);
}

View File

@ -158,7 +158,7 @@ public class Downloader
DownloadFile downloadFile = downloadList.get(i);
if (!downloadFile.isWorkDone())
{
if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount(context))
if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount())
{
currentDownloading = downloadFile;
currentDownloading.download();
@ -181,7 +181,7 @@ public class Downloader
}
// If the downloadList contains no work, check the backgroundDownloadList
if ((preloaded + 1 == n || preloaded >= Util.getPreloadCount(context) || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty())
if ((preloaded + 1 == n || preloaded >= Util.getPreloadCount() || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty())
{
for (int i = 0; i < backgroundDownloadList.size(); i++)
{
@ -401,7 +401,7 @@ public class Downloader
private synchronized void checkShufflePlay(Context context)
{
// Get users desired random playlist size
int listSize = Util.getMaxSongs(context);
int listSize = Util.getMaxSongs();
boolean wasEmpty = downloadList.isEmpty();
long revisionBefore = revision;

View File

@ -309,13 +309,13 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
@Override
public RepeatMode getRepeatMode()
{
return Util.getRepeatMode(context);
return Util.getRepeatMode();
}
@Override
public synchronized void setRepeatMode(RepeatMode repeatMode)
{
Util.setRepeatMode(context, repeatMode);
Util.setRepeatMode(repeatMode);
MediaPlayerService mediaPlayerService = MediaPlayerService.getRunningInstance();
if (mediaPlayerService != null) mediaPlayerService.setNextPlaying();
}

View File

@ -138,7 +138,7 @@ public class MediaPlayerLifecycleSupport
* while Ultrasonic is running.
*/
private void registerHeadsetReceiver() {
final SharedPreferences sp = Util.getPreferences(context);
final SharedPreferences sp = Util.getPreferences();
final String spKey = context
.getString(R.string.settings_playback_resume_play_on_headphones_plug);
@ -190,7 +190,7 @@ public class MediaPlayerLifecycleSupport
final int keyCode;
int receivedKeyCode = event.getKeyCode();
// Translate PLAY and PAUSE codes to PLAY_PAUSE to improve compatibility with old Bluetooth devices
if (Util.getSingleButtonPlayPause(context) &&
if (Util.getSingleButtonPlayPause() &&
(receivedKeyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
receivedKeyCode == KeyEvent.KEYCODE_MEDIA_PAUSE)) {
Timber.i("Single button Play/Pause is set, rewriting keyCode to PLAY_PAUSE");

View File

@ -70,7 +70,7 @@ public class AlbumHeader
if (!entry.isDirectory())
{
if (Util.shouldUseFolderForArtistName(context))
if (Util.shouldUseFolderForArtistName())
{
albumHeader.processGrandParents(entry);
}

View File

@ -120,7 +120,7 @@ public class CacheCleaner
return 0L;
}
long cacheSizeBytes = Util.getCacheSizeMB(context) * 1024L * 1024L;
long cacheSizeBytes = Util.getCacheSizeMB() * 1024L * 1024L;
long bytesUsedBySubsonic = 0L;
for (File file : files)

View File

@ -380,7 +380,7 @@ public class FileUtil
public static File getMusicDirectory(Context context)
{
File defaultMusicDirectory = getDefaultMusicDirectory(context);
String path = Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultMusicDirectory.getPath());
String path = Util.getPreferences().getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultMusicDirectory.getPath());
File dir = new File(path);
boolean hasAccess = ensureDirectoryExistsAndIsReadWritable(dir);

View File

@ -60,7 +60,7 @@ public class PermissionUtil {
* @param callback callback function to execute after the permission request is finished
*/
public void handlePermissionFailed(final PermissionRequestFinishedCallback callback) {
String currentCachePath = Util.getPreferences(applicationContext).getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory(applicationContext).getPath());
String currentCachePath = Util.getPreferences().getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory(applicationContext).getPath());
String defaultCachePath = FileUtil.getDefaultMusicDirectory(applicationContext).getPath();
// Ultrasonic can do nothing about this error when the Music Directory is already set to the default.
@ -136,7 +136,7 @@ public class PermissionUtil {
}
private static void setCacheLocation(Context context, String cacheLocation) {
Util.getPreferences(context).edit()
Util.getPreferences().edit()
.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, cacheLocation)
.apply();
}

View File

@ -50,6 +50,7 @@ import androidx.annotation.ColorInt;
import androidx.preference.PreferenceManager;
import org.moire.ultrasonic.R;
import org.moire.ultrasonic.app.UApp;
import org.moire.ultrasonic.data.ActiveServerProvider;
import org.moire.ultrasonic.domain.*;
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
@ -86,9 +87,6 @@ public class Util
public static final String CM_AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged";
public static final String CM_AVRCP_METADATA_CHANGED = "com.android.music.metachanged";
private static boolean mediaButtonsRegisteredForUI;
private static boolean mediaButtonsRegisteredForService;
// Used by hexEncode()
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
private static Toast toast;
@ -99,58 +97,63 @@ public class Util
{
}
public static boolean isScreenLitOnDownload(Context context)
// Retrieves an instance of the application Context
public static Context appContext() {
return UApp.Companion.applicationContext();
}
public static boolean isScreenLitOnDownload()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SCREEN_LIT_ON_DOWNLOAD, false);
}
public static RepeatMode getRepeatMode(Context context)
public static RepeatMode getRepeatMode()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return RepeatMode.valueOf(preferences.getString(Constants.PREFERENCES_KEY_REPEAT_MODE, RepeatMode.OFF.name()));
}
public static void setRepeatMode(Context context, RepeatMode repeatMode)
public static void setRepeatMode(RepeatMode repeatMode)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
SharedPreferences.Editor editor = preferences.edit();
editor.putString(Constants.PREFERENCES_KEY_REPEAT_MODE, repeatMode.name());
editor.apply();
}
public static boolean isNotificationEnabled(Context context)
public static boolean isNotificationEnabled()
{
// After API26 foreground services must be used for music playback, and they must have a notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return true;
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_NOTIFICATION, false);
}
public static boolean isNotificationAlwaysEnabled(Context context)
public static boolean isNotificationAlwaysEnabled()
{
// After API26 foreground services must be used for music playback, and they must have a notification
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return true;
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_ALWAYS_SHOW_NOTIFICATION, false);
}
@SuppressWarnings({"BooleanMethodIsAlwaysInverted"}) // It is inverted for readability
public static boolean isLockScreenEnabled(Context context)
public static boolean isLockScreenEnabled()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_LOCK_SCREEN_CONTROLS, false);
}
public static String getTheme(Context context)
public static String getTheme()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getString(Constants.PREFERENCES_KEY_THEME, Constants.PREFERENCES_KEY_THEME_DARK);
}
public static void applyTheme(Context context)
{
String theme = Util.getTheme(context);
String theme = Util.getTheme();
if (Constants.PREFERENCES_KEY_THEME_DARK.equalsIgnoreCase(theme) || "fullscreen".equalsIgnoreCase(theme))
{
@ -178,26 +181,26 @@ public class Util
}
boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(wifi ? Constants.PREFERENCES_KEY_MAX_BITRATE_WIFI : Constants.PREFERENCES_KEY_MAX_BITRATE_MOBILE, "0"));
}
public static int getPreloadCount(Context context)
public static int getPreloadCount()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
int preloadCount = Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_PRELOAD_COUNT, "-1"));
return preloadCount == -1 ? Integer.MAX_VALUE : preloadCount;
}
public static int getCacheSizeMB(Context context)
public static int getCacheSizeMB()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
int cacheSize = Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_CACHE_SIZE, "-1"));
return cacheSize == -1 ? Integer.MAX_VALUE : cacheSize;
}
public static SharedPreferences getPreferences(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context);
public static SharedPreferences getPreferences() {
return PreferenceManager.getDefaultSharedPreferences(appContext());
}
/**
@ -554,7 +557,7 @@ public class Util
boolean connected = networkInfo != null && networkInfo.isConnected();
boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
boolean wifiRequired = isWifiRequiredForDownload(context);
boolean wifiRequired = isWifiRequiredForDownload();
return connected && (!wifiRequired || wifiConnected);
}
@ -564,34 +567,30 @@ public class Util
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
private static boolean isWifiRequiredForDownload(Context context)
private static boolean isWifiRequiredForDownload()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD, false);
}
public static boolean shouldDisplayBitrateWithArtist(Context context)
public static boolean shouldDisplayBitrateWithArtist()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_DISPLAY_BITRATE_WITH_ARTIST, true);
}
public static boolean shouldUseFolderForArtistName(Context context)
public static boolean shouldUseFolderForArtistName()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_USE_FOLDER_FOR_ALBUM_ARTIST, false);
}
public static boolean shouldShowTrackNumber(Context context)
public static boolean shouldShowTrackNumber()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_TRACK_NUMBER, false);
}
public static void info(Context context, int titleId, int messageId)
{
showDialog(context, android.R.drawable.ic_dialog_info, titleId, messageId);
}
private static void showDialog(Context context, int icon, int titleId, int messageId)
{
@ -669,7 +668,7 @@ public class Util
public static int getScaledHeight(Bitmap bitmap, int width)
{
return getScaledHeight((double) bitmap.getHeight(), (double) bitmap.getWidth(), width);
return getScaledHeight(bitmap.getHeight(), bitmap.getWidth(), width);
}
public static Bitmap scaleBitmap(Bitmap bitmap, int size)
@ -742,7 +741,7 @@ public class Util
public static void broadcastA2dpMetaDataChange(Context context, int playerPosition, DownloadFile currentPlaying, int listSize, int id)
{
if (!Util.getShouldSendBluetoothNotifications(context))
if (!Util.getShouldSendBluetoothNotifications())
{
return;
}
@ -763,7 +762,7 @@ public class Util
avrcpIntent.putExtra("album_artist", "");
avrcpIntent.putExtra("album_artist_name", "");
if (Util.getShouldSendBluetoothAlbumArt(context))
if (Util.getShouldSendBluetoothAlbumArt())
{
avrcpIntent.putExtra("coverart", (Parcelable) null);
avrcpIntent.putExtra("cover", (Parcelable) null);
@ -796,7 +795,7 @@ public class Util
avrcpIntent.putExtra("album_artist_name", artist);
if (Util.getShouldSendBluetoothAlbumArt(context))
if (Util.getShouldSendBluetoothAlbumArt())
{
File albumArtFile = FileUtil.getAlbumArtFile(context, song);
avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
@ -818,7 +817,7 @@ public class Util
public static void broadcastA2dpPlayStatusChange(Context context, PlayerState state, Entry currentSong, Integer listSize, Integer id, Integer playerPosition)
{
if (!Util.getShouldSendBluetoothNotifications(context))
if (!Util.getShouldSendBluetoothNotifications())
{
return;
}
@ -852,7 +851,7 @@ public class Util
avrcpIntent.putExtra("album_artist", artist);
avrcpIntent.putExtra("album_artist_name", artist);
if (Util.getShouldSendBluetoothAlbumArt(context))
if (Util.getShouldSendBluetoothAlbumArt())
{
File albumArtFile = FileUtil.getAlbumArtFile(context, currentSong);
avrcpIntent.putExtra("coverart", albumArtFile.getAbsolutePath());
@ -985,109 +984,102 @@ public class Util
return inSampleSize;
}
// TODO: Shouldn't this be used when making requests?
public static int getNetworkTimeout(Context context)
public static int getDefaultAlbums()
{
SharedPreferences preferences = getPreferences(context);
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT, "15000"));
}
public static int getDefaultAlbums(Context context)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_ALBUMS, "5"));
}
public static int getMaxAlbums(Context context)
public static int getMaxAlbums()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_MAX_ALBUMS, "20"));
}
public static int getDefaultSongs(Context context)
public static int getDefaultSongs()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SONGS, "10"));
}
public static int getMaxSongs(Context context)
public static int getMaxSongs()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_MAX_SONGS, "25"));
}
public static int getMaxArtists(Context context)
public static int getMaxArtists()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_MAX_ARTISTS, "10"));
}
public static int getDefaultArtists(Context context)
public static int getDefaultArtists()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_ARTISTS, "3"));
}
public static int getBufferLength(Context context)
public static int getBufferLength()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_BUFFER_LENGTH, "5"));
}
public static int getIncrementTime(Context context)
public static int getIncrementTime()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_INCREMENT_TIME, "5"));
}
public static boolean getMediaButtonsEnabled(Context context)
public static boolean getMediaButtonsEnabled()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true);
}
public static boolean getShowNowPlayingPreference(Context context)
public static boolean getShowNowPlayingPreference()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_NOW_PLAYING, true);
}
public static boolean getGaplessPlaybackPreference(Context context)
public static boolean getGaplessPlaybackPreference()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_GAPLESS_PLAYBACK, false);
}
public static boolean getShouldTransitionOnPlaybackPreference(Context context)
public static boolean getShouldTransitionOnPlaybackPreference()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_DOWNLOAD_TRANSITION, true);
}
public static boolean getShouldUseId3Tags(Context context)
public static boolean getShouldUseId3Tags()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_ID3_TAGS, false);
}
public static boolean getShouldShowArtistPicture(Context context)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
boolean isOffline = ActiveServerProvider.Companion.isOffline(context);
boolean isId3Enabled = preferences.getBoolean(Constants.PREFERENCES_KEY_ID3_TAGS, false);
boolean shouldShowArtistPicture = preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ARTIST_PICTURE, false);
return (!isOffline) && isId3Enabled && shouldShowArtistPicture;
}
public static int getChatRefreshInterval(Context context)
public static int getChatRefreshInterval()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_CHAT_REFRESH_INTERVAL, "5000"));
}
public static int getDirectoryCacheTime(Context context)
public static int getDirectoryCacheTime()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_DIRECTORY_CACHE_TIME, "300"));
}
@ -1102,27 +1094,27 @@ public class Util
return formatTotalDuration(totalDuration, false);
}
public static boolean getShouldClearPlaylist(Context context)
public static boolean getShouldClearPlaylist()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_CLEAR_PLAYLIST, false);
}
public static boolean getShouldSortByDisc(Context context)
public static boolean getShouldSortByDisc()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_DISC_SORT, false);
}
public static boolean getShouldClearBookmark(Context context)
public static boolean getShouldClearBookmark()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_CLEAR_BOOKMARK, false);
}
public static boolean getSingleButtonPlayPause(Context context)
public static boolean getSingleButtonPlayPause()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SINGLE_BUTTON_PLAY_PAUSE, false);
}
@ -1155,9 +1147,9 @@ public class Util
else return minutes > 0 ? String.format(Locale.getDefault(), "%d:%02d", minutes, seconds) : String.format(Locale.getDefault(), "0:%02d", seconds);
}
public static VideoPlayerType getVideoPlayerType(Context context)
public static VideoPlayerType getVideoPlayerType()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return VideoPlayerType.forKey(preferences.getString(Constants.PREFERENCES_KEY_VIDEO_PLAYER, VideoPlayerType.MX.getKey()));
}
@ -1232,51 +1224,51 @@ public class Util
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted") // Inverted for readability
public static boolean getShouldSendBluetoothNotifications(Context context)
public static boolean getShouldSendBluetoothNotifications()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_NOTIFICATIONS, true);
}
public static boolean getShouldSendBluetoothAlbumArt(Context context)
public static boolean getShouldSendBluetoothAlbumArt()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SEND_BLUETOOTH_ALBUM_ART, true);
}
public static int getViewRefreshInterval(Context context)
public static int getViewRefreshInterval()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_VIEW_REFRESH, "1000"));
}
public static boolean getShouldAskForShareDetails(Context context)
public static boolean getShouldAskForShareDetails()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_ASK_FOR_SHARE_DETAILS, true);
}
public static String getDefaultShareDescription(Context context)
public static String getDefaultShareDescription()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION, "");
}
public static String getShareGreeting(Context context)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_GREETING, String.format(context.getResources().getString(R.string.share_default_greeting), context.getResources().getString(R.string.common_appname)));
}
public static String getDefaultShareExpiration(Context context)
public static String getDefaultShareExpiration()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION, "0");
}
public static long getDefaultShareExpirationInMillis(Context context)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
String preference = preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION, "0");
String[] split = PATTERN.split(preference);
@ -1294,33 +1286,33 @@ public class Util
return 0;
}
public static void setShouldAskForShareDetails(Context context, boolean shouldAskForShareDetails)
public static void setShouldAskForShareDetails(boolean shouldAskForShareDetails)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(Constants.PREFERENCES_KEY_ASK_FOR_SHARE_DETAILS, shouldAskForShareDetails);
editor.apply();
}
public static void setDefaultShareExpiration(Context context, String defaultShareExpiration)
public static void setDefaultShareExpiration(String defaultShareExpiration)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
SharedPreferences.Editor editor = preferences.edit();
editor.putString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_EXPIRATION, defaultShareExpiration);
editor.apply();
}
public static void setDefaultShareDescription(Context context, String defaultShareDescription)
public static void setDefaultShareDescription(String defaultShareDescription)
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
SharedPreferences.Editor editor = preferences.edit();
editor.putString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION, defaultShareDescription);
editor.apply();
}
public static boolean getShouldShowAllSongsByArtist(Context context)
public static boolean getShouldShowAllSongsByArtist()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST, false);
}
@ -1331,20 +1323,12 @@ public class Util
context.sendBroadcast(scanFileIntent);
}
public static int getImageLoaderConcurrency(Context context)
public static int getImageLoaderConcurrency()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_IMAGE_LOADER_CONCURRENCY, "5"));
}
public static @ColorInt int getColorFromAttribute(Context context, int resId)
{
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(resId, typedValue, true);
return typedValue.data;
}
public static int getResourceFromAttribute(Context context, int resId)
{
TypedValue typedValue = new TypedValue();
@ -1353,9 +1337,9 @@ public class Util
return typedValue.resourceId;
}
public static boolean isFirstRun(Context context)
public static boolean isFirstRun()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
boolean firstExecuted = preferences.getBoolean(Constants.PREFERENCES_KEY_FIRST_RUN_EXECUTED, false);
if (firstExecuted) return false;
SharedPreferences.Editor editor = preferences.edit();
@ -1364,21 +1348,21 @@ public class Util
return true;
}
public static int getResumeOnBluetoothDevice(Context context)
public static int getResumeOnBluetoothDevice()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getInt(Constants.PREFERENCES_KEY_RESUME_ON_BLUETOOTH_DEVICE, Constants.PREFERENCE_VALUE_DISABLED);
}
public static int getPauseOnBluetoothDevice(Context context)
public static int getPauseOnBluetoothDevice()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getInt(Constants.PREFERENCES_KEY_PAUSE_ON_BLUETOOTH_DEVICE, Constants.PREFERENCE_VALUE_A2DP);
}
public static boolean getDebugLogToFile(Context context)
public static boolean getDebugLogToFile()
{
SharedPreferences preferences = getPreferences(context);
SharedPreferences preferences = getPreferences();
return preferences.getBoolean(Constants.PREFERENCES_KEY_DEBUG_LOG_TO_FILE, false);
}

View File

@ -54,7 +54,7 @@ public class AlbumView extends UpdateView
this.context = context;
this.imageLoader = imageLoader;
String theme = Util.getTheme(context);
String theme = Util.getTheme();
boolean themesMatch = theme.equals(AlbumView.theme);
AlbumView.theme = theme;
@ -152,7 +152,7 @@ public class AlbumView extends UpdateView
@Override
public void run()
{
boolean useId3 = Util.getShouldUseId3Tags(getContext());
boolean useId3 = Util.getShouldUseId3Tags();
try
{

View File

@ -116,7 +116,7 @@ public class UpdateView extends LinearLayout
Timber.w(x, "Error when updating song views.");
}
uiHandler.postDelayed(updateRunnable, Util.getViewRefreshInterval(context));
uiHandler.postDelayed(updateRunnable, Util.getViewRefreshInterval());
}
};

View File

@ -142,7 +142,7 @@ class NavigationActivity : AppCompatActivity() {
}
// Determine first run and migrate server settings to DB as early as possible
var showWelcomeScreen = Util.isFirstRun(this)
var showWelcomeScreen = Util.isFirstRun()
val areServersMigrated: Boolean = serverSettingsModel.migrateFromPreferences()
// If there are any servers in the DB, do not show the welcome screen
@ -296,7 +296,7 @@ class NavigationActivity : AppCompatActivity() {
private fun loadSettings() {
PreferenceManager.setDefaultValues(this, R.xml.settings, false)
val preferences = Util.getPreferences(this)
val preferences = Util.getPreferences()
if (!preferences.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) {
val editor = preferences.edit()
editor.putString(
@ -336,7 +336,7 @@ class NavigationActivity : AppCompatActivity() {
}
private fun showNowPlaying() {
if (!Util.getShowNowPlayingPreference(this)) {
if (!Util.getShowNowPlayingPreference()) {
hideNowPlaying()
return
}

View File

@ -1,5 +1,6 @@
package org.moire.ultrasonic.app
import android.content.Context
import androidx.multidex.MultiDexApplication
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
@ -21,15 +22,20 @@ import timber.log.Timber.DebugTree
/**
* The Main class of the Application
*/
@Suppress("unused")
class UApp : MultiDexApplication() {
init {
instance = this
}
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
}
if (Util.getDebugLogToFile(this)) {
if (Util.getDebugLogToFile()) {
FileLoggerTree.plantToTimberForest(this)
}
@ -49,4 +55,12 @@ class UApp : MultiDexApplication() {
)
}
}
companion object {
private var instance: UApp? = null
fun applicationContext(): Context {
return instance!!.applicationContext
}
}
}

View File

@ -140,7 +140,7 @@ class ActiveServerProvider(
* Queries the Id of the Active Server
*/
fun getActiveServerId(context: Context): Int {
val preferences = Util.getPreferences(context)
val preferences = Util.getPreferences()
return preferences.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, -1)
}
@ -150,7 +150,7 @@ class ActiveServerProvider(
fun setActiveServerId(context: Context, serverId: Int) {
resetMusicService()
val preferences = Util.getPreferences(context)
val preferences = Util.getPreferences()
val editor = preferences.edit()
editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, serverId)
editor.apply()
@ -163,7 +163,7 @@ class ActiveServerProvider(
if (isOffline(context)) {
return false
}
val preferences = Util.getPreferences(context)
val preferences = Util.getPreferences()
return preferences.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, false)
}
@ -174,7 +174,7 @@ class ActiveServerProvider(
if (isOffline(context)) {
return false
}
val preferences = Util.getPreferences(context)
val preferences = Util.getPreferences()
return preferences.getBoolean(Constants.PREFERENCES_KEY_SERVER_SCALING, false)
}
}

View File

@ -16,7 +16,7 @@ const val SP_NAME = "Default_SP"
* This Koin module contains registration of classes related to permanent storage
*/
val appPermanentStorage = module {
single(named(SP_NAME)) { Util.getPreferences(androidContext()) }
single(named(SP_NAME)) { Util.getPreferences() }
single {
Room.databaseBuilder(

View File

@ -80,7 +80,7 @@ class ArtistListModel(
withContext(Dispatchers.IO) {
val musicService = MusicServiceFactory.getMusicService(context)
val isOffline = ActiveServerProvider.isOffline(context)
val useId3Tags = Util.getShouldUseId3Tags(context)
val useId3Tags = Util.getShouldUseId3Tags()
try {
if (!isOffline && !useId3Tags) {

View File

@ -298,7 +298,7 @@ class SelectAlbumFragment : Fragment() {
model.getRandom(albumListSize)
} else {
setTitle(name)
if (!isOffline(activity) && Util.getShouldUseId3Tags(activity)) {
if (!isOffline(activity) && Util.getShouldUseId3Tags()) {
if (isAlbum) {
model.getAlbum(refresh, id, name, parentId)
} else {
@ -710,7 +710,7 @@ class SelectAlbumFragment : Fragment() {
private fun updateInterfaceWithEntries(musicDirectory: MusicDirectory) {
val entries = musicDirectory.getChildren()
if (model.currentDirectoryIsSortable && Util.getShouldSortByDisc(context)) {
if (model.currentDirectoryIsSortable && Util.getShouldSortByDisc()) {
Collections.sort(entries, EntryByDiscAndTrackComparator())
}

View File

@ -75,7 +75,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
} else {
val musicDirectory = service.getMusicDirectory(id, name, refresh, context)
if (Util.getShouldShowAllSongsByArtist(context) &&
if (Util.getShouldShowAllSongsByArtist() &&
musicDirectory.findChild(allSongsId) == null &&
hasOnlyFolders(musicDirectory)
) {
@ -133,7 +133,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
val musicDirectory = service.getArtist(id, name, refresh, context)
if (Util.getShouldShowAllSongsByArtist(context) &&
if (Util.getShouldShowAllSongsByArtist() &&
musicDirectory.findChild(allSongsId) == null &&
hasOnlyFolders(musicDirectory)
) {
@ -213,7 +213,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
val musicDirectory: MusicDirectory
val context = context
if (Util.getShouldUseId3Tags(context)) {
if (Util.getShouldUseId3Tags()) {
musicDirectory = Util.getSongsFromSearchResult(service.getStarred2(context))
} else {
musicDirectory = Util.getSongsFromSearchResult(service.getStarred(context))
@ -286,7 +286,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
showHeader = false
showSelectFolderHeader = !ActiveServerProvider.isOffline(context) &&
!Util.getShouldUseId3Tags(context) && (
!Util.getShouldUseId3Tags() && (
(albumListType == AlbumListType.SORTED_BY_NAME.toString()) ||
(albumListType == AlbumListType.SORTED_BY_ARTIST.toString())
)
@ -300,7 +300,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
null
}
if (Util.getShouldUseId3Tags(context)) {
if (Util.getShouldUseId3Tags()) {
musicDirectory = service.getAlbumList2(
albumListType, size,
offset, musicFolderId, context

View File

@ -60,7 +60,7 @@ class SelectArtistFragment : Fragment() {
}
if (!ActiveServerProvider.isOffline(this.context) &&
!Util.getShouldUseId3Tags(this.context)
!Util.getShouldUseId3Tags()
) {
selectFolderHeader = SelectMusicFolderView(
requireContext(), view as ViewGroup,

View File

@ -25,7 +25,7 @@ class AudioFocusHandler(private val context: Context) {
}
private val preferences by lazy {
Util.getPreferences(context)
Util.getPreferences()
}
private val lossPref: Int

View File

@ -312,7 +312,7 @@ class DownloadFile(
private fun acquireWakeLock(wakeLock: WakeLock?): WakeLock? {
var wakeLock1 = wakeLock
if (Util.isScreenLitOnDownload(context)) {
if (Util.isScreenLitOnDownload()) {
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
val flags = PowerManager.SCREEN_DIM_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE
wakeLock1 = pm.newWakeLock(flags, toString())

View File

@ -472,7 +472,7 @@ class LocalMediaPlayer(
nextMediaPlayer!!.setOnPreparedListener {
try {
setNextPlayerState(PlayerState.PREPARED)
if (Util.getGaplessPlaybackPreference(context) &&
if (Util.getGaplessPlaybackPreference() &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
(
playerState === PlayerState.STARTED ||
@ -526,7 +526,7 @@ class LocalMediaPlayer(
Timber.i("Ending position %d of %d", pos, duration)
if (!isPartial || downloadFile.isWorkDone && abs(duration - pos) < 1000) {
setPlayerState(PlayerState.COMPLETED)
if (Util.getGaplessPlaybackPreference(context) &&
if (Util.getGaplessPlaybackPreference() &&
nextPlaying != null &&
nextPlayerState === PlayerState.PREPARED
) {
@ -628,7 +628,7 @@ class LocalMediaPlayer(
}
init {
var bufferLength = Util.getBufferLength(context).toLong()
var bufferLength = Util.getBufferLength().toLong()
if (bufferLength == 0L) {
// Set to seconds in a day, basically infinity
bufferLength = 86400L

View File

@ -65,7 +65,7 @@ class MediaPlayerService : Service() {
private var notificationBuilder: NotificationCompat.Builder? = null
private val repeatMode: RepeatMode
get() = Util.getRepeatMode(this)
get() = Util.getRepeatMode()
override fun onBind(intent: Intent): IBinder {
return binder
@ -176,7 +176,7 @@ class MediaPlayerService : Service() {
@Synchronized
fun setNextPlaying() {
val gaplessPlayback = Util.getGaplessPlaybackPreference(this)
val gaplessPlayback = Util.getGaplessPlaybackPreference()
if (!gaplessPlayback) {
localMediaPlayer.clearNextPlaying(true)
@ -376,7 +376,7 @@ class MediaPlayerService : Service() {
}
val showWhenPaused = playerState !== PlayerState.STOPPED &&
Util.isNotificationAlwaysEnabled(context)
Util.isNotificationAlwaysEnabled()
val show = playerState === PlayerState.STARTED || showWhenPaused
val song = currentPlaying?.song
@ -421,7 +421,7 @@ class MediaPlayerService : Service() {
if (currentPlaying != null) {
val song = currentPlaying.song
if (song.bookmarkPosition > 0 && Util.getShouldClearBookmark(context)) {
if (song.bookmarkPosition > 0 && Util.getShouldClearBookmark()) {
val musicService = getMusicService(context)
try {
musicService.deleteBookmark(song.id, context)
@ -433,7 +433,7 @@ class MediaPlayerService : Service() {
when (repeatMode) {
RepeatMode.OFF -> {
if (index + 1 < 0 || index + 1 >= downloader.downloadList.size) {
if (Util.getShouldClearPlaylist(context)) {
if (Util.getShouldClearPlaylist()) {
clear(true)
jukeboxMediaPlayer.updatePlaylist()
}
@ -576,7 +576,7 @@ class MediaPlayerService : Service() {
fun updateNotification(playerState: PlayerState, currentPlaying: DownloadFile?) {
val notification = buildForegroundNotification(playerState, currentPlaying)
if (Util.isNotificationEnabled(this)) {
if (Util.isNotificationEnabled()) {
if (isInForeground) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
@ -868,7 +868,7 @@ class MediaPlayerService : Service() {
}
fun updateMediaButtonReceiver() {
if (Util.getMediaButtonsEnabled(applicationContext)) {
if (Util.getMediaButtonsEnabled()) {
registerMediaButtonEventReceiver()
} else {
unregisterMediaButtonEventReceiver()

View File

@ -219,7 +219,7 @@ open class RESTMusicService(
return try {
if (
!isOffline(context) &&
Util.getShouldUseId3Tags(context)
Util.getShouldUseId3Tags()
) search3(criteria)
else search2(criteria)
} catch (ignored: ApiNotSupportedException) {

View File

@ -53,7 +53,7 @@ class DownloadHandler(
mediaPlayerController.suggestedPlaylistName = playlistName
}
if (autoPlay) {
if (Util.getShouldTransitionOnPlaybackPreference(fragment.activity)) {
if (Util.getShouldTransitionOnPlaybackPreference()) {
fragment.findNavController().popBackStack(R.id.playerFragment, true)
fragment.findNavController().navigate(R.id.playerFragment)
}
@ -203,11 +203,11 @@ class DownloadHandler(
val musicService = getMusicService(activity)
val songs: MutableList<MusicDirectory.Entry> = LinkedList()
val root: MusicDirectory
if (!isOffline(activity) && isArtist && Util.getShouldUseId3Tags(activity)) {
if (!isOffline(activity) && isArtist && Util.getShouldUseId3Tags()) {
getSongsForArtist(id, songs)
} else {
if (isDirectory) {
root = if (!isOffline(activity) && Util.getShouldUseId3Tags(activity))
root = if (!isOffline(activity) && Util.getShouldUseId3Tags())
musicService.getAlbum(id, name, false, activity)
else
musicService.getMusicDirectory(id, name, false, activity)
@ -252,7 +252,7 @@ class DownloadHandler(
) {
val root: MusicDirectory = if (
!isOffline(activity) &&
Util.getShouldUseId3Tags(activity)
Util.getShouldUseId3Tags()
) musicService.getAlbum(id1, title, false, activity)
else musicService.getMusicDirectory(id1, title, false, activity)
getSongsRecursively(root, songs)
@ -285,7 +285,7 @@ class DownloadHandler(
}
override fun done(songs: List<MusicDirectory.Entry>) {
if (Util.getShouldSortByDisc(activity)) {
if (Util.getShouldSortByDisc()) {
Collections.sort(songs, EntryByDiscAndTrackComparator())
}
if (songs.isNotEmpty()) {
@ -307,7 +307,7 @@ class DownloadHandler(
)
if (
!append &&
Util.getShouldTransitionOnPlaybackPreference(activity)
Util.getShouldTransitionOnPlaybackPreference()
) {
fragment.findNavController().popBackStack(
R.id.playerFragment,

View File

@ -31,7 +31,7 @@ class ImageLoaderProvider(val context: Context) {
if (imageLoader == null || !imageLoader!!.isRunning) {
val legacyImageLoader = LegacyImageLoader(
context,
Util.getImageLoaderConcurrency(context)
Util.getImageLoaderConcurrency()
)
val isNewImageLoaderEnabled = get(FeatureStorage::class.java)
.isFeatureEnabled(Feature.NEW_IMAGE_DOWNLOADER)

View File

@ -40,13 +40,13 @@ class ShareHandler(val context: Context) {
swipe: SwipeRefreshLayout?,
cancellationToken: CancellationToken
) {
val askForDetails = Util.getShouldAskForShareDetails(context)
val askForDetails = Util.getShouldAskForShareDetails()
val shareDetails = ShareDetails()
shareDetails.Entries = entries
if (askForDetails) {
showDialog(fragment, shareDetails, swipe, cancellationToken)
} else {
shareDetails.Description = Util.getDefaultShareDescription(context)
shareDetails.Description = Util.getDefaultShareDescription()
shareDetails.Expiration = TimeSpan.getCurrentTime().add(
Util.getDefaultShareExpirationInMillis(context)
).totalMilliseconds
@ -131,17 +131,16 @@ class ShareHandler(val context: Context) {
}
shareDetails.Description = shareDescription!!.text.toString()
if (hideDialogCheckBox!!.isChecked) {
Util.setShouldAskForShareDetails(context, false)
Util.setShouldAskForShareDetails(false)
}
if (saveAsDefaultsCheckBox!!.isChecked) {
val timeSpanType: String = timeSpanPicker!!.timeSpanType
val timeSpanAmount: Int = timeSpanPicker!!.timeSpanAmount
Util.setDefaultShareExpiration(
context,
if (!noExpirationCheckBox!!.isChecked && timeSpanAmount > 0)
String.format("%d:%s", timeSpanAmount, timeSpanType) else ""
)
Util.setDefaultShareDescription(context, shareDetails.Description)
Util.setDefaultShareDescription(shareDetails.Description)
}
share(fragment, shareDetails, swipe, cancellationToken)
}
@ -156,8 +155,8 @@ class ShareHandler(val context: Context) {
b ->
timeSpanPicker!!.isEnabled = !b
}
val defaultDescription = Util.getDefaultShareDescription(context)
val timeSpan = Util.getDefaultShareExpiration(context)
val defaultDescription = Util.getDefaultShareDescription()
val timeSpan = Util.getDefaultShareExpiration()
val split = pattern.split(timeSpan)
if (split.size == 2) {
val timeSpanAmount = split[0].toInt()

View File

@ -14,7 +14,7 @@ class VideoPlayer() {
Util.toast(context, R.string.select_album_no_network)
return
}
val player = Util.getVideoPlayerType(context)
val player = Util.getVideoPlayerType()
try {
player.playVideo(context, entry)
} catch (e: Exception) {

View File

@ -112,13 +112,13 @@ class SongView(context: Context) : UpdateView(context), Checkable {
fileFormat = if (
TextUtils.isEmpty(transcodedSuffix) || transcodedSuffix == suffix ||
song.isVideo && Util.getVideoPlayerType(this.context) !== VideoPlayerType.FLASH
song.isVideo && Util.getVideoPlayerType() !== VideoPlayerType.FLASH
) suffix else String.format("%s > %s", suffix, transcodedSuffix)
val artistName = song.artist
if (artistName != null) {
if (Util.shouldDisplayBitrateWithArtist(this.context)) {
if (Util.shouldDisplayBitrateWithArtist()) {
artist.append(artistName).append(" (").append(
String.format(
this.context.getString(R.string.song_details_all),
@ -132,7 +132,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
val trackNumber = song.track ?: 0
if (Util.shouldShowTrackNumber(this.context) && trackNumber != 0) {
if (Util.shouldShowTrackNumber() && trackNumber != 0) {
viewHolder?.track?.text = String.format("%02d.", trackNumber)
} else {
viewHolder?.track?.visibility = GONE
@ -141,7 +141,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
val title = StringBuilder(60)
title.append(song.title)
if (song.isVideo && Util.shouldDisplayBitrateWithArtist(this.context)) {
if (song.isVideo && Util.shouldDisplayBitrateWithArtist()) {
title.append(" (").append(
String.format(
this.context.getString(R.string.song_details_all),
@ -358,7 +358,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
}
init {
val theme = Util.getTheme(context)
val theme = Util.getTheme()
val themesMatch = theme == Companion.theme
inflater = LayoutInflater.from(this.context)