Support ordered set in DPreference

Note the ordered set need to be stored internally as String,
not string set
This commit is contained in:
yuhan6665
2020-08-28 21:52:43 -04:00
parent 8efdab43d7
commit d850c88c63
2 changed files with 21 additions and 6 deletions
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.LinkedHashSet;
import java.util.Set;
public class StringSetConverter {
@@ -13,8 +14,8 @@ public class StringSetConverter {
return gson.toJson(src);
}
public static Set<String> decode(String json) {
Type setType = new TypeToken<Set<String>>() {
public static LinkedHashSet<String> decode(String json) {
Type setType = new TypeToken<LinkedHashSet<String>>() {
}.getType();
return gson.fromJson(json, setType);
}