summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlado <herrlado@gmail.com>2012-05-02 01:01:25 +0200
committerlado <herrlado@gmail.com>2012-05-02 01:01:25 +0200
commit30e8c495ec552b0241f4c1dd460ad0d4a41dc9eb (patch)
treed79470e32cdea288d8dc2551c5d2f2655996f200
parente676c188de8e751468514c534018d3fc0de17ecd (diff)
downloadvdr-manager-30e8c495ec552b0241f4c1dd460ad0d4a41dc9eb.tar.gz
vdr-manager-30e8c495ec552b0241f4c1dd460ad0d4a41dc9eb.tar.bz2
switch channel
-rw-r--r--vdrmanager/res/values/strings.xml5
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java27
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java55
3 files changed, 87 insertions, 0 deletions
diff --git a/vdrmanager/res/values/strings.xml b/vdrmanager/res/values/strings.xml
index 8b537bb..652f0e8 100644
--- a/vdrmanager/res/values/strings.xml
+++ b/vdrmanager/res/values/strings.xml
@@ -289,6 +289,7 @@
<string name="progress_whatson_loading">Loading EPG…</string>
<string name="progress_timers_loading">Loading timers…</string>
<string name="progress_recordings_loading">Loading recordings…</string>
+ <string name="progress_switching">Switching…</string>
<string name="progress_channels_loading">Loading channels…</string>
<string name="progress_disconnect">Disconnecting…</string>
<string name="progress_wakeup_sending">Initiating wakeup request…</string>
@@ -334,4 +335,8 @@
<string name="timer_detail_title_vps">%1$s (VPS)</string>
+
+ <string name="channel_item_menu_switch">Switch to</string>
+ <string name="switching_success">Switched to %s</string>
+ <string name="switching_failed">Switching to %1$s failed: %2$s</string>
</resources> \ No newline at end of file
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
index 08a1956..f185932 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
@@ -14,6 +14,7 @@ import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
@@ -33,9 +34,12 @@ import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Preferences;
import de.bjusystems.vdrmanager.tasks.VoidAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
+import de.bjusystems.vdrmanager.utils.svdrp.SwitchChannelClient;
/**
* This class is used for showing what's current running on all channels
@@ -365,7 +369,30 @@ public class ChannelListActivity extends
case R.id.channel_item_menu_hide_permanent:
// TODO http://projects.vdr-developer.org/issues/722
break;
+
+ case R.id.channel_item_menu_switch:
+ final String name = channel.getName();
+ final SwitchChannelClient scc = new SwitchChannelClient(channel.getId());
+ SvdrpAsyncTask<String, SwitchChannelClient> task = new SvdrpAsyncTask<String, SwitchChannelClient>(scc);
+ task.addListener(new SvdrpAsyncListener<String>() {
+ public void svdrpEvent(SvdrpEvent event, String result) {
+ if(event == SvdrpEvent.FINISHED_SUCCESS){
+ say(getString(R.string.switching_success, name));
+ } else if(event == SvdrpEvent.CONNECT_ERROR || event == SvdrpEvent.FINISHED_ABNORMALY || event == SvdrpEvent.ABORTED || event == SvdrpEvent.ERROR || event == SvdrpEvent.CACHE_HIT){
+ say(getString(R.string.switching_failed, name, event.name()));
+ }
+
+ }
+
+ public void svdrpException(SvdrpException e) {
+ Log.w(TAG, e.getMessage(), e);
+ say(e.getMessage());
+ }
+ });
+ task.run();
}
+
+
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java
new file mode 100644
index 0000000..d9fd77a
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java
@@ -0,0 +1,55 @@
+package de.bjusystems.vdrmanager.utils.svdrp;
+
+import de.bjusystems.vdrmanager.R;
+
+
+/**
+ * Class for switching a channel by SETCHANNEL <NR|CHID>
+ *
+ * @author lado
+ *
+ */
+public class SwitchChannelClient extends SvdrpClient<String> {
+
+ private Integer nr;
+
+ private String chid;
+
+ public SwitchChannelClient(Integer nr){
+ this.nr = nr;
+ }
+
+ public SwitchChannelClient(String chid){
+ this.chid = chid;
+ }
+
+ /**
+ * Constructor
+ */
+ public SwitchChannelClient() {
+ super();
+ }
+
+ /**
+ * Starts the wakeup request
+ */
+ @Override
+ public void run() throws SvdrpException {
+ if(nr != null){
+ runCommand("SETCHANNEL " + String.valueOf(nr));
+ } else {
+ runCommand("SETCHANNEL " + chid);
+ }
+ }
+
+ @Override
+ public String parseAnswer(final String line) {
+ return line;
+ }
+
+ @Override
+ public int getProgressTextId() {
+ return R.string.progress_switching;
+ }
+
+} \ No newline at end of file