[Android] Asynchronize preferences saving when possible

Geoffrey Métais git at videolan.org
Tue Jan 6 10:16:41 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  5 17:47:12 2015 +0100| [7733732f8752b46365f276f9a7ed98e45e0325f3] | committer: Geoffrey Métais

Asynchronize preferences saving when possible

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7733732f8752b46365f276f9a7ed98e45e0325f3
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java        |    9 ++++-----
 vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java |    5 +++--
 .../src/org/videolan/vlc/gui/audio/EqualizerFragment.java     |    6 +++---
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java   |    9 +++++----
 vlc-android/src/org/videolan/vlc/util/CustomDirectories.java  |    4 ++--
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 454bd06..594dd81 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -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);
                 }
             });
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index c22bded..cea10ea 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -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;
             }
         });
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
index 10b20ce..ffd272e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/EqualizerFragment.java
@@ -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() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index b36adfd..e370bf5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -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() {
diff --git a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
index 9bffa43..1a1ac1b 100644
--- a/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
+++ b/vlc-android/src/org/videolan/vlc/util/CustomDirectories.java
@@ -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() {



More information about the Android mailing list