use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class TeamsView method onActivityResult.
/**
* Receives data from activities originally launched from this class
* @param requestCode the request code the original activity was launched with
* @param resultCode the result code return from the launched activity
* @param data any payload data received from the launched activity
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Constants.CUSTOM_SORT_CONFIRMED) {
// the user selected a custom sort token, retrieve it and sort
lastCustomSortToken = data.getStringExtra("sortToken");
lastFilter = SORT_TYPE.CUSTOM_SORT;
executeLoadTeamsTask(lastFilter, false);
ignoreOnResumeOnce = true;
} else if (Constants.MASTER_FORM == requestCode && resultCode == Constants.FORM_CONFIRMED) {
// the user edited the master form, retrieve it and save it
Bundle b = data.getExtras();
if (b != null) {
settings.setMaster((RForm) b.getSerializable("form"));
}
io.saveSettings(settings);
} else /*
* This must occur BEFORE the straight up NEW_EVENT_CREATED return.
* This will be called after the user does a TBA sync
*/
if (requestCode == Constants.EVENT_SETTINGS_REQUEST && resultCode == Constants.NEW_EVENT_CREATED) {
executeLoadTeamsTask(lastFilter, true);
} else if (resultCode == Constants.NEW_EVENT_CREATED) {
// The user created an event, let's get the ID and select it
Bundle d = data.getExtras();
eventDrawerManager.loadEventsToDrawer();
eventDrawerManager.selectEvent(d != null ? d.getInt("eventID") : 0);
} else if (resultCode == Constants.MY_MATCHES_EXITED) {
executeLoadTeamsTask(lastFilter, true);
} else if (resultCode == Constants.CUSTOM_SORT_CANCELLED) {
// user exited custom sort, don't make the button in the filter dialog still display custom sort
lastFilter = settings.getLastFilter();
} else if (resultCode == Constants.TEAM_EDITED) {
// the user edited a team, let's toss it in the teams array and reload it also
if (eventDrawerManager.getEvent() == null)
return;
RTeam temp = io.loadTeam(eventDrawerManager.getEvent().getID(), data.getIntExtra("teamID", 0));
// Reload the teams array
for (int i = 0; i < teams.size(); i++) {
if (teams.get(i).getID() == temp.getID()) {
teams.set(i, temp);
break;
}
}
// Reload the edited team into the adapter
adapter.reAdd(temp);
if (lastQuery != null && !lastQuery.equals(""))
executeLoadTeamsTask(SORT_TYPE.SEARCH, false);
else
executeLoadTeamsTask(lastFilter, false);
ignoreOnResumeOnce = true;
} else if (resultCode == Constants.EVENT_SETTINGS_CHANGED) {
// user edited the event
int eventID = data.getIntExtra("eventID", 0);
eventDrawerManager.loadEventsToDrawer();
eventDrawerManager.selectEvent(eventID);
if (getSupportActionBar() != null)
getSupportActionBar().setSubtitle(eventDrawerManager.getEvent().getName());
executeLoadTeamsTask(lastFilter, true);
} else if (resultCode == Constants.SETTINGS_CHANGED) {
// user changed application settings (refresh UI to make sure it matches a possible RUI change)
// reload settings
settings = new IO(getApplicationContext()).loadSettings();
eventDrawerManager.loadEventsToDrawer();
if (eventDrawerManager.getEvent() != null)
eventDrawerManager.selectEvent(eventDrawerManager.getEvent().getID());
// new UIHandler(this, toolbar).update();
// eventDrawerManager = new EventDrawerManager(this, toolbar, this);
}
}
use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class CustomSort method onCreate.
@Override
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_customsort);
/*
* Load the form and remove the team NAME and NUMBER metrics (since the user can sort by
* this already without using CustomSort). Good news is that we know the form will ALWAYS
* keep the team NAME and NUMBER as ID 0 and 1 respectively.
*/
RForm form = new IO(getApplicationContext()).loadForm(getIntent().getIntExtra("eventID", 0));
for (int i = 0; i < form.getPit().size(); i++) {
if (form.getPit().get(i).getID() == 0 || form.getPit().get(i).getID() == 1 || form.getPit().get(i) instanceof RDivider || form.getPit().get(i) instanceof RFieldDiagram) {
form.getPit().remove(i);
i--;
}
}
// Remove dividers - they are useless for sorting
for (int i = 0; i < form.getMatch().size(); i++) {
if (form.getMatch().get(i) instanceof RDivider || form.getMatch().get(i) instanceof RFieldDiagram) {
form.getMatch().remove(i);
i--;
}
}
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle("Custom sort");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
// Setup tabs
TabLayout tabLayout = findViewById(R.id.tab_layout);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setBackgroundColor(new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
// Setup the adapter - the back-end to the UI (manages all the MetricFragments)
MetricSortAdapter adapter = new MetricSortAdapter(getSupportFragmentManager(), form, getIntent().getIntExtra("eventID", 0));
ViewPager pager = findViewById(R.id.pager);
pager.addOnPageChangeListener(this);
pager.setAdapter(adapter);
tabLayout.setupWithViewPager(pager);
// Sync UI with user preferences
new UIHandler(this, toolbar).update();
}
use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class FormViewer method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_form);
/*
* Load dependencies
*/
/*
Stores the user's UI preferences
*/
RUI rui = new IO(getApplicationContext()).loadSettings().getRui();
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Form editor");
if (getIntent().getBooleanExtra("master", false))
getSupportActionBar().setSubtitle("Master form");
}
// Bottom bar - selector that lets the user switch between PIT and MATCH forms
BottomBar bBar = findViewById(R.id.bottomBar);
bBar.setOnTabSelectListener(this);
BottomBarTab tab = bBar.getTabAtPosition(0);
BottomBarTab tab2 = bBar.getTabAtPosition(1);
tab.setBarColorWhenSelected(rui.getPrimaryColor());
tab2.setBarColorWhenSelected(rui.getPrimaryColor());
bBar.selectTabAtPosition(0);
// Add the "New metric" button
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(this);
// Recycler view setup
RecyclerView rv = findViewById(R.id.movie_recycler_view);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
rv.setLayoutManager(linearLayoutManager);
((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
metricsAdapter = new FormRecyclerAdapter(this, this);
rv.setAdapter(metricsAdapter);
// Gesture helper
ItemTouchHelper.Callback callback = new FormRecyclerTouchHelper(metricsAdapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(rv);
/*
* Check to see if we received a form from a different class or
* if we need to create a new one
*/
if (getIntent().getSerializableExtra("form") != null) {
form = (RForm) getIntent().getSerializableExtra("form");
} else {
RTextfield name = new RTextfield(0, "Team name", false, true, "");
RTextfield number = new RTextfield(1, "Team number", true, true, "");
ArrayList<RMetric> pit = new ArrayList<>();
pit.add(name);
pit.add(number);
form = new RForm(pit, new ArrayList<RMetric>());
}
loadViews(true, 0);
new UIHandler(this, toolbar, fab).update();
}
use of com.cpjd.roblu.models.RForm in project Roblu by wdavies973.
the class TeamViewer method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_team_viewer);
// load the checkout that the user requested
int teamID = getIntent().getIntExtra("teamID", 0);
event = new IO(getApplicationContext()).loadEvent(getIntent().getIntExtra("eventID", 0));
team = new IO(getApplicationContext()).loadTeam(event.getID(), teamID);
/*
Flag that determines if any of this team information should be editable. Team information
should be read only if it's loaded from the "checkouts" list
*/
editable = getIntent().getBooleanExtra("editable", true);
/*
* Optional parameter for choosing a page to go to
*/
String requestedMatch = getIntent().getStringExtra("match");
if (requestedMatch != null) {
for (int i = 0; i < team.getTabs().size(); i++) {
if (team.getTabs().get(i).getTitle().equalsIgnoreCase(requestedMatch)) {
team.setPage(i + 1);
break;
}
}
}
/*
* What's the RForm reference for? It's used for verifying that a local checkout's form is matched with the Roblu Master form.
* However, with update 4.0.0, we're not actually going to force a sync on the client if a form isn't available. Instead, all
* incoming Checkouts will be re-verified by Roblu Master, so if the form can't be loaded here, no biggy.
*/
RForm form = new IO(getApplicationContext()).loadForm(event.getID());
if (form == null)
Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), this, "Form could not by synced with server. Local form may contain discrepancies.", true, 0);
else {
// verify the form
team.verify(form);
if (editable)
new IO(this).saveTeam(event.getID(), team);
// else Utils.showSnackbar(findViewById(R.id.teams_viewer_layout), getApplicationContext(), "Read only mode is enabled", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
}
/*
* Setup UI
*/
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
rui = new IO(getApplicationContext()).loadSettings().getRui();
tabLayout = findViewById(R.id.tab_layout);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
getSupportActionBar().setTitle(team.getName());
getSupportActionBar().setSubtitle("#" + String.valueOf(team.getNumber()));
tabAdapter = new TeamTabAdapter(getSupportFragmentManager(), event, form, getApplicationContext(), editable);
pager = findViewById(R.id.pager);
pager.addOnPageChangeListener(this);
pager.setAdapter(tabAdapter);
pager.setCurrentItem(team.getPage());
onPageSelected(team.getPage());
tabLayout.setupWithViewPager(pager);
tabLayout.setBackgroundColor(rui.getPrimaryColor());
tabLayout.setSelectedTabIndicatorColor(rui.getAccent());
tabLayout.setTabTextColors(RUI.darker(rui.getText(), 0.95f), rui.getText());
new UIHandler(this, toolbar).update();
if (team.getPage() > 1)
onPageSelected(team.getPage());
/*
* Attach to background service
*/
serviceFilter = new IntentFilter();
serviceFilter.addAction(Constants.SERVICE_ID);
}
use of com.cpjd.roblu.models.RForm 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);
}
}
}
}
}
}
Aggregations