summaryrefslogtreecommitdiff
path: root/vdrmanager
diff options
context:
space:
mode:
authorlado <herrlado@gmail.com>2013-02-14 23:40:06 +0100
committerlado <herrlado@gmail.com>2013-02-14 23:40:06 +0100
commitf07838d27a0da1ab0dedd6a638b6e095b3190477 (patch)
treec09c77e63d1d2444d8ddf0f126fc249d5b4549f7 /vdrmanager
parent0e470f46112e219bd328d2649b8a9c0b66cc4015 (diff)
downloadvdr-manager-f07838d27a0da1ab0dedd6a638b6e095b3190477.tar.gz
vdr-manager-f07838d27a0da1ab0dedd6a638b6e095b3190477.tar.bz2
Feature #864
Diffstat (limited to 'vdrmanager')
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java104
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java141
2 files changed, 169 insertions, 76 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java
index fa16e69..8f89b54 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Vdr.java
@@ -10,7 +10,7 @@ import com.j256.ormlite.table.DatabaseTable;
public class Vdr {
/**
- *
+ *
*/
@DatabaseField(columnName = "_id", generatedId = true)
private Integer id;
@@ -62,7 +62,7 @@ public class Vdr {
/**
* vdr mac for wol
- *
+ *
* @since 0.2
*/
@DatabaseField
@@ -70,9 +70,9 @@ public class Vdr {
/**
* which wakeup method to use
- *
+ *
* @since 0.2
- *
+ *
*/
@DatabaseField
private String wakeupMethod;
@@ -107,7 +107,7 @@ public class Vdr {
/**
* Which port to use for streaming
- *
+ *
* @since 0.2
*/
@DatabaseField
@@ -115,7 +115,7 @@ public class Vdr {
/**
* Which format to use for streaming
- *
+ *
* @since 0.2
*/
@DatabaseField
@@ -123,7 +123,7 @@ public class Vdr {
/**
* Do not send broadcasts, send directly to the host (router problem)
- *
+ *
* @since 0.2
*/
@DatabaseField
@@ -173,17 +173,16 @@ public class Vdr {
@DatabaseField
private String streamingPassword;
-
+
@DatabaseField
private int livePort;
-
+
@DatabaseField
private String recStreamMethod;
-
+
@DatabaseField
private boolean enableRecStreaming = false;
-
public String getRecStreamMethod() {
return recStreamMethod;
}
@@ -208,7 +207,6 @@ public class Vdr {
this.enableRecStreaming = enableRecStreaming;
}
-
public String getStreamingPassword() {
return streamingPassword;
}
@@ -478,10 +476,14 @@ public class Vdr {
}
private static <T> T get(Map<String, Object> map, String key, Object def) {
- return (T) map.get(key);
+ if(map.containsKey(key)){
+ return (T) map.get(key);
+ }
+ return (T)def;
}
- private static Integer getInteger(Map<String, Object> map, String key, Integer def) {
+ private static Integer getInteger(Map<String, Object> map, String key,
+ Integer def) {
if (map.containsKey(key) == false) {
return def;
}
@@ -506,8 +508,13 @@ public class Vdr {
}
private static Boolean getBoolean(Map<String, Object> map, String key) {
+ return getBoolean(map, key, false);
+ }
+
+ private static Boolean getBoolean(Map<String, Object> map, String key,
+ boolean defValue) {
if (map.containsKey(key) == false) {
- return Boolean.FALSE;
+ return defValue;
}
Object obj = get(map, key);
if (obj instanceof Boolean) {
@@ -554,13 +561,64 @@ public class Vdr {
map.put("remux_enable", enableRemux);
map.put("key_rec_stream_enable", enableRecStreaming);
map.put("key_live_port", livePort);
- map.put("key_recstream_method", recStreamMethod );
+ map.put("key_recstream_method", recStreamMethod);
return map;
}
+ public void set(Map<String, Object> map) {
+ name = get(map, "vdr_name", name);
+ host = get(map, "vdr_host", host);
+ port = getInteger(map, "vdr_port", port);
+ password = get(map, "vdr_password", password);
+ secure = getBoolean(map, "vdr_secure", secure);
+
+ filterChannels = getBoolean(map, "limit_channels", filterChannels);
+ channelFilter = get(map, "last_channel", channelFilter);
+
+ wakeupEnabled = getBoolean(map, "key_wakeup_enabled", wakeupEnabled);
+ wakeupUrl = get(map, "key_wakeup_url", wakeupUrl);
+ wakeupUser = get(map, "key_wakeup_user", wakeupUser);
+ wakeupPassword = get(map, "key_wakeup_password", wakeupPassword);
+ wakeupMethod = get(map, "key_wakeup_method", wakeupMethod);
+ wolCustomBroadcast = get(map, "key_wol_custom_broadcast",
+ wolCustomBroadcast);
+ mac = get(map, "key_wakeup_wol_mac", mac);
+
+ connectionTimeout = getInteger(map, "key_conntimeout_key",
+ connectionTimeout);
+ readTimeout = getInteger(map, "key_vdr_readtimeout", readTimeout);
+ timeout = getInteger(map, "key_vdr_timeout", timeout);
+
+ timerPreMargin = getInteger(map, "timer_pre_start_buffer",
+ timerPreMargin);
+ timerPostMargin = getInteger(map, "timer_post_end_buffer",
+ timerPostMargin);
+ timerDefaultPriority = getInteger(map, "timer_default_priority",
+ timerDefaultPriority);
+ timerDefaultLifetime = getInteger(map, "timer_default_lifetime",
+ timerDefaultLifetime);
+
+ streamPort = getInteger(map, "streamingport", streamPort);
+ streamingPassword = get(map, "key_streaming_password",
+ streamingPassword);
+ streamingUsername = get(map, "key_streaming_username",
+ streamingUsername);
+ encoding = get(map, "key_vdr_encoding", encoding);
+ streamFormat = get(map, "livetv_streamformat", streamFormat);
+ remuxCommand = get(map, "remux_command", remuxCommand);
+ remuxParameter = get(map, "remux_parameter", remuxParameter);
+ enableRemux = getBoolean(map, "remux_enable", enableRemux);
+
+ enableRecStreaming = getBoolean(map, "key_rec_stream_enable",
+ enableRecStreaming);
+ livePort = getInteger(map, "key_live_port", livePort);
+ recStreamMethod = get(map, "key_recstream_method", recStreamMethod);
+
+ }
+
public void init(Map<String, Object> map) {
name = get(map, "vdr_name", name);
- host = get(map, "vdr_host" );
+ host = get(map, "vdr_host");
port = getInteger(map, "vdr_port");
password = get(map, "vdr_password");
secure = getBoolean(map, "vdr_secure");
@@ -570,11 +628,11 @@ public class Vdr {
wakeupEnabled = getBoolean(map, "key_wakeup_enabled");
wakeupUrl = get(map, "key_wakeup_url", "0.0.0.0");
- wakeupUser = get(map, "key_wakeup_user","");
- wakeupPassword = get(map, "key_wakeup_password","");
- wakeupMethod = get(map, "key_wakeup_method","wol");
- wolCustomBroadcast = get(map, "key_wol_custom_broadcast","");
- mac = get(map, "key_wakeup_wol_mac","");
+ wakeupUser = get(map, "key_wakeup_user", "");
+ wakeupPassword = get(map, "key_wakeup_password", "");
+ wakeupMethod = get(map, "key_wakeup_method", "wol");
+ wolCustomBroadcast = get(map, "key_wol_custom_broadcast", "");
+ mac = get(map, "key_wakeup_wol_mac", "");
connectionTimeout = getInteger(map, "key_conntimeout_key");
readTimeout = getInteger(map, "key_vdr_readtimeout");
@@ -593,7 +651,7 @@ public class Vdr {
remuxCommand = get(map, "remux_command");
remuxParameter = get(map, "remux_parameter");
enableRemux = getBoolean(map, "remux_enable");
-
+
enableRecStreaming = getBoolean(map, "key_rec_stream_enable");
livePort = getInteger(map, "key_live_port");
recStreamMethod = get(map, "key_recstream_method");
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java
index 86103bf..a55e821 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/VdrSharedPreferences.java
@@ -1,6 +1,7 @@
package de.bjusystems.vdrmanager.data;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -14,31 +15,40 @@ import com.j256.ormlite.dao.RuntimeExceptionDao;
public class VdrSharedPreferences implements SharedPreferences {
private static final String EMPTY_STRING = "";
-
- public int commits = 0;
-
+
+ public int commits = 0;
+
public RuntimeExceptionDao<Vdr, Integer> dao;
-
- public Vdr instance;
-
+
+ private Vdr instance;
+
+ public Vdr getInstance() {
+ return instance;
+ }
+
+ public void setInstance(Vdr instance) {
+ this.instance = instance;
+ map.putAll(instance.toMap());
+ }
+
protected List<OnSharedPreferenceChangeListener> listeners = new LinkedList<OnSharedPreferenceChangeListener>();
Map<String, Object> map = new HashMap<String, Object>();
-
- public VdrSharedPreferences(){
-
- }
- public VdrSharedPreferences (Vdr vdr){
- map.putAll(vdr.toMap());
- instance = vdr;
+
+ public VdrSharedPreferences() {
+
}
-
+
+// public VdrSharedPreferences(Vdr vdr) {
+
+// }
+
public boolean contains(String key) {
return map.containsKey(key);
}
public Editor edit() {
- return new Editor();
+ return new Editor();
}
public Map<String, Object> getAll() {
@@ -70,7 +80,7 @@ public class VdrSharedPreferences implements SharedPreferences {
public String getString(String key, String defValue) {
Object obj = get(key, defValue);
- if(obj == null){
+ if (obj == null) {
return EMPTY_STRING;
}
return String.valueOf(obj);
@@ -89,85 +99,110 @@ public class VdrSharedPreferences implements SharedPreferences {
OnSharedPreferenceChangeListener listener) {
listeners.remove(listener);
}
-
-
+
+ /**
+ * @author lado
+ *
+ */
public class Editor implements SharedPreferences.Editor {
-
- Map<String, Object> data = new HashMap<String, Object>();
+
+ Map<String, Object> modified = new HashMap<String, Object>();
+
+ private boolean clear = false;
public SharedPreferences.Editor clear() {
- data.clear();
+ clear = true;
+ modified.clear();
return this;
}
public boolean commit() {
- instance.init(map);
- CreateOrUpdateStatus custatus = dao.createOrUpdate(instance);
+
+ if(instance == null){
+ map.putAll(modified);
+ return true;
+ }
+
+ instance.set(modified);
+
+ CreateOrUpdateStatus custatus = dao.createOrUpdate(instance);
+
boolean status = custatus.isCreated() || custatus.isUpdated();
- if(status == false)
+ if (status == false)
return false;
-
+
+ map.putAll(modified);
+
+
++commits;
-
+
// and update any listeners
- for (OnSharedPreferenceChangeListener listener : listeners) {
- listener.onSharedPreferenceChanged(
- VdrSharedPreferences.this, null);
+ for (String key : modified.keySet()) {
+ for (OnSharedPreferenceChangeListener listener : listeners) {
+ listener.onSharedPreferenceChanged(
+ VdrSharedPreferences.this, key);
+ }
}
+ modified.clear();
+
return true;
}
-
- public android.content.SharedPreferences.Editor put(
- String key, Object value) {
- map.put(key, value);
- return this;
-
+ public android.content.SharedPreferences.Editor put(String key,
+ Object value) {
+ synchronized (this) {
+ modified.put(key, value);
+ return this;
+ }
}
- public android.content.SharedPreferences.Editor putBoolean(
- String key, boolean value) {
- return put(key,value);
+
+ public android.content.SharedPreferences.Editor putBoolean(String key,
+ boolean value) {
+ return put(key, value);
}
- public android.content.SharedPreferences.Editor putFloat(
- String key, float value) {
- return put(key,value);
+ public android.content.SharedPreferences.Editor putFloat(String key,
+ float value) {
+ return put(key, value);
}
public android.content.SharedPreferences.Editor putInt(String key,
int value) {
- return put(key,value);
+ return put(key, value);
}
public android.content.SharedPreferences.Editor putLong(String key,
long value) {
- return put(key,value);
+ return put(key, value);
}
- public android.content.SharedPreferences.Editor putString(
- String key, String value) {
- return put(key,value);
+ public android.content.SharedPreferences.Editor putString(String key,
+ String value) {
+ return put(key, value);
}
public android.content.SharedPreferences.Editor remove(String key) {
- map.remove(key);
- return this;
+ synchronized (this) {
+ modified.remove(key);
+ return this;
+ }
}
-
public void apply() {
commit();
}
-
public android.content.SharedPreferences.Editor putStringSet(
- String arg0, Set<String> arg1) {
- // TODO Auto-generated method stub
- return null;
+ String key, Set<String> values) {
+ synchronized (this) {
+ modified.put(key, (values == null) ? null
+ : new HashSet<String>(values));
+ return this;
+ }
}
}