private void setSpannelStyle(String str, ShortChannelData shortChannelData) { if (str == null) return; try { int end = str.indexOf("-"); shortChannelData.spannableTimeInfo = CommonUtils.getSpannableString(str, 0, end, span); } catch (Exception e) { shortChannelData.spannableTimeInfo = null; } }
/** * @param list * @param s * @return */ private String parse(ArrayList<TypeChannelData> list, String s) { int errCode = 1; try { JSONObject jsonObject = new JSONObject(s); if (jsonObject.has("code")) { errCode = jsonObject.getInt("code"); } else if (jsonObject.has("errcode")) { errCode = jsonObject.getInt("errcode"); } else if (jsonObject.has("errorCode")) { errCode = jsonObject.getInt("errorCode"); } if (jsonObject.has("jsession")) { UserNow.current().jsession = jsonObject.getString("jsession"); } if (errCode == JSONMessageType.SERVER_CODE_OK) { JSONObject content = jsonObject.getJSONObject("content"); if (content.has("column")) { JSONArray typeChannelArray = content.getJSONArray("column"); for (int i = 0; i < typeChannelArray.length(); ++i) { JSONObject channelColumnObject = typeChannelArray.getJSONObject(i); TypeChannelData typeChannelData = new TypeChannelData(); typeChannelData.channelTypeName = channelColumnObject.optString("name"); if (channelColumnObject.has("items")) { ArrayList<ShortChannelData> programList = new ArrayList<ShortChannelData>(); JSONArray channelProgramItems = channelColumnObject.getJSONArray("items"); for (int j = 0; j < channelProgramItems.length(); ++j) { JSONObject channelProgram = channelProgramItems.getJSONObject(j); ShortChannelData tempShortChannelData = new ShortChannelData(); tempShortChannelData.programId = channelProgram.optInt("programId"); tempShortChannelData.channelId = channelProgram.optInt("channelId"); String time = channelProgram.optString("timeInfo"); if (time != null) { tempShortChannelData.timeInfo = time; setSpannelStyle(time, tempShortChannelData); } tempShortChannelData.programInfo = channelProgram.optString("programInfo"); tempShortChannelData.topicId = channelProgram.optString("topicId"); tempShortChannelData.channelName = channelProgram.optString("channelName"); tempShortChannelData.programName = channelProgram.optString("programTitle"); tempShortChannelData.channelPicUrl = channelProgram.optString("channelPhoto"); tempShortChannelData.cpId = channelProgram.optInt("cpId"); tempShortChannelData.flagMyChannel = channelProgram.optInt("flagMyChannel") == 1 ? true : false; tempShortChannelData.livePlay = channelProgram.optInt("livePlay") == 1 ? true : false; tempShortChannelData.channelType = channelProgram.optInt("channelType"); if (channelProgram.has("play")) { JSONArray play = channelProgram.getJSONArray("play"); ArrayList<NetPlayData> netPlayDatas = new ArrayList<NetPlayData>(); for (int x = 0; x < play.length(); ++x) { NetPlayData netPlayData = new NetPlayData(); JSONObject playItem = play.getJSONObject(x); netPlayData.name = playItem.optString("name"); netPlayData.pic = playItem.optString("pic"); netPlayData.url = playItem.optString("url"); netPlayData.videoPath = playItem.optString("videoPath"); netPlayData.channelName = tempShortChannelData.channelName; netPlayDatas.add(netPlayData); } tempShortChannelData.netPlayDatas = netPlayDatas; } // TODO: 仅用于机锋 if (tempShortChannelData.programName.contains("喜羊羊")) { tempShortChannelData.programName = "没有节目数据"; tempShortChannelData.programId = 0; tempShortChannelData.topicId = "0"; } programList.add(tempShortChannelData); } typeChannelData.typeChannelData = programList; } list.add(typeChannelData); } } } else { return jsonObject.getString("msg"); } } catch (JSONException e) { e.printStackTrace(); return "parseErr"; } return null; }