public static boolean submitDeteltePartner( int userID, Partner partnerContexted, Activity managerHomeActivity) { try { URL url = new URL( "http://www.256design.com/projectTransparency/project/deletePartnerHeader.php?id=" + userID + "&email=" + partnerContexted.getEmail()); HttpClient client = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url.toURI()); int executeCount = 0; HttpResponse response; int responseCode; do { // publishProgress(executeCount+1,5); // Execute HTTP Post Request executeCount++; response = client.execute(httppost); responseCode = response.getStatusLine().getStatusCode(); } while (executeCount < 5 && responseCode == 408); if (responseCode == 202) return true; else return false; } catch (Exception e) { return false; } }
public static boolean syncPartners(int userID, SQLiteDatabase db) throws Exception { try { URL url = new URL( "http://www.256design.com/projectTransparency/project/syncPartners.php?id=" + userID); URLConnection conn = url.openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = ""; ArrayList<Partner> newPartnersList = new ArrayList<Partner>(); while ((line = rd.readLine()) != null) { // Log.d("SPENCER", line); if (line.equals("None")) { break; } String[] splitLine = line.split(":"); Partner partnerToAdd = new Partner(splitLine[1]); if (splitLine[0].equals("Conf")) { partnerToAdd.setState(CONFIRMED); newPartnersList.add(partnerToAdd); } else if (splitLine[0].equals("Unconf")) { partnerToAdd.setState(UNCONFIRMED); newPartnersList.add(partnerToAdd); } else { partnerToAdd.setState(DENIED); newPartnersList.add(partnerToAdd); } // Log.d("SPENCER", "added " + splitLine[1] + " to " + splitLine[0]); } ArrayList<String> currentPartners = DatabaseHelper.getPartnerEmails(db); topLevel: for (String currentPartnerEmail : currentPartners) { // Log.d("SPENCER", "checking " + currentPartnerEmail); for (Partner partner : newPartnersList) { if (currentPartnerEmail.equals(partner.getEmail())) { DatabaseHelper.updatePartnerState(partner.getEmail(), partner.getState(), db); newPartnersList.remove(partner); continue topLevel; } } DatabaseHelper.updatePartnerState(currentPartnerEmail, Partner.DENIED, db); } for (Partner partner : newPartnersList) { DatabaseHelper.addPartner(partner, db); } return true; } catch (Exception e) { return false; } }
public static boolean submitAddPartner(Context context, Partner partner) { String result; // Register User Here try { HttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.256design.com/projectTransparency/project/regesterPartner.php"); // add values to list List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("emailAddress", partner.getEmail())); nameValuePairs.add( new BasicNameValuePair("userID", "" + new SharedPreferencesHelper(context).getUserID())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response; do { // Execute HTTP Post Request Log.d("SPENCER", "send add partner request"); response = client.execute(httppost); // Log.d("SPENCER", response.getStatusLine().getStatusCode() + " Status Code"); } while (response.getStatusLine().getStatusCode() == 408); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); // Log.d("SPENCER", "send register request"); String line = ""; result = line; while ((line = rd.readLine()) != null) { // Log.d("SPENCER", "|" + line + "|"); result = line; } } catch (Exception e) { result = "Error"; Log.e("SPENCER", "|" + e.getMessage() + "|"); } Log.d("SPENCER", "|" + result + "|"); if (result.equals("Success")) { return true; } else { return false; } }