summaryrefslogtreecommitdiff
path: root/vdrmanager/src/de/bjusystems
diff options
context:
space:
mode:
authorlado <herrlado@gmail.com>2013-02-24 23:09:23 +0100
committerlado <herrlado@gmail.com>2013-02-24 23:09:23 +0100
commit60182cc6439948e025df7698c68a70c563fa8e34 (patch)
tree1b5ce370079a60b5f30bac3280d7f89a0858fcc4 /vdrmanager/src/de/bjusystems
parent1e97f93da09d726a746670fe23e21b457327d4d3 (diff)
downloadvdr-manager-60182cc6439948e025df7698c68a70c563fa8e34.tar.gz
vdr-manager-60182cc6439948e025df7698c68a70c563fa8e34.tar.bz2
current
Diffstat (limited to 'vdrmanager/src/de/bjusystems')
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java88
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java33
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java24
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/P.java11
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java48
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/RecentChannelDAO.java86
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/RecenteChannel.java59
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java11
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/TimerMatch.java7
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Timerable.java6
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/db/DBAccess.java95
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java66
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java175
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java23
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java210
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java7
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java101
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java115
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java48
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java55
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java83
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java12
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java6
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java33
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java92
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java4
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java10
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java10
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncListener.java7
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java118
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java165
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java4
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java19
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpExceptionListener.java5
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpListener.java6
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpResultListener.java6
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java12
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java2
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java2
42 files changed, 1298 insertions, 572 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java
index 1a75469..f885be8 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Channel.java
@@ -1,5 +1,7 @@
package de.bjusystems.vdrmanager.data;
+import java.util.ArrayList;
+import java.util.List;
import android.os.Parcel;
import android.os.Parcelable;
@@ -13,27 +15,64 @@ import de.bjusystems.vdrmanager.app.C;
@DatabaseTable
public class Channel implements Parcelable {
-
- @DatabaseField(id=true)
+ @DatabaseField(id = true)
String id;
private int number;
-
+
@DatabaseField
private String name;
-
- @DatabaseField(index=true)
+
+ @DatabaseField(index = true)
private String provider;
@DatabaseField
private String rawAudio;
-
+
@DatabaseField(index = true)
private String group;
+ private String source;
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
public String getGroup() {
return group;
}
+ private List<Audio> audio;
+
+ public List<Audio> getAudio() {
+ if (audio != null) {
+ return audio;
+ }
+
+ String[] splitted = rawAudio.split("\\|");
+ if (splitted == null || splitted.length == 0) {
+ audio = new ArrayList<Channel.Audio>(0);
+ } else {
+ audio = new ArrayList<Channel.Audio>(splitted.length);
+ for (String a : splitted) {
+ String[] ar = a.split(",");
+ if (ar == null || ar.length != 3) {
+ continue;
+ }
+ Audio track = new Audio();
+ track.type = ar[0];
+ track.index = Integer.valueOf(ar[1]);
+ track.display = ar[2];
+ audio.add(track);
+ }
+ }
+ return audio;
+
+ }
+
public void setGroup(String group) {
this.group = group;
}
@@ -43,19 +82,26 @@ public class Channel implements Parcelable {
}
public Channel(final String channelData) {
- String[] words = StringUtils.splitPreserveAllTokens(channelData, C.DATA_SEPARATOR);
+ String[] words = StringUtils.splitPreserveAllTokens(channelData,
+ C.DATA_SEPARATOR);
this.number = Integer.valueOf(words[0].substring(1));
if (words.length > 2) {
this.name = words[1];
this.provider = words[2];
this.id = words[3];
this.rawAudio = words[4];
+ if (words.length > 5) {
+ this.source = words[5];
+ } else {
+ this.source = "Default";
+ }
} else {
this.name = words[1];
this.id = "-1";
this.provider = "Unknown";
this.rawAudio = "";
}
+
}
public Channel() {
@@ -72,6 +118,7 @@ public class Channel implements Parcelable {
this.provider = in.readString();
this.id = in.readString();
this.rawAudio = in.readString();
+ this.source = in.readString();
}
public boolean isGroupSeparator() {
@@ -90,10 +137,10 @@ public class Channel implements Parcelable {
return provider;
}
- public String getId(){
+ public String getId() {
return id;
}
-
+
@Override
public String toString() {
final StringBuilder text = new StringBuilder();
@@ -115,6 +162,7 @@ public class Channel implements Parcelable {
dest.writeString(provider);
dest.writeString(id);
dest.writeString(rawAudio);
+ dest.writeString(source);
}
@@ -127,21 +175,31 @@ public class Channel implements Parcelable {
return new Channel[size];
}
};
-
+
public boolean equals(Object o) {
- if(o instanceof Channel == false){
+ if (o instanceof Channel == false) {
return false;
}
- if(o == this){
+ if (o == this) {
return true;
}
- return number == ((Channel)o).getNumber();
+ return number == ((Channel) o).getNumber();
};
-
+
@Override
public int hashCode() {
return number;
}
-
+
+ class Audio {
+
+ public int index;
+
+ public String type;
+
+ public String display;
+
+ }
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
index 709cb46..8d077bb 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Epg.java
@@ -2,7 +2,6 @@ package de.bjusystems.vdrmanager.data;
import java.util.Date;
-
import de.bjusystems.vdrmanager.StringUtils;
import de.bjusystems.vdrmanager.app.C;
@@ -10,24 +9,35 @@ import static de.bjusystems.vdrmanager.gui.Utils.mapSpecialChars;
/**
* Class for EPG events
+ *
* @author bju
*/
public class Epg extends Event implements Timerable {
private Timer timer;
+ private TimerMatch timerMatch;
+
+ public TimerMatch getTimerMatch() {
+ return timerMatch;
+ }
+
+ public void setTimerMatch(TimerMatch timerMatch) {
+ this.timerMatch = timerMatch;
+ }
+
public Epg(final String line) {
- final String[] words = StringUtils.splitPreserveAllTokens(line, C.DATA_SEPARATOR);
- channelNumber = words[0].substring(1);
+ final String[] words = StringUtils.splitPreserveAllTokens(line,
+ C.DATA_SEPARATOR);
+ channelNumber = Long.valueOf(words[0].substring(1));
channelName = words[1];
- start = new Date(Long.parseLong(words[2])*1000);
- stop = new Date(Long.parseLong(words[3])*1000);
+ start = new Date(Long.parseLong(words[2]) * 1000);
+ stop = new Date(Long.parseLong(words[3]) * 1000);
title = mapSpecialChars(words[4]);
- description = words.length > 5 ? mapSpecialChars(words[5]): "";
+ description = words.length > 5 ? mapSpecialChars(words[5]) : "";
shortText = words.length > 6 ? mapSpecialChars(words[6]) : "";
channelId = words.length > 7 ? mapSpecialChars(words[7]) : "";
}
-
public Timer getTimer() {
return timer;
@@ -35,6 +45,13 @@ public class Epg extends Event implements Timerable {
public void setTimer(final Timer timer) {
this.timer = timer;
+ if (start.before(timer.getStart())) {
+ timerMatch = TimerMatch.End;
+ } else if (stop.after(timer.getStop())) {
+ timerMatch = TimerMatch.Begin;
+ } else {
+ timerMatch = TimerMatch.Full;
+ }
}
public TimerState getTimerState() {
@@ -44,7 +61,7 @@ public class Epg extends Event implements Timerable {
return timer.getTimerState();
}
}
-
+
public Timer createTimer() {
return new Timer(this);
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
index 7be01e2..af45ba5 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Event.java
@@ -5,14 +5,14 @@ import java.util.Date;
import android.text.TextUtils;
/**
- * Basisc class for all Events
- *
+ * Basisc class for all Events
+ *
* @author bju,lado
*
*/
public abstract class Event {
- protected String channelNumber;
+ protected Long channelNumber;
protected String channelId;
protected String channelName;
@@ -21,18 +21,18 @@ public abstract class Event {
protected String description;
protected Date start;
protected Date stop;
-
-
+
+
public long getDuration(){
long millis = getStop().getTime() - getStart().getTime();
return millis;
}
-
+
public Event(){
-
+
}
-
- public void setChannelNumber(String channelNumber) {
+
+ public void setChannelNumber(Long channelNumber) {
this.channelNumber = channelNumber;
}
@@ -70,7 +70,7 @@ public abstract class Event {
stop = event.getStop();
}
- public String getChannelNumber() {
+ public Long getChannelNumber() {
return channelNumber;
}
@@ -116,7 +116,7 @@ public abstract class Event {
if(channelId != null){
return channelId;
}
- return channelNumber;
+ return String.valueOf(channelNumber);
}
-
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/P.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/P.java
new file mode 100644
index 0000000..b3e9918
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/P.java
@@ -0,0 +1,11 @@
+package de.bjusystems.vdrmanager.data;
+
+public interface P {
+
+ public static String CHANNELS_LAST_ORDER = "CHANNELS_LAST_ORDER";
+
+ public static String EPG_LAST_SORT = "EPG_LAST_SORT";
+
+ public static String CHANNELS_LAST_ORDER_REVERSE = "CHANNELS_LAST_ORDER_ORDER";
+
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java
index 85394ba..38ce1d0 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java
@@ -25,20 +25,49 @@ public class Preferences {
private static Vdr current;
+ public static void set(Context context, String key, int value) {
+ final SharedPreferences sharedPrefs = getSharedPreferences(context);
+ sharedPrefs.edit().putInt(key, value).commit();
+ }
+
+ public static void set(Context context, String key, boolean value) {
+ final SharedPreferences sharedPrefs = getSharedPreferences(context);
+ sharedPrefs.edit().putBoolean(key, value).commit();
+ }
+
+ public static int get(Context context, String key, int defValue) {
+ final SharedPreferences sharedPrefs = getSharedPreferences(context);
+ return sharedPrefs.getInt(key, defValue);
+
+ }
+
+ public static String get(Context context, String key, String defValue) {
+ final SharedPreferences sharedPrefs = getSharedPreferences(context);
+ return sharedPrefs.getString(key, defValue);
+
+ }
+
+
+ public static boolean get(Context context, String key, boolean defValue) {
+ final SharedPreferences sharedPrefs = getSharedPreferences(context);
+ return sharedPrefs.getBoolean(key, defValue);
+
+ }
+
public static void setCurrentVdr(Context context, Vdr vdr) {
current = vdr;
final SharedPreferences sharedPrefs = getSharedPreferences(context);
sharedPrefs
.edit()
.putInt(context.getString(R.string.current_vdr_id_key),
- current != null ? current.getId() : -1 ).commit();
+ current != null ? current.getId() : -1).commit();
}
public Vdr getCurrentVdr() {
return current;
}
- public int getCurrentVdrContext(Context context){
+ public int getCurrentVdrContext(Context context) {
return getInteger(context, R.string.current_vdr_id_key, -1);
}
@@ -445,11 +474,10 @@ public class Preferences {
return thePrefs;
}
- public String getRecStreamMethod(){
+ public String getRecStreamMethod() {
return getCurrentVdr().getRecStreamMethod();
}
-
/**
*
* Gets the previous loaded preferences, same as getPreferences();
@@ -532,12 +560,12 @@ public class Preferences {
}
return initFromOldVersion(context);
- //Intent intent = new Intent();
- //intent.setClass(context, VdrListActivity.class);
- //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- //intent.putExtra(Intents.EMPTY_CONFIG, Boolean.TRUE);
- //context.startActivity(intent);
- //Toast.makeText(context, R.string.no_vdr, Toast.LENGTH_SHORT).show();
+ // Intent intent = new Intent();
+ // intent.setClass(context, VdrListActivity.class);
+ // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ // intent.putExtra(Intents.EMPTY_CONFIG, Boolean.TRUE);
+ // context.startActivity(intent);
+ // Toast.makeText(context, R.string.no_vdr, Toast.LENGTH_SHORT).show();
}
/**
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/RecentChannelDAO.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/RecentChannelDAO.java
new file mode 100644
index 0000000..d8a8c41
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/RecentChannelDAO.java
@@ -0,0 +1,86 @@
+package de.bjusystems.vdrmanager.data;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import android.util.Log;
+
+import com.j256.ormlite.dao.BaseDaoImpl;
+import com.j256.ormlite.support.ConnectionSource;
+
+public class RecentChannelDAO extends BaseDaoImpl<RecenteChannel, String> {
+
+ private static final String TAG = RecentChannelDAO.class.getName();
+
+ public RecentChannelDAO(ConnectionSource connectionSource)
+ throws SQLException {
+ super(connectionSource, RecenteChannel.class);
+ }
+
+ public List<RecenteChannel> loadByLastAccess(long max) {
+ try {
+ return queryBuilder().orderBy("lastAccess", false).limit(max).query();
+ } catch (SQLException e) {
+ Log.w(TAG, e.getMessage(), e);
+ return new ArrayList<RecenteChannel>(0);
+ }
+ }
+
+ public List<RecenteChannel> loadByRecentUse(long max) {
+ try {
+ return queryBuilder().orderBy("count", false).limit(max).query();
+ } catch (SQLException e) {
+ Log.w(TAG, e.getMessage(), e);
+ return new ArrayList<RecenteChannel>(0);
+ }
+ }
+
+ public RecenteChannel queryForId(String id) {
+ try {
+ return super.queryForId(id);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public List<Channel> getRecentChannels(Map<String, Channel> all, List<RecenteChannel> recents){
+
+ List<Channel> filtered = new ArrayList<Channel>();
+ for(RecenteChannel rc : recents){
+ Channel c = all.get(rc.getChannelId());
+ if(c == null){
+ try {
+ delete(rc);
+ } catch (SQLException e) {
+ Log.w(TAG, e.getMessage(), e);
+ }
+ } else {
+ filtered.add(c);
+ }
+ }
+ return filtered;
+ }
+
+ public CreateOrUpdateStatus createOrUpdate(RecenteChannel data) {
+ try {
+ return super.createOrUpdate(data);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void hit(String channelId) {
+ RecenteChannel rc = queryForId(channelId);
+
+ if (rc == null) {
+ rc = new RecenteChannel();
+ rc.setChannelId(channelId);
+ }
+ rc.touch();
+ rc.incUse();
+ createOrUpdate(rc);
+ }
+
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/RecenteChannel.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/RecenteChannel.java
new file mode 100644
index 0000000..b747537
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/RecenteChannel.java
@@ -0,0 +1,59 @@
+package de.bjusystems.vdrmanager.data;
+
+import java.util.Date;
+
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+@DatabaseTable(daoClass=RecentChannelDAO.class)
+public class RecenteChannel {
+
+ @DatabaseField(id=true, generatedId = false)
+ private String channelId;
+
+ @DatabaseField
+ private long count = 0;
+
+ @DatabaseField
+ private Date lastAccess;
+
+ public Date getLastAccess() {
+ return lastAccess;
+ }
+
+ public void setLastAccess(Date lastAccess) {
+ this.lastAccess = lastAccess;
+ }
+
+ public long getCount() {
+ return count;
+ }
+
+ public void setCount(long count) {
+ this.count = count;
+ }
+
+ public String getChannelId() {
+ return channelId;
+ }
+
+ public void setChannelId(String channelId) {
+ this.channelId = channelId;
+ }
+
+ public void incUse(){
+ count++;
+ }
+
+ public void touch(){
+ lastAccess = new Date();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("[id="+channelId +", count="+count+", lastAccess=" + lastAccess);
+ return super.toString();
+ }
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
index 9d1d6d9..6b8dd09 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timer.java
@@ -71,7 +71,7 @@ public class Timer extends Event implements Timerable {
// flags, channel number and channel name
this.flags = Integer.valueOf(values[1]);
- this.channelNumber = values[2];
+ this.channelNumber = Long.valueOf(values[2]);
this.channelName = Utils.mapSpecialChars(values[3]);
// get start and stop
@@ -239,4 +239,13 @@ public class Timer extends Event implements Timerable {
public Timer createTimer() {
return new Timer(this);
}
+
+
+ @Override
+ public TimerMatch getTimerMatch() {
+ return TimerMatch.Full;
+ }
+
+
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/TimerMatch.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/TimerMatch.java
new file mode 100644
index 0000000..72cc52c
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/TimerMatch.java
@@ -0,0 +1,7 @@
+package de.bjusystems.vdrmanager.data;
+
+public enum TimerMatch {
+ Full, //
+ Begin, //
+ End//
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timerable.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timerable.java
index f3f648e..aa371ed 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Timerable.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Timerable.java
@@ -11,10 +11,12 @@ public interface Timerable {
Recorded
;
}
-
+
public Timer createTimer();
-
+
public abstract Timer getTimer();
public TimerState getTimerState();
+
+ public TimerMatch getTimerMatch();
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DBAccess.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DBAccess.java
index f0c788b..b1f02fc 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DBAccess.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DBAccess.java
@@ -8,11 +8,15 @@ import android.util.Log;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import de.bjusystems.vdrmanager.R;
+import de.bjusystems.vdrmanager.data.RecentChannelDAO;
+import de.bjusystems.vdrmanager.data.RecenteChannel;
import de.bjusystems.vdrmanager.data.Vdr;
/**
@@ -21,23 +25,24 @@ import de.bjusystems.vdrmanager.data.Vdr;
* classes.
*/
public class DBAccess extends OrmLiteSqliteOpenHelper {
-
+
public static final String TAG = DBAccess.class.getName();
// name of the database file for your application -- change to something
// appropriate for your app
public static final String DATABASE_NAME = "vdrmanager.db";
// any time you make changes to your database objects, you may have to
// increase the database version
- private static final int DATABASE_VERSION = 2;
+ // Version 3 since 0.6
+ private static final int DATABASE_VERSION = 3;
private RuntimeExceptionDao<Vdr, Integer> vdrDAO = null;
+ private RecentChannelDAO recentChannelDAO = null;
-
- public static String getDataBaseFile(){
+ public static String getDataBaseFile() {
return "/data/data/de.bjusystems.vdrmanager/databases/" + DATABASE_NAME;
}
-
+
public DBAccess(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION,
R.raw.ormlite_config);
@@ -53,6 +58,7 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
try {
Log.i(DBAccess.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, Vdr.class);
+ TableUtils.createTable(connectionSource, RecenteChannel.class);
} catch (SQLException e) {
Log.e(DBAccess.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
@@ -68,17 +74,22 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
int oldVersion, int newVersion) {
try {
- Log.i(DBAccess.class.getName(), "onUpgrade");
- TableUtils.dropTable(connectionSource, Vdr.class, true);
+
+ // Log.i(DBAccess.class.getName(), "onUpgrade");
+ // TableUtils.dropTable(connectionSource, Vdr.class, true);
// after we drop the old databases, we create the new ones
- onCreate(db, connectionSource);
+ // onCreate(db, connectionSource);
+
+ if (oldVersion < 3) {
+ TableUtils.createTable(connectionSource, RecenteChannel.class);
+ }
+
} catch (SQLException e) {
Log.e(DBAccess.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
-
/**
* Close the database connections and clear any cached DAOs.
*/
@@ -87,14 +98,11 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
super.close();
vdrDAO = null;
}
-
static volatile DBAccess helper;
static volatile boolean created = false;
static volatile boolean destroyed = false;
-
-
-
+
/**
* Get a helper for this action.
*/
@@ -104,16 +112,17 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
helper = getHelperInternal(ctx);
created = true;
}
-
-
+
if (helper == null) {
if (!created) {
- throw new IllegalStateException("A call has not been made to onCreate() yet so the helper is null");
+ throw new IllegalStateException(
+ "A call has not been made to onCreate() yet so the helper is null");
} else if (destroyed) {
throw new IllegalStateException(
"A call to onDestroy has already been made and the helper cannot be used after that point");
} else {
- throw new IllegalStateException("Helper is null for some unknown reason");
+ throw new IllegalStateException(
+ "Helper is null for some unknown reason");
}
} else {
return helper;
@@ -127,31 +136,36 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
return get(ctx).getConnectionSource();
}
-
/**
- * This is called internally by the class to populate the helper object instance. This should not be called directly
- * by client code unless you know what you are doing. Use {@link #getHelper()} to get a helper instance. If you are
- * managing your own helper creation, override this method to supply this activity with a helper instance.
- *
+ * This is called internally by the class to populate the helper object
+ * instance. This should not be called directly by client code unless you
+ * know what you are doing. Use {@link #getHelper()} to get a helper
+ * instance. If you are managing your own helper creation, override this
+ * method to supply this activity with a helper instance.
+ *
* <p>
- * <b> NOTE: </b> If you override this method, you most likely will need to override the
- * {@link #releaseHelper(OrmLiteSqliteOpenHelper)} method as well.
+ * <b> NOTE: </b> If you override this method, you most likely will need to
+ * override the {@link #releaseHelper(OrmLiteSqliteOpenHelper)} method as
+ * well.
* </p>
*/
protected static DBAccess getHelperInternal(Context context) {
@SuppressWarnings({ "unchecked", "deprecation" })
- DBAccess newHelper = (DBAccess) OpenHelperManager.getHelper(context, DBAccess.class);
- logger.trace("{}: got new helper {} from OpenHelperManager", "", newHelper);
+ DBAccess newHelper = (DBAccess) OpenHelperManager.getHelper(context,
+ DBAccess.class);
+ logger.trace("{}: got new helper {} from OpenHelperManager", "",
+ newHelper);
return newHelper;
}
/**
- * Release the helper instance created in {@link #getHelperInternal(Context)}. You most likely will not need to call
- * this directly since {@link #onDestroy()} does it for you.
- *
+ * Release the helper instance created in
+ * {@link #getHelperInternal(Context)}. You most likely will not need to
+ * call this directly since {@link #onDestroy()} does it for you.
+ *
* <p>
- * <b> NOTE: </b> If you override this method, you most likely will need to override the
- * {@link #getHelperInternal(Context)} method as well.
+ * <b> NOTE: </b> If you override this method, you most likely will need to
+ * override the {@link #getHelperInternal(Context)} method as well.
* </p>
*/
protected void releaseHelper(DBAccess helper) {
@@ -161,10 +175,25 @@ public class DBAccess extends OrmLiteSqliteOpenHelper {
}
public RuntimeExceptionDao<Vdr, Integer> getVdrDAO() {
- if(vdrDAO == null){
+ if (vdrDAO == null) {
vdrDAO = getRuntimeExceptionDao(Vdr.class);
}
return vdrDAO;
}
-
+
+ public RecentChannelDAO getRecentChannelDAO() {
+ if (recentChannelDAO == null) {
+ try {
+ recentChannelDAO = getDao(RecenteChannel.class);
+ } catch (SQLException e) {
+ throw new RuntimeException(
+ "Could not create RuntimeExcepitionDao for class "
+ + RecenteChannel.class, e);
+ }
+
+ }
+
+ return recentChannelDAO;
+ }
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
index 36c7633..5e43e92 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
@@ -5,27 +5,27 @@ import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
-import android.view.Gravity;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
-import android.widget.Toast;
import android.widget.ViewFlipper;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Preferences;
-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.SvdrpExceptionListener;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpListener;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpResultListener;
-public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseActivity
- implements OnClickListener, SvdrpAsyncListener<Result>, Cache {
+public abstract class BaseActivity<Result, T extends ListView> extends
+ ICSBaseActivity implements OnClickListener,
+ SvdrpResultListener<Result>, SvdrpListener, SvdrpExceptionListener,
+ Cache {
public static final String TAG = BaseActivity.class.getName();
@@ -91,6 +91,7 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
Preferences.setLocale(this);
super.onConfigurationChanged(newConfig);
}
+
@Override
protected void onResume() {
Preferences.setLocale(this);
@@ -128,7 +129,6 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
// setTitle(title);
// }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -150,7 +150,8 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
}
@Override
- public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.Menu menu) {
+ public boolean onCreateOptionsMenu(
+ final com.actionbarsherlock.view.Menu menu) {
// MenuItem item;
// item = menu.add(MENU_GROUP_REFRESH, MENU_REFRESH, 0,
@@ -174,7 +175,8 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
abstract protected SvdrpClient<Result> getClient();
@Override
- public boolean onOptionsItemSelected(final com.actionbarsherlock.view.MenuItem item) {
+ public boolean onOptionsItemSelected(
+ final com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.list_refresh:
backupViewSelection();
@@ -237,7 +239,7 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
}
protected void alert(String msg) {
- if(isFinishing()){
+ if (isFinishing()) {
return;
}
new AlertDialog.Builder(this)//
@@ -272,7 +274,23 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
return false;
}
- public void svdrpEvent(final SvdrpEvent event, final Result result) {
+ public void svdrpEvent(Result result) {
+ resultReceived(result);
+ }
+
+ @Override
+ public void svdrpEvent(SvdrpEvent event, Throwable t) {
+ Utils.say(this, t.getLocalizedMessage());
+ }
+
+ protected void addListener(SvdrpAsyncTask<Result, SvdrpClient<Result>> task) {
+ task.addSvdrpExceptionListener(this);
+ task.addSvdrpResultListener(this);
+ task.addSvdrpListener(this);
+ }
+
+ @Override
+ public void svdrpEvent(final SvdrpEvent event) {
switch (event) {
case LOGIN:
@@ -296,13 +314,13 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
case DISCONNECTED:
break;
case ABORTED:
+ progress.dismiss();
say(R.string.aborted);
break;
case ERROR:
- alert(R.string.epg_client_errors);
progress.dismiss();
+ alert(R.string.epg_client_errors);
break;
-
case CONNECTED:
connected();
break;
@@ -314,23 +332,24 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
noConnection(event);
break;
case CACHE_HIT:
- cacheHit();
progress.dismiss();
+ cacheHit();
return;
case FINISHED_SUCCESS:
-
+ progress.dismiss();
if (finishedSuccess()) {
finishedSuccess = true;
restoreViewSelection();
} else {
say(R.string.epg_no_items);
}
- progress.dismiss();
- break;
- case RESULT_RECEIVED:
- resultReceived(result);
+
break;
}
+ // case RESULT_RECEIVED:
+ // resultReceived(result);
+ // break;
+ // }
}
private void setMessage(int progressConnect) {
@@ -354,7 +373,10 @@ public abstract class BaseActivity<Result, T extends ListView> extends ICSBaseAc
protected abstract void resultReceived(Result result);
protected void connected() {
-
+ if (flipper != null) {
+ flipper.setDisplayedChild(0);
+ }
+ // results.clear();
}
public void svdrpException(final SvdrpException exception) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java
index e78c3b8..dbc7826 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java
@@ -14,8 +14,6 @@ import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
-import android.view.Menu;
-import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
@@ -28,7 +26,10 @@ import de.bjusystems.vdrmanager.app.Intents;
import de.bjusystems.vdrmanager.data.Channel;
import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
+import de.bjusystems.vdrmanager.data.P;
+import de.bjusystems.vdrmanager.data.Preferences;
import de.bjusystems.vdrmanager.gui.SimpleGestureFilter.SimpleGestureListener;
+import de.bjusystems.vdrmanager.tasks.VoidAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.EpgClient;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
@@ -50,7 +51,6 @@ public abstract class BaseEventListActivity<T extends Event> extends
public static final int MENU_TO_CAL = 91;
-
private SimpleGestureFilter detector;
protected EpgClient epgClient;
@@ -69,15 +69,18 @@ public abstract class BaseEventListActivity<T extends Event> extends
AlertDialog sortByDialog = null;
- public static final int MENU_GROUP_TIME = 0;
+ public static final int MENU_GROUP_DEFAULT = 0;
public static final int MENU_GROUP_ALPHABET = 1;
- private int sortBy = MENU_GROUP_TIME;
+ protected int sortBy;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ sortBy = Preferences.get(this, getViewID() + "_"
+ + P.EPG_LAST_SORT, MENU_GROUP_DEFAULT);
// Attach view
setContentView(getMainLayout());
setTitle(getWindowTitle());
@@ -109,7 +112,8 @@ public abstract class BaseEventListActivity<T extends Event> extends
* .view.Menu)
*/
@Override
- public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.Menu menu) {
+ public boolean onCreateOptionsMenu(
+ final com.actionbarsherlock.view.Menu menu) {
super.onCreateOptionsMenu(menu);
final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
@@ -168,11 +172,14 @@ public abstract class BaseEventListActivity<T extends Event> extends
return true;
}
- private String[] getAvailableSortByEntries() {
- ArrayList<String> entries = new ArrayList<String>(2);
- entries.add(getString(R.string.sortby_time));
- entries.add(getString(R.string.sortby_alphabet));
- return entries.toArray(Utils.EMPTY);
+
+
+ protected int getAvailableSortByEntries() {
+ return 0;
+ }
+
+ protected void fillAdapter() {
+
}
/*
@@ -182,7 +189,8 @@ public abstract class BaseEventListActivity<T extends Event> extends
* de.bjusystems.vdrmanager.gui.BaseActivity#onOptionsItemSelected(android
* .view.MenuItem)
*/
- public boolean onOptionsItemSelected(final com.actionbarsherlock.view.MenuItem item) {
+ public boolean onOptionsItemSelected(
+ final com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.epg_list_menu_channels:
@@ -199,11 +207,33 @@ public abstract class BaseEventListActivity<T extends Event> extends
sortBy, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
+
+ if (sortBy == which) {
+ sortByDialog.dismiss();
+ return;
+ }
+
sortBy = which;
- // fillAdapter();
- adapter.sort(sortBy);
+
+ new VoidAsyncTask() {
+
+ @Override
+ protected Void doInBackground(
+ Void... params) {
+ Preferences
+ .set(BaseEventListActivity.this,
+ getViewID()
+ + "_"
+ + P.EPG_LAST_SORT,
+ sortBy);
+ return null;
+ }
+ }.execute();
+
sortByDialog.dismiss();
+ fillAdapter();
}
+
}).create();
}
@@ -308,14 +338,6 @@ public abstract class BaseEventListActivity<T extends Event> extends
}
@Override
- protected void connected() {
- if (flipper != null) {
- flipper.setDisplayedChild(0);
- }
- results.clear();
- }
-
- @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int index = savedInstanceState.getInt("INDEX");
@@ -365,12 +387,12 @@ public abstract class BaseEventListActivity<T extends Event> extends
}
- protected void sortItemsByChannel(List<T> result) {
- final Comparator<T> comparator = new Comparator<T>() {
+ protected void sortItemsByChannel(List<Event> result) {
+ final Comparator<Event> comparator = new Comparator<Event>() {
- public int compare(final T item1, final T item2) {
- return Integer.valueOf(item1.getChannelNumber()).compareTo(
- Integer.valueOf(item2.getChannelNumber()));
+ public int compare(final Event item1, final Event item2) {
+ return item1.getChannelNumber().compareTo(
+ item2.getChannelNumber());
}
};
Collections.sort(result, comparator);
@@ -380,11 +402,57 @@ public abstract class BaseEventListActivity<T extends Event> extends
sortItemsByTime(result, false);
}
- class BaseEventComparator implements Comparator<T> {
+ protected void sortItemsByTime(List<T> result, final boolean reverse) {
+ Collections.sort(result, new TimeAndChannelComparator(reverse));
+ }
+
+ public void svdrpException(final SvdrpException exception) {
+ Log.w(TAG, exception);
+ alert(getString(R.string.vdr_error_text, exception.getMessage()));
+ }
+
+ abstract protected boolean finishedSuccessImpl();
+
+ protected String getViewID(){
+ return this.getClass().getSimpleName();
+ }
+
+ protected final synchronized boolean finishedSuccess() {
+ setTitle(getString(R.string.epg_window_title_count, getWindowTitle(),
+ results.size()));
+ try {
+ return finishedSuccessImpl();
+ } finally {
+ results.clear();
+ }
+ }
+
+ @Override
+ protected boolean displayingResults() {
+ return results.isEmpty() == false;
+ }
+
+ class TitleComparator implements Comparator<Event> {
+
+ @Override
+ public int compare(Event lhs, Event rhs) {
+ if (lhs == null || lhs.getTitle() == null) {
+ return 1;
+ }
+ if (rhs == null || rhs.getTitle() == null) {
+ return 0;
+ }
+ return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ }
+ };
+
+ class TimeAndChannelComparator implements Comparator<T> {
boolean r = false;
- BaseEventComparator(boolean r){
+
+ TimeAndChannelComparator(boolean r) {
this.r = r;
}
+
public int compare(final T item1, final T item2) {
int c = item1.getStart().compareTo(item2.getStart());
@@ -403,36 +471,45 @@ public abstract class BaseEventListActivity<T extends Event> extends
if (item2.getChannelNumber() == null) {
return -1;
}
- return Integer.valueOf(item1.getChannelNumber()).compareTo(
- Integer.valueOf(item2.getChannelNumber()));
+ return item1.getChannelNumber().compareTo(item2.getChannelNumber());
}
}
- protected void sortItemsByTime(List<T> result, final boolean reverse) {
+ class TimeComparator implements Comparator<Event> {
+ boolean r = false;
- Collections.sort(result, getTimeComparator(reverse));
- }
+ TimeComparator(boolean r) {
+ this.r = r;
+ }
- protected Comparator<? super T> getTimeComparator(boolean reverse) {
- return new BaseEventComparator(reverse);
- }
+ public int compare(final Event item1, final Event item2) {
- public void svdrpException(final SvdrpException exception) {
- Log.w(TAG, exception);
- alert(getString(R.string.vdr_error_text, exception.getMessage()));
+ int c = item1.getStart().compareTo(item2.getStart());
+ if (c == 0) {
+ return c;
+ }
+ if (r == false)
+ return c;
+ return -1 * c;
+ }
}
- abstract protected boolean finishedSuccessImpl();
+ class ChannelComparator implements Comparator<Event> {
- protected final boolean finishedSuccess() {
- setTitle(getString(R.string.epg_window_title_count, getWindowTitle(),
- results.size()));
- return finishedSuccessImpl();
- }
+ public int compare(final Event item1, final Event item2) {
- @Override
- protected boolean displayingResults() {
- return results.isEmpty() == false;
+ if (item1.getChannelNumber() == null
+ && item2.getChannelNumber() == null) {
+ return 0;
+ }
+ if (item1.getChannelNumber() == null) {
+ return 1;
+ }
+ if (item2.getChannelNumber() == null) {
+ return -1;
+ }
+ return item1.getChannelNumber().compareTo(item2.getChannelNumber());
+ }
}
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java
index 02c0b65..289dc63 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java
@@ -45,8 +45,10 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
private int groupBy = -1;
+ private boolean reverse = false;
+
public void fill(ArrayList<String> groups,
- Map<String, ArrayList<Channel>> data, int groupBy) {
+ Map<String, ArrayList<Channel>> data, int groupBy, boolean reverse) {
this.groupBy = groupBy;
this.groups.clear();
this.groups.addAll(groups);
@@ -104,6 +106,8 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
itemHolder.aux.setText(item.getGroup());
} else if(groupBy == ChannelListActivity.MENU_GROUP) {
itemHolder.aux.setText(item.getProvider());
+ } else if(groupBy== ChannelListActivity.MENU_SOURCE){
+ itemHolder.aux.setText(item.getSource());
} else {
itemHolder.aux.setText(item.getProvider());
}
@@ -179,6 +183,8 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
private String groupFilter = null;
+ private String sourceFilter = null;
+
private String channelFilter = null;
public Filter getFilter() {
@@ -199,7 +205,7 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
.getGroupChannels().get(str));
}
}
-
+
} else if (groupBy == ChannelListActivity.MENU_PROVIDER) {
groupFilter = String.valueOf(arg0).toLowerCase();
for (Map.Entry<String, ArrayList<Channel>> p : ChannelClient
@@ -212,6 +218,17 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
}
}
+ } else if(groupBy == ChannelListActivity.MENU_SOURCE) {
+ sourceFilter = String.valueOf(arg0).toLowerCase();
+ for (Map.Entry<String, ArrayList<Channel>> p : ChannelClient
+ .getSourceChannels().entrySet()) {
+ String pr = p.getKey();
+ String g = pr.toLowerCase();
+ if (g.indexOf(q) != -1) {
+ groups.add(pr);
+ groupChannels.put(pr, p.getValue());
+ }
+ }
} else {
channelFilter = String.valueOf(arg0).toLowerCase();
ArrayList<Channel> channels = new ArrayList<Channel>();
@@ -233,7 +250,7 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// ,
@Override
protected void publishResults(CharSequence arg0, FilterResults arg1) {
Pair<ArrayList<String>, HashMap<String, ArrayList<Channel>>> res = (Pair<ArrayList<String>, HashMap<String, ArrayList<Channel>>>) arg1.values;
- fill(res.first, res.second, groupBy);
+ fill(res.first, res.second, groupBy, reverse);
}
};
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
index d83ca5b..f126baf 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java
@@ -2,8 +2,6 @@ package de.bjusystems.vdrmanager.gui;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
@@ -29,12 +27,14 @@ import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.TextView;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Channel;
+import de.bjusystems.vdrmanager.data.P;
import de.bjusystems.vdrmanager.data.Preferences;
+import de.bjusystems.vdrmanager.data.RecenteChannel;
+import de.bjusystems.vdrmanager.data.db.DBAccess;
import de.bjusystems.vdrmanager.tasks.VoidAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient;
-import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
/**
* This class is used for showing what's current running on all channels
@@ -53,15 +53,21 @@ public class ChannelListActivity extends
Preferences prefs;
- private static final LinkedList<Channel> RECENT = new LinkedList<Channel>();
+ // private static final LinkedList<Channel> RECENT = new
+ // LinkedList<Channel>();
public static final int MENU_GROUP = 0;
public static final int MENU_PROVIDER = 1;
- public static final int MENU_NAME = 2;
+ public static final int MENU_SOURCE = 2;
+ public static final int MENU_NAME = 3;
- private int groupBy = MENU_GROUP;
+ public static final boolean GROUP_NATURAL = false;
- private int groupByInverse = 0;
+ public static final boolean GROUP_REVERSE = true;
+
+ private int groupBy;
+
+ private boolean groupByReverse;
final static ArrayList<String> ALL_CHANNELS_GROUP = new ArrayList<String>(1);
@@ -78,6 +84,11 @@ public class ChannelListActivity extends
setContentView(getMainLayout());
setTitle(getWindowTitle());
initFlipper();
+
+ groupBy = Preferences.get(this, P.CHANNELS_LAST_ORDER, MENU_GROUP);
+ groupByReverse = Preferences.get(this, P.CHANNELS_LAST_ORDER_REVERSE,
+ GROUP_NATURAL);
+
adapter = new ChannelAdapter(this);
listView = (ExpandableListView) findViewById(R.id.channel_list);
@@ -108,14 +119,14 @@ public class ChannelListActivity extends
return;
}
- if(channelClient == null){
+ if (channelClient == null) {
// get channel task
channelClient = new ChannelClient();
} else {
channelClient.removeSvdrpListener(this);
}
- if(useCache == false){
+ if (useCache == false) {
ChannelClient.clearCache();
}
@@ -123,27 +134,28 @@ public class ChannelListActivity extends
final SvdrpAsyncTask<Channel, SvdrpClient<Channel>> task = new SvdrpAsyncTask<Channel, SvdrpClient<Channel>>(
channelClient);
- task.addListener(this);
+ task.addSvdrpExceptionListener(this);
+ task.addSvdrpResultListener(this);
+ task.addSvdrpListener(this);
// start task
task.run();
}
static RecentChannelsAdapter RECENT_ADAPTER = null;
-
- static class RecentChannelsAdapter extends ArrayAdapter<Channel>{
+ static class RecentChannelsAdapter extends ArrayAdapter<Channel> {
private Activity context;
int resId;
- public RecentChannelsAdapter(Activity context, List<Channel> list) {
- super(context, android.R.layout.simple_list_item_1, list);
+ public RecentChannelsAdapter(Activity context) {
+ super(context, android.R.layout.simple_list_item_1);
this.context = context;
showChannelNumbers = Preferences.get().isShowChannelNumbers();
if (Build.VERSION.SDK_INT < 11) {
resId = android.R.layout.select_dialog_item;
} else {
- resId = android.R.layout.simple_list_item_1;
+ resId = android.R.layout.simple_list_item_1;
}
}
@@ -154,8 +166,7 @@ public class ChannelListActivity extends
TextView text1;
View view = convertView;
if (view == null) {
- view = this.context.getLayoutInflater().inflate(
- resId, null);
+ view = this.context.getLayoutInflater().inflate(resId, null);
text1 = (TextView) view.findViewById(android.R.id.text1);
view.setTag(text1);
} else {
@@ -163,7 +174,8 @@ public class ChannelListActivity extends
}
Channel c = getItem(position);
- String text = showChannelNumbers ? text = c.toString() : c.getName();
+ String text = showChannelNumbers ? text = c.toString() : c
+ .getName();
text1.setText(text);
return view;
@@ -171,14 +183,14 @@ public class ChannelListActivity extends
}
private ArrayAdapter<Channel> getRecentAdapter() {
- if (RECENT_ADAPTER != null)
- {
- RECENT_ADAPTER.showChannelNumbers = Preferences.get().isShowChannelNumbers();
+ if (RECENT_ADAPTER != null) {
+ RECENT_ADAPTER.showChannelNumbers = Preferences.get()
+ .isShowChannelNumbers();
RECENT_ADAPTER.notifyDataSetChanged();
return RECENT_ADAPTER;
}
- RECENT_ADAPTER = new RecentChannelsAdapter(this, RECENT);
+ RECENT_ADAPTER = new RecentChannelsAdapter(this);
return RECENT_ADAPTER;
}
@@ -192,7 +204,8 @@ public class ChannelListActivity extends
switch (groupBy) {
case MENU_GROUP:
ArrayList<String> cgs = ChannelClient.getChannelGroups();
- adapter.fill(cgs, ChannelClient.getGroupChannels(), groupBy);
+ adapter.fill(cgs, ChannelClient.getGroupChannels(), groupBy,
+ groupByReverse);
if (cgs.size() == 1) {// one group or first no first group
listView.expandGroup(0);
} else if ((cgs.size() > 1 && TextUtils.isEmpty(cgs.get(0)))) {
@@ -200,10 +213,25 @@ public class ChannelListActivity extends
}
updateWindowTitle();
break;
+
+ case MENU_SOURCE:
+ ArrayList<String> css = ChannelClient.getChannelSources();
+ adapter.fill(css, ChannelClient.getSourceChannels(), groupBy,
+ groupByReverse);
+ if (css.size() == 1) {// one group or first no first group
+ listView.expandGroup(0);
+ } else if ((css.size() > 1 && TextUtils.isEmpty(css.get(0)))) {
+ listView.expandGroup(0);
+ }
+ updateWindowTitle();
+ break;
+
+
case MENU_PROVIDER:
ArrayList<String> gs = new ArrayList<String>(ChannelClient
.getProviderChannels().keySet());
- adapter.fill(gs, ChannelClient.getProviderChannels(), groupBy);
+ adapter.fill(gs, ChannelClient.getProviderChannels(), groupBy,
+ groupByReverse);
if (gs.size() == 1) {
listView.expandGroup(0);
}
@@ -218,10 +246,11 @@ public class ChannelListActivity extends
1);
channels.put(getString(R.string.groupby_name_all_channels_group),
ChannelClient.getChannels());
- adapter.fill(ALL_CHANNELS_GROUP, channels, groupBy);
+ adapter.fill(ALL_CHANNELS_GROUP, channels, groupBy, groupByReverse);
listView.expandGroup(0);
updateWindowTitle();
}
+ adapter.notifyDataSetChanged();
}
public boolean onPrepareOptionsMenu(com.actionbarsherlock.view.Menu menu) {
@@ -229,7 +258,8 @@ public class ChannelListActivity extends
}
@Override
- public final boolean onCreateOptionsMenu(final com.actionbarsherlock.view.Menu menu) {
+ public final boolean onCreateOptionsMenu(
+ final com.actionbarsherlock.view.Menu menu) {
super.onCreateOptionsMenu(menu);
final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
@@ -238,20 +268,15 @@ public class ChannelListActivity extends
return true;
}
-
-
- private String[] getAvailableGroupByEntries() {
- ArrayList<String> entries = new ArrayList<String>(2);
- entries.add(getString(R.string.groupby_group));
- entries.add(getString(R.string.groupby_provider));
- entries.add(getString(R.string.groupby_name));
- return entries.toArray(Utils.EMPTY);
+ private int getAvailableGroupByEntries() {
+ return R.array.channels_group_by;
}
AlertDialog groupByDialog = null;
@Override
- public boolean onOptionsItemSelected(final com.actionbarsherlock.view.MenuItem item) {
+ public boolean onOptionsItemSelected(
+ final com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.channels_groupby:
@@ -265,7 +290,37 @@ public class ChannelListActivity extends
groupBy, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
+
+ final boolean reversed = which == groupBy ? true
+ : false;
groupBy = which;
+ new VoidAsyncTask() {
+
+ @Override
+ protected Void doInBackground(
+ Void... params) {
+
+ if (reversed) {
+ if (groupByReverse == true) {
+ groupByReverse = false;
+ } else {
+ groupByReverse = true;
+ }
+ Preferences
+ .set(ChannelListActivity.this,
+ P.CHANNELS_LAST_ORDER_REVERSE,
+ groupByReverse);
+
+ } else {
+ Preferences
+ .set(ChannelListActivity.this,
+ P.CHANNELS_LAST_ORDER,
+ groupBy);
+ }
+ return null;
+ }
+ }.execute();
+
fillAdapter();
groupByDialog.dismiss();
}
@@ -276,26 +331,58 @@ public class ChannelListActivity extends
return true;
case R.id.channels_recent_channels:
- if (RECENT.isEmpty()) {
+
+ String order = Preferences.get(ChannelListActivity.this,
+ "gui_recent_channels_order", "most");
+
+ List<RecenteChannel> rcs = null;
+
+ if (order.equals("most")) {
+ rcs = DBAccess
+ .get(ChannelListActivity.this)
+ .getRecentChannelDAO()
+ .loadByRecentUse(
+ Preferences.get().getMaxRecentChannels());
+ } else if (order.equals("last")) {
+ rcs = DBAccess
+ .get(ChannelListActivity.this)
+ .getRecentChannelDAO()
+ .loadByLastAccess(
+ Preferences.get().getMaxRecentChannels());
+ } else {
+ return true;
+ }
+
+ if (rcs.isEmpty()) {
say(R.string.recent_channels_no_history);
return true;
}
- if(Preferences.get().getMaxRecentChannels() <= 0){
- RECENT.clear();
+ if (Preferences.get().getMaxRecentChannels() <= 0) {
say(R.string.recent_channels_no_history);
return true;
}
+ final ArrayAdapter<Channel> recentAdapter = getRecentAdapter();
+
+ recentAdapter.clear();
+ for (Channel c : DBAccess.get(ChannelListActivity.this)
+ .getRecentChannelDAO()
+ .getRecentChannels(channelClient.getIdChannels(), rcs)) {
+ recentAdapter.add(c);
+ }
+
new AlertDialog.Builder(this)
.setTitle(R.string.recent_channels)
- .setAdapter(getRecentAdapter(), new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int which) {
- Channel c = RECENT.get(which);
- startChannelEPG(c);
- }
- })//
+ .setAdapter(getRecentAdapter(),
+ new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog,
+ int which) {
+ Channel c = recentAdapter.getItem(which);
+ startChannelEPG(c);
+ }
+ })//
.create().show();
return true;
default:
@@ -369,8 +456,6 @@ public class ChannelListActivity extends
break;
}
-
-
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView
@@ -401,23 +486,13 @@ public class ChannelListActivity extends
@Override
protected Void doInBackground(Void... arg0) {
int max = Preferences.get().getMaxRecentChannels();
- if(max <= 0){
+ if (max <= 0) {
return null;
}
- Iterator<Channel> i = RECENT.iterator();
- while (i.hasNext()) {
- Channel c = i.next();
- if (c.equals(channel)) {
- i.remove();
- break;
- }
- }
- if (RECENT.size() >= Preferences.get().getMaxRecentChannels()) {
- RECENT.removeLast();
+ DBAccess.get(ChannelListActivity.this).getRecentChannelDAO()
+ .hit(channel.getId());
- }
- RECENT.addFirst(channel);
return (Void) null;
}
}.execute((Void) null);
@@ -479,7 +554,16 @@ public class ChannelListActivity extends
.append(getString(R.string.groupby_window_title_templte,
getString(R.string.groupby_group)));
break;
+
+ case MENU_SOURCE: {
+ sb.append(getString(R.string.action_menu_channels))
+ .append(" > ")
+ .append(getString(R.string.groupby_window_title_templte,
+ getString(R.string.groupby_source)));
+ break;
}
+ }
+
return sb.toString();
}
@@ -490,7 +574,7 @@ public class ChannelListActivity extends
}
@Override
- protected boolean finishedSuccess() {
+ protected synchronized boolean finishedSuccess() {
fillAdapter();
restoreViewSelection();
updateWindowTitle();
@@ -520,8 +604,4 @@ public class ChannelListActivity extends
return channelClient;
}
- public void svdrpEvent(SvdrpEvent event, Channel result){
- super.svdrpEvent(event, result);
- }
-
} \ No newline at end of file
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
index 33a2fc9..4c22597 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java
@@ -444,7 +444,7 @@ public class EpgDetailsActivity extends ICSBaseActivity implements OnClickListen
if(cEvent instanceof Recording){
Utils.streamRecording(this, (Recording)cEvent);
} else {
- Utils.stream(this, cEvent.getChannelNumber());
+ Utils.stream(this, String.valueOf(cEvent.getChannelNumber()));
}
break;
case R.id.epg_event_create_timer:
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
index f0e3945..b9c426b 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java
@@ -20,7 +20,6 @@ import de.bjusystems.vdrmanager.data.Preferences;
import de.bjusystems.vdrmanager.data.db.EPGSearchSuggestionsProvider;
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;
@@ -30,7 +29,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient;
* @author bju
*/
public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements
- OnItemClickListener, SvdrpAsyncListener<Epg> {
+ OnItemClickListener {
private void initSearch(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
@@ -106,7 +105,7 @@ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements
epgClient);
// create progress
- task.addListener(this);
+ addListener(task);
// start task
task.run();
@@ -137,7 +136,7 @@ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements
adapter.add(new EventListItem((Epg) e));
}
listView.setSelectionAfterHeaderView();
- return results.isEmpty() == false;
+ return adapter.getCount() > 0;
}
protected void prepareDetailsViewData(final EventListItem item) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
index 052192f..a1a7775 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java
@@ -21,6 +21,7 @@ import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventFormatter;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.data.Recording;
+import de.bjusystems.vdrmanager.data.TimerMatch;
import de.bjusystems.vdrmanager.data.Timerable;
abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
@@ -38,15 +39,14 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
String highlight;
- /**
- * Lock used to modify the content of {@link #mObjects}. Any write operation
- * performed on the array should be synchronized on this lock. This lock is also
- * used by the filter (see {@link #getFilter()} to make a synchronized copy of
- * the original array of data.
- */
- private final Object _Lock = new Object();
+ /**
+ * Lock used to modify the content of {@link #mObjects}. Any write operation
+ * performed on the array should be synchronized on this lock. This lock is
+ * also used by the filter (see {@link #getFilter()} to make a synchronized
+ * copy of the original array of data.
+ */
+ private final Object _Lock = new Object();
-
public EventAdapter(final Context context, int layout) {
super(context, layout);
this.layout = layout;
@@ -63,51 +63,8 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
items.add(object);
super.add(object);
}
-
-
- void sort(int sortBy){
-
- ArrayList<EventListItem> events = new ArrayList<EventListItem>(items);
-
- if(sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET){
-
- Collections.sort(events, new Comparator<EventListItem>() {
- @Override
- public int compare(EventListItem lhs, EventListItem rhs) {
- if(lhs == null || lhs.getTitle() == null){
- return 1;
- }
- if(rhs == null || rhs.getTitle() == null){
- return 0;
- }
- return lhs.getTitle().compareTo(rhs.getTitle());
- }
- });
-
- } else if(sortBy == BaseEventListActivity.MENU_GROUP_TIME) {
-
- Collections.sort(events, new Comparator<EventListItem>() {
- @Override
- public int compare(EventListItem lhs, EventListItem rhs) {
- if(lhs == null || lhs.getStart() == null){
- return 1;
- }
- if(rhs == null || rhs.getStart() == null){
- return 0;
- }
- return lhs.getStart().compareTo(rhs.getStart());
- }
- });
-
- }
-
- clear();
- for(EventListItem eli : events){
- add(eli);
- }
-
- notifyDataSetChanged();
- }
+
+
@Override
public int getItemViewType(int position) {
@@ -188,31 +145,45 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
return itemHolder;
}
+ private int getTimerStateDrawable(TimerMatch match, int full, int begin,
+ int end) {
+ if (match == TimerMatch.Full) {
+ return full;
+ }
+
+ if (match == TimerMatch.Begin) {
+ return begin;
+ }
+
+ return end;
+ }
+
public void fillEventViewHolder(EventListItemHolder itemHolder,
EventListItem item) {
-
-
-
-
+
+
+
+
itemHolder.state.setVisibility(View.VISIBLE);
-
+
if(item.getEvent() instanceof Timerable == false){
- itemHolder.state.setImageResource(R.drawable.timer_none);
+ itemHolder.state.setImageResource(R.drawable.timer_none);
} else if(item.getEvent() instanceof Recording){
if(Utils.isLive(item.getEvent())){
- itemHolder.state.setImageResource(R.drawable.timer_recording);
+ itemHolder.state.setImageResource(R.drawable.timer_recording);
}
} else {
+ TimerMatch match = ((Timerable)item.getEvent()).getTimerMatch();
switch (((Timerable)item.getEvent()).getTimerState()) {
case Active:
- itemHolder.state.setImageResource(R.drawable.timer_active);
+ itemHolder.state.setImageResource(getTimerStateDrawable(match, R.drawable.timer_active, R.drawable.timer_active_begin, R.drawable.timer_active_end));
break;
case Inactive:
- itemHolder.state.setImageResource(R.drawable.timer_inactive);
+ itemHolder.state.setImageResource(getTimerStateDrawable(match, R.drawable.timer_inactive, R.drawable.timer_inactive_begin, R.drawable.timer_inactive_end));
break;
case Recording:
- itemHolder.state.setImageResource(R.drawable.timer_recording);
+ itemHolder.state.setImageResource(getTimerStateDrawable(match, R.drawable.timer_recording, R.drawable.timer_recording_begin, R.drawable.timer_recording_end));
break;
case None:
itemHolder.state.setImageResource(R.drawable.timer_none);
@@ -296,11 +267,11 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements
}
// TODO implement locking in performFiltering, check the parent class
- //http://stackoverflow.com/questions/5846385/how-to-update-android-listview-with-dynamic-data-in-real-time
+ // http://stackoverflow.com/questions/5846385/how-to-update-android-listview-with-dynamic-data-in-real-time
public Filter getFilter() {
return new Filter() {
/**
- *
+ *
*/
EventListItem prevHead = null;
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
index eedcc76..91ef2d4 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java
@@ -2,7 +2,10 @@ package de.bjusystems.vdrmanager.gui;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Date;
+import java.util.List;
import android.content.Intent;
import android.os.Bundle;
@@ -18,8 +21,10 @@ 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.EpgSearchTimeValue;
import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventListItem;
+import de.bjusystems.vdrmanager.gui.BaseEventListActivity.TitleComparator;
import de.bjusystems.vdrmanager.tasks.ChannelsTask;
import de.bjusystems.vdrmanager.utils.date.DateFormatter;
import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient;
@@ -30,7 +35,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
/**
* This class is used for showing what's current running on all channels
- *
+ *
* @author bju
*/
public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
@@ -106,6 +111,15 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
}
+ @Override
+ protected int getAvailableSortByEntries() {
+ return R.array.epg_sort_by_time_alpha;
+ }
+
+ protected String getViewID() {
+ return EventEpgListActivity.class.getSimpleName();
+ }
+
private void startQuery() {
new ChannelsTask(this, new ChannelClient()) {
public void finished(SvdrpEvent event) {
@@ -136,6 +150,14 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
}
+ void sort() {
+ if (sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) {
+ Collections.sort(CACHE, new TitleComparator());
+ } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) {
+ Collections.sort(CACHE, new TimeComparator(false));
+ }
+ }
+
@Override
protected void onPause() {
super.onPause();
@@ -163,6 +185,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
private void clearCache() {
cachedChannel = null;
+ CACHE.clear();
}
private boolean useCache() {
@@ -230,7 +253,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
// create progress
- task.addListener(this);
+ addListener(task);
// start task
task.run();
@@ -241,23 +264,19 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
return this.epgClient;
}
- /*
- * (non-Javadoc) TODO this method also should be used in startEpgQuery on
- * cache hit
- *
- * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess()
- */
@Override
- synchronized protected boolean finishedSuccessImpl() {
- adapter.clear();
- CACHE.clear();
- Date now = new Date();
- nextForceCache = FUTURE;
+ protected void fillAdapter() {
+
+ if (CACHE.isEmpty()) {
+ return;
+ }
+
+ sort();
+
Calendar cal = Calendar.getInstance();
int day = -1;
- sortItemsByTime(results);
- for (Event e : results) {
- CACHE.add(e);
+ adapter.clear();
+ for (Event e : CACHE) {
cal.setTime(e.getStart());
int eday = cal.get(Calendar.DAY_OF_YEAR);
if (eday != day) {
@@ -266,12 +285,76 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements
.getDailyHeader()));
}
adapter.add(new EventListItem((Epg) e));
+ }
+
+
+ adapter.notifyDataSetChanged();
+
+ }
+
+ /*
+ * (non-Javadoc) TODO this method also should be used in startEpgQuery on
+ * cache hit
+ *
+ * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess()
+ */
+ @Override
+ synchronized protected boolean finishedSuccessImpl() {
+ // adapter.clear();
+ // CACHE.clear();
+
+ clearCache();
+
+ if (results.isEmpty()) {
+ return false;
+ }
+
+ Date now = new Date();
+
+ nextForceCache = FUTURE;
+ // Calendar cal = Calendar.getInstance();
+ // int day = -1;
+ // sortItemsByTime(results);
+ for (Event e : results) {
+ CACHE.add(e);
+ // 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()));
+ // }
+ // adapter.add(new EventListItem((Epg) e));
if (e.getStop().before(nextForceCache) && e.getStop().after(now)) {
nextForceCache = e.getStop();
}
}
cachedChannel = currentChannel;
+
+ fillAdapter();
+ listView.setSelectionAfterHeaderView();
return results.isEmpty() == false;
+
+ // ///////////////
+
+ // // get spinner value
+ // final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner
+ // .getSelectedItem();
+ // nextForceCache = FUTURE;
+ // cachedTime = selection.getValue();
+ // Date now = new Date();
+ //
+ // //adapter.add(new EventListItem(new DateFormatter(results.get(0)
+ // // .getStart()).getDailyHeader()));
+ //
+ // for (Event e : results) {
+ // CACHE.add(e);
+ // if (e.getStop().before(nextForceCache) && e.getStop().after(now)) {
+ // nextForceCache = e.getStop();
+ // }
+ // }
+ //
+
}
protected void prepareDetailsViewData(final EventListItem item) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
index 7d921df..573f45f 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java
@@ -5,12 +5,9 @@ import java.util.Calendar;
import android.app.AlertDialog;
import android.content.DialogInterface;
-
import android.os.Bundle;
-
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
-import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@@ -26,7 +23,6 @@ import de.bjusystems.vdrmanager.data.Recording;
import de.bjusystems.vdrmanager.tasks.DeleteRecordingTask;
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;
@@ -37,7 +33,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
* @author bju
*/
public class RecordingListActivity extends BaseEventListActivity<Recording>
- implements OnItemLongClickListener, SvdrpAsyncListener<Recording> {
+ implements OnItemLongClickListener {
RecordingClient recordingClient;
@@ -76,7 +72,6 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
startRecordingQuery();
}
-
private String[] getAvailableGroupByEntries() {
ArrayList<String> entries = new ArrayList<String>(2);
entries.add(getString(R.string.groupby_date));
@@ -88,7 +83,8 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
AlertDialog groupByDialog = null;
@Override
- public boolean onOptionsItemSelected(final com.actionbarsherlock.view.MenuItem item) {
+ public boolean onOptionsItemSelected(
+ final com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_groupby:
@@ -102,13 +98,14 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
groupBy, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
- if(groupBy == which){
- ASC_DESC = ASC_DESC == ASC ? DESC : ASC;
+ if (groupBy == which) {
+ ASC_DESC = ASC_DESC == ASC ? DESC
+ : ASC;
} else {
groupBy = which;
ASC_DESC = ASC;
}
- //fillAdapter();
+ // fillAdapter();
groupByDialog.dismiss();
say("Comming soon...");
}
@@ -122,6 +119,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
return super.onOptionsItemSelected(item);
}
}
+
/*
* (non-Javadoc)
*
@@ -130,13 +128,13 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
* .view.Menu)
*/
@Override
- public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.Menu menu) {
+ public boolean onCreateOptionsMenu(
+ final com.actionbarsherlock.view.Menu menu) {
final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.recording_list_menu, menu);
- return super.onCreateOptionsMenu(menu);
+ return super.onCreateOptionsMenu(menu);
}
-
@Override
protected SvdrpClient<Recording> getClient() {
return this.recordingClient;
@@ -159,7 +157,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final EventListItem item = adapter.getItem(info.position);
- if(item.isHeader()){
+ if (item.isHeader()) {
return;
}
@@ -170,7 +168,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
menu.setHeaderTitle(formatter.getTitle());
inflater.inflate(R.menu.recording_list_item_menu, menu);
- if(Preferences.get().isEnableRecStream() == false){
+ if (Preferences.get().isEnableRecStream() == false) {
menu.removeItem(R.id.recording_item_menu_stream);
}
@@ -178,13 +176,12 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
super.onCreateContextMenu(menu, v, menuInfo);
//
-// http://projects.vdr-developer.org/issues/863
- if(Utils.isLive(item)){
+ // http://projects.vdr-developer.org/issues/863
+ if (Utils.isLive(item)) {
menu.removeItem(R.id.epg_item_menu_live_tv);
}
}
-
@Override
public boolean onContextItemSelected(final MenuItem item) {
@@ -197,8 +194,10 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
DeleteRecordingTask drt = new DeleteRecordingTask(this, rec) {
@Override
public void finished(SvdrpEvent event) {
- backupViewSelection();
- refresh();
+ if (event == SvdrpEvent.FINISHED_SUCCESS) {
+ backupViewSelection();
+ refresh();
+ }
}
};
drt.start();
@@ -206,7 +205,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
}
case R.id.recording_item_menu_stream: {
Utils.streamRecording(this, rec);
- //say("Sorry, not yet. It would be. File -> " + rec.getFileName());
+ // say("Sorry, not yet. It would be. File -> " + rec.getFileName());
break;
}
@@ -218,7 +217,6 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
private void startRecordingQuery() {
-
if (checkInternetConnection() == false) {
return;
}
@@ -232,7 +230,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
// create progress dialog
- task.addListener(this);
+ addListener(task);
// start task
task.run();
@@ -270,10 +268,10 @@ public class RecordingListActivity extends BaseEventListActivity<Recording>
adapter.add(new EventListItem(new DateFormatter(cal)
.getDailyHeader()));
}
- adapter.add(new EventListItem((Recording)rec));
+ adapter.add(new EventListItem((Recording) rec));
}
// adapter.sortItems();
- return results.isEmpty() == false;
+ return adapter.isEmpty() == false;
}
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java
index 1b3b1a9..4c72795 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java
@@ -1,34 +1,31 @@
package de.bjusystems.vdrmanager.gui;
-import android.app.Activity;
import android.app.ProgressDialog;
+import android.content.Context;
import android.content.DialogInterface;
-import de.bjusystems.vdrmanager.R;
-import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener;
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.SvdrpExceptionListener;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpListener;
public class SvdrpProgressDialog<T> extends ProgressDialog implements
- SvdrpAsyncListener<T>, DialogInterface.OnCancelListener {
+ SvdrpExceptionListener, SvdrpListener, DialogInterface.OnCancelListener {
+
ProgressDialog progress;
- Activity activity;
+
SvdrpClient<? extends Object> client;
- public SvdrpProgressDialog(final Activity activity,
+ public SvdrpProgressDialog(final Context context,
final SvdrpClient<T> client) {
- super(activity);
- this.activity = activity;
+ super(context);
+
this.client = client;
- progress = new ProgressDialog(activity);
+ progress = new ProgressDialog(context);
progress.setOnCancelListener(this);
}
- public void svdrpEvent(final SvdrpEvent event) {
- svdrpEvent(event, null);
- }
-
- public void svdrpEvent(final SvdrpEvent sevent, T e) {
+ public void svdrpEvent(final SvdrpEvent sevent) {
switch (sevent) {
case ABORTED:
case CONNECTION_TIMEOUT:
@@ -40,37 +37,13 @@ public class SvdrpProgressDialog<T> extends ProgressDialog implements
case CACHE_HIT:
progress.dismiss();
break;
- case CONNECTING:
- progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- setMessage(R.string.progress_connect);
- progress.show();
- break;
- case LOGGED_IN:
- setMessage(R.string.progress_login);
- break;
- case COMMAND_SENT:
- setMessage(client.getProgressTextId());
- break;
- case RESULT_RECEIVED:
- break;
- case DISCONNECTING:
- setMessage(R.string.progress_disconnect);
- break;
case DISCONNECTED:
break;
}
}
public void svdrpException(final SvdrpException exception) {
- progress.dismiss();
- }
- private void setMessage(final int resId, Object... args) {
- if (args.length == 0) {
- progress.setMessage(activity.getText(resId));
- } else {
- progress.setMessage(activity.getString(resId, args));
- }
}
private void abort() {
@@ -85,4 +58,10 @@ public class SvdrpProgressDialog<T> extends ProgressDialog implements
public void onCancel(DialogInterface dialog) {
abort();
}
+
+ @Override
+ public void svdrpEvent(SvdrpEvent event, Throwable t) {
+ progress.dismiss();
+ Utils.say(getContext(), t.getLocalizedMessage());
+ }
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
index 4d69659..92ab1eb 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java
@@ -2,6 +2,7 @@ package de.bjusystems.vdrmanager.gui;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
@@ -33,7 +34,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient;
/**
* This class is used for showing what's current running on all channels
- *
+ *
* @author bju
*/
public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
@@ -62,13 +63,13 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
cachedTime = null;
super.reset();
}
-
-
+
+
@Override
protected SvdrpClient<Epg> getClient() {
return this.epgClient;
}
-
+
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -209,6 +210,7 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
private void clearCache() {
cachedTime = null;
+ CACHE.clear();
}
private boolean useCache(String time) {
@@ -234,17 +236,7 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
private void startEpgQuery(String time, boolean force) {
if (useCache(time) && !force) {
- // TODO unschön, refactor to have one code for filling adapter.
- adapter.clear();
- if (CACHE.isEmpty() == false) {
- adapter.add(new EventListItem(new DateFormatter(CACHE.get(0)
- .getStart()).getDailyHeader()));
- }
- for (Event e : CACHE) {
- adapter.add(new EventListItem((Epg) e));
- }
- // adapter.sortItems();
- listView.setSelectionAfterHeaderView();
+ fillAdapter();
return;
}
@@ -252,8 +244,6 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
return;
}
- clearCache();
-
epgClient = new EpgClient(time);
// remove old listeners
@@ -264,39 +254,76 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements
epgClient);
// create progress
- task.addListener(this);
+ addListener(task);
// start task
task.run();
}
+
+ @Override
+ protected void fillAdapter() {
+ if(CACHE.isEmpty()){
+ return;
+ }
+
+ sort();
+ adapter.clear();
+ adapter.add(new EventListItem(new DateFormatter(CACHE.get(0)
+ .getStart()).getDailyHeader()));
+
+ for (Event e : CACHE) {
+ adapter.add(new EventListItem((Epg) e));
+ }
+ adapter.notifyDataSetChanged();
+ }
+
+ void sort() {
+ if(sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) {
+ Collections.sort(CACHE, new TitleComparator());
+ } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) {
+ Collections.sort(CACHE, new ChannelComparator());
+ }
+ }
+
+
+ @Override
+ protected int getAvailableSortByEntries() {
+ return R.array.epg_sort_by_channels_alpha;
+ }
+
+
+ protected String getViewID(){
+ return TimeEpgListActivity.class.getSimpleName();
+ }
+
@Override
protected boolean finishedSuccessImpl() {
+ clearCache();
+
+ if (results.isEmpty()) {
+ return false;
+ }
+
// get spinner value
final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner
.getSelectedItem();
- adapter.clear();
- CACHE.clear();
nextForceCache = FUTURE;
cachedTime = selection.getValue();
Date now = new Date();
- sortItemsByChannel(results);
- if (results.isEmpty()) {
- return false;
- }
- adapter.add(new EventListItem(new DateFormatter(results.get(0)
- .getStart()).getDailyHeader()));
+ //adapter.add(new EventListItem(new DateFormatter(results.get(0)
+ // .getStart()).getDailyHeader()));
for (Event e : results) {
CACHE.add(e);
- adapter.add(new EventListItem((Epg) e));
if (e.getStop().before(nextForceCache) && e.getStop().after(now)) {
nextForceCache = e.getStop();
}
}
+ fillAdapter();
listView.setSelectionAfterHeaderView();
- return CACHE.isEmpty() == false;
+ return results.isEmpty() == false;
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
index b40a544..edb5325 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java
@@ -4,9 +4,6 @@ import java.util.Calendar;
import java.util.Comparator;
import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import de.bjusystems.vdrmanager.R;
@@ -14,7 +11,6 @@ import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.EventListItem;
import de.bjusystems.vdrmanager.data.Timer;
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.TimerClient;
@@ -25,7 +21,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.TimerClient;
* @author bju
*/
public class TimerListActivity extends BaseTimerEditActivity<Timer> implements
- OnItemClickListener, SvdrpAsyncListener<Timer> {
+ OnItemClickListener {
private static final int MENU_NEW_TIMER = 2;
@@ -95,7 +91,7 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements
// attach listener
// task.addListener(progress);
- task.addListener(this);
+ addListener(task);
// start task
task.run();
@@ -128,7 +124,7 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements
}
protected Comparator<Timer> getTimeComparator(boolean reverse) {
- return new BaseEventComparator(reverse) {
+ return new TimeAndChannelComparator(reverse) {
@Override
public int compare(Timer item1, Timer item2) {
if (item1.isRecurring()) {
@@ -163,7 +159,7 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements
adapter.add(new EventListItem(e));
}
listView.setSelectionAfterHeaderView();
- return results.isEmpty() == false;
+ return adapter.isEmpty() == false;
}
@Override
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java
index bd3dc7a..fb4ea49 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java
@@ -34,10 +34,10 @@ import de.bjusystems.vdrmanager.data.Event;
import de.bjusystems.vdrmanager.data.EventFormatter;
import de.bjusystems.vdrmanager.data.Preferences;
import de.bjusystems.vdrmanager.data.Recording;
-import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncTask;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpListener;
import de.bjusystems.vdrmanager.utils.svdrp.SwitchChannelClient;
public class Utils {
@@ -371,8 +371,8 @@ public class Utils {
final SwitchChannelClient scc = new SwitchChannelClient(id);
SvdrpAsyncTask<String, SwitchChannelClient> task = new SvdrpAsyncTask<String, SwitchChannelClient>(
scc);
- task.addListener(new SvdrpAsyncListener<String>() {
- public void svdrpEvent(SvdrpEvent event, String result) {
+ task.addSvdrpListener(new SvdrpListener() {
+ public void svdrpEvent(SvdrpEvent event) {
if (event == SvdrpEvent.FINISHED_SUCCESS) {
Utils.say(ctx, ctx.getString(R.string.switching_success,
(name != null ? name : id)));
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java
index 26bc510..870bc70 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java
@@ -2,21 +2,21 @@ package de.bjusystems.vdrmanager.tasks;
import android.app.Activity;
import de.bjusystems.vdrmanager.gui.SvdrpProgressDialog;
-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;
public abstract class AsyncProgressTask<Result> {
- class AsyncProgress extends SvdrpProgressDialog<Result> implements SvdrpAsyncListener<Result> {
+ class AsyncProgress extends SvdrpProgressDialog<Result> {
- public AsyncProgress(final Activity activity, final SvdrpClient<Result> client) {
+ public AsyncProgress(final Activity activity,
+ final SvdrpClient<Result> client) {
super(activity, client);
}
- public void svdrpEvent(final SvdrpEvent event, final Result result) {
- super.svdrpEvent(event, result);
+ public void svdrpEvent(final SvdrpEvent event) {
+ super.svdrpEvent(event);
switch (event) {
case ABORTED:
case CONNECT_ERROR:
@@ -35,7 +35,8 @@ public abstract class AsyncProgressTask<Result> {
Activity activity;
SvdrpClient<Result> client;
- public AsyncProgressTask(final Activity activity, final SvdrpClient<Result> client) {
+ public AsyncProgressTask(final Activity activity,
+ final SvdrpClient<Result> client) {
this.activity = activity;
this.client = client;
}
@@ -43,17 +44,17 @@ public abstract class AsyncProgressTask<Result> {
public void start() {
// delete timer
-/*
- final SetTimerClient client = new SetTimerClient(timer, true) {
- @Override
- public int getProgressTextId() {
- return R.string.progress_timer_delete;
- }
- };
-*/
- final SvdrpAsyncTask<Result, SvdrpClient<Result>> task = new SvdrpAsyncTask<Result, SvdrpClient<Result>>(client);
+ /*
+ * final SetTimerClient client = new SetTimerClient(timer, true) {
+ *
+ * @Override public int getProgressTextId() { return
+ * R.string.progress_timer_delete; } };
+ */
+ final SvdrpAsyncTask<Result, SvdrpClient<Result>> task = new SvdrpAsyncTask<Result, SvdrpClient<Result>>(
+ client);
final AsyncProgress progress = new AsyncProgress(activity, client);
- task.addListener(progress);
+ task.addSvdrpListener(progress);
+ task.addSvdrpExceptionListener(progress);
task.run();
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java
index f8372e9..ebaee8c 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java
@@ -24,7 +24,7 @@ public class AliveClient extends SvdrpClient<AliveState> {
* @param parameter parameter for lste
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
runCommand("aliv");
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java
index ecbed98..3c65fcc 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java
@@ -3,6 +3,8 @@ 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.Map;
import java.util.TreeMap;
import de.bjusystems.vdrmanager.R;
@@ -11,29 +13,40 @@ import de.bjusystems.vdrmanager.data.Preferences;
/**
* Class for retrieving informations about the running program
- *
+ *
* @author bju
- *
+ *
*/
public class ChannelClient extends SvdrpClient<Channel> implements
- SvdrpListener<Channel> {
+ SvdrpListener, SvdrpResultListener<Channel> {
private static final ArrayList<String> channelGroups = new ArrayList<String>();
+ private static final ArrayList<String> channelSources = 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 TreeMap<String, ArrayList<Channel>> sourceChannels = new TreeMap<String, ArrayList<Channel>>();
+
private static ArrayList<Channel> channels = new ArrayList<Channel>();
+ private static Map<String, Channel> idChannels = new HashMap<String, Channel>();
+
+ public static Map<String, Channel> getIdChannels() {
+ return idChannels;
+ }
+
private static boolean inited = false;
public ChannelClient() {
super();
-// if (useCache == false) {
-// clearCache();
-// }
+ // if (useCache == false) {
+ // clearCache();
+ // }
addSvdrpListener(this);
+ addSvdrpResultListener(this);
}
public static void clearCache() {
@@ -41,6 +54,7 @@ public class ChannelClient extends SvdrpClient<Channel> implements
groupChannels.clear();
providerChannels.clear();
channels.clear();
+ idChannels.clear();
inited = false;
}
@@ -48,6 +62,11 @@ public class ChannelClient extends SvdrpClient<Channel> implements
return channelGroups;
}
+ public static ArrayList<String> getChannelSources() {
+ return channelSources;
+ }
+
+
public static HashMap<String, ArrayList<Channel>> getGroupChannels() {
return groupChannels;
}
@@ -56,13 +75,17 @@ public class ChannelClient extends SvdrpClient<Channel> implements
return providerChannels;
}
+ public static TreeMap<String, ArrayList<Channel>> getSourceChannels() {
+ return sourceChannels;
+ }
+
public static ArrayList<Channel> getChannels() {
return channels;
}
/**
* Constructor
- *
+ *
* @param host
* host
* @param port
@@ -70,21 +93,21 @@ public class ChannelClient extends SvdrpClient<Channel> implements
* @param ssl
* use ssl
*/
-// public ChannelClient() {
-// this(true);
-//
-// }
+ // public ChannelClient() {
+ // this(true);
+ //
+ // }
/**
* Starts the EPG request
- *
+ *
* @param parameter
* parameter for lste
*/
@Override
- synchronized public void run() throws SvdrpException {
+ synchronized public void run() {
if (inited == true) {
- informListener(SvdrpEvent.CACHE_HIT, null);
+ informListener(SvdrpEvent.CACHE_HIT);
} else {
runCommand("channels " + Preferences.get().getChannels());
}
@@ -101,22 +124,43 @@ public class ChannelClient extends SvdrpClient<Channel> implements
}
ArrayList<Channel> currentChannels = new ArrayList<Channel>();
+
String currentGroup;
-
+
+ private void addSourceChannel(Channel c){
+ ArrayList<Channel> channels = sourceChannels.get(c.getSource());
+
+ if(channels == null){
+ channels = new ArrayList<Channel>();
+ sourceChannels.put(c.getSource(), channels);
+ channelSources.add(c.getSource());
+ }
+ channels.add(c);
+ }
+
private void received(Channel c) {
+
+
+
+
if (c.isGroupSeparator()) {
currentGroup = c.getName();
channelGroups.add(currentGroup);
currentChannels = new ArrayList<Channel>();
groupChannels.put(c.getName(), currentChannels);
} else {
- if(channelGroups.isEmpty()){//receiver channel with no previous group
+
+ addSourceChannel(c);
+
+ if (channelGroups.isEmpty()) {// receiver channel with no previous
+ // group
channelGroups.add("");
groupChannels.put("", currentChannels);
}
-
+
c.setGroup(currentGroup);
channels.add(c);
+ idChannels.put(c.getId(), c);
currentChannels.add(c);
String provider = c.getProvider();
ArrayList<Channel> pchannels = providerChannels.get(provider);
@@ -128,12 +172,14 @@ public class ChannelClient extends SvdrpClient<Channel> implements
}
}
- public void svdrpEvent(SvdrpEvent event, Channel c) {
- if (event == SvdrpEvent.RESULT_RECEIVED) {
- received(c);
- return;
- }
- if(event == SvdrpEvent.FINISHED_SUCCESS){
+ @Override
+ public void svdrpEvent(Channel c) {
+ received(c);
+ }
+
+ @Override
+ public void svdrpEvent(SvdrpEvent event) {
+ if (event == SvdrpEvent.FINISHED_SUCCESS) {
inited = true;
}
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java
index a6b2f8f..efd5c6d 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java
@@ -15,7 +15,7 @@ public class DelRecordingClient extends SvdrpClient<Recording> {
/**
* Constructor
- * Recording
+ * Recording
*/
public DelRecordingClient(final Recording recording) {
super();
@@ -26,7 +26,7 @@ public class DelRecordingClient extends SvdrpClient<Recording> {
* Starts the request
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
final StringBuilder command = new StringBuilder();
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java
index 90e5358..0e7464e 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java
@@ -61,7 +61,7 @@ public class EpgClient extends SvdrpClient<Epg> {
* @param parameter parameter for lste
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
if (time != null) {
runCommand(String.format("tevents %s %s", time, Preferences.getPreferences().getChannels()));
} else if (channel != null) {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java
index 40de70a..ab832bc 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java
@@ -3,13 +3,7 @@ package de.bjusystems.vdrmanager.utils.svdrp;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.data.Recording;
-public class RecordingClient extends SvdrpClient<Recording> implements SvdrpListener<Recording> {
-
- public void svdrpEvent(SvdrpEvent event, Recording result) {
-// if(event == SvdrpEvent.RESULT_RECEIVED){
-// results.add(result);
-// }
- }
+public class RecordingClient extends SvdrpClient<Recording> {
@Override
protected Recording parseAnswer(String line) {
@@ -22,7 +16,7 @@ public class RecordingClient extends SvdrpClient<Recording> implements SvdrpList
}
@Override
- public void run() throws SvdrpException {
+ public void run() {
runCommand("recordings");
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
index 765e780..72ca70e 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java
@@ -23,14 +23,14 @@ public class SetTimerClient extends SvdrpClient<Timer> {
public String getCommand(){
return this.command;
}
-
+
}
-
+
/** channel names for timer */
Timer newTimer;
Timer oldTimer;
-
+
/** timer should be deleted */
private TimerOperation timerOperation;
@@ -53,12 +53,12 @@ public class SetTimerClient extends SvdrpClient<Timer> {
this.timerOperation = op;
}
-
+
/**
* Starts the request
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
final StringBuilder command = new StringBuilder();
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncListener.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncListener.java
deleted file mode 100644
index fc388bf..0000000
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncListener.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package de.bjusystems.vdrmanager.utils.svdrp;
-
-public interface SvdrpAsyncListener<Result> extends SvdrpListener<Result> {
-
- void svdrpException(SvdrpException exception);
-
-}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java
index 743fca6..a979931 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java
@@ -4,26 +4,58 @@ import java.util.ArrayList;
import java.util.List;
import android.os.AsyncTask;
-import android.util.Log;
-public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>>
- extends AsyncTask<Void, Object, Void>
- implements SvdrpListener<Result> {
+public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>> extends
+ AsyncTask<Void, Object, Void> implements SvdrpListener,
+ SvdrpExceptionListener {
Client client;
- List<SvdrpAsyncListener<Result>> listeners = new ArrayList<SvdrpAsyncListener<Result>>();
+
+ Throwable ex;
+
+ SvdrpEvent event;
+
+ List<SvdrpListener> eventListeners = new ArrayList<SvdrpListener>();
+
+ List<SvdrpExceptionListener> exceptionListeners = new ArrayList<SvdrpExceptionListener>();
public SvdrpAsyncTask(final Client client) {
this.client = client;
- client.addSvdrpListener(this);
+ this.client.addSvdrpListener(this);
+ this.client.addSvdrpExceptionListener(this);
+ }
+
+ /**
+ * Adds the listener to the list of listeners
+ *
+ * @param listener
+ * listener
+ */
+ public void addSvdrpListener(final SvdrpListener listener) {
+ // client.addSvdrpListener(listener);
+ eventListeners.add(listener);
}
- public void addListener(final SvdrpAsyncListener<Result> listener) {
- listeners.add(listener);
+ /**
+ * Adds the listener to the list of listeners
+ *
+ * @param listener
+ * listener
+ */
+ public void addSvdrpResultListener(
+ final SvdrpResultListener<Result> listener) {
+ client.addSvdrpResultListener(listener);
}
- public void removeListener(final SvdrpAsyncListener<Result> listener) {
- listeners.remove(listener);
+ /**
+ * Adds the listener to the list of listeners
+ *
+ * @param listener
+ * listener
+ */
+ public void addSvdrpExceptionListener(final SvdrpExceptionListener listener) {
+ // client.addSvdrpExceptionListener(listener);
+ exceptionListeners.add(listener);
}
public void run() {
@@ -32,36 +64,58 @@ public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>>
@Override
protected Void doInBackground(final Void... params) {
- try {
- client.run();
- } catch (final SvdrpException e) {
- publishProgress(e);
- }
+ client.run();
return null;
}
- public void svdrpEvent(final SvdrpEvent event, final Result result) {
- publishProgress(event, result);
- if(event == SvdrpEvent.FINISHED_SUCCESS || event == SvdrpEvent.FINISHED_ABNORMALY || event == SvdrpEvent.ABORTED || event == SvdrpEvent.ERROR || event == SvdrpEvent.CACHE_HIT){
- client.removeSvdrpListener(this);
- }
- }
-
- @SuppressWarnings("unchecked")
@Override
protected void onProgressUpdate(final Object... values) {
- super.onProgressUpdate(values);
- if (values.length == 2) {
- for(final SvdrpAsyncListener<Result> listener : listeners) {
- listener.svdrpEvent((SvdrpEvent)values[0], (Result)values[1]);
+ if (values.length == 1) {
+ for (final SvdrpListener listener : eventListeners) {
+ listener.svdrpEvent((SvdrpEvent) values[0]);
}
- } else if(values.length == 1) {
- for(final SvdrpAsyncListener<Result> listener : listeners) {
- listener.svdrpException((SvdrpException)values[0]);
+
+ } else if (values.length == 2) {
+ for (final SvdrpExceptionListener listener : exceptionListeners) {
+ listener.svdrpEvent((SvdrpEvent) values[0],
+ (Throwable) values[1]);
}
- } else {
- Log.w(toString(), "Unknonw count of argument in onProgressUpdate");
}
+
+ /*
+ * switch (event) { case CONNECTING: {
+ * setMessage(R.string.progress_connect); progress.show(); break; }
+ *
+ * case LOGGED_IN: { setMessage(R.string.progress_login); break; }
+ *
+ * case COMMAND_SENT: { setMessage(client.getProgressTextId()); break; }
+ *
+ * case DISCONNECTING: { setMessage(R.string.progress_disconnect);
+ * break; }
+ *
+ * case ERROR: case CONNECTION_TIMEOUT: case CONNECT_ERROR: case
+ * FINISHED_ABNORMALY: case CACHE_HIT: case FINISHED_SUCCESS: case
+ * LOGIN_ERROR: { progress.dismiss(); }
+ *
+ * }
+ */
+ }
+
+ // @Override
+ // protected void onPostExecute(SvdrpException exception) {
+ // for (SvdrpExceptionListener l : exceptionListeners) {
+ // l.svdrpEvent(exception.getEvent(), ex);
+ // }
+ // }
+
+ @Override
+ public void svdrpEvent(SvdrpEvent event) {
+ publishProgress(event);
+ }
+
+ @Override
+ public void svdrpEvent(SvdrpEvent event, Throwable t) {
+ publishProgress(event, t);
}
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
index 66a4c94..90262e5 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java
@@ -22,9 +22,9 @@ import de.bjusystems.vdrmanager.data.Preferences;
/**
* Class for SVDRP communication
- *
+ *
* @author bju
- *
+ *
*/
public abstract class SvdrpClient<Result> {
@@ -39,7 +39,15 @@ public abstract class SvdrpClient<Result> {
/** flag for stopping the current request */
private boolean abort;
/** listener */
- private final List<SvdrpListener<Result>> listeners = new ArrayList<SvdrpListener<Result>>();
+ private final List<SvdrpListener> svdrpListeners = new ArrayList<SvdrpListener>();
+
+ private final List<SvdrpResultListener<Result>> svdrpResultListeners = new ArrayList<SvdrpResultListener<Result>>();
+
+ private final List<SvdrpExceptionListener> svdrpExceptionListeners = new ArrayList<SvdrpExceptionListener>();
+
+ // private final List<SvdrpListener<>> listeners = new
+ // ArrayList<SvdrpListener<Result>>();
+
/** list of results */
// private final List<Result> results = new ArrayList<Result>();
/** should the listener be informed about each received result */
@@ -53,7 +61,7 @@ public abstract class SvdrpClient<Result> {
private Timer watchDog = new Timer();
- //private NativeDES crypt = new NativeDES();
+ // private NativeDES crypt = new NativeDES();
public boolean isConnected() {
if (socket == null) {
@@ -64,7 +72,7 @@ public abstract class SvdrpClient<Result> {
/**
* Parse received answer line
- *
+ *
* @param line
* line
* @return received data object or null if not completed yet
@@ -73,11 +81,11 @@ public abstract class SvdrpClient<Result> {
public abstract int getProgressTextId();
- public abstract void run() throws SvdrpException;
+ public abstract void run();
/**
* Constructor
- *
+ *
* @param prefs
* Preferences
*/
@@ -88,28 +96,61 @@ public abstract class SvdrpClient<Result> {
/**
* Remove all listeners
*/
- public void clearSvdrpListener() {
- listeners.clear();
+ public void clearListener() {
+ svdrpExceptionListeners.clear();
+ svdrpListeners.clear();
+ svdrpResultListeners.clear();
+ }
+
+ /**
+ * Adds the listener to the list of listeners
+ *
+ * @param listener
+ * listener
+ */
+ public void addSvdrpListener(final SvdrpListener listener) {
+ svdrpListeners.add(listener);
+ }
+
+ /**
+ * Adds the listener to the list of listeners
+ *
+ * @param listener
+ * listener
+ */
+ public void addSvdrpResultListener(
+ final SvdrpResultListener<Result> listener) {
+ svdrpResultListeners.add(listener);
}
/**
* Adds the listener to the list of listeners
- *
+ *
* @param listener
* listener
*/
- public void addSvdrpListener(final SvdrpListener<Result> listener) {
- listeners.add(listener);
+ public void addSvdrpExceptionListener(final SvdrpExceptionListener listener) {
+ svdrpExceptionListeners.add(listener);
}
/**
* Removes the listener from the list of listeners
- *
+ *
* @param listener
* listener
*/
- public void removeSvdrpListener(final SvdrpListener<Result> listener) {
- listeners.remove(listener);
+ public void removeSvdrpListener(final SvdrpListener listener) {
+ svdrpListeners.remove(listener);
+ }
+
+ public void removeSvdrpResultListener(
+ final SvdrpResultListener<Result> listener) {
+ svdrpResultListeners.remove(listener);
+ }
+
+ public void removeSvdrpExceptionListener(
+ final SvdrpExceptionListener listener) {
+ svdrpExceptionListeners.remove(listener);
}
/**
@@ -140,7 +181,7 @@ public abstract class SvdrpClient<Result> {
/**
* Connect to SVDRP
- *
+ *
* @param host
* host
* @param port
@@ -155,7 +196,7 @@ public abstract class SvdrpClient<Result> {
final Preferences prefs = Preferences.get();
try {
// connect
- informListener(SvdrpEvent.CONNECTING, null);
+ informListener(SvdrpEvent.CONNECTING);
if (false && Preferences.get().isSecure()) {
@@ -172,7 +213,7 @@ public abstract class SvdrpClient<Result> {
.getSvdrpPort()),
prefs.getConnectionTimeout() * 1000);// 8 secs for connect
if (abort) {
- informListener(SvdrpEvent.ABORTED, null);
+ informListener(SvdrpEvent.ABORTED);
}
//
socket.setSoTimeout(prefs.getReadTimeout() * 1000);// 15 sec for
@@ -191,22 +232,22 @@ public abstract class SvdrpClient<Result> {
abort = true;
}
}, delay);
- informListener(SvdrpEvent.CONNECTED, null);
+ informListener(SvdrpEvent.CONNECTED);
} catch (final SocketTimeoutException sote) {
Log.w(TAG, sote);
if (abort) {
- informListener(SvdrpEvent.ABORTED, null);
+ informListener(SvdrpEvent.ABORTED);
} else {
- informListener(SvdrpEvent.CONNECTION_TIMEOUT, null);
+ informListener(SvdrpEvent.CONNECTION_TIMEOUT);
}
return false;
} catch (final Exception e) {
Log.w(TAG, e);
if (abort) {
- informListener(SvdrpEvent.ABORTED, null);
+ informListener(SvdrpEvent.ABORTED);
} else {
- informListener(SvdrpEvent.CONNECT_ERROR, null);
+ informListener(SvdrpEvent.CONNECT_ERROR);
}
return false;
}
@@ -218,36 +259,36 @@ public abstract class SvdrpClient<Result> {
// inputStream = new InflaterInputStream(socket.getInputStream())
// password needed?
- informListener(SvdrpEvent.LOGIN, null);
+ informListener(SvdrpEvent.LOGIN);
writeLine("passwd " + prefs.getPassword());
if (!readLine().startsWith("!OK")) {
- informListener(SvdrpEvent.LOGIN_ERROR, null);
+ informListener(SvdrpEvent.LOGIN_ERROR);
disconnect();
return false;
} else {
- informListener(SvdrpEvent.LOGGED_IN, null);
+ informListener(SvdrpEvent.LOGGED_IN);
}
return true;
}
/**
* Disconnect from SVDRP if connected
- *
+ *
* @throws IOException
* on errors
*/
protected void disconnect() throws IOException {
- informListener(SvdrpEvent.DISCONNECTING, null);
+ informListener(SvdrpEvent.DISCONNECTING);
if (socket != null && socket.isConnected()) {
socket.close();
socket = null;
}
- informListener(SvdrpEvent.DISCONNECTED, null);
+ informListener(SvdrpEvent.DISCONNECTED);
}
/**
* Sends one line to SVDRP
- *
+ *
* @param line
* line of text
* @throws IOException
@@ -256,9 +297,9 @@ public abstract class SvdrpClient<Result> {
protected void writeLine(final String line) throws IOException {
String command = line + "\r\n";
- //if (false && Preferences.get().isSecure()) {
- //command = crypt.encrypt(command, Preferences.get().getPassword());
- //}
+ // if (false && Preferences.get().isSecure()) {
+ // command = crypt.encrypt(command, Preferences.get().getPassword());
+ // }
final byte[] bytes = command.getBytes("utf-8");
outputStream.write(bytes);
outputStream.flush();
@@ -266,7 +307,7 @@ public abstract class SvdrpClient<Result> {
/**
* Reads one line from SVDRP
- *
+ *
* @return line read
* @throws IOException
* on errors
@@ -306,13 +347,13 @@ public abstract class SvdrpClient<Result> {
Log.w(TAG, usex);
line = lineBytes.toString();
}
- //if (false && Preferences.get().isSecure()) {
- //line = crypt.decrypt(line, Preferences.get().getPassword());
- //}
+ // if (false && Preferences.get().isSecure()) {
+ // line = crypt.decrypt(line, Preferences.get().getPassword());
+ // }
return line;
}
- public void runCommand(final String command) throws SvdrpException {
+ public void runCommand(final String command) {
try {
@@ -329,9 +370,9 @@ public abstract class SvdrpClient<Result> {
}
// send command
- informListener(SvdrpEvent.COMMAND_SENDING, null);
+ informListener(SvdrpEvent.COMMAND_SENDING);
writeLine(command);
- informListener(SvdrpEvent.COMMAND_SENT, null);
+ informListener(SvdrpEvent.COMMAND_SENT);
Log.i(TAG, SvdrpEvent.COMMAND_SENT + ":" + command);
// read first line
@@ -358,7 +399,14 @@ public abstract class SvdrpClient<Result> {
// error?
if (line.startsWith("!ERROR")) {
Log.w(TAG, line);
- informListener(SvdrpEvent.ERROR, null);
+ String msg;
+ if (line.startsWith("!ERROR:")) {
+ msg = line.substring(7);
+ } else {
+ msg = line;
+ }
+ disconnect();
+ informListener(SvdrpEvent.ERROR, new SvdrpException(msg));
break;
}
@@ -366,17 +414,19 @@ public abstract class SvdrpClient<Result> {
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;
+ Log.w(TAG, "line: " + line);
+ informListener(SvdrpEvent.ERROR, ex);
+ return;
}
if (result != null) {
+ informListener(result);
// results.add(result);
// if (resultInfoEnabled) {
- informListener(SvdrpEvent.RESULT_RECEIVED, result);
+
// }
}
@@ -386,15 +436,14 @@ public abstract class SvdrpClient<Result> {
disconnect();
if (abort) {
- informListener(SvdrpEvent.ABORTED, null);
+ informListener(SvdrpEvent.ABORTED);
} else {
- informListener(SvdrpEvent.FINISHED_SUCCESS, null);
+ informListener(SvdrpEvent.FINISHED_SUCCESS);
}
} catch (final Exception e) {
- // throw new SvdrpException(e);
Log.w(TAG, e);
- informListener(SvdrpEvent.FINISHED_ABNORMALY, null);
+ informListener(SvdrpEvent.FINISHED_ABNORMALY, e);
}
}
@@ -402,14 +451,22 @@ public abstract class SvdrpClient<Result> {
// this.resultInfoEnabled = resultInfoEnabled;
// }
- protected void informListenerError(final SvdrpEvent event,
- final Throwable result) {
+ protected void informListener(final SvdrpEvent event, final Throwable e) {
+ for (final SvdrpExceptionListener listener : svdrpExceptionListeners) {
+ listener.svdrpEvent(event, e);
+ }
+ }
+ protected void informListener(final SvdrpEvent event) {
+ for (final SvdrpListener listener : svdrpListeners) {
+ listener.svdrpEvent(event);
+ }
}
- protected void informListener(final SvdrpEvent event, final Result result) {
- for (final SvdrpListener<Result> listener : listeners) {
- listener.svdrpEvent(event, result);
+ protected void informListener(final Result result) {
+ for (final SvdrpResultListener<Result> listener : svdrpResultListeners) {
+ listener.svdrpEvent(result);
}
}
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java
index 7eb6fac..a64f905 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpEvent.java
@@ -9,7 +9,7 @@ public enum SvdrpEvent {
LOGIN_ERROR,
COMMAND_SENDING,
COMMAND_SENT,
- RESULT_RECEIVED,
+ //RESULT_RECEIVED,
DISCONNECTING,
DISCONNECTED,
FINISHED_ABNORMALY,
@@ -20,5 +20,5 @@ public enum SvdrpEvent {
CONNECTION_TIMEOUT
//
;
-
+
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java
index 9c6d5e0..fe0824e 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java
@@ -8,14 +8,27 @@ package de.bjusystems.vdrmanager.utils.svdrp;
@SuppressWarnings("serial")
public class SvdrpException extends Exception {
- public SvdrpException(String text) {
+ SvdrpEvent event;
+
+ public SvdrpEvent getEvent() {
+ return event;
+ }
+
+ public void setEvent(SvdrpEvent event) {
+ this.event = event;
+ }
+
+ public SvdrpException(SvdrpEvent event, String text) {
super(text);
}
-
+ public SvdrpException(String text) {
+ this(null,text);
+ }
+
public SvdrpException(String text, Throwable cause) {
super(text, cause);
}
-
+
public SvdrpException(Throwable cause) {
super(cause);
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpExceptionListener.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpExceptionListener.java
new file mode 100644
index 0000000..1483e6d
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpExceptionListener.java
@@ -0,0 +1,5 @@
+package de.bjusystems.vdrmanager.utils.svdrp;
+
+public interface SvdrpExceptionListener {
+ void svdrpEvent(SvdrpEvent event, Throwable t);
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpListener.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpListener.java
index df8762b..88ea35e 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpListener.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpListener.java
@@ -1,7 +1,9 @@
package de.bjusystems.vdrmanager.utils.svdrp;
-public interface SvdrpListener<Result>{
+public interface SvdrpListener{
+
+
+ void svdrpEvent(SvdrpEvent event);
- void svdrpEvent(SvdrpEvent event, Result result);
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpResultListener.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpResultListener.java
new file mode 100644
index 0000000..fbea3c3
--- /dev/null
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpResultListener.java
@@ -0,0 +1,6 @@
+package de.bjusystems.vdrmanager.utils.svdrp;
+
+public interface SvdrpResultListener<Result> {
+
+ void svdrpEvent(Result result);
+}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java
index d9fd77a..e5b2b68 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java
@@ -5,24 +5,24 @@ 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
*/
@@ -34,7 +34,7 @@ public class SwitchChannelClient extends SvdrpClient<String> {
* Starts the wakeup request
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
if(nr != null){
runCommand("SETCHANNEL " + String.valueOf(nr));
} else {
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java
index 9d75421..bd98773 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java
@@ -33,7 +33,7 @@ public class TimerClient extends SvdrpClient<Timer> {
* @param parameter parameter for lste
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
runCommand("timers");
}
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java
index be8a0ef..12068fc 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java
@@ -24,7 +24,7 @@ public class WakeupUrlClient extends SvdrpClient<WakeupState> {
* Starts the wakeup request
*/
@Override
- public void run() throws SvdrpException {
+ public void run() {
runCommand("wake");
}