Skip to content

Instantly share code, notes, and snippets.

@ImDevinC
Created March 1, 2014 01:30
Show Gist options
  • Save ImDevinC/9283435 to your computer and use it in GitHub Desktop.
Save ImDevinC/9283435 to your computer and use it in GitHub Desktop.
Better if statements
String tempToken = conn.getData(url + "/etm/login.jsp");
if (tempToken != null) {
loginToken = parseToken(tempToken);
} else {
String error = parseError(tempToken);
if (error != null) {
showError(error);
} else {
showError("Error retrieving your login token, make sure you have a valid network connection");
}
return;
}
String postResults = null;
// This creates our login information
List<NameValuePair> parameters = createParams();
if (loginToken != null) {
// Here we send the information to the server and login
postResults = conn.postData(url + "/etm/login.jsp", parameters);
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("Error retrieving your login token, make sure you have a valid network connection");
}
return;
}
if (postResults != null && postResults.contains("etmMenu.jsp")) {
updateStatus("Retrieving schedule...");
postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp");
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("Error logging in, please verify your username and password");
}
return;
}
// if (postResults != null && isTlcActive(postResults)) {
// updateStatus("Retrieving schedule...");
// postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp");
// } else {
// showError("MyTLC is currently undergoing updates, please try again later");
// return;
// }
// If we successfully got the information, then parse out the schedule to read it properly
String secToken = null;
if (postResults != null) {
updateStatus("Parsing schedule...");
workDays = parseSchedule(postResults);
secToken = parseSecureToken(postResults);
wbat = parseWbat(postResults);
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("Could not obtain user schedule, make sure you have a valid network connection");
}
return;
}
if (secToken != null) {
parameters = createSecondParams(secToken);
postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters);
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("Error retrieving your login token, make sure you have a valid network connection");
}
return;
}
List<String[]> secondMonth = null;
if (postResults != null) {
secondMonth = parseSchedule(postResults);
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("Could not obtain user schedule, make sure you have a valid network connection");
}
return;
}
if (secondMonth != null) {
if (workDays == null) {
workDays = secondMonth;
} else {
workDays.addAll(secondMonth);
}
finalDays = workDays;
} else {
String error = parseError(postResults);
if (error != null) {
showError(error);
} else {
showError("There was an error retrieving your schedule, please try again");
}
return;
}
// Add our shifts to the calendar
updateStatus("Adding shifts to calendar...");
if (finalDays != null && addDays()) {
// Report back that we're successful!
Message msg = Message.obtain();
Bundle b = new Bundle();
b.putString("status", "DONE");
b.putInt("count", workDays.size());
msg.setData(b);
try {
messenger.send(msg);
} catch (Exception e) {
// Nothing
}
} else {
showError("Couldn't add your shifts to your calendar, please try again");
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment