make version of Editor.apply() for SDK 8
This is not pretty, but its the best I could think of. Fixes this lint error: Call requires API level 9 (current min is 8): android.content.SharedPreferences.Editor#apply [NewApi]
This commit is contained in:
parent
5175eacd6d
commit
610ead83d0
@ -6,6 +6,8 @@ import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.compat.PreferencesCompat;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
@ -36,9 +38,8 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
|
||||
preferences.edit()
|
||||
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName())
|
||||
.apply();
|
||||
PreferencesCompat.apply(preferences.edit()
|
||||
.putString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +112,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
|
||||
public void setPrivilegedInstallerEnabled(boolean enable) {
|
||||
preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable).apply();
|
||||
PreferencesCompat.apply(preferences.edit().putBoolean(PREF_PRIVILEGED_INSTALLER, enable));
|
||||
}
|
||||
|
||||
public boolean isFirstTime() {
|
||||
@ -119,7 +120,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
|
||||
public void setFirstTime(boolean firstTime) {
|
||||
preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime).apply();
|
||||
PreferencesCompat.apply(preferences.edit().putBoolean(PREF_FIRST_TIME, firstTime));
|
||||
}
|
||||
|
||||
public boolean isPostPrivilegedInstall() {
|
||||
@ -127,7 +128,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
|
||||
public void setPostPrivilegedInstall(boolean postInstall) {
|
||||
preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall).apply();
|
||||
PreferencesCompat.apply(preferences.edit().putBoolean(PREF_POST_PRIVILEGED_INSTALL, postInstall));
|
||||
}
|
||||
|
||||
public boolean shouldCacheApks() {
|
||||
@ -147,7 +148,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
|
||||
}
|
||||
|
||||
public void setShowNfcDuringSwap(boolean show) {
|
||||
preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show).apply();
|
||||
PreferencesCompat.apply(preferences.edit().putBoolean(PREF_SHOW_NFC_DURING_SWAP, show));
|
||||
}
|
||||
|
||||
public boolean expertMode() {
|
||||
|
@ -40,6 +40,7 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.fdroid.fdroid.compat.PreferencesCompat;
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
@ -406,7 +407,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
|
||||
SharedPreferences.Editor e = prefs.edit();
|
||||
e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
|
||||
e.apply();
|
||||
PreferencesCompat.apply(e);
|
||||
|
||||
if (errorRepos == 0) {
|
||||
if (changes) {
|
||||
|
@ -0,0 +1,15 @@
|
||||
package org.fdroid.fdroid.compat;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
public class PreferencesCompat {
|
||||
|
||||
public static void apply(SharedPreferences.Editor e) {
|
||||
if (Build.VERSION.SDK_INT < 9) {
|
||||
e.commit();
|
||||
} else {
|
||||
e.apply();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import org.fdroid.fdroid.AppDetails;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.UpdateService;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.compat.PreferencesCompat;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.views.AppListAdapter;
|
||||
@ -141,7 +142,7 @@ public abstract class AppListFragment extends ListFragment implements
|
||||
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
|
||||
if (!hasTriedEmptyUpdate) {
|
||||
Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update.");
|
||||
prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
|
||||
PreferencesCompat.apply(prefs.edit().putBoolean(triedEmptyUpdate, true));
|
||||
UpdateService.updateNow(getActivity());
|
||||
return true;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.compat.ArrayAdapterCompat;
|
||||
import org.fdroid.fdroid.compat.PreferencesCompat;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.views.AppListAdapter;
|
||||
import org.fdroid.fdroid.views.AvailableAppListAdapter;
|
||||
@ -230,7 +231,7 @@ public class AvailableAppsFragment extends AppListFragment implements
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor e = p.edit();
|
||||
e.putString(CATEGORY_KEY, currentCategory);
|
||||
e.apply();
|
||||
PreferencesCompat.apply(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@ import org.fdroid.fdroid.FDroidApp;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.PreferencesActivity;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.compat.PreferencesCompat;
|
||||
import org.fdroid.fdroid.installer.PrivilegedInstaller;
|
||||
|
||||
import info.guardianproject.netcipher.NetCipher;
|
||||
@ -204,13 +205,13 @@ public class PreferencesFragment extends PreferenceFragment
|
||||
// privileged permission are granted, i.e. the extension is installed correctly
|
||||
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, true);
|
||||
editor.apply();
|
||||
PreferencesCompat.apply(editor);
|
||||
pref.setChecked(true);
|
||||
} else {
|
||||
// privileged permission not available
|
||||
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
|
||||
editor.apply();
|
||||
PreferencesCompat.apply(editor);
|
||||
pref.setChecked(false);
|
||||
|
||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
|
||||
@ -248,7 +249,7 @@ public class PreferencesFragment extends PreferenceFragment
|
||||
} else {
|
||||
SharedPreferences.Editor editor = pref.getSharedPreferences().edit();
|
||||
editor.putBoolean(Preferences.PREF_PRIVILEGED_INSTALLER, false);
|
||||
editor.apply();
|
||||
PreferencesCompat.apply(editor);
|
||||
pref.setChecked(false);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user