diff options
author | git-vdr <herrlado@gmail.com> | 2011-10-04 01:36:45 +0200 |
---|---|---|
committer | git-vdr <herrlado@gmail.com> | 2011-10-04 01:36:45 +0200 |
commit | 0c4bee99f65b76c7ac24a37cf339a868a969266f (patch) | |
tree | 84baaa84787c120329961473dee2d0c970e502c2 /vdrmanager/src | |
parent | 9d76c34ea607e8801d9165967a8e6e3493505215 (diff) | |
download | vdr-manager-0c4bee99f65b76c7ac24a37cf339a868a969266f.tar.gz vdr-manager-0c4bee99f65b76c7ac24a37cf339a868a969266f.tar.bz2 |
added caching
Diffstat (limited to 'vdrmanager/src')
-rw-r--r-- | vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java | 111 |
1 files changed, 103 insertions, 8 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java index c087358..5ec1a6a 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java @@ -1,33 +1,96 @@ package de.bjusystems.vdrmanager.utils.svdrp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.TreeMap; + import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Preferences; /** * Class for retrieving informations about the running program + * * @author bju - * + * */ -public class ChannelClient extends SvdrpClient<Channel> { +public class ChannelClient extends SvdrpClient<Channel> implements + SvdrpListener<Channel> { + + private static final ArrayList<String> channelGroups = new ArrayList<String>(); + + private static LinkedHashMap<String, ArrayList<Channel>> groupChannels = new LinkedHashMap<String, ArrayList<Channel>>(); + + private static TreeMap<String, ArrayList<Channel>> providerChannels = new TreeMap<String, ArrayList<Channel>>(); + + private static ArrayList<Channel> channels = new ArrayList<Channel>(); + + private static boolean inited = false; + + + public ChannelClient(boolean useCache){ + super(); + if(useCache == false){ + clearCache(); + } + addSvdrpListener(this); + } + + private void clearCache(){ + channelGroups.clear(); + groupChannels.clear(); + providerChannels.clear(); + channels.clear(); + inited = false; + } + + + public static ArrayList<String> getChannelGroups() { + return channelGroups; + } + + public static HashMap<String, ArrayList<Channel>> getGroupChannels() { + return groupChannels; + } + + public static TreeMap<String, ArrayList<Channel>> getProviderChannels() { + return providerChannels; + } + + public static ArrayList<Channel> getChannels() { + return channels; + } /** * Constructor - * @param host host - * @param port port - * @param ssl use ssl + * + * @param host + * host + * @param port + * port + * @param ssl + * use ssl */ public ChannelClient() { - super(); + this(true); + } /** * Starts the EPG request - * @param parameter parameter for lste + * + * @param parameter + * parameter for lste */ @Override public void run() throws SvdrpException { - runCommand("channels " + Preferences.getPreferences().getChannels()); + if (inited == true) { + informListener(SvdrpEvent.CACHE_HIT, null); + } else { + runCommand("channels " + Preferences.getPreferences().getChannels()); + } } @Override @@ -40,5 +103,37 @@ public class ChannelClient extends SvdrpClient<Channel> { return R.string.progress_channels_loading; } + private synchronized void initChannels(List<Channel> results) { + if(inited){ + return; + } + ArrayList<Channel> currentChannels = null; + for (Channel c : results) { + if (c.isGroupSeparator()) { + channelGroups.add(c.getName()); + currentChannels = new ArrayList<Channel>(); + groupChannels.put(c.getName(), currentChannels); + } else { + channels.add(c); + currentChannels.add(c); + String provider = c.getProvider(); + ArrayList<Channel> channels = providerChannels.get(provider); + if (channels == null) { + channels = new ArrayList<Channel>(); + providerChannels.put(provider, channels); + } + channels.add(c); + } + } + inited = true; + } + + public void svdrpEvent(SvdrpEvent event, Channel result) { + if(event != SvdrpEvent.FINISHED_SUCCESS){ + return; + } + initChannels(getResults()); + getResults().clear(); + } }
\ No newline at end of file |