use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.
the class EventDrawerManager method selectEvent.
/**
* Selects an event and flags the main activity to start loading
* teams and updating the UI appropriately
* @param ID the ID of the event to set as active
*/
public void selectEvent(int ID) {
if (events == null || events.size() == 0)
return;
for (REvent e : events) {
if (e.getID() == ID) {
event = e;
// Update the action bar title, it will get updated again when the teams are loaded by the LoadTeamsTask AsyncTask
if (((AppCompatActivity) activity).getSupportActionBar() != null) {
((AppCompatActivity) activity).getSupportActionBar().setTitle(event.getName());
((AppCompatActivity) activity).getSupportActionBar().setSubtitle("Teams");
}
// Save the event the user just selected to settings so Roblu can remember where they left off when the app is relaunched
RSettings settings = new IO(activity).loadSettings();
settings.setLastEventID(ID);
new IO(activity).saveSettings(settings);
// Tell the main activity to start loading the teams
// we'll provide a REvent reference for convenience, but TeamsView still has access to it with a getter
listener.eventSelected(event);
return;
}
}
}
use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.
the class EventEditor method createEvent.
/**
* This method is more of a courtesy method to the source code reader,
* an event will get created from EventEditor whenever this method is called, no exceptions.
* @param form the form to save with the event
*/
private void createEvent(RForm form) {
IO io = new IO(getApplicationContext());
REvent event = new REvent(io.getNewEventID(), eventName.getText().toString());
// we call this twice because the /event/ dir is required for the form to save
io.saveEvent(event);
io.saveForm(event.getID(), form);
/*
* We need to check if the user included any TBA information that we should include in this event creation
*/
if (!editing && getIntent().getSerializableExtra("tbaEvent") != null) {
ProgressDialog d = ProgressDialog.show(this, "Hold on tight!", "Generating team profiles from event...", true);
d.setCancelable(false);
event.setKey(((Event) getIntent().getSerializableExtra("tbaEvent")).key);
io.saveEvent(event);
UnpackTBAEvent unpackTBAEvent = new UnpackTBAEvent((Event) getIntent().getSerializableExtra("tbaEvent"), event.getID(), this, d);
if (((Switch) findViewById(R.id.switch1)).isChecked())
unpackTBAEvent.setRandomize(true);
unpackTBAEvent.execute();
} else /*
* If we started the UnpackTask, then we have to wait to return, if not, return now
*/
{
io.saveEvent(event);
Intent result = new Intent();
result.putExtra("eventID", event.getID());
setResult(Constants.NEW_EVENT_CREATED, result);
finish();
}
}
use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.
the class InitPacker method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
/*
* Make sure this thread has network permissions
*/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
Log.d("RBS", "Executing InitPacker task...");
IO io = ioWeakReference.get();
RSettings settings = io.loadSettings();
RSyncSettings cloudSettings = io.loadCloudSettings();
cloudSettings.setPurgeRequested(false);
io.saveCloudSettings(cloudSettings);
io.saveSettings(settings);
Request r = new Request(settings.getServerIP());
if (!r.ping()) {
listener.statusUpdate("It appears as though the server is offline. Try again later.");
return false;
}
/*
* Load all teams from the event, also make sure that that the teams are verified
*/
REvent event = io.loadEvent(eventID);
event.setReadOnlyTeamNumber(-1);
RForm form = io.loadForm(eventID);
RTeam[] teams = io.loadTeams(eventID);
if (event == null || form == null || teams == null || teams.length == 0) {
Log.d("RBS", "Not enough data to warrant an event upload.");
listener.statusUpdate("This event doesn't contain any teams or sufficient data to upload to the server. Create some teams!");
return false;
}
// Generate the checkouts
SyncHelper syncHelper = new SyncHelper(io, event, SyncHelper.MODES.NETWORK);
ArrayList<RCheckout> checkouts = syncHelper.generateCheckoutsFromEvent(teams, -1);
// Remove field data
try {
for (RCheckout checkout : checkouts) {
for (RTab tab : checkout.getTeam().getTabs()) {
for (RMetric metric : tab.getMetrics()) {
if (metric instanceof RFieldData) {
((RFieldData) metric).setData(null);
}
}
}
}
} catch (Exception e) {
// Doesn't matter
}
/*
* Convert into JSON and upload
*/
ObjectMapper mapper = new ObjectMapper();
try {
// serialization all the checkouts and pack them in an json array, this will be processed by the server
String serializedCheckouts = syncHelper.packCheckouts(checkouts);
String serializedForm = mapper.writeValueAsString(form);
String serializedUI = mapper.writeValueAsString(settings.getRui());
String eventName = event.getName();
if (eventName == null)
eventName = "";
if (event.getKey() == null)
event.setKey("");
CloudCheckoutRequest ccr = new CloudCheckoutRequest(r, settings.getCode());
Log.d("RBS", "Initializing init packer upload...");
boolean success = ccr.init(settings.getTeamNumber(), eventName, serializedForm, serializedUI, serializedCheckouts, event.getKey());
/*
* Disable all other events with cloud syncing enabled
*/
if (success) {
REvent[] events = io.loadEvents();
for (int i = 0; events != null && i < events.length; i++) {
events[i].setCloudEnabled(events[i].getID() == eventID);
io.saveEvent(events[i]);
}
cloudSettings.getCheckoutSyncIDs().clear();
/*
* Add default sync ids
*/
for (RCheckout checkout : checkouts) {
cloudSettings.getCheckoutSyncIDs().put(checkout.getID(), 0L);
}
io.saveCloudSettings(cloudSettings);
io.saveSettings(settings);
} else
listener.statusUpdate("An error occurred. Event was not uploaded.");
return success;
} catch (Exception e) {
Log.d("RBS", "An error occurred in InitPacker: " + e.getMessage());
listener.statusUpdate("An error occurred. Event was not uploaded.");
return false;
} finally {
/*
* Set all images to null to return memory to normal
*/
for (RCheckout checkout : checkouts) {
for (RTab tab : checkout.getTeam().getTabs()) {
for (RMetric metric : tab.getMetrics()) {
if (metric instanceof RGallery) {
((RGallery) metric).setImages(null);
}
}
}
}
}
}
use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.
the class BTServer method run.
/**
* Starts the sync task
*/
@Override
public void run() {
/*
* Load the active Bluetooth event
*/
IO io = new IO(bluetooth.getActivity());
REvent[] events = io.loadEvents();
if (events == null || events.length == 0) {
bluetooth.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(bluetooth.getActivity(), "No events found. Please create an event to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
}
});
pd.dismiss();
return;
}
for (REvent event : events) {
if (event.isBluetoothEnabled()) {
this.event = event;
break;
}
}
if (this.event == null) {
bluetooth.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(bluetooth.getActivity(), "No active Bluetooth event found. Please enable Bluetooth in event settings to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
}
});
pd.dismiss();
return;
}
this.syncHelper = new SyncHelper(bluetooth.getActivity(), this.event, SyncHelper.MODES.BLUETOOTH);
if (bluetooth.isEnabled()) {
bluetooth.startServer();
} else
bluetooth.enable();
}
use of com.cpjd.roblu.models.REvent in project Roblu by wdavies973.
the class OurMatches method generateSheet.
@Override
public void generateSheet(XSSFSheet sheet, REvent event, RForm form, RTeam[] teams, ArrayList<RCheckout> checkouts) {
if (event.getKey() == null || event.getKey().equalsIgnoreCase("") || io.loadSettings().getTeamNumber() == 0)
return;
int teamNumber = io.loadSettings().getTeamNumber();
// Allow this thread to access the internet
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
XSSFCellStyle blue = setCellStyle(BorderStyle.THIN, IndexedColors.CORNFLOWER_BLUE, IndexedColors.BLACK, false);
XSSFCellStyle red = setCellStyle(BorderStyle.THIN, IndexedColors.CORAL, IndexedColors.BLACK, false);
/*
* Create header row
*/
Row one = createRow(sheet, 0);
setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, true);
createCell(one, 0, "Match#");
setStyle(blue);
createCell(one, 1, "Team1");
createCell(one, 2, "Team2");
createCell(one, 3, "Team3");
setStyle(red);
createCell(one, 4, "Team4");
createCell(one, 5, "Team5");
createCell(one, 6, "Team6");
// Determine event year
Settings.disableAll();
Settings.GET_EVENT_MATCHES = true;
try {
Event tbaEvent = new TBA().getEvent(event.getKey());
for (Match m : tbaEvent.matches) {
if (m.doesMatchContainTeam(teamNumber) > 0) {
Row row = createRow(sheet);
setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, true);
createCell(row, 0, String.valueOf(m.match_number));
setStyle(blue);
createCell(row, 1, m.blueTeams[0].replace("frc", ""));
createCell(row, 2, m.blueTeams[1].replace("frc", ""));
createCell(row, 3, m.blueTeams[2].replace("frc", ""));
setStyle(red);
createCell(row, 4, m.redTeams[0].replace("frc", ""));
createCell(row, 5, m.redTeams[1].replace("frc", ""));
createCell(row, 6, m.redTeams[2].replace("frc", ""));
}
}
} catch (Exception e) {
Row r = createRow(sheet);
createCell(r, 0, "Failed to pull data from TheBlueAlliance.com.");
}
}
Aggregations