Skip to content

Commit 0d87d93

Browse files
author
videopls
committed
解决桌面小程序获取最近小程序倒序问题
1 parent 28500e9 commit 0d87d93

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

VideoOS/VenvyLibrary/src/main/java/cn/com/venvy/CacheConstants.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.json.JSONException;
99
import org.json.JSONObject;
1010

11+
import java.util.ArrayList;
12+
1113
import cn.com.venvy.common.utils.VenvyPreferenceHelper;
1214

1315
/**
@@ -29,6 +31,7 @@ public class CacheConstants {
2931
* @param id
3032
*/
3133
public static void putVisionProgramId(Context context, String fileName, @NonNull String id) {
34+
3235
String data = VenvyPreferenceHelper.getString(context, fileName, RECENT_MINI_APP_ID, "[]");
3336
try {
3437
JSONArray array = new JSONArray(data);
@@ -49,23 +52,36 @@ public static void putVisionProgramId(Context context, String fileName, @NonNull
4952
}
5053
array.put(id);
5154
}
55+
5256
VenvyPreferenceHelper.putString(context, fileName, RECENT_MINI_APP_ID, array.toString());
5357
} catch (JSONException e) {
5458
e.printStackTrace();
5559
}
5660
}
5761

62+
private static JSONArray reverse(JSONArray jsonArray) throws JSONException {
63+
for (int i = 0; i < jsonArray.length() / 2; i++) {
64+
Object temp = jsonArray.get(i);
65+
jsonArray.put(i,jsonArray.get(jsonArray.length() - 1 - i));
66+
jsonArray.put(jsonArray.length() - 1 - i, temp);
67+
}
68+
return jsonArray;
69+
}
70+
5871
/**
5972
* 获取最近使用的所有的小程序的id 集合
6073
*
6174
* @param context
6275
* @return
6376
*/
6477
public static String getVisionProgramId(Context context, String fileName) {
65-
return VenvyPreferenceHelper.getString(context, fileName, RECENT_MINI_APP_ID, "{}");
78+
try {
79+
return reverse(new JSONArray(VenvyPreferenceHelper.getString(context, fileName, RECENT_MINI_APP_ID, "[]"))).toString();
80+
} catch (JSONException e) {
81+
return "[]";
82+
}
6683
}
6784

68-
6985
private static JSONArray removeDuplicates(JSONArray array, String id) throws JSONException {
7086
boolean isContains;
7187
for (int i = 0, len = array.length(); i < len; i++) {

0 commit comments

Comments
 (0)