private void processData(String res, boolean isCache) throws JSONException { JSONObject root = new JSONObject(res); JSONArray array = root.getJSONArray("data"); LinkedHashMap<String, List<PrefixVideo>> tmp = new LinkedHashMap<String, List<PrefixVideo>>(); for (int i = 0; i < array.length(); i++) { JSONObject group = array.getJSONObject(i); String title = group.getString("title"); JSONArray data = group.getJSONArray("data"); for (int j = 0; j < data.length(); j++) { final PrefixVideo info = new PrefixVideo(data.getJSONObject(j), title); info.downloadListener = this; if (!isCache) { PrefixVideo p = PrefixVideo.query(info.id); if (p == null) { PrefixVideo.insert(info); } else { info.total = p.total; } } info.initialize(); List<PrefixVideo> items = tmp.get(title); if (items == null) { items = new LinkedList<PrefixVideo>(); tmp.put(title, items); } items.add(info); if (!info.coverFile.exists()) { App.THREAD.execute( new Runnable() { @Override public void run() { info.downloadCoverImage(); handler.sendEmptyMessage(HANDLER_UPDATE); } }); } } } List<PrefixVideoGroup> groups = new LinkedList<PrefixVideoGroup>(); Set<Entry<String, List<PrefixVideo>>> entrys = tmp.entrySet(); for (Entry<String, List<PrefixVideo>> i : entrys) { PrefixVideoGroup group = new PrefixVideoGroup(i.getValue().get(0).type, i.getKey()); group.items.addAll(i.getValue()); groups.add(group); } synchronized (adapter.dataSource) { adapter.dataSource.clear(); adapter.dataSource.addAll(groups); } handler.sendEmptyMessage(HANDLER_UPDATE); }