/** Generates the List of Programs */ private void generateList(Date date, int time) { // If Time > 24 try next Day if (time > 60 * 24) { date = date.addDays(1); time -= 60 * 24; } Channel[] channels = Plugin.getPluginManager().getSubscribedChannels(); if ((mChannels != null) && (mChannels.getSelectedIndex() > 0)) { FilterComponent component = FilterComponentList.getInstance() .getFilterComponentByName(mChannels.getSelectedItem().toString()); if (component instanceof ChannelFilterComponent) { channels = ((ChannelFilterComponent) component).getChannels(); } } for (Channel channel : channels) { Program prg = findProgram(date, time, channel, false); Program nprg = null; if (prg == null) { prg = findProgram(date.addDays(-1), time + 60 * 24, channel, false); } if (prg != null) { nprg = findNextProgram(prg); } else { Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(date, channel); if (it.hasNext()) { Program p = it.next(); if (p.getStartTime() > time && mCurrentFilter.accept(p)) { nprg = p; } else { nprg = findProgram(date, time + 60, channel, true); } } else { nprg = findProgram(date, time + 60, channel, true); } if (nprg == null) { it = Plugin.getPluginManager().getChannelDayProgram(date.addDays(1), channel); while (it.hasNext() && nprg == null) { Program p = it.next(); if (!p.isExpired() && mCurrentFilter.accept(p)) { nprg = p; } } } } mModel.updateRow(channel, prg, nprg); } }
/** * Finds a Program for a Date/time on a certain Channel * * @param date Date * @param time Time * @param channel Channel * @return added a Program */ private Program findProgram(Date date, int time, Channel channel, boolean next) { for (Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(date, channel); it.hasNext(); ) { Program program = it.next(); int start = program.getStartTime(); int ende = program.getStartTime() + program.getLength(); if (((!next && (start <= time) && (ende > time)) || (next && start > IOUtilities.getMinutesAfterMidnight())) && mCurrentFilter.accept(program)) { return program; } } return null; }
/** * Finds the program after the given Program * * @param prg Search Program after this * @return following Program */ private Program findNextProgram(Program prg) { Iterator<Program> it = Plugin.getPluginManager().getChannelDayProgram(prg.getDate(), prg.getChannel()); Program nprg = null; boolean last = false; while (it.hasNext()) { Program p = it.next(); if (prg.equals(p) && it.hasNext()) { while (it.hasNext()) { Program test = it.next(); if (!test.isExpired() && mCurrentFilter.accept(test)) { return test; } } last = true; } else if (prg.equals(p) && !it.hasNext()) { last = true; } } if (last) { it = Plugin.getPluginManager() .getChannelDayProgram(prg.getDate().addDays(1), prg.getChannel()); while (it.hasNext()) { Program p = it.next(); if (!p.isExpired() && mCurrentFilter.accept(p)) { return p; } } } return nprg; }