use of com.cpjd.roblu.csv.csvSheets.CSVSheet in project Roblu by wdavies973.
the class ExportCSVTask method run.
@Override
public void run() {
if (Build.VERSION.SDK_INT < 21) {
listener.errorOccurred("Your device does not support CSV exporting.");
return;
}
/*
* Check to see if the event is null, if it is, we must cancel this task
*/
if (event == null) {
listener.errorOccurred("Event could not be loaded.");
return;
}
/*
* Load teams
*/
teams = new IO(contextWeakReference.get()).loadTeams(event.getID());
form = new IO(contextWeakReference.get()).loadForm(event.getID());
/*
* Check to see if the teams or forms are null, if they are, cancel the task
*/
if (teams == null || teams.length == 0 || form == null) {
listener.errorOccurred("This event doesn't contain any teams");
return;
}
/*
* Verify all the teams
*/
for (RTeam team : teams) {
if (team != null) {
// also sneak in a line here to tell each team to sort by numerical if a sort request is made
team.setFilter(TeamsView.SORT_TYPE.NUMERICAL);
team.verify(form);
new IO(contextWeakReference.get()).saveTeam(event.getID(), team);
}
}
/*
* Sort the teams by number
*/
Collections.sort(Arrays.asList(teams));
/*
* Build checkouts array, nice way to store data
*/
final ArrayList<RCheckout> checkouts = new ArrayList<>();
for (RTeam team : teams) {
RTeam temp = team.clone();
temp.removeAllTabsButPIT();
RCheckout newCheckout = new RCheckout(temp);
checkouts.add(newCheckout);
}
/*
* Next, add an assignment for every match, for every team
*/
for (RTeam team : teams) {
if (team.getTabs() == null || team.getTabs().size() == 0)
continue;
for (int i = 2; i < team.getTabs().size(); i++) {
RTeam temp = team.clone();
temp.setPage(0);
temp.removeAllTabsBut(i);
RCheckout check = new RCheckout(temp);
checkouts.add(check);
}
}
Collections.sort(checkouts);
// Create an IO reference
final IO io = new IO(contextWeakReference.get());
/*
* Start executing all the different CSVSheets generate commands
*/
for (final CSVSheet s : CSVSheets) {
new Thread() {
public void run() {
if (s.isEnabled()) {
try {
s.setIo(io);
s.setVerboseness(verboseness);
s.setWorkbook(workbook);
Log.d("RBS", "ExportCSVTask: Generating sheet: " + s.getSheetName());
// sets the default, this may get overrided at any point in time by the user
s.setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, false);
s.generateSheet(sheets.get(s.getSheetName()), event, form, teams, checkouts);
for (int i = 0; i < sheets.get(s.getSheetName()).getRow(0).getLastCellNum(); i++) sheets.get(s.getSheetName()).setColumnWidth(i, s.getColumnWidth());
} catch (Exception e) {
listener.errorOccurred("Failed to execute " + s.getSheetName() + " sheet generation.");
Log.d("RBS", "Failed to execute " + s.getSheetName() + " sheet generation. Err: " + e.getMessage());
}
threadCompleted(s.getSheetName());
}
}
}.start();
}
}