I have an array of cell[]
containing all classes for a student ID, each cell has two variables relevant to this context:
int day
and int startTime
.
I also have two given values for the currentDay
and currentTime
, both in the same format as cell's day and startTime
I want to make a loop that finds the cell element that contains the next class.
I've tried looping through the cell array and selecting the closest day that contains at least one class, with some success, and I imagine that I would need to make another array that contains all the classes for that day then do the same logic to them. I just can't figure out how.
public Cell getNextClass(int studentID, Context context){
DBHelper dbHelper = new DBHelper(context);
Cell[] cell = dbHelper.queryCellData(studentID);
Date currentTime = Calendar.getInstance().getTime();
int currentDay = getCurrentDay(currentTime.toString());
Log.d(TAG, "currentDay: " + currentDay);
DateFormat dateFormat = new SimpleDateFormat("hh a");
String formattedDate= dateFormat.format(currentTime);
int currentHour = getCurrentHour(formattedDate);
//TODO Find next class given currentDay and currentHour
Cell nextClass = cell[0];
for (int i = 0; i < cell.length; i++) {
if (cell[i].getDay() >= currentDay && cell[i].getDay() <= nextClass.getDay()){
//?????
}
}
return nextClass;
}
}
In this example, cell[0]
has one class on hour 12, and is displayed by default because the loop doesn't change anything. However at time of posting in NZ the values would be:
currentDay = 2
currentHour = 21
As shown in this screenshot of my timetable: i.imgur.com/X6HzR6y.png
The next class will be tomorrow, day 3, hour 8.