mOnAirRowProgramsArr = null;
}
private void handleTimerEvent() {
checkAutomaticGotoNow();
Date date = Date.getCurrentDate();
if(mLastTimerMinutesAfterMidnight == -1) {
resetOnAirArrays();
mAutoDownloadTimer = RandomUtils.nextInt(24 * 60 - 10);
}
// Avoid a repaint 6 times a minute (Once a minute is enough)
try {
int minutesAfterMidnight = IOUtilities.getMinutesAfterMidnight();
boolean onAirChanged = false;
if (minutesAfterMidnight != mLastTimerMinutesAfterMidnight && (downloadingThread == null || !downloadingThread.isAlive())) {
mLastTimerMinutesAfterMidnight = minutesAfterMidnight;
Channel[] ch = ChannelList.getSubscribedChannels();
if(ch != null) {
/* If no date array is available we have to find
* the on air programs */
if(mChannelDateArr == null) {
onAirChanged = true;
fillOnAirArrays(ch);
}
else {
/* We have a date array and can test the programs */
for(int i = 0; i < mChannelDateArr.length; i++) {
if(mChannelDateArr[i] != null) {
ChannelDayProgram chProg = TvDataBase.getInstance().getDayProgram(mChannelDateArr[i],ch[i]);
if(chProg != null && chProg.getProgramCount() > 0 && mOnAirRowProgramsArr[i] != -1) {
if (mOnAirRowProgramsArr[i] >= chProg.getProgramCount()) {
fillOnAirArrays(ch);
mLog.warning("Reset of on-air-arrays");
}
Program p = chProg.getProgramAt(mOnAirRowProgramsArr[i]);
if(p.isOnAir()) {
p.validateMarking();
} else if(p.isExpired()) {
onAirChanged = true;
p.validateMarking();
int n = mOnAirRowProgramsArr[i]+1;
if(n < chProg.getProgramCount()) {
mOnAirRowProgramsArr[i] = n;
chProg.getProgramAt(mOnAirRowProgramsArr[i]).validateMarking();
}
else {
/* The last day program is expired so we have to
* look for the on air program on the next day */
mChannelDateArr[i] = mChannelDateArr[i].addDays(1);
chProg = TvDataBase.getInstance().getDayProgram(mChannelDateArr[i],ch[i]);
// The next day has no data
if(chProg == null || chProg.getProgramCount() < 1) {
mOnAirRowProgramsArr[i] = -1;
} else {
mOnAirRowProgramsArr[i] = 0;
chProg.getProgramAt(mOnAirRowProgramsArr[i]).validateMarking();
}
}
}
}
else if(mChannelDateArr[i].compareTo(Date.getCurrentDate()) < 0) {
/* If the date array for the channel contains a date
* earlier than today we have to use today instead */
mChannelDateArr[i] = Date.getCurrentDate();
onAirChanged = true;
chProg = TvDataBase.getInstance().getDayProgram(mChannelDateArr[i],ch[i]);
if(chProg != null && chProg.getProgramCount() > 0) {
mOnAirRowProgramsArr[i] = 0;
chProg.getProgramAt(mOnAirRowProgramsArr[i]).validateMarking();
}
}
}
}
}
}
}
if (onAirChanged) {
if(Settings.propTableLayout.getString().equals(Settings.LAYOUT_OPTIMIZED_COMPACT_TIME_BLOCK)) {
mProgramTableScrollPane.getProgramTable().updateLayout();
}
// update filtered view if the "on air" condition changed for any program
if(!getProgramFilter().equals(FilterManagerImpl.getInstance().getDefaultFilter())) {
setProgramFilter(getProgramFilter());
}
}
}catch(Exception e) {}
if (mPluginView != null) {
mPluginView.repaint();
}
if ((mLastAutoUpdateRun + Settings.propDataServiceAutoUpdateTime.getInt() * 60000L) <= System.currentTimeMillis() && !TvDataUpdater.getInstance().isDownloading()) {
runAutoUpdate();
}
if(Settings.propAutoDataDownloadEnabled.getBoolean() && (mAutoDownloadTimer < IOUtilities.getMinutesAfterMidnight() || !date.equals(mCurrentDay)) && mAutoDownloadTimer != -1 && (downloadingThread == null || !downloadingThread.isAlive())) {
TVBrowser.handleAutomaticDownload();
mAutoDownloadTimer = -1;
}
if (date.equals(mCurrentDay)) {
return;
}
if(mCurrentDay != null) {
if(mProgramTableModel.getDate().compareTo(Date.getCurrentDate().addDays(-1)) < 0) {