summaryrefslogtreecommitdiff
path: root/vdrmanager/src/de
diff options
context:
space:
mode:
authorlado <herrlado@gmail.com>2011-10-20 14:39:34 +0200
committerlado <herrlado@gmail.com>2011-10-20 14:39:34 +0200
commit3b452963b56e2d50fc03a3a66cabd973b4789665 (patch)
tree5975193a555765152601f1d1a6c3760fe2f002f4 /vdrmanager/src/de
parent437f9d29198fd7160ef7ed23eb782a5bc4a54da0 (diff)
parent0342f25d24a2a2534c26e7588aac6eba00d0950a (diff)
downloadvdr-manager-3b452963b56e2d50fc03a3a66cabd973b4789665.tar.gz
vdr-manager-3b452963b56e2d50fc03a3a66cabd973b4789665.tar.bz2
Merge branch 'master' of ssh://projects.vdr-developer.org/vdr-manager
Diffstat (limited to 'vdrmanager/src/de')
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java24
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/BaseEvent.java25
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java3
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/EventListItem.java87
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java1
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java22
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java (renamed from vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEpgListActivity.java)213
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java349
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java26
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java29
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java190
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java29
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java202
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/SimpleGestureFilter.java3
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java86
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java259
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java19
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java3
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java23
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java3
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java27
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java19
24 files changed, 919 insertions, 727 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java
index a714845..6f19f36 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java
@@ -8,6 +8,7 @@ import android.app.Application;
import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Epg;
import de.bjusystems.vdrmanager.data.EpgSearchParams;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.Timer;
public class VdrManagerApp extends Application {
@@ -19,16 +20,17 @@ public class VdrManagerApp extends Application {
}
private EpgListState epgListState;
- private Epg currentEvent;
+ private Event currentEvent;
private Timer currentTimer;
private Channel currentChannel;
- private List<Epg> currentEpgList = new ArrayList<Epg>();
- public List<Epg> getCurrentEpgList() {
+ private List<Event> currentEpgList = new ArrayList<Event>();
+
+ public List<Event> getCurrentEpgList() {
return currentEpgList;
}
- public void setCurrentEpgList(List<Epg> currentEpgList) {
+ public void setCurrentEpgList(List<Event> currentEpgList) {
this.currentEpgList = currentEpgList;
}
@@ -51,18 +53,18 @@ public class VdrManagerApp extends Application {
this.epgListState = EpgListState.EPG_TIME;
}
- public Epg getCurrentEvent() {
+ public Event getCurrentEvent() {
return currentEvent;
}
- public void setCurrentEvent(final Epg currentEvent) {
+ public void setCurrentEvent(final Event currentEvent) {
clear();
this.currentEvent = currentEvent;
- if (currentEvent.getTimer() != null) {
- this.currentTimer = currentEvent.getTimer();
- } else {
- this.currentTimer = new Timer(currentEvent);
- }
+ //if (currentEvent.getTimer() != null) {
+ //this.currentTimer = currentEvent.getTimer();
+ //} else {
+ //this.currentTimer = new Timer(currentEvent);
+ //}
}
public Timer getCurrentTimer() {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/BaseEvent.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/BaseEvent.java
index 43789ca..b044b1a 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/BaseEvent.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/BaseEvent.java
@@ -6,7 +6,6 @@ import android.text.TextUtils;
public abstract class BaseEvent implements Event {
- protected Event event;
protected String channelNumber;
protected String channelName;
protected String title;
@@ -14,15 +13,19 @@ public abstract class BaseEvent implements Event {
protected String description;
protected Date start;
protected Date stop;
-
- public Event getEvent() {
- return event;
+
+ public BaseEvent(){
+
}
- public void setEvent(Event event) {
- this.event = event;
+ public Timer createTimer() {
+ return new Timer(this);
}
-
+
+ public TimerState getTimerState() {
+ return TimerState.None;
+ }
+
public void setChannelNumber(String channelNumber) {
this.channelNumber = channelNumber;
}
@@ -52,7 +55,13 @@ public abstract class BaseEvent implements Event {
}
public BaseEvent(Event event) {
- this.event = event;
+ channelNumber = event.getChannelNumber();
+ channelName = event.getChannelName();
+ title = event.getTitle();
+ shortText = event.getShortText();
+ description = event.getDescription();
+ start = event.getStart();
+ stop = event.getStop();
}
public String getChannelNumber() {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
index d9d07b0..079fcf0 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
@@ -11,10 +11,7 @@ public class Epg extends BaseEvent {
private Timer timer;
public Epg(final String line) {
- super(null);
-
final String[] words = line.split(":");
-
channelNumber = words[0].substring(1);
channelName = words[1];
start = new Date(Long.parseLong(words[2])*1000);
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
index 8bf9270..62805a2 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
@@ -20,5 +20,5 @@ public interface Event {
String getShortText();
Date getStart();
Date getStop();
- TimerState getTimerState();
+// TimerState getTimerState();
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/EventListItem.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/EventListItem.java
index 18829f5..995a55b 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/EventListItem.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/EventListItem.java
@@ -1,21 +1,47 @@
package de.bjusystems.vdrmanager.data;
-import java.util.Date;
-
import de.bjusystems.vdrmanager.gui.Utils;
+/**
+ * @author lado
+ *
+ * TODO auf Event Interface umstellen und die Aufrufen an event delegieren. Das hier ist nicht gut.
+ */
public class EventListItem extends BaseEvent {
+
+ Event event;
+
+ public Event getEvent() {
+ return event;
+ }
+
+ public void setEvent(Event event) {
+ this.event = event;
+ }
+
private final Recording rec;
private final Timer timer;
private final Epg epg;
private final String header;
+//
+// public EventListItem(final Event event){
+// if(event instanceof Recording){
+// this((Recording)event);
+// } else if (event instanceof Timer){
+// this((Timer)event);
+// } else {
+// this((Epg)event);
+// }
+// throw new IllegalArgumentException("Uknown event type " + event);
+// }
public EventListItem(final Recording rec) {
super(rec);
+ event = rec;
this.header = null;
this.rec = rec;
this.epg = null;
@@ -24,6 +50,7 @@ public class EventListItem extends BaseEvent {
public EventListItem(final Timer timer) {
super(timer);
+ event = timer;
this.header = null;
this.timer = timer;
this.epg = null;
@@ -32,14 +59,22 @@ public class EventListItem extends BaseEvent {
public EventListItem(final Epg epg) {
super(epg);
+ event = epg;
this.header = null;
this.timer = null;
this.epg = epg;
this.rec = null;
}
+
+ @Override
+ public TimerState getTimerState() {
+ if(epg != null){
+ return epg.getTimerState();
+ }
+ return super.getTimerState();
+ }
public EventListItem(final String header) {
- super(null);
this.header = header;
this.timer = null;
this.epg = null;
@@ -54,38 +89,11 @@ public class EventListItem extends BaseEvent {
return timer != null;
}
- public Date getStart() {
- return event != null ? event.getStart() : null;
- }
-
- public Date getStop() {
- return event != null ? event.getStop() : null;
- }
-
- public String getChannelNumber() {
- return event != null ? event.getChannelNumber() : null;
- }
-
- public String getChannelName() {
- return event != null ? event.getChannelName() : null;
- }
-
- public String getTitle() {
- return event != null ? event.getTitle() : null;
- }
-
- public String getDescription() {
- return event != null ? event.getDescription() : null;
- }
public String getHeader() {
return header;
}
- public TimerState getTimerState() {
- return event != null ? event.getTimerState() : TimerState.None;
- }
-
public Timer getTimer() {
return timer;
}
@@ -94,12 +102,12 @@ public class EventListItem extends BaseEvent {
return epg;
}
- public Event getEvent() {
- return event;
- }
-
+// public Event getEvent() {
+// return event;
+// }
+//
public boolean isLive(){
- return Utils.isLive(event);
+ return Utils.isLive(this);
}
@Override
@@ -108,16 +116,13 @@ public class EventListItem extends BaseEvent {
return "Header: " + header;
}
- final EventFormatter formatter = new EventFormatter(event);
+ final EventFormatter formatter = new EventFormatter(this);
final StringBuilder text = new StringBuilder();
text.append(isTimer() ? "Timer: " : "Event: ");
- text.append("Channel: ").append(event.getChannelNumber());
- text.append(" (").append(event.getChannelName()).append("), ");
+ text.append("Channel: ").append(getChannelNumber());
+ text.append(" (").append(getChannelName()).append("), ");
text.append("Zeit: ").append(formatter.getDate()).append(" ").append(formatter.getTime());
return text.toString();
}
- public String getShortText() {
- return event != null ? event.getShortText() : null;
- }
} \ No newline at end of file
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java
index f9eeecb..c0481f7 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Recording.java
@@ -6,7 +6,6 @@ import java.util.Date;
public class Recording extends BaseEvent{
public Recording(String line) {
- super(null);
final String[] words = line.split(":");
start = new Date(Long.parseLong(words[0])*1000);
stop = new Date(Long.parseLong(words[1]) * 1000);
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
index 20a0975..d357d5a 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
@@ -4,6 +4,8 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
+
/**
* Class for timer data
* @author bju
@@ -27,7 +29,6 @@ public class Timer extends BaseEvent {
* @param channels list of channels
*/
public Timer(final String timerData) {
- super(null);
final String[] values = timerData.split(":");
@@ -49,12 +50,19 @@ public class Timer extends BaseEvent {
// title and description
this.title = values[8];
+
this.description = values.length > 9 ? values[9] : "";
+
+ this.shortText = values.length > 10 ? values[10] : "";
+
+ if(values.length > 11){
+ this.description = values[11];
+ }
+
+
}
- public Timer(final Epg event) {
- super(event);
-
+ public Timer(final Event event) {
final Preferences prefs = Preferences.getPreferences();
this.number = 0;
@@ -71,7 +79,7 @@ public class Timer extends BaseEvent {
this.description = event.getDescription();
}
- public String toCommandLine() {
+ public String toCommandLine(TimerOperation op) {
final StringBuilder line = new StringBuilder();
@@ -90,7 +98,9 @@ public class Timer extends BaseEvent {
line.append(priority).append(":");
line.append(lifetime).append(":");
line.append(title).append(":");
- line.append(description);
+ if(op != TimerOperation.DELETE){
+ line.append(description);
+ }
return line.toString();
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java
index d298de1..09ee612 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEpgListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java
@@ -1,8 +1,12 @@
package de.bjusystems.vdrmanager.gui;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Date;
+import java.util.List;
-import android.app.Activity;
+import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -15,28 +19,28 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
+import android.widget.Toast;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.Intents;
import de.bjusystems.vdrmanager.data.Channel;
-import de.bjusystems.vdrmanager.data.Epg;
-import de.bjusystems.vdrmanager.data.EventFormatter;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.gui.SimpleGestureFilter.SimpleGestureListener;
-import de.bjusystems.vdrmanager.tasks.DeleteTimerTask;
-import de.bjusystems.vdrmanager.tasks.ToggleTimerTask;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
/**
* @author lado
*
*/
-public abstract class BaseEpgListActivity extends BaseActivity implements
+public abstract class BaseEventListActivity<T extends Event> extends
+ BaseActivity implements OnItemClickListener,SvdrpAsyncListener<T>,
SimpleGestureListener {
- private static final int REQUEST_CODE_TIMED_EDIT = 41;
-
private SimpleGestureFilter detector;
protected EpgClient epgClient;
@@ -57,6 +61,9 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
abstract protected int getWindowTitle();
+ protected List<Event> results = new ArrayList<Event>();
+
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -72,17 +79,7 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
.getParcelableExtra(Intents.CURRENT_CHANNEL);
}
- protected void deleteTimer(final EventListItem item) {
-
- final DeleteTimerTask task = new DeleteTimerTask(this, item.getEpg()
- .getTimer()) {
- @Override
- public void finished() {
- refresh();
- }
- };
- task.start();
- }
+
/*
* (non-Javadoc)
@@ -104,6 +101,7 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
}
+
/*
* (non-Javadoc)
*
@@ -116,27 +114,11 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
.getMenuInfo();
final EventListItem event = adapter.getItem(info.position);
+
switch (item.getItemId()) {
- case R.id.epg_item_menu_timer_add:
- case R.id.epg_item_menu_timer_modify: {
- prepareTimer(event);
- final Intent intent = new Intent();
- intent.setClass(this, TimerDetailsActivity.class);
- startActivityForResult(intent, REQUEST_CODE_TIMED_EDIT);
- break;
- }
- case R.id.epg_item_menu_timer_delete: {
- deleteTimer(event);
- break;
- }
- case R.id.epg_item_menu_timer_toggle: {
- toggleTimer(event);
- break;
- }
case R.id.epg_item_menu_live_tv: {
- Utils.stream(this, event.getEvent());
+ Utils.stream(this, event);
break;
-
}
}
@@ -156,7 +138,7 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
switch (item.getItemId()) {
case R.id.epg_menu_search:
- //startSearchManager();
+ // startSearchManager();
super.onSearchRequested();
break;
case R.id.epg_menu_times:
@@ -179,62 +161,18 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
final ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
- if (v.getId() == R.id.whatson_list) {
- final MenuInflater inflater = getMenuInflater();
+ //if (v.getId() == R.id.whatson_list) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
// set menu title
final EventListItem item = adapter.getItem(info.position);
- final EventFormatter formatter = new EventFormatter(item);
- menu.setHeaderTitle(formatter.getTitle());
-
- inflater.inflate(R.menu.epg_list_item_menu, menu);
-
- // remove unneeded menu items
- if (item.getEpg().getTimer() != null) {
- menu.findItem(R.id.epg_item_menu_timer_add).setVisible(false);
- menu.findItem(R.id.epg_item_menu_timer_modify).setVisible(true);
- menu.findItem(R.id.epg_item_menu_timer_delete).setVisible(true);
- final MenuItem enableMenuItem = menu
- .findItem(R.id.epg_item_menu_timer_toggle);
- enableMenuItem.setVisible(true);
- enableMenuItem
- .setTitle(item.getEpg().getTimer().isEnabled() ? R.string.epg_item_menu_timer_disable
- : R.string.epg_item_menu_timer_enable);
- }
-
- if (item.isLive()) {
+
+ if (item.isLive()) {
menu.findItem(R.id.epg_item_menu_live_tv).setVisible(true);
}
- }
-
- }
+ //}
- protected void toggleTimer(final EventListItem item) {
- final ToggleTimerTask task = new ToggleTimerTask(this, item.getEpg()
- .getTimer()) {
- @Override
- public void finished() {
- refresh();
- }
- };
- task.start();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see android.app.Activity#onActivityResult(int, int,
- * android.content.Intent)
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == REQUEST_CODE_TIMED_EDIT) {
- if (resultCode == Activity.RESULT_OK) {
- refresh();
- }
- }
}
/**
@@ -279,47 +217,73 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
}
}
- public void svdrpEvent(final SvdrpEvent event, final Epg result) {
+ public void svdrpEvent(final SvdrpEvent event, final T result) {
if (progress != null) {
progress.svdrpEvent(event);
}
switch (event) {
+ case ERROR:
+ Toast.makeText(this, R.string.epg_client_errors, Toast.LENGTH_SHORT)
+ .show();
+ dismiss(progress);
+ break;
case CONNECTING:
break;
+ case CONNECTED:
+ results.clear();
+ break;
case CONNECT_ERROR:
case FINISHED_ABNORMALY:
case LOGIN_ERROR:
switchNoConnection();
break;
case FINISHED_SUCCESS:
- finishedSuccess();
+ if (finishedSuccess() == false) {
+ say(R.string.epg_no_items);
+ }
break;
case RESULT_RECEIVED:
+ resultReceived(result);
break;
}
}
- @Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- super.onRestoreInstanceState(savedInstanceState);
- int index = savedInstanceState.getInt("INDEX");
- int top = savedInstanceState.getInt("TOP");
- listView.setSelectionFromTop(index, top);
+ protected void resultReceived(Event result) {
+ results.add(result);
}
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- int index = listView.getFirstVisiblePosition();
- View v = listView.getChildAt(0);
- int top = (v == null) ? 0 : v.getTop();
- outState.putInt("INDEX", index);
- outState.putInt("TOP", top);
- super.onSaveInstanceState(outState);
+ //
+ // @Override
+ // protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ // super.onRestoreInstanceState(savedInstanceState);
+ // int index = savedInstanceState.getInt("INDEX");
+ // int top = savedInstanceState.getInt("TOP");
+ // listView.setSelectionFromTop(index, top);
+ // }
+ //
+ // @Override
+ // protected void onSaveInstanceState(Bundle outState) {
+ // int index = listView.getFirstVisiblePosition();
+ // View v = listView.getChildAt(0);
+ // int top = (v == null) ? 0 : v.getTop();
+ // outState.putInt("INDEX", index);
+ // outState.putInt("TOP", top);
+ // super.onSaveInstanceState(outState);
+ // }
+
+ protected void dismiss(AlertDialog dialog) {
+ if (dialog == null) {
+ return;
+ }
+ dialog.dismiss();
}
- protected abstract void finishedSuccess();
+ /**
+ * @return false, if no results found
+ */
+ protected abstract boolean finishedSuccess();
public boolean onSearchRequested() {
InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -343,8 +307,49 @@ public abstract class BaseEpgListActivity extends BaseActivity implements
}
public void onDoubleTap() {
- // TODO Auto-generated method stub
}
+ protected void sortItemsByChannel(List<Event> result) {
+ final Comparator<Event> comparator = new Comparator<Event>() {
+
+ public int compare(final Event item1, final Event item2) {
+ return Integer.valueOf(item1.getChannelNumber()).compareTo(
+ Integer.valueOf(item2.getChannelNumber()));
+ }
+ };
+ Collections.sort(result, comparator);
+ }
+
+ protected void sortItemsByTime(List<Event> result) {
+ final Comparator<Event> comparator = new Comparator<Event>() {
+
+ public int compare(final Event item1, final Event item2) {
+ int c = item1.getStart().compareTo(item2.getStart());
+ if (c != 0) {
+ return c;
+ }
+ return Integer.valueOf(item1.getChannelNumber()).compareTo(
+ Integer.valueOf(item2.getChannelNumber()));
+ }
+ };
+ Collections.sort(result, comparator);
+ }
+
+ public void svdrpException(final SvdrpException exception) {
+ if (progress != null) {
+ progress.svdrpException(exception);
+ }
+ }
+
+
+ protected void say(int res) {
+ Toast.makeText(this, res, Toast.LENGTH_SHORT).show();
+ }
+
+ protected void say(String msg) {
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
+ }
+
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java
new file mode 100644
index 0000000..c4fc5fd
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java
@@ -0,0 +1,349 @@
+package de.bjusystems.vdrmanager.gui;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import android.app.AlertDialog;
+import android.app.DatePickerDialog;
+import android.app.DatePickerDialog.OnDateSetListener;
+import android.app.TimePickerDialog;
+import android.app.TimePickerDialog.OnTimeSetListener;
+import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.DatePicker;
+import android.widget.TextView;
+import android.widget.TimePicker;
+import de.bjusystems.vdrmanager.R;
+import de.bjusystems.vdrmanager.data.Epg;
+import de.bjusystems.vdrmanager.data.Event;
+import de.bjusystems.vdrmanager.data.EventFormatter;
+import de.bjusystems.vdrmanager.data.EventListItem;
+import de.bjusystems.vdrmanager.data.Timer;
+import de.bjusystems.vdrmanager.tasks.CreateTimerTask;
+import de.bjusystems.vdrmanager.tasks.DeleteTimerTask;
+import de.bjusystems.vdrmanager.tasks.ModifyTimerTask;
+import de.bjusystems.vdrmanager.tasks.ToggleTimerTask;
+import de.bjusystems.vdrmanager.utils.date.DateFormatter;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
+
+public abstract class BaseTimerEditActivity<T extends Event> extends
+ BaseEventListActivity<T> implements OnClickListener, OnDateSetListener,
+ OnTimeSetListener // SvdrpAsyncListener<Timer>,
+{
+
+ public class EditTimerViewHolder {
+ View view;
+ TextView title;
+ TextView channel;
+ TextView dateField;
+ TextView startField;
+ TextView endField;
+ Button saveButton;
+ Button modifyButton;
+ }
+
+ EditTimerViewHolder tView = null;
+ AlertDialog tDialog = null;
+
+ boolean editStart;
+
+ // SetTimerClient setTimerClient;
+
+ Timer timer;
+
+ private void updateDisplay(TimerOperation op) {
+ updateDisplay();
+ switch (op) {
+ case CREATE:
+ tView.modifyButton.setVisibility(View.GONE);
+ tView.saveButton.setVisibility(View.VISIBLE);
+ tView.saveButton.setText(R.string.timer_details_save_title);
+ break;
+ case MODIFY:
+ tView.saveButton.setVisibility(View.GONE);
+ tView.modifyButton.setVisibility(View.VISIBLE);
+ }
+
+ }
+
+ private void updateDisplay() {
+ final DateFormatter dateFormatter = new DateFormatter(timer.getStart());
+ tView.channel.setText(timer.getChannelNumber() + " "
+ + timer.getChannelName());
+ tView.title.setText(timer.getTitle());
+ tView.dateField.setText(dateFormatter.getDateString());
+ tView.startField.setText(dateFormatter.getTimeString());
+ tView.endField.setText(new DateFormatter(timer.getStop())
+ .getTimeString());
+ }
+
+ protected Timer getTimer(EventListItem item) {
+ return item.getEpg().getTimer();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
+ */
+ @Override
+ public boolean onContextItemSelected(final MenuItem item) {
+
+ final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
+ .getMenuInfo();
+ final EventListItem event = adapter.getItem(info.position);
+
+ if (tView == null) {
+ tView = new EditTimerViewHolder();
+ View view = getLayoutInflater()
+ .inflate(R.layout.timer_detail, null);
+ tView.view = view;
+ tView.title = (TextView) view.findViewById(R.id.timer_detail_title);
+ tView.channel = (TextView) view
+ .findViewById(R.id.timer_detail_channel);
+ tView.dateField = (TextView) view
+ .findViewById(R.id.timer_detail_day);
+ tView.startField = (TextView) view
+ .findViewById(R.id.timer_detail_start);
+ tView.endField = (TextView) view
+ .findViewById(R.id.timer_detail_end);
+ tView.saveButton = (Button) view
+ .findViewById(R.id.timer_details_save);
+ tView.modifyButton = (Button) view
+ .findViewById(R.id.timer_details_modify);
+
+ view.findViewById(R.id.timer_details_cancel).setOnClickListener(
+ this);
+ tView.dateField.setOnClickListener(this);
+ tView.startField.setOnClickListener(this);
+ tView.endField.setOnClickListener(this);
+ tView.saveButton.setOnClickListener(this);
+ tView.modifyButton.setOnClickListener(this);
+
+ tDialog = new AlertDialog.Builder(this)
+
+ .setView(view).create();
+ }
+
+ switch (item.getItemId()) {
+ case R.id.epg_item_menu_timer_add:
+ timer = event.createTimer();
+ updateDisplay(TimerOperation.CREATE);
+ tDialog.show();
+ break;
+ case R.id.epg_item_menu_timer_modify: {
+ timer = getTimer(event);
+ updateDisplay(TimerOperation.MODIFY);
+ tDialog.show();
+ // final Intent intent = new Intent();
+ // intent.setClass(this, TimerDetailsActivity.class);
+ // startActivityForResult(intent, REQUEST_CODE_TIMED_EDIT);
+ break;
+ }
+ case R.id.epg_item_menu_timer_delete: {
+ deleteTimer(getTimer(event));
+ break;
+ }
+ case R.id.epg_item_menu_timer_toggle: {
+ toggleTimer(getTimer(event));
+ break;
+ }
+ default:
+ return super.onContextItemSelected(item);
+ }
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu,
+ * android.view.View, android.view.ContextMenu.ContextMenuInfo)
+ */
+ @Override
+ public void onCreateContextMenu(final ContextMenu menu, final View v,
+ final ContextMenuInfo menuInfo) {
+ // if (v.getId() == R.id.whatson_list) {
+ final MenuInflater inflater = getMenuInflater();
+ final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
+
+ // set menu title
+ final EventListItem item = adapter.getItem(info.position);
+ final EventFormatter formatter = new EventFormatter(item);
+ menu.setHeaderTitle(formatter.getTitle());
+
+ inflater.inflate(R.menu.epg_list_item_menu, menu);
+ Timer timer = getTimer(item);
+ // remove unneeded menu items
+ if (timer != null) {
+ menu.findItem(R.id.epg_item_menu_timer_add).setVisible(false);
+ menu.findItem(R.id.epg_item_menu_timer_modify).setVisible(true);
+ menu.findItem(R.id.epg_item_menu_timer_delete).setVisible(true);
+ final MenuItem enableMenuItem = menu
+ .findItem(R.id.epg_item_menu_timer_toggle);
+ enableMenuItem.setVisible(true);
+ enableMenuItem
+ .setTitle(timer.isEnabled() ? R.string.epg_item_menu_timer_disable
+ : R.string.epg_item_menu_timer_enable);
+ }
+
+ super.onCreateContextMenu(menu, v, menuInfo);
+
+ // }
+
+ }
+
+ protected void toggleTimer(Timer timer) {
+ final ToggleTimerTask task = new ToggleTimerTask(this, timer) {
+ @Override
+ public void finished() {
+ refresh();
+ }
+ };
+ task.start();
+ }
+
+ public void onClick(final View view) {
+ switch (view.getId()) {
+ case R.id.timer_detail_day: {
+ final Calendar cal = new GregorianCalendar();
+ cal.setTime(timer.getStart());
+ final DatePickerDialog dialog = new DatePickerDialog(this, this,
+ cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
+ cal.get(Calendar.DAY_OF_MONTH));
+ dialog.show();
+ break;
+ }
+ case R.id.timer_detail_start: {
+ final Calendar cal = new GregorianCalendar();
+ cal.setTime(timer.getStart());
+ editStart = true;
+ final TimePickerDialog dialog = new TimePickerDialog(this, this,
+ cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
+ true);
+ dialog.show();
+ break;
+ }
+ case R.id.timer_detail_end: {
+ final Calendar cal = new GregorianCalendar();
+ cal.setTime(timer.getStop());
+ editStart = false;
+ final TimePickerDialog dialog = new TimePickerDialog(this, this,
+ cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
+ true);
+ dialog.show();
+ break;
+ }
+ case R.id.timer_details_cancel: {
+ tDialog.dismiss();
+ break;
+ }
+ case R.id.timer_details_modify:
+ modifyTimer(timer);
+ tDialog.dismiss();
+ say(R.string.done);
+ break;
+
+ case R.id.timer_details_save: {
+ createTimer(timer);
+ tDialog.dismiss();
+ say(R.string.done);
+ break;
+ }
+ }
+ }
+
+ private void modifyTimer(Timer timer) {
+ final ModifyTimerTask task = new ModifyTimerTask(this, timer) {
+ @Override
+ public void finished() {
+ refresh();
+ say(R.string.done);
+ }
+ };
+ task.start();
+ }
+
+ protected void deleteTimer(final Timer timer) {
+
+ final DeleteTimerTask task = new DeleteTimerTask(this, timer) {
+ @Override
+ public void finished() {
+ refresh();
+ say(R.string.done);
+ }
+ };
+ task.start();
+ }
+
+ private void createTimer(Timer timer) {
+ final CreateTimerTask task = new CreateTimerTask(this, timer) {
+ @Override
+ public void finished() {
+ refresh();
+ say(R.string.done);
+ }
+ };
+ task.start();
+ }
+
+ public void onTimeSet(final TimePicker view, final int hourOfDay,
+ final int minute) {
+ if (editStart) {
+ timer.setStart(calculateTime(timer.getStart(), hourOfDay, minute,
+ null));
+ } else {
+ timer.setStop(calculateTime(timer.getStop(), hourOfDay, minute,
+ timer.getStart()));
+ }
+ updateDisplay();
+ }
+
+ public void onDateSet(final DatePicker view, final int year,
+ final int monthOfYear, final int dayOfMonth) {
+ timer.setStart(calculateDate(timer.getStart(), year, monthOfYear,
+ dayOfMonth));
+ updateDisplay();
+ }
+
+ private Date calculateDate(final Date oldDate, final int year,
+ final int monthOfYear, final int dayOfMonth) {
+
+ final Calendar cal = new GregorianCalendar();
+ cal.setTime(oldDate);
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.MONTH, monthOfYear);
+ cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+
+ return cal.getTime();
+ }
+
+ private Date calculateTime(final Date oldTime, final int hourOfDay,
+ final int minute, final Date startTime) {
+
+ // set hour and minute
+ final Calendar cal = new GregorianCalendar();
+ cal.setTime(oldTime);
+ cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
+ cal.set(Calendar.MINUTE, minute);
+
+ // go to the next day if end time before start time
+ if (startTime != null) {
+ if (cal.getTime().before(startTime)) {
+ cal.add(Calendar.DAY_OF_MONTH, 1);
+ }
+ }
+
+ return cal.getTime();
+
+ }
+
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
index 8c52801..b0a7c01 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
@@ -20,8 +20,10 @@ import de.bjusystems.vdrmanager.app.Intents;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Epg;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventFormatter;
import de.bjusystems.vdrmanager.data.Preferences;
+import de.bjusystems.vdrmanager.data.Timer;
import de.bjusystems.vdrmanager.gui.SimpleGestureFilter.SimpleGestureListener;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
@@ -64,17 +66,17 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
// current event
final VdrManagerApp app = (VdrManagerApp) getApplication();
epgs = app.getCurrentEpgList();
- Epg epg = app.getCurrentEvent();
+ Event epg = app.getCurrentEvent();
counter = 0;
- for(Epg e : epgs){
+ for(Event e : epgs){
if(epg == e){
break;
}
counter++;
}
-
+
new AsyncTask<Void,Void,Void>(){
@@ -102,7 +104,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
app.clearActivitiesToFinish();
}
- public void publishEPG(Epg event) {
+ public void publishEPG(Event event) {
String cn = event.getChannelName();
@@ -177,7 +179,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
// setThisAsOnClickListener(R.id.epg_event_right);
// set button text
- if (event.getTimer() == null) {
+ if (event instanceof Timer) {
// timeButton.setText(R.string.epg_event_create_timer_text);
} else {
// timeButton.setText(R.string.epg_event_modify_timer_text);
@@ -213,7 +215,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
final VdrManagerApp app = (VdrManagerApp) getApplication();
switch (v.getId()) {
case R.id.epg_event_livetv:
- Epg event = app.getCurrentEvent();
+ Event event = app.getCurrentEvent();
Utils.stream(this, event.getChannelNumber());
break;
case R.id.epg_event_create_timer:
@@ -241,7 +243,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
}
private void prevEPG() {
- Epg epg;
+ Event epg;
if (counter == 0) {
epg = epgs.get(0);
} else {
@@ -252,7 +254,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
}
- List<Epg> epgs = null;
+ List<Event> epgs = null;
int counter = 0;
public void initEPGs() {
@@ -260,10 +262,10 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
if (epgs != null) {
return;
}
- epgs = new ArrayList<Epg>();
+ epgs = new ArrayList<Event>();
final VdrManagerApp app = (VdrManagerApp) getApplication();
- final Epg event = app.getCurrentEvent();
+ final Event event = app.getCurrentEvent();
EpgClient c = new EpgClient(new Channel() {
@Override
public String getName() {
@@ -289,7 +291,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
}
epgs.addAll(e);
- Epg fe = epgs.get(0);
+ Event fe = epgs.get(0);
if (event.getStart().equals(fe.getStart()) == false) {
epgs.set(0, event);
;
@@ -300,7 +302,7 @@ public class EpgDetailsActivity extends Activity implements OnClickListener,
if(counter < epgs.size() - 1){
counter ++ ;
}
- Epg epg = epgs.get(counter);
+ Event epg = epgs.get(counter);
publishEPG(epg);
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
index 4dba61d..85aae19 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
@@ -14,6 +14,7 @@ import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Epg;
import de.bjusystems.vdrmanager.data.EpgSearchParams;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.utils.date.DateFormatter;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
@@ -27,11 +28,9 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
*
* @author bju
*/
-public class EpgSearchListActivity extends BaseEpgListActivity implements
+public class EpgSearchListActivity extends BaseEventListActivity<Epg> implements
OnItemClickListener, SvdrpAsyncListener<Epg> {
- public List<Epg> results;
-
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -43,9 +42,9 @@ public class EpgSearchListActivity extends BaseEpgListActivity implements
highlight = query.trim();
}
}
- adapter = new ChannelEventAdapter(this);
+ adapter = new TimeEventAdapter(this);
adapter.setHideDescription(false);
-
+ startEpgQuery();
// Create adapter for EPG list
listView = (ListView) findViewById(R.id.whatson_list);
listView.setAdapter(adapter);
@@ -62,7 +61,7 @@ public class EpgSearchListActivity extends BaseEpgListActivity implements
protected void onResume() {
super.onResume();
// adapter.notifyDataSetChanged();
- startEpgQuery();
+
}
@@ -95,6 +94,8 @@ public class EpgSearchListActivity extends BaseEpgListActivity implements
// start task
task.run();
}
+
+
/*
* (non-Javadoc) TODO this method also should be used in startEpgQuery on
@@ -103,14 +104,14 @@ public class EpgSearchListActivity extends BaseEpgListActivity implements
* @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess()
*/
@Override
- protected void finishedSuccess() {
+ protected boolean finishedSuccess() {
adapter.clear();
adapter.highlight = this.highlight;
Calendar cal = Calendar.getInstance();
int day = -1;
- results = epgClient.getResults();
- for (Epg e : results) {
+ sortItemsByTime(results);
+ for (Event e : results) {
cal.setTime(e.getStart());
int eday = cal.get(Calendar.DAY_OF_YEAR);
if (eday != day) {
@@ -118,14 +119,14 @@ public class EpgSearchListActivity extends BaseEpgListActivity implements
adapter.add(new EventListItem(new DateFormatter(cal)
.getDailyHeader()));
}
- adapter.add(new EventListItem(e));
+ adapter.add(new EventListItem((Epg)e));
}
listView.setSelectionAfterHeaderView();
- if (progress != null) {
- progress.dismiss();
- progress = null;
- }
+ dismiss(progress);
+ return results.isEmpty() == false;
}
+
+
public void svdrpException(final SvdrpException exception) {
if (progress != null) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
index 98adbb9..3f7fc4d 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
@@ -4,11 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import android.content.Context;
-import android.graphics.Color;
-import android.text.Spannable;
-import android.text.SpannableString;
-import android.text.TextUtils;
-import android.text.style.ForegroundColorSpan;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
@@ -17,6 +12,7 @@ import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
+import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import de.bjusystems.vdrmanager.R;
@@ -43,6 +39,9 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
inflater = LayoutInflater.from(context);
}
+
+
+
@Override
public void add(EventListItem object) {
items.add(object);
@@ -53,11 +52,25 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
public View getView(final int position, final View convertView,
final ViewGroup parent) {
+ // get item
+ final EventListItem item = getItem(position);
+
+ if (item.isHeader()) {
+ return getHeaderView(item, convertView, parent);
+ } else {
+ return getEventView(item, convertView, parent);
+ }
+
+ }
+
+ private View getEventView(EventListItem item, View convertView,
+ ViewGroup parent) {
+
EventListItemHolder itemHolder = new EventListItemHolder();
// recycle view?
View view = convertView;
- if (view == null) {
+ if (view == null || view instanceof ListView == false) {
view = inflater.inflate(layout, null);
itemHolder = new EventListItemHolder();
@@ -83,92 +96,99 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
itemHolder = (EventListItemHolder) view.getTag();
}
- // get item
- final EventListItem item = getItem(position);
- // fill item
- if (item.isHeader()) {
- view.setPadding(view.getPaddingLeft(), 0, view.getPaddingRight(), 0);
- view.setBackgroundColor(Color.DKGRAY);
- itemHolder.state.setVisibility(View.GONE);
- itemHolder.channel.setVisibility(View.VISIBLE);
- itemHolder.channel.setText(item.getHeader());
- itemHolder.title.setVisibility(View.GONE);
- itemHolder.time.setVisibility(View.GONE);
- itemHolder.progress.setVisibility(View.GONE);
- itemHolder.shortText.setVisibility(View.GONE);
- itemHolder.duration.setVisibility(View.GONE);
- itemHolder.description.setVisibility(View.GONE);
+// itemHolder.title.setVisibility(View.VISIBLE);
+ itemHolder.state.setVisibility(View.VISIBLE);
+ //itemHolder.shortText.setVisibility(View.VISIBLE);
+ //itemHolder.duration.setVisibility(View.VISIBLE);
+ // itemHolder.state.setVisibility(View.);
+ switch (item.getTimerState()) {
+ case Active:
+ //itemHolder.state.setVisibility(View.VISIBLE);
+ itemHolder.state.setImageResource(R.drawable.timer_active);
+ break;
+ case Inactive:
+ //itemHolder.state.setVisibility(View.VISIBLE);
+ itemHolder.state.setImageResource(R.drawable.timer_inactive);
+ break;
+ case Recording:
+ //itemHolder.state.setVisibility(View.VISIBLE);
+ itemHolder.state.setImageResource(R.drawable.timer_recording);
+ break;
+ case None:
+ //itemHolder.state.setVisibility(View.GONE);
+ itemHolder.state.setImageResource(R.drawable.timer_none);
+ break;
+ }
+
+ final EventFormatter formatter = getEventFormatter(item);
+ itemHolder.time.setText(formatter.getTime());
+ if (hideChannelName) {
+ itemHolder.channel.setVisibility(View.GONE);
} else {
+ itemHolder.channel.setText(item.getChannelName());
+ }
- view.setBackgroundColor(Color.BLACK);
- // itemHolder.channel.setVisibility(View.VISIBLE);
- itemHolder.time.setVisibility(View.VISIBLE);
- itemHolder.title.setVisibility(View.VISIBLE);
- itemHolder.state.setVisibility(View.VISIBLE);
- // itemHolder.channel.setVisibility(View.VISIBLE);
- itemHolder.shortText.setVisibility(View.VISIBLE);
- itemHolder.duration.setVisibility(View.VISIBLE);
- // itemHolder.state.setVisibility(View.);
- switch (item.getTimerState()) {
- case Active:
- itemHolder.state.setImageResource(R.drawable.timer_active);
- break;
- case Inactive:
- itemHolder.state.setImageResource(R.drawable.timer_inactive);
- break;
- case Recording:
- itemHolder.state.setImageResource(R.drawable.timer_recording);
- break;
- case None:
- itemHolder.state.setImageResource(R.drawable.timer_none);
- break;
- }
- final EventFormatter formatter = getEventFormatter(item.getEvent());
- itemHolder.time.setText(formatter.getTime());
- if (hideChannelName) {
- itemHolder.channel.setVisibility(View.GONE);
- } else {
- itemHolder.channel.setText(item.getChannelName());
- }
+ CharSequence title = Utils.highlight(formatter.getTitle(), highlight);
+ CharSequence shortText = Utils.highlight(formatter.getShortText(),
+ highlight);
+ itemHolder.title.setText(title);
+ itemHolder.shortText.setText(shortText);
- CharSequence title = Utils.highlight(formatter.getTitle(),
- highlight);
- CharSequence shortText = Utils.highlight(formatter.getShortText(),
- highlight);
- itemHolder.title.setText(title);
- itemHolder.shortText.setText(shortText);
-
- if (hideDescription == false) {
- Pair<Boolean, CharSequence> desc = Utils.highlight2(
- formatter.getDescription(), highlight);
- if (desc.first == true) {
- itemHolder.description.setVisibility(View.VISIBLE);
- itemHolder.description.setText(desc.second);
- }
+ if (hideDescription == false) {
+ Pair<Boolean, CharSequence> desc = Utils.highlight2(
+ formatter.getDescription(), highlight);
+ if (desc.first == true) {
+ itemHolder.description.setVisibility(View.VISIBLE);
+ itemHolder.description.setText(desc.second);
}
+ }
- int p = Utils.getProgress(item);
- if (p == -1) {
- itemHolder.progress.setVisibility(View.GONE);
- // itemHolder.time.setTypeface(null, Typeface.NORMAL);
- // itemHolder.title.setTypeface(null, Typeface.NORMAL);
- // itemHolder.shortText.setTypeface(null, Typeface.NORMAL);
- int dura = Utils.getDuration(item);
- itemHolder.duration.setText(getContext().getString(
- R.string.epg_duration_template, dura));
- } else {
- itemHolder.progress.setVisibility(View.VISIBLE);
- itemHolder.progress.setProgress(p);
- // itemHolder.time.setTypeface(null, Typeface.BOLD);
- // itemHolder.title.setTypeface(null, Typeface.BOLD);
- // itemHolder.shortText.setTypeface(null, Typeface.BOLD);
- int dura = Utils.getDuration(item);
- int rest = dura - (dura * p / 100);
- itemHolder.duration.setText(getContext().getString(
- R.string.epg_duration_template_live, rest, dura));
- }
+ int p = Utils.getProgress(item);
+ if (p == -1) {
+ itemHolder.progress.setVisibility(View.GONE);
+ // itemHolder.time.setTypeface(null, Typeface.NORMAL);
+ // itemHolder.title.setTypeface(null, Typeface.NORMAL);
+ // itemHolder.shortText.setTypeface(null, Typeface.NORMAL);
+ int dura = Utils.getDuration(item);
+ itemHolder.duration.setText(getContext().getString(
+ R.string.epg_duration_template, dura));
+ } else {
+ itemHolder.progress.setVisibility(View.VISIBLE);
+ itemHolder.progress.setProgress(p);
+ // itemHolder.time.setTypeface(null, Typeface.BOLD);
+ // itemHolder.title.setTypeface(null, Typeface.BOLD);
+ // itemHolder.shortText.setTypeface(null, Typeface.BOLD);
+ int dura = Utils.getDuration(item);
+ int rest = dura - (dura * p / 100);
+ itemHolder.duration.setText(getContext().getString(
+ R.string.epg_duration_template_live, rest, dura));
+ }
+
+ return view;
+ }
+
+ class EventListItemHeaderHolder {
+ public TextView header;
+ }
+
+ private View getHeaderView(EventListItem item, View convertView,
+ ViewGroup parent) {
+
+ EventListItemHeaderHolder itemHolder = new EventListItemHeaderHolder();
+
+ // recycle view?
+ View view = convertView;
+ if (view == null || convertView instanceof TextView == false) {
+ view = inflater.inflate(R.layout.header_item, null);
+
+ itemHolder = new EventListItemHeaderHolder();
+
+ itemHolder.header = (TextView) view.findViewById(R.id.header_item);
+ } else {
+ itemHolder = (EventListItemHeaderHolder) view.getTag();
}
+ itemHolder.header.setText(item.getHeader());
return view;
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
index 476bdd9..f481244 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
@@ -5,10 +5,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.List;
-import android.app.SearchManager;
-import android.content.Intent;
import android.os.Bundle;
-import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -21,24 +18,23 @@ import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Epg;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.utils.date.DateFormatter;
import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
-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.SvdrpException;
/**
* This class is used for showing what's current running on all channels
*
* @author bju
*/
-public class EventEpgListActivity extends BaseEpgListActivity implements
- OnItemClickListener, OnItemSelectedListener, SvdrpAsyncListener<Epg> {
+public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
+ OnItemClickListener, OnItemSelectedListener {
- private final static ArrayList<Epg> CACHE = new ArrayList<Epg>();
+ private final static ArrayList<Event> CACHE = new ArrayList<Event>();
protected static Date nextForceCache = null;
@@ -149,7 +145,8 @@ public class EventEpgListActivity extends BaseEpgListActivity implements
if (useCache(channel) && !force) {
Calendar cal = Calendar.getInstance();
int day = -1;
- for (Epg e : CACHE) {
+ for (Event i : CACHE) {
+ Epg e = (Epg)i;
cal.setTime(e.getStart());
int eday = cal.get(Calendar.DAY_OF_YEAR);
if (eday != day) {
@@ -189,7 +186,7 @@ public class EventEpgListActivity extends BaseEpgListActivity implements
* @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess()
*/
@Override
- protected void finishedSuccess() {
+ protected boolean finishedSuccess() {
adapter.clear();
CACHE.clear();
Date now = new Date();
@@ -212,16 +209,8 @@ public class EventEpgListActivity extends BaseEpgListActivity implements
}
cachedChannel = currentChannel;
listView.setSelectionAfterHeaderView();
- if (progress != null) {
- progress.dismiss();
- progress = null;
- }
- }
-
- public void svdrpException(final SvdrpException exception) {
- if (progress != null) {
- progress.svdrpException(exception);
- }
+ dismiss(progress);
+ return CACHE.isEmpty() == false;
}
protected void prepareTimer(final EventListItem item) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
index 20ba517..8dfc530 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
@@ -2,55 +2,38 @@ package de.bjusystems.vdrmanager.gui;
import java.util.Calendar;
-import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
-import android.widget.Toast;
import de.bjusystems.vdrmanager.R;
-import de.bjusystems.vdrmanager.app.VdrManagerApp;
-import de.bjusystems.vdrmanager.data.Epg;
import de.bjusystems.vdrmanager.data.EventFormatter;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.data.Recording;
-import de.bjusystems.vdrmanager.data.Timer;
-import de.bjusystems.vdrmanager.tasks.DeleteTimerTask;
import de.bjusystems.vdrmanager.utils.date.DateFormatter;
import de.bjusystems.vdrmanager.utils.svdrp.RecordingClient;
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;
/**
* This class is used for showing what's current running on all channels
*
* @author bju
*/
-public class RecordingListActivity extends BaseActivity implements
- OnItemClickListener, SvdrpAsyncListener<Recording> {
+public class RecordingListActivity extends BaseEventListActivity<Recording>
+ implements OnItemLongClickListener, SvdrpAsyncListener<Recording> {
RecordingClient recordingClient;
- EventAdapter adapter;
- SvdrpProgressDialog progress;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- // set title
- setTitle(R.string.action_menu_recordings);
-
- // Attach view
- setContentView(getMainLayout());
-
// create an adapter
adapter = new RecordingAdapter(this);
@@ -59,8 +42,9 @@ public class RecordingListActivity extends BaseActivity implements
listView.setAdapter(adapter);
// set click listener
+ listView.setOnItemLongClickListener(this);
+ // register EPG item click
listView.setOnItemClickListener(this);
-
// context menu wanted
registerForContextMenu(listView);
@@ -73,25 +57,19 @@ public class RecordingListActivity extends BaseActivity implements
super.onResume();
}
- protected void updateWindowTitle(int topic, int subtopic) {
- String title;
- title = getString(topic);
- if (subtopic != -1) {
- title += " > " + getString(subtopic);
- }
- setTitle(title);
- }
-
@Override
protected void onPause() {
super.onPause();
if (recordingClient != null) {
recordingClient.abort();
}
- if (progress != null) {
- progress.dismiss();
- progress = null;
- }
+ dismiss(progress);
+ }
+
+ @Override
+ protected void prepareTimer(EventListItem event) {
+ getApp().setCurrentEvent(event);
+ getApp().setCurrentEpgList(results);
}
@Override
@@ -112,47 +90,25 @@ public class RecordingListActivity extends BaseActivity implements
}
}
- @Override
- public boolean onContextItemSelected(final MenuItem item) {
-
- final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
- .getMenuInfo();
- final EventListItem event = adapter.getItem(info.position);
-
- switch (item.getItemId()) {
- case R.id.recording_item_menu_delete: {
-
- break;
- }
- case R.id.recording_item_menu_stream: {
- break;
- }
- }
- return true;
- }
-
- public void onItemClick(final AdapterView<?> parent, final View view,
- final int position, final long id) {
-
- // save selected item
- final Timer timer = adapter.getItem(position).getTimer();
- if (timer == null) {
- // header click
- return;
- }
-
- final VdrManagerApp app = (VdrManagerApp) getApplication();
- app.setCurrentTimer(timer);
-
- // after timer editing return to the timer list
- app.setNextActivity(RecordingListActivity.class);
- app.clearActivitiesToFinish();
-
- // show timer details
- final Intent intent = new Intent();
- intent.setClass(this, TimerDetailsActivity.class);
- startActivity(intent);
- }
+ // @Override
+ // public boolean onContextItemSelected(final MenuItem item) {
+ //
+ // final AdapterView.AdapterContextMenuInfo info =
+ // (AdapterView.AdapterContextMenuInfo) item
+ // .getMenuInfo();
+ // final EventListItem event = adapter.getItem(info.position);
+ //
+ // switch (item.getItemId()) {
+ // case R.id.recording_item_menu_delete: {
+ //
+ // break;
+ // }
+ // case R.id.recording_item_menu_stream: {
+ // break;
+ // }
+ // }
+ // return true;
+ // }
private void startRecordingQuery() {
@@ -173,72 +129,6 @@ public class RecordingListActivity extends BaseActivity implements
task.run();
}
-
- private void dismiss(){
- if (progress != null) {
- progress.dismiss();
- }
- }
-
- public void svdrpEvent(final SvdrpEvent event, final Recording result) {
-
- if (progress != null) {
- progress.svdrpEvent(event);
- }
-
- switch (event) {
- case CONNECTING:
- break;
- case FINISHED_ABNORMALY:
- case CONNECT_ERROR:
- switchNoConnection();// TODO pass arg, what is the problem
- case LOGIN_ERROR:
- dismiss();
- switchNoConnection();
- break;
- case FINISHED_SUCCESS:
- adapter.clear();
- Calendar cal = Calendar.getInstance();
- int day = -1;
- for (final Recording rec : recordingClient.getResults()) {
- cal.setTime(rec.getStart());
- int eday = cal.get(Calendar.DAY_OF_YEAR);
- if (eday != day) {
- day = eday;
- adapter.add(new EventListItem(new DateFormatter(cal)
- .getDailyHeader()));
- }
- adapter.add(new EventListItem(rec));
- }
- // adapter.sortItems();
- dismiss();
- if (recordingClient.getResults().isEmpty()) {
- Toast.makeText(RecordingListActivity.this,
- R.string.epg_no_items, Toast.LENGTH_SHORT).show();
- }
- break;
- }
- }
-
- public void svdrpException(final SvdrpException exception) {
- if (progress != null) {
- progress.svdrpException(exception);
- }
- }
-
- private void deleteTimer(final EventListItem item) {
-
- final DeleteTimerTask task = new DeleteTimerTask(this, item.getTimer()) {
- @Override
- public void finished() {
- // refresh epg list after return
- final VdrManagerApp app = (VdrManagerApp) getApplication();
- app.setReload(true);
- }
- };
- task.start();
- }
-
protected void retry() {
startRecordingQuery();
}
@@ -252,5 +142,35 @@ public class RecordingListActivity extends BaseActivity implements
return R.layout.recording_list;
}
+ @Override
+ protected int getWindowTitle() {
+ return R.string.remux_title;
+ }
+
+ @Override
+ protected boolean finishedSuccess() {
+ adapter.clear();
+ Calendar cal = Calendar.getInstance();
+ int day = -1;
+ for (final Recording rec : recordingClient.getResults()) {
+ results.add(rec);
+ cal.setTime(rec.getStart());
+ int eday = cal.get(Calendar.DAY_OF_YEAR);
+ if (eday != day) {
+ day = eday;
+ adapter.add(new EventListItem(new DateFormatter(cal)
+ .getDailyHeader()));
+ }
+ adapter.add(new EventListItem(rec));
+ }
+ // adapter.sortItems();
+ return results.isEmpty() == false;
+ }
+
+ public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
+ long arg3) {
+
+ return false;
+ }
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SimpleGestureFilter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SimpleGestureFilter.java
index 85b6b5d..2afe23a 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SimpleGestureFilter.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SimpleGestureFilter.java
@@ -120,6 +120,7 @@ public class SimpleGestureFilter extends SimpleOnGestureListener{
result = true;
}
+ /*
else if(velocityY > this.swipe_Min_Velocity && yDistance > this.swipe_Min_Distance){
if(e1.getY() > e2.getY()) // bottom to up
this.listener.onSwipe(SWIPE_UP);
@@ -128,7 +129,7 @@ public class SimpleGestureFilter extends SimpleOnGestureListener{
result = true;
}
-
+*/
return result;
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
index e6fcb1f..f237a89 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
@@ -1,12 +1,10 @@
package de.bjusystems.vdrmanager.gui;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.Date;
-import java.util.List;
import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -14,27 +12,27 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
+import android.widget.TextView;
import android.widget.Toast;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Epg;
import de.bjusystems.vdrmanager.data.EpgSearchTimeValue;
import de.bjusystems.vdrmanager.data.EpgSearchTimeValues;
+import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.utils.date.DateFormatter;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
-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.SvdrpException;
/**
* This class is used for showing what's current running on all channels
*
* @author bju
*/
-public class TimeEpgListActivity extends BaseEpgListActivity implements
- OnItemClickListener, OnItemSelectedListener, SvdrpAsyncListener<Epg> {
+public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
+ OnItemClickListener, OnItemSelectedListener {
Spinner timeSpinner;
@@ -42,16 +40,14 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
protected static Date nextForceCache = null;
- private final static ArrayList<Epg> CACHE = new ArrayList<Epg>();
+ private final static ArrayList<Event> CACHE = new ArrayList<Event>();
private static String cachedTime = null;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
-
// create adapter for time spinner
timeSpinnerAdapter = new ArrayAdapter<EpgSearchTimeValue>(this,
android.R.layout.simple_spinner_item);
@@ -81,6 +77,10 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
}
+ private void addCustom() {
+
+ }
+
private void fillTimeSpinnerValues() {
final EpgSearchTimeValues values = new EpgSearchTimeValues(this);
timeSpinnerAdapter.clear();
@@ -88,17 +88,15 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
timeSpinnerAdapter.add(value);
}
}
-
+
private int currentPostion = 0;
@Override
protected void onPause() {
super.onPause();
-
- }
+ }
-
@Override
protected void onResume() {
super.onResume();
@@ -152,8 +150,8 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
adapter.add(new EventListItem(new DateFormatter(CACHE.get(0)
.getStart()).getDailyHeader()));
}
- for (Epg e : CACHE) {
- adapter.add(new EventListItem(e));
+ for (Event e : CACHE) {
+ adapter.add(new EventListItem((Epg) e));
}
// adapter.sortItems();
listView.setSelectionAfterHeaderView();
@@ -163,6 +161,7 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
clearCache();
epgClient = new EpgClient(time);
+ epgClient.setResultInfoEnabled(true);
// remove old listeners
// epgClient.clearSvdrpListener();
@@ -181,7 +180,7 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
}
@Override
- protected void finishedSuccess() {
+ protected boolean finishedSuccess() {
// get spinner value
final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner
.getSelectedItem();
@@ -190,41 +189,22 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
nextForceCache = FUTURE;
cachedTime = selection.getValue();
Date now = new Date();
- List<Epg> results = epgClient.getResults();
sortItemsByChannel(results);
if (results.isEmpty() == false) {
adapter.add(new EventListItem(new DateFormatter(results.get(0)
.getStart()).getDailyHeader()));
}
- for (Epg e : results) {
+ for (Event e : results) {
CACHE.add(e);
- adapter.add(new EventListItem(e));
+ adapter.add(new EventListItem((Epg) e));
if (e.getStop().before(nextForceCache) && e.getStop().after(now)) {
nextForceCache = e.getStop();
}
}
listView.setSelectionAfterHeaderView();
- if (progress != null) {
- progress.dismiss();
- progress = null;
- }
- }
+ dismiss(progress);
+ return CACHE.isEmpty() == false;
- public void svdrpException(final SvdrpException exception) {
- if (progress != null) {
- progress.svdrpException(exception);
- }
- }
-
- private void sortItemsByChannel(List<Epg> result) {
- final Comparator<Epg> comparator = new Comparator<Epg>() {
-
- public int compare(final Epg item1, final Epg item2) {
- return Integer.valueOf(item1.getChannelNumber()).compareTo(
- Integer.valueOf(item2.getChannelNumber()));
- }
- };
- Collections.sort(result, comparator);
}
protected void prepareTimer(final EventListItem item) {
@@ -253,31 +233,32 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
protected void retry() {
refresh();
}
-
+
@Override
protected int getWindowTitle() {
return R.string.epg_by_time;
}
-
- private void nextEvent(){
+ private void nextEvent() {
int pos = timeSpinner.getSelectedItemPosition();
- if(pos + 1 >= timeSpinnerAdapter.getCount()){
- Toast.makeText(this, R.string.navigae_at_the_end, Toast.LENGTH_SHORT).show();
+ if (pos + 1 >= timeSpinnerAdapter.getCount()) {
+ Toast.makeText(this, R.string.navigae_at_the_end,
+ Toast.LENGTH_SHORT).show();
return;
}
- timeSpinner.setSelection(pos+1, true);
+ timeSpinner.setSelection(pos + 1, true);
}
-
- private void prevEvent(){
+
+ private void prevEvent() {
int pos = timeSpinner.getSelectedItemPosition();
- if(pos <= 0){
- Toast.makeText(this, R.string.navigae_at_the_start, Toast.LENGTH_SHORT).show();
+ if (pos <= 0) {
+ Toast.makeText(this, R.string.navigae_at_the_start,
+ Toast.LENGTH_SHORT).show();
return;
}
- timeSpinner.setSelection(pos-1, true);
+ timeSpinner.setSelection(pos - 1, true);
}
-
+
@Override
public void onSwipe(int direction) {
switch (direction) {
@@ -289,5 +270,4 @@ public class TimeEpgListActivity extends BaseEpgListActivity implements
break;
}
}
-
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java
index 10f1822..5a79c30 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java
@@ -120,7 +120,7 @@ public class TimerDetailsActivity extends Activity implements OnClickListener,
.getText().toString());
// create client for saving the timer
- setTimerClient = new SetTimerClient(timer, false);
+ //setTimerClient = new SetTimerClient(timer, false);
// create backgound task
final SvdrpAsyncTask<Timer, SvdrpClient<Timer>> task = new SvdrpAsyncTask<Timer, SvdrpClient<Timer>>(
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
index 7cf96c0..f796fa6 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
@@ -1,28 +1,18 @@
package de.bjusystems.vdrmanager.gui;
-import android.content.Intent;
+import java.util.Calendar;
+
import android.os.Bundle;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
-import android.widget.Toast;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
-import de.bjusystems.vdrmanager.data.EventFormatter;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.data.Timer;
-import de.bjusystems.vdrmanager.tasks.DeleteTimerTask;
-import de.bjusystems.vdrmanager.tasks.ToggleTimerTask;
+import de.bjusystems.vdrmanager.utils.date.DateFormatter;
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.TimerClient;
/**
@@ -30,23 +20,17 @@ import de.bjusystems.vdrmanager.utils.svdrp.TimerClient;
*
* @author bju
*/
-public class TimerListActivity extends BaseActivity implements
+public class TimerListActivity extends BaseTimerEditActivity<Timer> implements
OnItemClickListener, SvdrpAsyncListener<Timer> {
-
- private static final int REQUEST_CODE_TIMED_EDIT = 41;
-
TimerClient timerClient;
- EventAdapter adapter;
- SvdrpProgressDialog progress;
+
+
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- // set title
- setTitle(R.string.action_menu_timers);
-
// Attach view
setContentView(getMainLayout());
@@ -54,8 +38,10 @@ public class TimerListActivity extends BaseActivity implements
adapter = new TimeEventAdapter(this);
// attach adapter to ListView
- final ListView listView = (ListView) findViewById(R.id.timer_list);
+ listView = (ListView) findViewById(R.id.timer_list);
listView.setAdapter(adapter);
+ listView.setFastScrollEnabled(true);
+ listView.setTextFilterEnabled(true);
// set click listener
listView.setOnItemClickListener(this);
@@ -70,25 +56,6 @@ public class TimerListActivity extends BaseActivity implements
@Override
protected void onResume() {
super.onResume();
- reloadIfNeeded();
- }
-
- private void reloadIfNeeded() {
-
- final VdrManagerApp app = (VdrManagerApp) getApplication();
- if (app.isReload()) {
- app.setReload(false);
- startTimerQuery();
- }
- }
-
- protected void updateWindowTitle(int topic, int subtopic) {
- String title;
- title = getString(topic);
- if (subtopic != -1) {
- title += " > " + getString(subtopic);
- }
- setTitle(title);
}
@Override
@@ -97,81 +64,9 @@ public class TimerListActivity extends BaseActivity implements
if (timerClient != null) {
timerClient.abort();
}
- if (progress != null) {
- progress.dismiss();
- progress = null;
- }
+ dismiss(progress);
}
- @Override
- public void onCreateContextMenu(final ContextMenu menu, final View v,
- final ContextMenuInfo menuInfo) {
- super.onCreateContextMenu(menu, v, menuInfo);
-
- if (v.getId() == R.id.timer_list) {
- final MenuInflater inflater = getMenuInflater();
- final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
-
- // set menu title
- final EventListItem item = adapter.getItem(info.position);
- final EventFormatter formatter = new EventFormatter(item);
- menu.setHeaderTitle(formatter.getTitle());
-
- inflater.inflate(R.menu.epg_list_item_menu, menu);
-
- // remove unneeded menu items
- menu.findItem(R.id.epg_item_menu_timer_add).setVisible(false);
- final MenuItem enableMenuItem = menu
- .findItem(R.id.epg_item_menu_timer_toggle);
- enableMenuItem
- .setTitle(item.getTimer().isEnabled() ? R.string.epg_item_menu_timer_disable
- : R.string.epg_item_menu_timer_enable);
- }
- }
-//
-// @Override
-// public boolean onContextItemSelected(final MenuItem item) {
-//
-// final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
-// .getMenuInfo();
-// final EventListItem event = adapter.getItem(info.position);
-//
-// switch (item.getItemId()) {
-// case R.id.epg_item_menu_timer_modify: {
-// onItemClick(null, null, info.position, 0);
-// break;
-// }
-// case R.id.epg_item_menu_timer_delete: {
-// deleteTimer(event);
-// break;
-// }
-// case R.id.epg_item_menu_timer_toggle: {
-// toggleTimer(event);
-// }
-// }
-//
-// return true;
-// }
-
- public void onItemClick(final AdapterView<?> parent, final View view,
- final int position, final long id) {
-
- // save selected item
- final Timer timer = adapter.getItem(position).getTimer();
- if (timer == null) {
- // header click
- return;
- }
-
-
- //timer.getChannelName()
- //timer.getEvent();
-
- // show details
- final Intent intent = new Intent();
- intent.setClass(this, EpgDetailsActivity.class);
- startActivity(intent);
- }
private void startTimerQuery() {
@@ -192,118 +87,56 @@ public class TimerListActivity extends BaseActivity implements
task.run();
}
- public void svdrpEvent(final SvdrpEvent event, final Timer result) {
-
- if (progress != null) {
- progress.svdrpEvent(event);
- }
- switch (event) {
- case CONNECTING:
- break;
- case FINISHED_ABNORMALY:
- case CONNECT_ERROR:
- switchNoConnection();// TODO pass arg, what is the problem
- case LOGIN_ERROR:
- progress.dismiss();
- switchNoConnection();
- break;
- case FINISHED_SUCCESS:
- adapter.clear();
- for (final Timer timer : timerClient.getResults()) {
- adapter.add(new EventListItem(timer));
- }
- // adapter.sortItems();
- progress.dismiss();
- progress = null;
- if (timerClient.getResults().isEmpty()) {
- Toast.makeText(TimerListActivity.this, R.string.epg_no_items,
- Toast.LENGTH_SHORT).show();
- }
- break;
- }
- }
-
- public void svdrpException(final SvdrpException exception) {
- if (progress != null) {
- progress.svdrpException(exception);
- }
+ @Override
+ protected Timer getTimer(EventListItem item) {
+ return item.getTimer();
}
-
- private void deleteTimer(final EventListItem item) {
-
- final DeleteTimerTask task = new DeleteTimerTask(this, item.getTimer()) {
- @Override
- public void finished() {
- // refresh epg list after return
- final VdrManagerApp app = (VdrManagerApp) getApplication();
- app.setReload(true);
- reloadIfNeeded();
+ protected void prepareTimer(final EventListItem item) {
+ final VdrManagerApp app = (VdrManagerApp) getApplication();
+ // remember event for details view and timer things
+ app.setCurrentEvent(item.getTimer());
+ app.setCurrentEpgList(results);
+ }
+
+ protected boolean finishedSuccess() {
+ adapter.clear();
+ for(Timer e : timerClient.getResults()){
+ results.add(e);
+ Calendar cal = Calendar.getInstance();
+ int day = -1;
+ cal.setTime(e.getStart());
+ int eday = cal.get(Calendar.DAY_OF_YEAR);
+ if (eday != day) {
+ day = eday;
+ adapter.add(new EventListItem(new DateFormatter(cal)
+ .getDailyHeader()));
}
- };
- task.start();
- }
-
- @Override
- public boolean onContextItemSelected(final MenuItem item) {
-
- final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
- .getMenuInfo();
- final EventListItem event = adapter.getItem(info.position);
-
- switch (item.getItemId()) {
- case R.id.epg_item_menu_timer_add:
- case R.id.epg_item_menu_timer_modify: {
- //prepareTimer(event);
- final Intent intent = new Intent();
- intent.setClass(this, TimerDetailsActivity.class);
- startActivityForResult(intent, REQUEST_CODE_TIMED_EDIT);
- break;
- }
- case R.id.epg_item_menu_timer_delete: {
- deleteTimer(event);
- break;
+ adapter.add(new EventListItem(e));
}
- case R.id.epg_item_menu_timer_toggle: {
- toggleTimer(event);
- break;
- }
- case R.id.epg_item_menu_live_tv: {
- Utils.stream(this, event.getEvent());
- break;
-
- }
- }
-
- return true;
+ listView.setSelectionAfterHeaderView();
+ dismiss(progress);
+ return results.isEmpty() == false;
}
-
-
- private void toggleTimer(final EventListItem item) {
- final ToggleTimerTask task = new ToggleTimerTask(this, item.getTimer()) {
- @Override
- public void finished() {
- // refresh epg list after return
- final VdrManagerApp app = (VdrManagerApp) getApplication();
- app.setReload(true);
- reloadIfNeeded();
- }
- };
- task.start();
+ @Override
+ protected int getWindowTitle() {
+ return R.string.action_menu_timers;
}
- protected void retry() {
- startTimerQuery();
+ @Override
+ protected int getMainLayout() {
+ return R.layout.timer_list;
}
+ @Override
protected void refresh() {
startTimerQuery();
}
@Override
- protected int getMainLayout() {
- return R.layout.timer_list;
+ protected void retry() {
+ refresh();
}
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java
new file mode 100644
index 0000000..f9ab94b
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java
@@ -0,0 +1,19 @@
+package de.bjusystems.vdrmanager.tasks;
+
+import android.app.Activity;
+import de.bjusystems.vdrmanager.R;
+import de.bjusystems.vdrmanager.data.Timer;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
+
+public abstract class CreateTimerTask extends AsyncProgressTask<Timer> {
+
+ public CreateTimerTask(final Activity activity, final Timer timer) {
+ super(activity, new SetTimerClient(timer, TimerOperation.CREATE) {
+ @Override
+ public int getProgressTextId() {
+ return R.string.progress_timer_save;
+ }
+ });
+ }
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java
index 48cdd23..f4ea149 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java
@@ -4,11 +4,12 @@ import android.app.Activity;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Timer;
import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
public abstract class DeleteTimerTask extends AsyncProgressTask<Timer> {
public DeleteTimerTask(final Activity activity, final Timer timer) {
- super(activity, new SetTimerClient(timer, true) {
+ super(activity, new SetTimerClient(timer, TimerOperation.DELETE) {
@Override
public int getProgressTextId() {
return R.string.progress_timer_delete;
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java
new file mode 100644
index 0000000..57fba6e
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java
@@ -0,0 +1,23 @@
+package de.bjusystems.vdrmanager.tasks;
+
+import android.app.Activity;
+import de.bjusystems.vdrmanager.R;
+import de.bjusystems.vdrmanager.data.Timer;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
+
+public abstract class ModifyTimerTask extends AsyncProgressTask<Timer> {
+
+ public ModifyTimerTask(final Activity activity, final Timer timer) {
+ super(activity, new SetTimerClient(timer, TimerOperation.MODIFY) {
+ @Override
+ public int getProgressTextId() {
+ return R.string.progress_timer_modify;
+ }
+
+
+ });
+
+
+ }
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java
index ee146e5..a3b5d6a 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java
@@ -4,11 +4,12 @@ import android.app.Activity;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Timer;
import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient;
+import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation;
public abstract class ToggleTimerTask extends AsyncProgressTask<Timer> {
public ToggleTimerTask(final Activity activity, final Timer timer) {
- super(activity, new SetTimerClient(timer, false) {
+ super(activity, new SetTimerClient(timer, TimerOperation.MODIFY) {
boolean enabled = timer.isEnabled();
@Override
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
index 0863c6d..c1e0f73 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
@@ -10,10 +10,24 @@ import de.bjusystems.vdrmanager.data.Timer;
*/
public class SetTimerClient extends SvdrpClient<Timer> {
+ public enum TimerOperation {
+ CREATE("C"),//
+ DELETE("D"),//
+ MODIFY("M");//
+ private String command;
+ private TimerOperation(String command){
+ this.command = command;
+ }
+ public String getCommand(){
+ return this.command;
+ }
+
+ }
+
/** channel names for timer */
Timer timer;
/** timer should be deleted */
- boolean deleteTimer;
+ private TimerOperation timerOperation;
/**
* Constructor
@@ -21,10 +35,10 @@ public class SetTimerClient extends SvdrpClient<Timer> {
* @param port port
* @param ssl use ssl
*/
- public SetTimerClient(final Timer timer, final boolean deleteTimer) {
+ public SetTimerClient(final Timer timer, TimerOperation op) {
super();
this.timer = timer;
- this.deleteTimer = deleteTimer;
+ this.timerOperation = op;
}
/**
@@ -36,12 +50,11 @@ public class SetTimerClient extends SvdrpClient<Timer> {
final StringBuilder command = new StringBuilder();
command.append("timer ");
- if (deleteTimer) {
- command.append("-");
- }
+ command.append(timerOperation.getCommand());
+
command.append(timer.getNumber());
command.append(" ");
- command.append(timer.toCommandLine());
+ command.append(timer.toCommandLine(timerOperation));
runCommand(command.toString());
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
index 374e2de..5f04578 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
@@ -236,11 +236,13 @@ public abstract class SvdrpClient<Result> {
informListener(SvdrpEvent.COMMAND_SENDING, null);
writeLine(command);
informListener(SvdrpEvent.COMMAND_SENT, null);
-
+ Log.i(TAG, SvdrpEvent.COMMAND_SENT +":" + command);
+
// read first line
String line = readLine();
if (!line.startsWith("START")) {
- throw new IOException("Answer not wellformed");
+ Log.w(TAG,line);
+ throw new IOException("Answer not wellformed: " + line);
}
// read answer lines
@@ -259,12 +261,22 @@ public abstract class SvdrpClient<Result> {
// error?
if (line.startsWith("!ERROR")) {
+ Log.w(TAG, line);
informListener(SvdrpEvent.ERROR, null);
break;
}
// delegate analysis
- final Result result = parseAnswer(line);
+ Result result = null;
+ try {
+ result = parseAnswer(line);
+ } catch(Exception ex){
+ Log.w(TAG, ex);
+ Log.w(TAG, "line: " + line);
+ informListener(SvdrpEvent.ERROR, null);
+ disconnect();
+ break;
+ }
if (result != null) {
results.add(result);
if (resultInfoEnabled) {
@@ -281,6 +293,7 @@ public abstract class SvdrpClient<Result> {
} catch (final Exception e) {
// throw new SvdrpException(e);
+ Log.w(TAG, e);
informListener(SvdrpEvent.FINISHED_ABNORMALY, null);
}
}