removeAllGroups();
TvDataServiceProxy[] services = TvDataServiceProxyManager.getInstance().getDataServices();
ProgressMonitorGroup progressGroup = new ProgressMonitorGroup(monitor, 30);
ProgressMonitor curMon = progressGroup.getNextProgressMonitor(10);
curMon.setMaximum(services.length);
for (int i = 0; i < services.length; i++) {
ChannelGroup[] groupArr = null;
if (services[i].supportsDynamicChannelGroups()) {
try {
groupArr = services[i].checkForAvailableGroups(null);
} catch (TvBrowserException e) {
ErrorHandler.handle(e);
}
} else {
groupArr = services[i].getAvailableGroups();
}
if (groupArr != null) {
for (ChannelGroup aGroupArr : groupArr) {
addGroup(services[i], aGroupArr);
}
}
curMon.setValue(i + 1);
}
curMon = progressGroup.getNextProgressMonitor(20);
curMon.setMaximum(services.length);
int channelCount = 0;
/*
* Call 'checkForAvailableChannels' for all groups to fetch the most recent
* channel lists
*/
TvDataServiceProxy[] proxies = TvDataServiceProxyManager.getInstance().getDataServices();
for (TvDataServiceProxy proxy : proxies) {
if (proxy.supportsDynamicChannelList()) {
ChannelGroup[] groups = proxy.getAvailableGroups();
int max = groups.length;
curMon.setMaximum(max);
for (int j = 0; j < max; j++) {
try {
final String channelCountString = Integer.toString(channelCount);
final ProgressMonitor finalMonitor = curMon;
// use a proxy progress monitor to be able to add the number of
// channels found so far
Channel[] channels = proxy.checkForAvailableChannels(groups[j], new ProgressMonitor() {
@Override
public void setValue(int value) {
finalMonitor.setValue(value);
}
@Override
public void setMessage(String msg) {
finalMonitor.setMessage(msg + " "
+ mLocalizer.msg("channelCount", "(Found {0} channels)", channelCountString));
}
@Override
public void setMaximum(int maximum) {
finalMonitor.setMaximum(maximum);
}
});
if (channels != null) {
channelCount += channels.length;
}