88import org .json .JSONException ;
99import org .json .JSONObject ;
1010
11+ import java .util .ArrayList ;
12+
1113import 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