public ArrayList<NotificationListObject> parseNotificationJSONObject(JSONObject jsonObject) throws JSONException { ArrayList<NotificationListObject> menuObjectArrayList = new ArrayList<NotificationListObject>(); Iterator<?> i = jsonObject.keys(); while (i.hasNext()) { String key = (String) i.next(); JSONObject js = jsonObject.getJSONObject(key); NotificationListObject m = new NotificationListObject(); m.setChannelId(js.getString("id")); m.setTitle(js.getString("title")); m.setOrder(js.getInt("order")); // Log.d("Key", key); menuObjectArrayList.add(m); } return menuObjectArrayList; }
@Override protected String doInBackground(Void... params) { Log.d(TAG, "doInBackground"); BufferedReader in = null; String page = ""; String url = Constants.ROOT_SCHOOLAPP_URL + "app/unsubscribe/"; // Doing a batch update // Make updates that will handle if there was a problem halfway through // Making the assumption that if this an all or nothing response. // If one "ERROR" they all failed // If "OK" they all passed if (phoneEmailListArrayList != null) { String phoneEmailString = ""; url += id + "/" + notificationListObject.getChannelId(); int i = 0; while (i < phoneEmailListArrayList.size()) { if (phoneEmailListArrayList.get(i).getType().equals(Constants.PHONENUMBER) || phoneEmailListArrayList.get(i).getType().equals(Constants.MASTER)) { phoneEmailString = "/" + phoneEmailListArrayList.get(i).getValue() + Constants.URLPIPE + ""; } else if (phoneEmailListArrayList.get(i).getType().equals(Constants.EMAIL)) { phoneEmailString = "/" + "" + Constants.URLPIPE + phoneEmailListArrayList.get(i).getValue(); } else { return "ERROR"; } HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android"); HttpGet request = new HttpGet(); request.setHeader("Content-Type", "text/plain; charset=utf-8"); Log.d("URL: ", url); try { request.setURI(new URI(url + phoneEmailString)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); page = sb.toString(); Log.d("page", page); } catch (Exception e) { e.printStackTrace(); } if (page.contains("ERROR") || page.equals("")) return page; i++; } } else if (channelListFromPhoneEmailId != null) { /* * this.schoolAppSettingsActivity = sASA; this.id = id; this.channelListFromPhoneEmailId = channelListFromPhoneEmailId; this.phoneEmailListObject = phoneEmailListObject; */ String phoneEmailString = ""; String channelIdString = ""; if (phoneEmailListObject.getType().equals(Constants.PHONENUMBER) || phoneEmailListObject.getType().equals(Constants.MASTER)) { phoneEmailString = "/" + phoneEmailListObject.getValue() + Constants.URLPIPE + ""; } else if (phoneEmailListObject.getType().equals(Constants.EMAIL)) { phoneEmailString = "/" + "" + Constants.URLPIPE + phoneEmailListObject.getValue(); } else { return "ERROR"; } int i = 0; while (i < channelListFromPhoneEmailId.size()) { channelIdString = id + "/" + channelListFromPhoneEmailId.get(i).getChannelId(); HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android"); HttpGet request = new HttpGet(); request.setHeader("Content-Type", "text/plain; charset=utf-8"); Log.d("URL: ", url); try { request.setURI(new URI(url + channelIdString + phoneEmailString)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); page = sb.toString(); Log.d("page", page); } catch (Exception e) { e.printStackTrace(); } if (page.contains("ERROR") || page.equals("")) return page; i++; } // Doing a single phone number/email } else { url += id + "/" + channelId; if (phoneEmailListObject.getType().equals(Constants.PHONENUMBER) || phoneEmailListObject.getType().equals(Constants.MASTER)) { url += "/" + phoneEmailListObject.getValue() + Constants.URLPIPE + ""; } else if (phoneEmailListObject.getType().equals(Constants.EMAIL)) { url += "/" + "" + Constants.URLPIPE + phoneEmailListObject.getValue(); } else { return "ERROR"; } HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android"); HttpGet request = new HttpGet(); request.setHeader("Content-Type", "text/plain; charset=utf-8"); Log.d("URL: ", url); try { request.setURI(new URI(url)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); page = sb.toString(); Log.d("page", page); } catch (Exception e) { e.printStackTrace(); } } return page; }