use of com.cpjd.roblu.ui.team.TeamViewer in project Roblu by wdavies973.
the class Match method changeMade.
/**
* This method is called when a change is made to a metric
* @param metric the modified metric
*/
@Override
public void changeMade(RMetric metric) {
/*
* Notify any calculation metrics that a change was made
*/
for (int i = 0; i < layout.getChildCount(); i++) {
CardView cv = (CardView) layout.getChildAt(i);
if (cv.getTag() != null && cv.getTag().toString().split(":")[0].equals("CALC")) {
// We've discovered a calculation metric, we have access to the ID, so acquire a new copy of the view
int ID = Integer.parseInt(cv.getTag().toString().split(":")[1]);
for (RMetric m : TeamViewer.team.getTabs().get(position).getMetrics()) {
if (m.getID() == ID) {
// Get the calculation
String value = m.getTitle() + "\nValue: " + ((RCalculation) m).getValue(TeamViewer.team.getTabs().get(position).getMetrics());
// Set the text
RelativeLayout rl = (RelativeLayout) cv.getChildAt(0);
TextView tv = (TextView) rl.getChildAt(0);
tv.setText(value);
break;
}
}
}
}
// set the metric as modified - this is a critical line, otherwise scouting data will get deleted
metric.setModified(true);
/*
* Check the team name and team number metrics to see if the action bar needs to be updated
*/
// since team name and team number are updated from the team model
boolean init = false;
// without the user's control, make sure not to update team's timestamp if it's only the team name or number metric
if (metric instanceof RTextfield) {
if (((RTextfield) metric).isOneLine() && ((RTextfield) metric).isNumericalOnly() && !((RTextfield) metric).getText().equals("")) {
TeamViewer.team.setNumber(Integer.parseInt(((RTextfield) metric).getText()));
((TeamViewer) getActivity()).setActionBarSubtitle("#" + TeamViewer.team.getNumber());
init = true;
}
if (((RTextfield) metric).isOneLine() && !((RTextfield) metric).isNumericalOnly() && !((RTextfield) metric).getText().equals("")) {
TeamViewer.team.setName(((RTextfield) metric).getText());
((TeamViewer) getActivity()).setActionBarTitle(TeamViewer.team.getName());
init = true;
}
}
if (!init) {
TeamViewer.team.setLastEdit(System.currentTimeMillis());
// Add local device to edit history list
if (event.isCloudEnabled()) {
LinkedHashMap<String, Long> edits = TeamViewer.team.getTabs().get(position).getEdits();
if (edits == null)
TeamViewer.team.getTabs().get(position).setEdits(new LinkedHashMap<String, Long>());
TeamViewer.team.getTabs().get(position).getEdits().put("me", System.currentTimeMillis());
}
}
// save the team
new IO(view.getContext()).saveTeam(event.getID(), TeamViewer.team);
}
Aggregations