protected void onPostExecute(String result) { loader.dismiss(); Log.d(TAG, result); if (schoolAppNotificationsListActivity != null) { if (phoneEmailListArrayList == null) schoolAppNotificationsListActivity.returnResult(result); else schoolAppNotificationsListActivity.returnUnsubscribeResult( result, notificationListObject, phoneEmailListArrayList); } else if (schoolAppListActivity != null) { schoolAppListActivity.returnResult(result); } else if (sACSA != null) { sACSA.returnUnsubscribeResult(result, phoneEmailListObject.getRowId()); } else if (schoolAppSettingsActivity != null) { schoolAppSettingsActivity.returnResult( result, channelListFromPhoneEmailId, phoneEmailListObject); } } // this.channelListFromPhoneEmailId = channelListFromPhoneEmailId;
@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; }