ArrayList<ProgramMenuItem> nextAdditionalPrograms = new ArrayList<ProgramMenuItem>();
/*
* Search through all channels.
*/
Date currentDate = Date.getCurrentDate();
for (Channel channel : channels) {
ChannelDayProgram today = TvDataBase.getInstance().getDayProgram(currentDate, channel);
if (today != null && today.getProgramCount() > 0) {
final int programCount = today.getProgramCount();
for (int j = 0; j < programCount; j++) {
if (j == 0 && today.getProgramAt(j).getStartTime() > IOUtilities.getMinutesAfterMidnight()) {
ChannelDayProgram yesterday = TvDataBase.getInstance().getDayProgram(currentDate.addDays(-1), channel);
if (yesterday != null && yesterday.getProgramCount() > 0) {
Program p = yesterday.getProgramAt(yesterday.getProgramCount() - 1);
if (p.isOnAir()) {
addToNowRunning(p, programs, additional);
Program p1 = today.getProgramAt(0);
addToNext(p1, nextPrograms, nextAdditionalPrograms);
break;
}
}
}
Program p = today.getProgramAt(j);
if (p.isOnAir()) {
addToNowRunning(p, programs, additional);
Program nextProgram = null;
if (j < programCount - 1) {
nextProgram = today.getProgramAt(j + 1);
} else {
ChannelDayProgram tomorrow = TvDataBase.getInstance().getDayProgram(currentDate.addDays(1), channel);
if (tomorrow != null && tomorrow.getProgramCount() > 0) {
nextProgram = tomorrow.getProgramAt(0);
}
}
if (nextProgram != null) {