Commit 7733732f authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Asynchronize preferences saving when possible

parent 6f2f9491
......@@ -165,7 +165,7 @@ public class MainActivity extends ActionBarActivity {
if (mFirstRun) {
Editor editor = mSettings.edit();
editor.putInt(PREF_FIRST_RUN, mVersionNumber);
editor.commit();
Util.commitPreferences(editor);
}
try {
......@@ -423,7 +423,7 @@ public class MainActivity extends ActionBarActivity {
/* Save the tab status in pref */
SharedPreferences.Editor editor = getSharedPreferences("MainActivity", MODE_PRIVATE).edit();
editor.putString("fragment", mCurrentFragment);
editor.commit();
Util.commitPreferences(editor);
mAudioController.removeAudioPlayer(mAudioPlayer);
AudioServiceController.getInstance().unbindAudioService(this);
......@@ -1004,10 +1004,9 @@ public class MainActivity extends ActionBarActivity {
@Override
public void onClick(View v) {
removeTipViewIfDisplayed();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
Editor editor = settings.edit();
Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
editor.putBoolean(settingKey, true);
editor.commit();
Util.commitPreferences(editor);
}
});
}
......
......@@ -31,6 +31,7 @@ import org.videolan.vlc.gui.audio.AudioUtil;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.BitmapCache;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import android.app.AlertDialog;
......@@ -101,7 +102,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(PreferencesActivity.this);
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString("screen_orientation_value", (String)newValue);
editor.commit();
Util.commitPreferences(editor);
return true;
}
});
......@@ -276,7 +277,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
editor.putInt("network_caching_value", 0);
editor.putString("network_caching", "0");
}
editor.commit();
Util.commitPreferences(editor);
return true;
}
});
......
......@@ -25,6 +25,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.interfaces.OnEqualizerBarChangeListener;
import org.videolan.vlc.util.Preferences;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.widget.EqualizerBar;
......@@ -173,12 +174,11 @@ public class EqualizerFragment extends Fragment {
preamp.setOnSeekBarChangeListener(null);
bands_layout.removeAllViews();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
SharedPreferences.Editor editor = preferences.edit();
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).edit();
editor.putBoolean("equalizer_enabled", button.isChecked());
Preferences.putFloatArray(editor, "equalizer_values", equalizer);
editor.putInt("equalizer_preset", equalizer_presets.getSelectedItemPosition());
editor.commit();
Util.commitPreferences(editor);
}
private final OnItemSelectedListener mPresetListener = new OnItemSelectedListener() {
......
......@@ -55,6 +55,7 @@ import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
import org.videolan.vlc.util.WeakHandler;
......@@ -414,7 +415,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
// Paused flag - per session too, like the subs list.
editor.remove(PreferencesActivity.VIDEO_PAUSED);
editor.commit();
Util.commitPreferences(editor);
IntentFilter filter = new IntentFilter();
if (mBattery != null)
......@@ -548,7 +549,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
}
editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, subtitleList_serialized);
editor.commit();
Util.commitPreferences(editor);
AudioServiceController.getInstance().unbindAudioService(this);
}
......@@ -2391,7 +2392,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
long rTime = mSettings.getLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
Editor editor = mSettings.edit();
editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, -1);
editor.commit();
Util.commitPreferences(editor);
if(rTime > 0)
mLibVLC.setTime(rTime);
......@@ -2659,7 +2660,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
mOverlayTips.setVisibility(View.GONE);
Editor editor = mSettings.edit();
editor.putBoolean(PREF_TIPS_SHOWN, true);
editor.commit();
Util.commitPreferences(editor);
}
private void updateNavStatus() {
......
......@@ -44,7 +44,7 @@ public class CustomDirectories {
}
SharedPreferences.Editor editor = preferences.edit();
editor.putString("custom_paths", builder.toString());
editor.commit();
Util.commitPreferences(editor);
}
public static void removeCustomDirectory(String path) {
......@@ -69,7 +69,7 @@ public class CustomDirectories {
}
SharedPreferences.Editor editor = preferences.edit();
editor.putString("custom_paths", custom_path);
editor.commit();
Util.commitPreferences(editor);
}
public static String[] getCustomDirectories() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment