use of com.cpjd.roblu.models.RSettings 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.RSettings 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.RSettings in project Roblu by wdavies973.
the class RUICategory method onBindView.
@Override
protected void onBindView(View view) {
super.onBindView(view);
TextView titleView = view.findViewById(android.R.id.title);
RSettings settings = new IO(view.getContext()).loadSettings();
if (settings != null)
titleView.setTextColor(settings.getRui().getAccent());
}
Aggregations