Skip to content

Commit 7b8d2e6

Browse files
authored
Merge pull request #283 from ajayyy/improvements
Changes For Worlds
2 parents 88c0578 + fc075e9 commit 7b8d2e6

File tree

9 files changed

+349
-232
lines changed

9 files changed

+349
-232
lines changed

app/src/main/java/ca/lakeeffect/scoutingapp/FieldUIPage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ public String[] getData() {
264264
int[] farRocket = new int[4];
265265
int[] closeRocket = new int[4];
266266
int[] fullRocket = new int[4];
267+
//the robot scored into any position
268+
int[] everything = new int[4];
267269

268270
int[] cargoShipLocations = {12, 13, 14, 15, 16, 17, 18};
269271
int[] sideCargoShipLocations = {12, 13, 14, 16, 17, 18};
@@ -333,9 +335,16 @@ public String[] getData() {
333335
if (MainActivity.arrayContains(closeRocketLocations, location)) {
334336
closeRocket[id]++;
335337
}
338+
339+
//totals for everything
340+
everything[id]++;
336341
}
337342

338343
for (int i = 0; i < labelActions.length; i++) {
344+
//overall data
345+
labels.append(fieldPeriod + "Total " + labelActions[i] + ",");
346+
data.append(everything[i] + ",");
347+
339348
//most important data
340349
labels.append(fieldPeriod + "Full Cargo Ship " + labelActions[i] + ",");
341350
data.append(cargoShip[i] + ",");

app/src/main/java/ca/lakeeffect/scoutingapp/ListeningActitivty.java

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
import android.content.Context;
55
import android.content.SharedPreferences;
66
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import android.widget.AdapterView;
79
import android.widget.ArrayAdapter;
10+
import android.widget.LinearLayout;
11+
import android.widget.ScrollView;
812
import android.widget.Spinner;
913
import android.widget.TextView;
1014

1115
import java.util.ArrayList;
16+
import java.util.Calendar;
1217

1318
//contains the base of what an activity using ConnectionThread
1419
// and ListenerThread should have
@@ -157,4 +162,132 @@ public int getLocationInSharedMessages(String message) {
157162
}
158163
return -1;
159164
}
165+
166+
public void openScheduleViewer() {
167+
ScrollView scheduleViewer = new ScrollView(this);
168+
169+
final LinearLayout scheduleViewerLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.schedule_viewer, null);
170+
171+
//figure out when the schedule was last updated
172+
TextView lastUpdated = scheduleViewerLayout.findViewById(R.id.scheduleViewerLastUpdate);
173+
String lastUpdatedMessage = "";
174+
SharedPreferences lastUpdatedPrefs = getSharedPreferences("lastScheduleUpdate", MODE_PRIVATE);
175+
int year = lastUpdatedPrefs.getInt("year", -1);
176+
int month = lastUpdatedPrefs.getInt("month", -1);
177+
int day = lastUpdatedPrefs.getInt("day", -1);
178+
int hour = lastUpdatedPrefs.getInt("hour", -1);
179+
int minute = lastUpdatedPrefs.getInt("minute", -1);
180+
181+
//get current dates to compare with
182+
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
183+
int currentMonth = Calendar.getInstance().get(Calendar.MONTH);
184+
int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
185+
int currentHour = Calendar.getInstance().get(Calendar.HOUR);
186+
int currentMinute = Calendar.getInstance().get(Calendar.MINUTE);
187+
188+
if (year == currentYear) {
189+
if (month == currentMonth) {
190+
if (day == currentDay) {
191+
if (hour == currentHour) {
192+
lastUpdatedMessage = (currentMinute - minute) + " minutes ago";
193+
} else {
194+
lastUpdatedMessage = (currentHour - hour) + " hours ago";
195+
}
196+
} else {
197+
lastUpdatedMessage = (currentDay - day) + " days ago";
198+
}
199+
} else {
200+
lastUpdatedMessage = (currentMonth - month) + " months ago";
201+
}
202+
} else {
203+
lastUpdatedMessage = (currentYear - year) + " years ago";
204+
}
205+
if (year == -1) {
206+
lastUpdatedMessage = "Never";
207+
}
208+
209+
//set the message onto the label
210+
lastUpdated.setText("Last Updated " + lastUpdatedMessage);
211+
212+
userIDSpinner = scheduleViewerLayout.findViewById(R.id.scheduleViewerUserIDSpinner);
213+
updateUserIDSpinner();
214+
215+
SharedPreferences prefs = getSharedPreferences("userID", MODE_PRIVATE);
216+
int userID = prefs.getInt("userID", -1);
217+
218+
if (userID != -1) {
219+
//set the spinner to this value
220+
userIDSpinner.setSelection(userID + 1);
221+
222+
//update the schedule view
223+
updateScheduleDialog(scheduleViewerLayout, userID);
224+
}
225+
226+
//add listener to the spinner
227+
userIDSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
228+
@Override
229+
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
230+
if (position > 0) {
231+
//if it is not on the "Choose one" selection
232+
updateScheduleDialog(scheduleViewerLayout, position - 1);
233+
}
234+
}
235+
@Override
236+
public void onNothingSelected(AdapterView<?> parent) {
237+
238+
}
239+
});
240+
241+
//add the layout to the scroll view (the entire view)
242+
scheduleViewer.addView(scheduleViewerLayout);
243+
244+
//create the dialog box
245+
new android.app.AlertDialog.Builder(this)
246+
.setTitle("View Schedule")
247+
.setView(scheduleViewer)
248+
.setPositiveButton("Dismiss", null)
249+
.show();
250+
}
251+
252+
public void updateScheduleDialog(View view, int userID) {
253+
TextView scheduleTextView = view.findViewById(R.id.scheduleViewerTextView);
254+
255+
//show all the times the scout is switching on or off
256+
StringBuilder scheduleMessage = new StringBuilder();
257+
258+
//the current match number being checked for
259+
int matchNumber = 0;
260+
261+
while (matchNumber < schedules.get(userID).robots.size()) {
262+
if (!schedules.get(userID).isOff(matchNumber)) {
263+
//add the next match off
264+
int nextMatchOff = getNextMatchOff(matchNumber, userID);
265+
266+
if (nextMatchOff == -1) {
267+
//no more switches on or off, this user is done for the day
268+
break;
269+
}
270+
271+
scheduleMessage.append("Off at match " + nextMatchOff + "\n\n");
272+
273+
//set the match number to check to the match number reached
274+
matchNumber = nextMatchOff;
275+
} else {
276+
//add the next match on
277+
int nextMatchOn = getNextMatchOn(matchNumber, userID);
278+
279+
if (nextMatchOn == -1) {
280+
//no more switches on or off, this user is done for the day
281+
break;
282+
}
283+
284+
scheduleMessage.append("On at match " + nextMatchOn + "\n\n");
285+
286+
//set the match number to check to the match number reached
287+
matchNumber = nextMatchOn;
288+
}
289+
}
290+
291+
scheduleTextView.setText(scheduleMessage.toString());
292+
}
160293
}

0 commit comments

Comments
 (0)