Use apply instead of commit

This commit is contained in:
Andrew Rabert 2017-06-11 11:09:09 -04:00
parent 707476cd65
commit 39da819765
12 changed files with 33 additions and 33 deletions

View File

@ -677,12 +677,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest5"); editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest5");
editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest"); editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
editor.commit(); editor.apply();
} }
if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) { if(!prefs.contains(Constants.PREFERENCES_KEY_SERVER_COUNT)) {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
editor.commit(); editor.apply();
} }
} }
@ -694,7 +694,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
} else { } else {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, newDirectory); editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, newDirectory);
editor.commit(); editor.apply();
return true; return true;
} }
} }

View File

@ -177,7 +177,7 @@ public class EqualizerFragment extends SubsonicFragment {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(Constants.PREFERENCES_EQUALIZER_ON, enabled); editor.putBoolean(Constants.PREFERENCES_EQUALIZER_ON, enabled);
editor.commit(); editor.apply();
for(int i = 0; i < 10; i++) { for(int i = 0; i < 10; i++) {
try { try {
equalizer.setEnabled(enabled); equalizer.setEnabled(enabled);
@ -243,7 +243,7 @@ public class EqualizerFragment extends SubsonicFragment {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel); editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
editor.commit(); editor.apply();
} }
} catch(Exception e) { } catch(Exception e) {
Log.e(TAG, "Failed to update bars"); Log.e(TAG, "Failed to update bars");
@ -430,7 +430,7 @@ public class EqualizerFragment extends SubsonicFragment {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel); editor.putInt(Constants.PREFERENCES_EQUALIZER_SETTINGS, masterLevel);
editor.commit(); editor.apply();
for (short i = 0; i < equalizer.getNumberOfBands(); i++) { for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
short level = (short) ((bars.get(i).getProgress() + minEQLevel) + masterLevel); short level = (short) ((bars.get(i).getProgress() + minEQLevel) + masterLevel);
equalizer.setBandLevel(i, level); equalizer.setBandLevel(i, level);

View File

@ -118,7 +118,7 @@ public class MainFragment extends SelectRecyclerFragment<Integer> {
if("newest".equals(type)) { if("newest".equals(type)) {
SharedPreferences.Editor editor = Util.getPreferences(context).edit(); SharedPreferences.Editor editor = Util.getPreferences(context).edit();
editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT + Util.getActiveServer(context), 0); editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT + Util.getActiveServer(context), 0);
editor.commit(); editor.apply();
} }
SubsonicFragment fragment = new SelectDirectoryFragment(); SubsonicFragment fragment = new SelectDirectoryFragment();

View File

@ -287,7 +287,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null); editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, null);
editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + instance, "http://yourhost"); editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + instance, "http://yourhost");
editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, getResources().getString(R.string.settings_server_unused)); editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, getResources().getString(R.string.settings_server_unused));
editor.commit(); editor.apply();
ServerSettings ss = new ServerSettings(instance); ServerSettings ss = new ServerSettings(instance);
serverSettings.put(String.valueOf(instance), ss); serverSettings.put(String.valueOf(instance), ss);
@ -536,7 +536,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
serverCount--; serverCount--;
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount); editor.putInt(Constants.PREFERENCES_KEY_SERVER_COUNT, serverCount);
editor.commit(); editor.apply();
removeCurrent(); removeCurrent();
@ -626,7 +626,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultPath); editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultPath);
editor.commit(); editor.apply();
if(cacheLocation != null) { if(cacheLocation != null) {
cacheLocation.setSummary(defaultPath); cacheLocation.setSummary(defaultPath);

View File

@ -743,7 +743,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear); editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear);
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear); editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear);
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
editor.commit(); editor.apply();
DownloadService downloadService = getDownloadService(); DownloadService downloadService = getDownloadService();
if (downloadService == null) { if (downloadService == null) {

View File

@ -184,7 +184,7 @@ public class DownloadService extends Service {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try { try {
audioSessionId = mediaPlayer.getAudioSessionId(); audioSessionId = mediaPlayer.getAudioSessionId();
prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).commit(); prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).apply();
} catch (Throwable t) { } catch (Throwable t) {
// Froyo or lower // Froyo or lower
} }
@ -461,7 +461,7 @@ public class DownloadService extends Service {
} }
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.PREFERENCES_KEY_SHUFFLE_MODE, startShufflePlay); editor.putInt(Constants.PREFERENCES_KEY_SHUFFLE_MODE, startShufflePlay);
editor.commit(); editor.apply();
} }
if (currentPlayingIndex != -1) { if (currentPlayingIndex != -1) {
while(mediaPlayer == null) { while(mediaPlayer == null) {
@ -498,7 +498,7 @@ public class DownloadService extends Service {
} }
SharedPreferences.Editor editor = Util.getPreferences(this).edit(); SharedPreferences.Editor editor = Util.getPreferences(this).edit();
editor.putBoolean(Constants.PREFERENCES_KEY_REMOVE_PLAYED, enabled); editor.putBoolean(Constants.PREFERENCES_KEY_REMOVE_PLAYED, enabled);
editor.commit(); editor.apply();
} }
public boolean isRemovePlayed() { public boolean isRemovePlayed() {
return removePlayed; return removePlayed;
@ -511,7 +511,7 @@ public class DownloadService extends Service {
} }
SharedPreferences.Editor editor = Util.getPreferences(this).edit(); SharedPreferences.Editor editor = Util.getPreferences(this).edit();
editor.putInt(Constants.PREFERENCES_KEY_SHUFFLE_MODE, enabled ? SHUFFLE_MODE_ALL : SHUFFLE_MODE_NONE); editor.putInt(Constants.PREFERENCES_KEY_SHUFFLE_MODE, enabled ? SHUFFLE_MODE_ALL : SHUFFLE_MODE_NONE);
editor.commit(); editor.apply();
} }
public boolean isShufflePlayEnabled() { public boolean isShufflePlayEnabled() {
@ -552,7 +552,7 @@ public class DownloadService extends Service {
SharedPreferences prefs = Util.getPreferences(this); SharedPreferences prefs = Util.getPreferences(this);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(Constants.PREFERENCES_KEY_KEEP_SCREEN_ON, keepScreenOn); editor.putBoolean(Constants.PREFERENCES_KEY_KEEP_SCREEN_ON, keepScreenOn);
editor.commit(); editor.apply();
} }
public synchronized DownloadFile forSong(MusicDirectory.Entry song) { public synchronized DownloadFile forSong(MusicDirectory.Entry song) {
@ -1353,7 +1353,7 @@ public class DownloadService extends Service {
SharedPreferences.Editor editor = Util.getPreferences(this).edit(); SharedPreferences.Editor editor = Util.getPreferences(this).edit();
editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_NAME, name); editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_NAME, name);
editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_ID, id); editor.putString(Constants.PREFERENCES_KEY_PLAYLIST_ID, id);
editor.commit(); editor.apply();
} }
public String getSuggestedPlaylistName() { public String getSuggestedPlaylistName() {

View File

@ -225,7 +225,7 @@ public class DownloadServiceLifecycleSupport {
if(genre != null) { if(genre != null) {
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
} }
editor.commit(); editor.apply();
downloadService.clear(); downloadService.clear();
downloadService.setShufflePlayEnabled(true); downloadService.setShufflePlayEnabled(true);

View File

@ -111,7 +111,7 @@ public class IndexesParser extends MusicDirectoryEntryParser {
if(ignoredArticles != null) { if(ignoredArticles != null) {
SharedPreferences.Editor prefs = Util.getPreferences(context).edit(); SharedPreferences.Editor prefs = Util.getPreferences(context).edit();
prefs.putString(Constants.CACHE_KEY_IGNORE, ignoredArticles); prefs.putString(Constants.CACHE_KEY_IGNORE, ignoredArticles);
prefs.commit(); prefs.apply();
} }
if (!changed) { if (!changed) {

View File

@ -54,12 +54,12 @@ public class Updater {
if(lastVersion == 0) { if(lastVersion == 0) {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.LAST_VERSION, version); editor.putInt(Constants.LAST_VERSION, version);
editor.commit(); editor.apply();
} }
else if(version > lastVersion) { else if(version > lastVersion) {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.LAST_VERSION, version); editor.putInt(Constants.LAST_VERSION, version);
editor.commit(); editor.apply();
Log.i(TAG, "Updating from version " + lastVersion + " to " + version); Log.i(TAG, "Updating from version " + lastVersion + " to " + version);
for(Updater updater: updaters) { for(Updater updater: updaters) {

View File

@ -36,7 +36,7 @@ public class UpdaterSongPress extends Updater {
if(playNowAfter == false) { if(playNowAfter == false) {
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_SONG_PRESS_ACTION, "single"); editor.putString(Constants.PREFERENCES_KEY_SONG_PRESS_ACTION, "single");
editor.commit(); editor.apply();
} }
} }
} }

View File

@ -89,7 +89,7 @@ public final class ThemeUtil {
public static void setTheme(Context context, String theme) { public static void setTheme(Context context, String theme) {
SharedPreferences.Editor editor = Util.getPreferences(context).edit(); SharedPreferences.Editor editor = Util.getPreferences(context).edit();
editor.putString(Constants.PREFERENCES_KEY_THEME, theme); editor.putString(Constants.PREFERENCES_KEY_THEME, theme);
editor.commit(); editor.apply();
} }
public static void applyTheme(Context context, String theme) { public static void applyTheme(Context context, String theme) {

View File

@ -138,7 +138,7 @@ public final class Util {
SharedPreferences prefs = getPreferences(context); SharedPreferences prefs = getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, offline); editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, offline);
editor.commit(); editor.apply();
} }
public static boolean isScreenLitOnDownload(Context context) { public static boolean isScreenLitOnDownload(Context context) {
@ -155,14 +155,14 @@ public final class Util {
SharedPreferences prefs = getPreferences(context); SharedPreferences prefs = getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_REPEAT_MODE, repeatMode.name()); editor.putString(Constants.PREFERENCES_KEY_REPEAT_MODE, repeatMode.name());
editor.commit(); editor.apply();
} }
public static void setActiveServer(Context context, int instance) { public static void setActiveServer(Context context, int instance) {
SharedPreferences prefs = getPreferences(context); SharedPreferences prefs = getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, instance); editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, instance);
editor.commit(); editor.apply();
} }
public static int getActiveServer(Context context) { public static int getActiveServer(Context context) {
@ -210,7 +210,7 @@ public final class Util {
editor.putString(Constants.PREFERENCES_KEY_USERNAME + newInstance, null); editor.putString(Constants.PREFERENCES_KEY_USERNAME + newInstance, null);
editor.putString(Constants.PREFERENCES_KEY_PASSWORD + newInstance, null); editor.putString(Constants.PREFERENCES_KEY_PASSWORD + newInstance, null);
editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + newInstance, null); editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + newInstance, null);
editor.commit(); editor.apply();
if (instance == activeInstance) { if (instance == activeInstance) {
if(instance != 1) { if(instance != 1) {
@ -238,7 +238,7 @@ public final class Util {
SharedPreferences prefs = getPreferences(context); SharedPreferences prefs = getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, musicFolderId); editor.putString(Constants.PREFERENCES_KEY_MUSIC_FOLDER_ID + instance, musicFolderId);
editor.commit(); editor.apply();
} }
public static String getSelectedMusicFolderId(Context context) { public static String getSelectedMusicFolderId(Context context) {
@ -261,7 +261,7 @@ public final class Util {
SharedPreferences prefs = getPreferences(context); SharedPreferences prefs = getPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(Constants.PREFERENCES_KEY_ALBUMS_PER_FOLDER + instance, perFolder); editor.putBoolean(Constants.PREFERENCES_KEY_ALBUMS_PER_FOLDER + instance, perFolder);
editor.commit(); editor.apply();
} }
public static boolean getDisplayTrack(Context context) { public static boolean getDisplayTrack(Context context) {
@ -303,7 +303,7 @@ public final class Util {
return Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, false); return Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, false);
} }
public static void setBatchMode(Context context, boolean batchMode) { public static void setBatchMode(Context context, boolean batchMode) {
Util.getPreferences(context).edit().putBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, batchMode).commit(); Util.getPreferences(context).edit().putBoolean(Constants.PREFERENCES_KEY_BATCH_MODE, batchMode).apply();
} }
public static String getRestUrl(Context context, String method) { public static String getRestUrl(Context context, String method) {
@ -393,7 +393,7 @@ public final class Util {
public static void setBlockTokenUse(Context context, int instance, boolean block) { public static void setBlockTokenUse(Context context, int instance, boolean block) {
SharedPreferences.Editor editor = getPreferences(context).edit(); SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putBoolean(getBlockTokenUsePref(context, instance), block); editor.putBoolean(getBlockTokenUsePref(context, instance), block);
editor.commit(); editor.apply();
} }
public static boolean isTagBrowsing(Context context) { public static boolean isTagBrowsing(Context context) {
@ -435,7 +435,7 @@ public final class Util {
public static void setSyncDefault(Context context, String defaultValue) { public static void setSyncDefault(Context context, String defaultValue) {
SharedPreferences.Editor editor = Util.getOfflineSync(context).edit(); SharedPreferences.Editor editor = Util.getOfflineSync(context).edit();
editor.putString(Constants.OFFLINE_SYNC_DEFAULT, defaultValue); editor.putString(Constants.OFFLINE_SYNC_DEFAULT, defaultValue);
editor.commit(); editor.apply();
} }
public static String getCacheName(Context context, String name, String id) { public static String getCacheName(Context context, String name, String id) {
@ -543,7 +543,7 @@ public final class Util {
editor.putBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), true); editor.putBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), true);
} }
editor.commit(); editor.apply();
} }
public static boolean shouldStartOnHeadphones(Context context) { public static boolean shouldStartOnHeadphones(Context context) {