diff --git a/updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/UpdatePreference.java b/updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/UpdatePreference.java index 2d5904c..de01a55 100644 --- a/updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/UpdatePreference.java +++ b/updatepluginlib/src/main/java/org/lzh/framework/updatepluginlib/util/UpdatePreference.java @@ -17,8 +17,12 @@ import android.content.Context; import android.content.SharedPreferences; +import android.text.TextUtils; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -29,15 +33,20 @@ public class UpdatePreference { private static final String PREF_NAME = "update_preference"; - public static Set getIgnoreVersions () { - return getUpdatePref().getStringSet("ignoreVersions", new HashSet()); + public static List getIgnoreVersions () { + String txt = getUpdatePref().getString("ignoreVersions", ""); + if(TextUtils.isEmpty(txt))return new ArrayList<>(); + txt = txt.replace("[","").replace("]",""); + String[] result = txt.split(","); + // 杜绝 java.lang.UnsupportedOperationException + return new ArrayList<>(Arrays.asList(result)); } public static void saveIgnoreVersion(int versionCode) { - Set ignoreVersions = getIgnoreVersions(); + List ignoreVersions = getIgnoreVersions(); if (!ignoreVersions.contains(String.valueOf(versionCode))) { ignoreVersions.add(String.valueOf(versionCode)); - getUpdatePref().edit().putStringSet("ignoreVersions",ignoreVersions).apply(); + getUpdatePref().edit().putString("ignoreVersions",ignoreVersions.toString()).apply(); } }