From 1ef1be2f9fcb441313bb12bf770a245479f354d7 Mon Sep 17 00:00:00 2001 From: lado Date: Fri, 4 Nov 2011 01:33:38 +0100 Subject: refactoring --- vdrmanager/AndroidManifest.xml | 10 +- vdrmanager/res/xml/preferences.xml | 394 ++++++++++++++------- vdrmanager/res/xml/vdr_prefs.xml | 199 +++++++++++ .../bjusystems/vdrmanager/app/VdrManagerApp.java | 11 + .../de/bjusystems/vdrmanager/data/Preferences.java | 19 +- .../src/de/bjusystems/vdrmanager/data/VDR.java | 110 ++++++ .../vdrmanager/data/db/DataProvider.java | 170 +++++++++ .../de/bjusystems/vdrmanager/gui/BaseActivity.java | 65 ++-- .../vdrmanager/gui/BaseEventListActivity.java | 2 +- .../vdrmanager/gui/BasePreferencesActivity.java | 188 ++++++++++ .../bjusystems/vdrmanager/gui/ChannelAdapter.java | 4 +- .../vdrmanager/gui/ChannelListActivity.java | 47 ++- .../vdrmanager/gui/EpgSearchListActivity.java | 10 +- .../de/bjusystems/vdrmanager/gui/EventAdapter.java | 11 +- .../vdrmanager/gui/EventEpgListActivity.java | 81 +++-- .../vdrmanager/gui/RecordingListActivity.java | 4 +- .../vdrmanager/gui/TimeEpgListActivity.java | 20 +- .../vdrmanager/gui/TimerListActivity.java | 4 +- .../src/de/bjusystems/vdrmanager/gui/Utils.java | 9 +- .../bjusystems/vdrmanager/tasks/ChannelsTask.java | 12 + 20 files changed, 1135 insertions(+), 235 deletions(-) create mode 100644 vdrmanager/res/xml/vdr_prefs.xml create mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java create mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java create mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java diff --git a/vdrmanager/AndroidManifest.xml b/vdrmanager/AndroidManifest.xml index 7d8d9d1..cfff86a 100644 --- a/vdrmanager/AndroidManifest.xml +++ b/vdrmanager/AndroidManifest.xml @@ -1,9 +1,9 @@ + package="de.bjusystems.vdrmanager" android:versionName="0.2.6b" + android:versionCode="026"> @@ -81,7 +81,9 @@ - + + + diff --git a/vdrmanager/res/xml/preferences.xml b/vdrmanager/res/xml/preferences.xml index 001b2f9..a24ecaa 100644 --- a/vdrmanager/res/xml/preferences.xml +++ b/vdrmanager/res/xml/preferences.xml @@ -1,138 +1,258 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vdrmanager/res/xml/vdr_prefs.xml b/vdrmanager/res/xml/vdr_prefs.xml new file mode 100644 index 0000000..26be7d1 --- /dev/null +++ b/vdrmanager/res/xml/vdr_prefs.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java index c4dc2a4..c04b55b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/VdrManagerApp.java @@ -10,6 +10,7 @@ import de.bjusystems.vdrmanager.data.EpgSearchParams; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.data.VDR; public class VdrManagerApp extends Application { @@ -24,6 +25,16 @@ public class VdrManagerApp extends Application { private Timer currentTimer; private Channel currentChannel; + private VDR currentVDR; + + public VDR getCurrentVDR() { + return currentVDR; + } + + public void setCurrentVDR(VDR currentVDR) { + this.currentVDR = currentVDR; + } + private List currentEpgList = new ArrayList(); public List getCurrentEpgList() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java index f4e788a..de45363 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java @@ -70,6 +70,10 @@ public class Preferences { * @since 0.2 */ private int streamPort = 3000; + + private String streamingUsername = ""; + + private String streamingPassword = ""; /** * Which format to use for streaming @@ -183,6 +187,15 @@ public class Preferences { return showImdbButton; } + + public String getStreamingUsername() { + return streamingUsername; + } + + public String getStreamingPassword() { + return streamingPassword; + } + /** Properties singleton */ private static Preferences thePrefs; @@ -389,7 +402,7 @@ public class Preferences { public int getStreamPort() { return streamPort; } - + /** * Getter for selected streaming format * @@ -571,6 +584,10 @@ public class Preferences { prefs.readTimeout = getInt(context, R.string.vdr_readtimeout_key, 10); prefs.timeout = getInt(context, R.string.vdr_timeout_key, 120); + prefs.streamingUsername = getString(context, R.string.streaming_username_key, ""); + + prefs.streamingPassword = getString(context, R.string.streaming_password_key, ""); + thePrefs = prefs; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java new file mode 100644 index 0000000..05914c7 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/VDR.java @@ -0,0 +1,110 @@ +package de.bjusystems.vdrmanager.data; + +public class VDR { + + /** + * Use secure channel + */ + private boolean secure; + + /** SVDRP host name or ip */ + private String host; + + /** SVDRP port */ + private int port; + + /** Password */ + private String password; + + /** should channels be filtered? */ + private boolean filterChannels; + + /** last channel to retrieve */ + private String channelFilter; + + /** Enable remote wakeup */ + private boolean wakeupEnabled; + + /** URL of the wakeup script */ + private String wakeupUrl; + + /** User for wakeup */ + private String wakeupUser; + + /** Password for wakeup */ + private String wakeupPassword; + + /** + * vdr mac for wol + * + * @since 0.2 + */ + private String mac; + + /** + * which wakeup method to use + * + * @since 0.2 + * + */ + private String wakeupMethod; + + /** Check for running VDR is enabled */ + private boolean aliveCheckEnabled; + + /** Intervall for alive test */ + private int aliveCheckInterval; + + /** Buffer before event */ + private int timerPreMargin; + + /** Buffer after event */ + private int timerPostMargin; + + /** Default priority */ + private int timerDefaultPriority; + + /** Default lifetime */ + private int timerDefaultLifetime; + + /** user defined epg search times */ + private String epgSearchTimes; + + /** + * Which port to use for streaming + * + * @since 0.2 + */ + private int streamPort = 3000; + + /** + * Which format to use for streaming + * + * @since 0.2 + */ + private String streamFormat = "TS"; + + /** + * Do not send broadcasts, send directly to the host (router problem) + * + * @since 0.2 + */ + private String wolCustomBroadcast = ""; + + + /** + * Use remux ? + */ + private boolean enableRemux; + + /** + * Remux command + */ + private String remuxCommand; + + /** + * Remux command Parameter + */ + private String remuxParameter; + +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java index 23f93d2..95d4fdc 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/db/DataProvider.java @@ -67,6 +67,10 @@ public class DataProvider extends ContentProvider { private static final int REMUX_PARAMS = 1; private static final int REMUX_PARAMS_ID = 2; + + private static final int VDR= 3; + + private static final int VDR_ID = 4; // /** Internal id: terms. */ // private static final int TERMS_ID = 2; @@ -114,6 +118,8 @@ public class DataProvider extends ContentProvider { URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); URI_MATCHER.addURI(AUTHORITY, "remux_params", REMUX_PARAMS); URI_MATCHER.addURI(AUTHORITY, "remux_params/#", REMUX_PARAMS_ID); + URI_MATCHER.addURI(AUTHORITY, "vdr", VDR); + URI_MATCHER.addURI(AUTHORITY, "vdr/#", VDR_ID); } /** {@link DatabaseHelper}. */ @@ -231,6 +237,170 @@ public class DataProvider extends ContentProvider { } } + + public static final class Vdr { + /** Table name. */ + public static final String TABLE = "vdr"; + /** {@link HashMap} for projection. */ + private static final HashMap PROJECTION_MAP; + + /** Index in projection: ID. */ + public static final int INDEX_ID = 0; + /** Index in projection: name of hours group. */ + public static final int INDEX_NAME = 1; + public static final int INDEX_HOST = 2; + public static final int INDEX_PORT = 3; + public static final int INDEX_SECURE = 4; + public static final int INDEX_FILTER_CHANNELS = 5; + public static final int INDEX_CHANNEL_FILTER = 6; + public static final int INDEX_ENABLE_WAKEUP = 7; + public static final int INDEX_WAKEUP_METHOD = 8; + public static final int INDEX_WAKEUP_URL = 9; + public static final int INDEX_WAKEUP_USER = 10; + public static final int INDEX_WAKEUP_PASSWORD = 11; + public static final int INDEX_VDR_MAC = 12; + public static final int INDEX_ENABLE_ALIVE_CHECK = 13; + public static final int INDEX_ALIVE_CHECK_INTERVAL = 14; + public static final int INDEX_TIMER_PRE_MARGIN = 15; + public static final int INDEX_TIMER_POST_MARGIN = 15; + public static final int INDEX_TIMER_DEFAULT_PRIORITY = 16; + public static final int INDEX_TIMER_DEFAULT_LIFETIME = 17; + public static final int INDEX_STREAM_PORT = 18; + public static final int INDEX_STREAM_USERNAME = 19; + public static final int INDEX_STREAM_PASSWORD = 20; + public static final int INDEX_STREAMFORMAT = 21; + public static final int INDEX_WOL_CUSTOM_BROADCAST = 22; + public static final int INDEX_ENABLE_REMUX = 23; + public static final int INDEX_REMUX_PARAMETER = 24; + + + + /** ID. */ + public static final String ID = "_id"; + public static final String HOST = "host"; + public static final String PORT= "port"; + public static final String SECURE = "secure"; + /* + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + public static final String = ""; + + public static final String = ""; + public static final String = ""; + */ + + + /** Projection used for query. */ + public static final String[] PROJECTION = new String[] {// + ID,// + HOST, PORT, SECURE }; + + /** Content {@link Uri}. */ + public static final Uri CONTENT_URI = Uri.parse("content://" + + AUTHORITY + "/" + TABLE); + /** + * The MIME type of {@link #CONTENT_URI} providing a list. + */ + public static final String CONTENT_TYPE = // . + "vnd.android.cursor.dir/vnd.vdramager.remux_params"; + + /** + * The MIME type of a {@link #CONTENT_URI} single entry. + */ + public static final String CONTENT_ITEM_TYPE = // . + "vnd.android.cursor.item/vnd.vdramager.jobs"; + + static { + PROJECTION_MAP = new HashMap(); + for (String s : PROJECTION) { + PROJECTION_MAP.put(s, s); + } + } + + /** + * Get Name for id. + * + * @param cr + * {@link ContentResolver} + * @param id + * id + * @return name + */ + // public static String getName(final ContentResolver cr, final long id) + // { + // final Cursor cursor = cr.query( + // ContentUris.withAppendedId(CONTENT_URI, id), + // new String[] { NAME }, null, null, null); + // String ret = null; + // if (cursor != null && cursor.moveToFirst()) { + // ret = cursor.getString(0); + // } + // if (cursor != null && !cursor.isClosed()) { + // cursor.close(); + // } + // return ret; + // } + + /** + * Create table in {@link SQLiteDatabase}. + * + * @param db + * {@link SQLiteDatabase} + */ + public static void onCreate(final SQLiteDatabase db) { + Log.i(TAG, "create table: " + TABLE); + db.execSQL("DROP TABLE IF EXISTS " + TABLE); + db.execSQL("CREATE TABLE " + TABLE + " (" // . + + ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // . + + HOST + " TEXT, "// + + PORT + " INTEGER, " + + SECURE +" INTEGER" + + " " + + " " + + + + + + ");");// + } + + /** + * Upgrade table. + * + * @param db + * {@link SQLiteDatabase} + * @param oldVersion + * old version + * @param newVersion + * new version + */ + public static void onUpgrade(final SQLiteDatabase db, + final int oldVersion, final int newVersion) { + Log.w(TAG, "Upgrading table: " + TABLE); + // if(newVersion == 2){ + // final ContentValues[] values = backup(db, TABLE, PROJECTION, + // null); + // onCreate(db); + // reload(db, TABLE, values); + // } else if (newVersion >) + // db.execSQL("DROP INDEX IF EXISTS jobs.canceled_index"); + // db.execSQL("CREATE INDEX canceled_index ON jobs(canceled)"); + // db.execSQL("ALTER TABLE JOBS ADD " + EVENT_ID2 + " LONG"); + } + + /** Default constructor. */ + private Vdr() { + } + } + + + /** * Try to backup fields from table. * diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java index 0318699..57017f7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java @@ -21,7 +21,7 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; public abstract class BaseActivity extends Activity implements OnClickListener, SvdrpAsyncListener { - + public static final String TAG = BaseActivity.class.getName(); public static final int MENU_GROUP_REFRESH = 99; @@ -33,32 +33,33 @@ public abstract class BaseActivity extends Activity protected ViewFlipper flipper; private Button retry; - + protected SvdrpProgressDialog progress; - - abstract protected int getWindowTitle(); - + + abstract protected String getWindowTitle(); + abstract protected int getMainLayout(); protected void switchNothinFound() { if (flipper == null) { return; } - //say("can not connect..."); - //flipper.setDisplayedChild(1); + // say("can not connect..."); + // flipper.setDisplayedChild(1); } - + protected void switchNoConnection() { if (flipper == null) { return; } - //say("can not connect..."); - //flipper.setDisplayedChild(1); + //TODO check if we are displaying something (results + // say("can not connect..."); + // flipper.setDisplayedChild(1); } protected void initFlipper() { this.flipper = (ViewFlipper) findViewById(R.id.flipper); - retry = (Button) findViewById(R.id.retry_button); + retry = (Button) findViewById(R.id.retry_button); retry.setOnClickListener(this); } @@ -67,23 +68,23 @@ public abstract class BaseActivity extends Activity retry(); } } - - protected void updateWindowTitle(int topic, int subtopic) { - String title; - title = getString(topic); - if (subtopic != -1) { - title += " > " + getString(subtopic); - } - setTitle(title); - } - - protected void updateWindowTitle(String topic, String subtopic) { - String title = topic; - if (subtopic != null) { - title += " > " + subtopic; - } - setTitle(title); - } +// +// protected void updateWindowTitle(int topic, int subtopic) { +// String title; +// title = getString(topic); +// if (subtopic != -1) { +// title += " > " + getString(subtopic); +// } +// setTitle(title); +// } +// +// protected void updateWindowTitle(String topic, String subtopic) { +// String title = topic; +// if (subtopic != null) { +// title += " > " + subtopic; +// } +// setTitle(title); +// } @Override public boolean onCreateOptionsMenu(final Menu menu) { @@ -215,10 +216,10 @@ public abstract class BaseActivity extends Activity cacheHit(); return; case FINISHED_SUCCESS: - if (finishedSuccess() == false) { - say(R.string.epg_no_items); - } else { + if (finishedSuccess()) { restoreViewSelection(); + } else { + say(R.string.epg_no_items); } break; case RESULT_RECEIVED: @@ -242,7 +243,7 @@ public abstract class BaseActivity extends Activity protected abstract void resultReceived(Result result); protected void connected() { - + } 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 22be292..a433e64 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java @@ -329,7 +329,7 @@ public abstract class BaseEventListActivity extends abstract protected boolean finishedSuccessImpl(); protected final boolean finishedSuccess() { - setTitle(getString(R.string.epg_window_title_count, getString(getWindowTitle()), results.size())); + setTitle(getString(R.string.epg_window_title_count, getWindowTitle(), results.size())); return finishedSuccessImpl(); } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java new file mode 100644 index 0000000..ced04c7 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BasePreferencesActivity.java @@ -0,0 +1,188 @@ +package de.bjusystems.vdrmanager.gui; + +import android.preference.DialogPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.text.TextUtils; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import de.bjusystems.vdrmanager.R; + +/** + * + * Basis class for PreferencesActivities with some goodies in it + * @author lado + * + */ +public abstract class BasePreferencesActivity extends PreferenceActivity { + + protected void updateSummary(Preference ep) { + if (ep instanceof EditTextPreference) { + updateSummary((EditTextPreference) ep); + } else if (ep instanceof ListPreference) { + updateSummary((ListPreference) ep); + } + } + + /** + * If text set add it to the summary + * + * @param ep + */ + protected void updateSummary(EditTextPreference ep) { + String text = ep.getText(); + if (text == null) { + return; + } + + if(isPassword(ep.getEditText())){ + text = text.replaceAll(".", "*"); + } + + setSummary(text, ep); + } + + protected boolean isPassword(EditText et){ + if((et.getInputType() & EditorInfo.TYPE_TEXT_VARIATION_PASSWORD) == EditorInfo.TYPE_TEXT_VARIATION_PASSWORD){ + return true; + } + return false; + } + + protected void setSummary(CharSequence text, DialogPreference ep){ + CharSequence sm = ep.getSummary(); + String sum; + if (sm != null) { + sum = ep.getSummary().toString(); + sum = substringBeforeLast(sum, + getString(R.string.prefs_current_value)).trim(); + } else { + sum = ""; + } + + if(TextUtils.isEmpty(text)){ + text = getString(R.string.prefs_current_value_not_set); + } + + if (isBlank(sum)) { + sum = getString(R.string.prefs_current_value_template, text); + } else { + sum = sum + " " + + getString(R.string.prefs_current_value_template, text); + } + ep.setSummary(sum); + } + + protected void updateSummary(ListPreference ep) { + CharSequence text = ep.getEntry(); + + if (text == null) { + return; + } + setSummary(text, ep); + } + + /** + *

+ * Gets the substring before the last occurrence of a separator. The + * separator is not returned. + *

+ * + *

+ * A null string input will return null. An empty + * ("") string input will return the empty string. An empty or + * null separator will return the input string. + *

+ * + *
+	 * StringUtils.substringBeforeLast(null, *)      = null
+	 * StringUtils.substringBeforeLast("", *)        = ""
+	 * StringUtils.substringBeforeLast("abcba", "b") = "abc"
+	 * StringUtils.substringBeforeLast("abc", "c")   = "ab"
+	 * StringUtils.substringBeforeLast("a", "a")     = ""
+	 * StringUtils.substringBeforeLast("a", "z")     = "a"
+	 * StringUtils.substringBeforeLast("a", null)    = "a"
+	 * StringUtils.substringBeforeLast("a", "")      = "a"
+	 * 
+ * + * @param str + * the String to get a substring from, may be null + * @param separator + * the String to search for, may be null + * @return the substring before the last occurrence of the separator, + * null if null String input + * @since 2.0 + */ + public static String substringBeforeLast(String str, String separator) { + if (isEmpty(str) || isEmpty(separator)) { + return str; + } + int pos = str.lastIndexOf(separator); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + // Empty checks + // ----------------------------------------------------------------------- + /** + *

+ * Checks if a String is empty ("") or null. + *

+ * + *
+	 * StringUtils.isEmpty(null)      = true
+	 * StringUtils.isEmpty("")        = true
+	 * StringUtils.isEmpty(" ")       = false
+	 * StringUtils.isEmpty("bob")     = false
+	 * StringUtils.isEmpty("  bob  ") = false
+	 * 
+ * + *

+ * NOTE: This method changed in Lang version 2.0. It no longer trims the + * String. That functionality is available in isBlank(). + *

+ * + * @param str + * the String to check, may be null + * @return true if the String is empty or null + */ + public static boolean isEmpty(String str) { + return str == null || str.length() == 0; + } + + /** + *

+ * Checks if a String is whitespace, empty ("") or null. + *

+ * + *
+	 * StringUtils.isBlank(null)      = true
+	 * StringUtils.isBlank("")        = true
+	 * StringUtils.isBlank(" ")       = true
+	 * StringUtils.isBlank("bob")     = false
+	 * StringUtils.isBlank("  bob  ") = false
+	 * 
+ * + * @param str + * the String to check, may be null + * @return true if the String is null, empty or whitespace + * @since 2.0 + */ + public static boolean isBlank(String str) { + int strLen; + if (str == null || (strLen = str.length()) == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if ((Character.isWhitespace(str.charAt(i)) == false)) { + return false; + } + } + return true; + } + +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java index fff74a9..69d31fd 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelAdapter.java @@ -5,7 +5,6 @@ import java.util.HashMap; import java.util.Map; import android.content.Context; -import android.graphics.Color; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -91,7 +90,7 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// , itemHolder = (ChannelHolder) view.getTag(); } - view.setBackgroundColor(Color.BLACK); + //view.setBackgroundColor(Color.BLACK); CharSequence name = item.getName(); name = Utils.highlight(String.valueOf(name), channelFilter); @@ -158,6 +157,7 @@ class ChannelAdapter extends BaseExpandableListAdapter implements Filterable// , } itemHolder.name.setText(groupDisplay); itemHolder.aux.setText(String.valueOf(channelCount)); + return view; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java index b320ace..77ec58b 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Menu; @@ -118,13 +119,12 @@ public class ChannelListActivity extends case MENU_GROUP: ArrayList cgs = ChannelClient.getChannelGroups(); adapter.fill(cgs, ChannelClient.getGroupChannels(), groupBy); - if (cgs.size() == 1) { + if (cgs.size() == 1 ) {//one group or first no first group + listView.expandGroup(0); + } else if ((cgs.size() > 1 && TextUtils.isEmpty(cgs.get(0)))){ listView.expandGroup(0); } - updateWindowTitle( - getString(R.string.action_menu_channels), - getString(R.string.groupby_window_title_templte, - getString(R.string.groupby_group))); + updateWindowTitle(); break; case MENU_PROVIDER: ArrayList gs = new ArrayList(ChannelClient @@ -133,10 +133,7 @@ public class ChannelListActivity extends if (gs.size() == 1) { listView.expandGroup(0); } - updateWindowTitle( - getString(R.string.action_menu_channels), - getString(R.string.groupby_window_title_templte, - getString(R.string.groupby_provider))); + updateWindowTitle(); break; case MENU_NAME: if (ALL_CHANNELS_GROUP.isEmpty()) { @@ -149,10 +146,7 @@ public class ChannelListActivity extends ChannelClient.getChannels()); adapter.fill(ALL_CHANNELS_GROUP, channels, groupBy); listView.expandGroup(0); - - updateWindowTitle(R.string.action_menu_channels, - R.string.groupby_name_all_channels_group); - break; + updateWindowTitle(); } } @@ -330,12 +324,31 @@ public class ChannelListActivity extends return R.layout.channel_list; } + private String resolveWindowTitle(){ + StringBuilder sb = new StringBuilder(); + switch(groupBy){ + case MENU_NAME: + sb.append(getString(R.string.action_menu_channels)).append(" > ").append(getString(R.string.groupby_name_all_channels_group)); + break; + case MENU_PROVIDER: + sb.append(getString(R.string.action_menu_channels)).append(" > ").append(getString(R.string.groupby_window_title_templte,getString(R.string.groupby_provider))); + break; + case MENU_GROUP: + sb.append(getString(R.string.action_menu_channels)).append(" > ").append(getString(R.string.groupby_window_title_templte,getString(R.string.groupby_group))); + break; + } + return sb.toString(); + } + + private void updateWindowTitle(){ + setTitle(getString(R.string.channels_window_title_count,resolveWindowTitle(), adapter.groups.size(), ChannelClient.getChannels().size())); + } + @Override protected boolean finishedSuccess() { fillAdapter(); restoreViewSelection(); - setTitle(getString(R.string.channels_window_title_count,getString(getWindowTitle()), ChannelClient.getChannelGroups().size(), ChannelClient.getChannels().size())); - + updateWindowTitle(); return ChannelClient.getChannels().isEmpty() == false; } @@ -349,8 +362,8 @@ public class ChannelListActivity extends } @Override - protected int getWindowTitle() { - return R.string.action_menu_channels; + protected String getWindowTitle() { + return resolveWindowTitle(); } } \ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java index b59b3d3..b7fb8bc 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java @@ -90,7 +90,7 @@ public class EpgSearchListActivity extends BaseTimerEditActivity implements EpgSearchParams sp = new EpgSearchParams(); sp.setTitle(highlight); - setTitle(getString(R.string.epg_by_search_param, highlight)); + setTitle(getWindowTitle()); epgClient = new EpgClient(sp); // remove old listeners // epgClient.clearSvdrpListener(); @@ -163,8 +163,12 @@ public class EpgSearchListActivity extends BaseTimerEditActivity implements } @Override - protected int getWindowTitle() { - return R.string.epg_by_search; + protected String getWindowTitle() { + if(TextUtils.isEmpty(highlight)){ + return getString(R.string.epg_by_search); + } + + return getString(R.string.epg_by_search_param, highlight); } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java index 96e2e7e..978e344 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java @@ -34,6 +34,15 @@ abstract class EventAdapter extends ArrayAdapter 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(); + + public EventAdapter(final Context context, int layout) { super(context, layout); this.layout = layout; @@ -224,7 +233,7 @@ abstract class EventAdapter extends ArrayAdapter 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 public Filter getFilter() { return new Filter() { /** diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java index c99a8ed..70128cb 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java @@ -6,6 +6,7 @@ import java.util.Date; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -20,6 +21,7 @@ import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Epg; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventListItem; +import de.bjusystems.vdrmanager.tasks.ChannelsTask; import de.bjusystems.vdrmanager.utils.date.DateFormatter; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; import de.bjusystems.vdrmanager.utils.svdrp.EpgClient; @@ -39,6 +41,8 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements private final static ArrayList CACHE = new ArrayList(); + private static final String TAG = EventEpgListActivity.class.getSimpleName(); + protected static Date nextForceCache = null; private static Channel cachedChannel = null; @@ -61,7 +65,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); channelSpinner = (Spinner) findViewById(R.id.epg_list_channel_spinner); channelSpinner.setAdapter(channelSpinnerAdapter); - channelSpinner.setOnItemSelectedListener(this); + switcher = findViewById(R.id.switch_epg_view); switcher.setOnClickListener(this); @@ -88,7 +92,26 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements // register EPG item click listView.setOnItemClickListener(this); - startEpgQuery(); + + + new ChannelsTask(this, new ChannelClient()){ + public void finished(SvdrpEvent event) { + if (event == SvdrpEvent.CACHE_HIT + || event == SvdrpEvent.FINISHED_SUCCESS) { + ArrayList channels = ChannelClient.getChannels(); + for (final Channel c : channels) { + channelSpinnerAdapter.add(c); + } + currentChannel = getApp().getCurrentChannel(); + if(currentChannel != null){ + channelSpinner.setSelection(currentChannel.getNumber() - 1); + } + channelSpinner.setOnItemSelectedListener(EventEpgListActivity.this); + } else { + noConnection(event); + } + }}.start(); + } // private void ensureChannelList() { @@ -101,6 +124,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements @Override protected void onResume() { super.onResume(); + Log.d(TAG, "onResume()"); //backupViewSelection(); //startEpgQuery(); // @@ -108,15 +132,14 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements public void onItemSelected(final AdapterView parent, final View view, final int position, final long id) { - + Log.d(TAG, "onItemSelected()"); // get spinner value final Channel channel = (Channel) channelSpinner.getSelectedItem(); currentChannel = channel; setCurrent(channel); // setAsCurrent(channel); // update search - startEpgQuery(); - + startEpgQueryImpl(false); } // class LoadChannelsTask extends AsyncProgressTask { @@ -144,6 +167,7 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements // } public void onNothingSelected(final AdapterView arg0) { + Log.d(TAG, "onNothingSelected()"); // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); } @@ -168,15 +192,6 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements return true; } - // - - //private void startEpgQuery(boolean force) { - //startEpgQuery(force); - //} - - synchronized private void startEpgQuery() { - startEpgQuery(false); - } @Override public void onClick(View view) { @@ -191,20 +206,28 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements } } - private void startEpgQuery(boolean force) { + private void startEpgQuery(final boolean force) { + if(true){ + startEpgQueryImpl(force); + } + Log.d(TAG, "startEpgQuery, " + force); try { ChannelClient client = new ChannelClient(); + client.addSvdrpListener(new SvdrpListener() { public void svdrpEvent(SvdrpEvent event, Channel result) { if (event == SvdrpEvent.CACHE_HIT || event == SvdrpEvent.FINISHED_SUCCESS) { - ArrayList channels = ChannelClient - .getChannels(); + channelSpinnerAdapter.clear(); + ArrayList channels = ChannelClient.getChannels(); for (final Channel c : channels) { channelSpinnerAdapter.add(c); } + // startEpgQueryImpl(force); + } else { + noConnection(event); } - noConnection(event); + } }); client.run(); @@ -212,19 +235,21 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements svdrpException(ex); return; } - if(currentChannel == null && ChannelClient.getChannels().isEmpty() == false){ - currentChannel = ChannelClient.getChannels().get(0); - setCurrent(currentChannel); - } - if(currentChannel != null){ - startEpgQueryImpl(force); - } + //if(currentChannel == null && ChannelClient.getChannels().isEmpty() == false){ + //currentChannel = ChannelClient.getChannels().get(0); + //setCurrent(currentChannel); + //} + + //if(currentChannel != null){ + + //} } - synchronized private void startEpgQueryImpl(boolean force) { + private void startEpgQueryImpl(boolean force) { + Log.d(TAG,"startEpgQueryImpl"); if (useCache() && !force) { Calendar cal = Calendar.getInstance(); @@ -324,8 +349,8 @@ public class EventEpgListActivity extends BaseTimerEditActivity implements } @Override - protected int getWindowTitle() { - return R.string.epg_by_channel; + protected String getWindowTitle() { + return getString(R.string.epg_by_channel); } private void nextEvent() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java index 9974721..4ddca83 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java @@ -159,8 +159,8 @@ public class RecordingListActivity extends BaseEventListActivity } @Override - protected int getWindowTitle() { - return R.string.action_menu_recordings; + protected String getWindowTitle() { + return getString(R.string.action_menu_recordings); } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java index 5746170..72c2fb0 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java @@ -151,11 +151,23 @@ public class TimeEpgListActivity extends BaseTimerEditActivity implements counter++; } timeSpinner.setSelection(select); - setTitle(getString(R.string.epg_by_time_args, tm)); + setTitle(resolveWindowTitle()); // update search startEpgQuery(time.getValue(), false); } + private String resolveWindowTitle() { + if (timeSpinner == null) { + return getString(R.string.epg_by_time); + } + EpgSearchTimeValue v = (EpgSearchTimeValue) timeSpinner + .getSelectedItem(); + if (v == null) { + return getString(R.string.epg_by_time); + } + return getString(R.string.epg_by_time_args, v.getText()); + } + public void onItemSelected(final AdapterView parent, final View view, final int position, final long id) { @@ -262,7 +274,7 @@ public class TimeEpgListActivity extends BaseTimerEditActivity implements if (results.isEmpty()) { return false; } - + adapter.add(new EventListItem(new DateFormatter(results.get(0) .getStart()).getDailyHeader())); @@ -306,8 +318,8 @@ public class TimeEpgListActivity extends BaseTimerEditActivity implements } @Override - protected int getWindowTitle() { - return R.string.epg_by_time; + protected String getWindowTitle() { + return resolveWindowTitle(); } private void nextEvent() { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java index b0c9b46..b9d8ee1 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java @@ -137,8 +137,8 @@ public class TimerListActivity extends BaseTimerEditActivity implements } @Override - protected int getWindowTitle() { - return R.string.action_menu_timers; + protected String getWindowTitle() { + return getString(R.string.action_menu_timers); } @Override diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java index f22b4e3..1eea3ad 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java @@ -100,7 +100,14 @@ public class Utils { // "http://192.168.1.119:3000/TS/" StringBuilder sb = new StringBuilder(); Preferences p = Preferences.getPreferences(); - sb.append("http://").append(p.getSvdrpHost()).append(":") + String auth = p.getStreamingUsername().trim() + ":" + p.getStreamingPassword(); + if(auth.length() == 1){ + auth = ""; + } else { + auth += "@"; + } + + sb.append("http://").append(auth).append(p.getSvdrpHost()).append(":") .append(p.getStreamPort()).append("/") .append(p.getStreamFormat()).append("/").append(chn); return sb.toString(); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java new file mode 100644 index 0000000..f4a3358 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java @@ -0,0 +1,12 @@ +package de.bjusystems.vdrmanager.tasks; + +import android.app.Activity; +import de.bjusystems.vdrmanager.R; +import de.bjusystems.vdrmanager.data.Channel; +import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; + +public abstract class ChannelsTask extends AsyncProgressTask { + public ChannelsTask(final Activity activity, final ChannelClient client) { + super(activity, client); + } +} -- cgit v1.2.3