diff options
author | lado <herrlado@gmail.com> | 2011-11-11 14:54:44 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2011-11-11 14:54:44 +0100 |
commit | d747c7f0fbb5775daf4d3a214cdbb9c4fb8855c3 (patch) | |
tree | 32f1da343ff173ae0b0357eaf65f3b5d67fff683 /vdrmanager/src/de | |
parent | b756d8ee1e9d0c2256c5c6d250bf965d2175c526 (diff) | |
download | vdr-manager-d747c7f0fbb5775daf4d3a214cdbb9c4fb8855c3.tar.gz vdr-manager-d747c7f0fbb5775daf4d3a214cdbb9c4fb8855c3.tar.bz2 |
refactor
Diffstat (limited to 'vdrmanager/src/de')
10 files changed, 182 insertions, 62 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java index c6fccc6..64726d9 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java @@ -2,8 +2,7 @@ package de.bjusystems.vdrmanager.gui; import android.app.Activity; import android.app.AlertDialog; -import android.content.Context; -import android.net.ConnectivityManager; +import android.app.ProgressDialog; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -18,6 +17,7 @@ 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.SvdrpClient; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; @@ -35,8 +35,9 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity protected ViewFlipper flipper; private Button retry; - - protected SvdrpProgressDialog progress; + + private ProgressDialog progress; + //protected SvdrpProgressDialog progress; abstract protected String getWindowTitle(); @@ -101,6 +102,7 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Preferences.setLocale(this); + progress = new ProgressDialog(this); } @Override @@ -115,6 +117,8 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity abstract protected void refresh(); abstract protected void retry(); + + abstract protected SvdrpClient<Result> getClient(); @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -210,17 +214,34 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity public void svdrpEvent(final SvdrpEvent event, final Result result) { switch (event) { - + case LOGIN: + break; + case COMMAND_SENDING: + 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(getClient().getProgressTextId()); + break; + case DISCONNECTING: + setMessage(R.string.progress_disconnect); + break; + case DISCONNECTED: + break; case ABORTED: say(R.string.aborted); break; case ERROR: alert(R.string.epg_client_errors); - // say(R.string.epg_client_errors); - // dismiss(progress); - break; - case CONNECTING: + progress.dismiss(); break; + case CONNECTED: connected(); break; @@ -228,18 +249,22 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity case CONNECT_ERROR: case FINISHED_ABNORMALY: case LOGIN_ERROR: + progress.dismiss(); noConnection(event); break; case CACHE_HIT: cacheHit(); + progress.dismiss(); return; case FINISHED_SUCCESS: + if (finishedSuccess()) { finishedSuccess = true; restoreViewSelection(); } else { say(R.string.epg_no_items); } + progress.dismiss(); break; case RESULT_RECEIVED: resultReceived(result); @@ -247,6 +272,10 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity } } + private void setMessage(int progressConnect) { + progress.setMessage(getString(progressConnect)); + } + protected boolean finishedSuccess = false; protected void cacheHit() { @@ -268,9 +297,17 @@ public abstract class BaseActivity<Result, T extends ListView> extends Activity } public void svdrpException(final SvdrpException exception) { - progress.svdrpException(exception); +// svdrpException(exception); // Log.w(TAG, exception); alert(getString(R.string.vdr_error_text, exception.getMessage())); } + + @Override + protected void onDestroy() { + if(progress.isShowing()){ + progress.dismiss(); + } + super.onDestroy(); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java index b4f17b7..5dd1aff 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java @@ -1,5 +1,9 @@ package de.bjusystems.vdrmanager.gui; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import android.content.Intent; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -14,6 +18,7 @@ import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventFormatter; import de.bjusystems.vdrmanager.data.EventListItem; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.data.Timerable; import de.bjusystems.vdrmanager.tasks.DeleteTimerTask; import de.bjusystems.vdrmanager.tasks.ToggleTimerTask; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; @@ -23,19 +28,27 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; * This class is a base class for all the listings, which can deal with timers * * @author lado - * - * @param <T> Class extending Event + * + * @param <T> + * Class extending Event */ public abstract class BaseTimerEditActivity<T extends Event> extends BaseEventListActivity<T> implements OnClickListener // SvdrpAsyncListener<Timer>, { + private static final ScheduledExecutorService worker = Executors + .newSingleThreadScheduledExecutor(); + + // /@Override + // public boolean onPrepareOptionsMenu(Menu menu) { + // return super.onPrepareOptionsMenu(menu); + // } /* * (non-Javadoc) * * @see android.app.Activity#onContextItemSelected(android.view.MenuItem) */ - @Override + // @Override public boolean onContextItemSelected(final MenuItem item) { // final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item @@ -44,11 +57,13 @@ public abstract class BaseTimerEditActivity<T extends Event> extends getApp().setCurrentEvent(event.getEvent()); switch (item.getItemId()) { case R.id.epg_item_menu_timer_add: { - getApp().setCurrentTimer(event.createTimer()); + + getApp().setCurrentTimer(createTimer(event)); final Intent intent = new Intent(); intent.setClass(this, TimerDetailsActivity.class); intent.putExtra(Intents.TIMER_OP, Intents.ADD_TIMER); - startActivityForResult(intent, TimerDetailsActivity.REQUEST_CODE_TIMER_ADD); + startActivityForResult(intent, + TimerDetailsActivity.REQUEST_CODE_TIMER_ADD); } break; case R.id.epg_item_menu_timer_modify: { @@ -56,7 +71,8 @@ public abstract class BaseTimerEditActivity<T extends Event> extends final Intent intent = new Intent(); intent.setClass(this, TimerDetailsActivity.class); intent.putExtra(Intents.TIMER_OP, Intents.EDIT_TIMER); - startActivityForResult(intent, TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT); + startActivityForResult(intent, + TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT); break; } case R.id.epg_item_menu_timer_delete: { @@ -112,21 +128,34 @@ public abstract class BaseTimerEditActivity<T extends Event> extends super.onCreateContextMenu(menu, v, menuInfo); } + protected Timer createTimer(EventListItem item) { + Event e = item.getEvent(); + if (e instanceof Timerable == false) { + return null; + } + return ((Timerable) e).createTimer(); + + } + /** * Extract a Timer from a given {@link EventListItem} * - * @param item + * @param item * @return Timer if any on the event */ protected Timer getTimer(EventListItem item) { - return item.getTimer(); + Event e = item.getEvent(); + if (e instanceof Timerable == false) { + return null; + } + return ((Timerable) e).getTimer(); } protected void toggleTimer(Timer timer) { final ToggleTimerTask task = new ToggleTimerTask(this, timer) { @Override public void finished(SvdrpEvent event) { - refresh(); + timerModified(); restoreViewSelection(); } }; @@ -143,7 +172,7 @@ public abstract class BaseTimerEditActivity<T extends Event> extends final DeleteTimerTask task = new DeleteTimerTask(this, timer) { @Override public void finished(SvdrpEvent event) { - refresh(); + timerModified(); restoreViewSelection(); } }; @@ -151,16 +180,25 @@ public abstract class BaseTimerEditActivity<T extends Event> extends } /** - * Is called, if a timer has been changed and so update of the list is required + * Is called, if a timer has been changed and so update of the list is + * required */ protected void timerModified() { backupViewSelection(); - refresh(); + //say(R.string.update_will_start_in); + //Runnable task = new Runnable() { + //public void run() { + refresh(); + //} + //}; + //worker.schedule(task, 1000, TimeUnit.MILLISECONDS); } - /* (non-Javadoc) - * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) + /* + * (non-Javadoc) * + * @see android.app.Activity#onActivityResult(int, int, + * android.content.Intent) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java index 31774ae..3a23008 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java @@ -42,6 +42,11 @@ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements @Override + protected SvdrpClient<Epg> getClient() { + return this.epgClient; + } + + @Override protected void onNewIntent(Intent intent) { initSearch(intent); startSearch(); @@ -99,9 +104,6 @@ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog<Epg>(this, epgClient); - // attach listener - task.addListener(progress); task.addListener(this); // start task @@ -135,7 +137,6 @@ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements adapter.add(new EventListItem((Epg)e)); } listView.setSelectionAfterHeaderView(); - dismiss(progress); return results.isEmpty() == false; } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java index 978e344..8b77fa6 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java @@ -18,6 +18,8 @@ import de.bjusystems.vdrmanager.R; 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.Timerable; abstract class EventAdapter extends ArrayAdapter<EventListItem> implements Filterable { @@ -142,8 +144,20 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements public void fillEventViewHolder(EventListItemHolder itemHolder, EventListItem item) { + + + + itemHolder.state.setVisibility(View.VISIBLE); - switch (item.getTimerState()) { + + if(item.getEvent() instanceof Timerable == false){ + 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); + } + } else { + switch (((Timerable)item.getEvent()).getTimerState()) { case Active: itemHolder.state.setImageResource(R.drawable.timer_active); break; @@ -157,6 +171,7 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements itemHolder.state.setImageResource(R.drawable.timer_none); break; } + } final EventFormatter formatter = getEventFormatter(item); itemHolder.time.setText(formatter.getTime()); @@ -181,6 +196,7 @@ abstract class EventAdapter extends ArrayAdapter<EventListItem> implements } } + //TODO better render of duration int p = Utils.getProgress(item); if (p == -1) { itemHolder.progress.setVisibility(View.GONE); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java index f99e7b4..7264a77 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java @@ -215,15 +215,18 @@ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog<Epg>(this, epgClient); - // attach listener - task.addListener(progress); + task.addListener(this); // start task task.run(); } + + @Override + protected SvdrpClient<Epg> getClient() { + return this.epgClient; + } /* * (non-Javadoc) TODO this method also should be used in startEpgQuery on * cache hit diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java index 314e36c..3bbb5eb 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java @@ -56,6 +56,13 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> // start query startRecordingQuery(); } + + + + @Override + protected SvdrpClient<Recording> getClient() { + return this.recordingClient; + } @Override protected void onPause() { @@ -98,7 +105,6 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> DeleteRecordingTask drt = new DeleteRecordingTask(this, rec) { @Override public void finished(SvdrpEvent event) { - dismiss(progress); backupViewSelection(); refresh(); } @@ -133,11 +139,6 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> // create progress dialog - progress = new SvdrpProgressDialog(this, recordingClient); - - - // attach listener - task.addListener(progress); task.addListener(this); // start task @@ -167,7 +168,7 @@ public class RecordingListActivity extends BaseEventListActivity<Recording> adapter.clear(); Calendar cal = Calendar.getInstance(); int day = -1; - sortItemsByTime(results); + sortItemsByTime(results, true); for (final Event rec : results) { cal.setTime(rec.getStart()); int eday = cal.get(Calendar.DAY_OF_YEAR); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java index d9c0b6e..7d5d8a3 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java @@ -55,6 +55,13 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements int selectedIndex = 0; + + + @Override + protected SvdrpClient<Epg> getClient() { + return this.epgClient; + } + @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -250,9 +257,6 @@ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements epgClient); // create progress - progress = new SvdrpProgressDialog<Epg>(this, epgClient); - // attach listener - task.addListener(progress); task.addListener(this); // start task diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java index 448c490..c085442 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerDetailsActivity.java @@ -46,10 +46,10 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, tView.view = view; tView.title = (TextView) view.findViewById(R.id.timer_detail_title); tView.channel = (TextView) view.findViewById(R.id.timer_detail_channel); - tView.dateField = (TextView) view.findViewById(R.id.timer_detail_day); - tView.startField = (TextView) view + tView.dateField = (Button) view.findViewById(R.id.timer_detail_day); + tView.startField = (Button) view .findViewById(R.id.timer_detail_start); - tView.endField = (TextView) view.findViewById(R.id.timer_detail_end); + tView.endField = (Button) view.findViewById(R.id.timer_detail_end); tView.saveButton = (Button) view.findViewById(R.id.timer_details_save); tView.modifyButton = (Button) view .findViewById(R.id.timer_details_modify); @@ -62,6 +62,7 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, tView.modifyButton.setOnClickListener(this); setContentView(view); timer = getApp().getCurrentTimer(); + original = timer.copy(); int op = getIntent().getExtras().getInt(Intents.TIMER_OP); switch (op) { case Intents.ADD_TIMER: @@ -83,9 +84,9 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, View view; TextView title; TextView channel; - TextView dateField; - TextView startField; - TextView endField; + Button dateField; + Button startField; + Button endField; Button saveButton; Button modifyButton; } @@ -97,6 +98,8 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, // SetTimerClient setTimerClient; Timer timer; + + Timer original; private void updateDisplay(TimerOperation op) { updateDisplay(); @@ -176,12 +179,12 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, } case R.id.timer_details_modify: modifyTimer(timer); - say(R.string.done); + //say(R.string.done); break; case R.id.timer_details_save: { createTimer(timer); - say(R.string.done); + //say(R.string.done); break; } @@ -259,7 +262,7 @@ public class TimerDetailsActivity extends Activity implements OnClickListener, } private void modifyTimer(Timer timer) { - final ModifyTimerTask task = new ModifyTimerTask(this, timer) { + final ModifyTimerTask task = new ModifyTimerTask(this, timer, original) { @Override public void finished(SvdrpEvent event) { done(); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java index a2037f2..2029ed7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java @@ -3,6 +3,7 @@ package de.bjusystems.vdrmanager.gui; import java.util.Calendar; import android.os.Bundle; +import android.view.Menu; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import de.bjusystems.vdrmanager.R; @@ -24,11 +25,19 @@ import de.bjusystems.vdrmanager.utils.svdrp.TimerClient; public class TimerListActivity extends BaseTimerEditActivity<Timer> implements OnItemClickListener, SvdrpAsyncListener<Timer> { + private static final int MENU_NEW_TIMER = 2; + + private static final int MENU_GROUP_NEW_TIMER = 2; /** * */ TimerClient timerClient; + + @Override + protected SvdrpClient<Timer> getClient() { + return this.timerClient; + } /* * (non-Javadoc) * @@ -80,10 +89,10 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements timerClient); // create progress dialog - progress = new SvdrpProgressDialog(this, timerClient); + //progress = new SvdrpProgressDialog(this, timerClient); // attach listener - task.addListener(progress); + //task.addListener(progress); task.addListener(this); // start task @@ -118,7 +127,7 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements protected boolean finishedSuccessImpl() { adapter.clear(); - sortItemsByTime(results); + sortItemsByTime(results, true); int day = -1; Calendar cal = Calendar.getInstance(); for (Event e : results) { @@ -132,7 +141,6 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements adapter.add(new EventListItem(e)); } listView.setSelectionAfterHeaderView(); - dismiss(progress); return results.isEmpty() == false; } @@ -155,5 +163,14 @@ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements protected void retry() { refresh(); } + + public boolean onCreateOptionsMenu(final Menu menu) { + // MenuItem item; + //item = menu.add(MENU_GROUP_NEW_TIMER, MENU_NEW_TIMER, 0, R.string.new_timer); + //item.setIcon(android.R.drawable.ic_menu_add);; +// /item.setAlphabeticShortcut('r'); + return super.onCreateOptionsMenu(menu); + } + } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java index 9e6ed41..48b3389 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java @@ -133,17 +133,17 @@ public class Utils { } public static void stream(Activity activity, Event event) { - stream(activity, event.getChannelNumber()); + stream(activity, event.getStreamId()); } public static void stream(Activity a, Channel c) { - stream(a, String.valueOf(c.getNumber())); + stream(a, String.valueOf(c.getId())); } - public static void stream(final Activity activity, final String chn) { + public static void stream(final Activity activity, final String idornr) { if (Preferences.get().isEnableRemux() == false) { - String url = getStreamUrl(chn); + String url = getStreamUrl(idornr); startStream(activity, url); return; } @@ -169,10 +169,10 @@ public class Utils { String url = null; switch (which) { case 0: - url = getStreamUrl(chn); + url = getStreamUrl(idornr); break; case 1: - url = getRemuxStreamUrl(chn); + url = getRemuxStreamUrl(idornr); break; } startStream(activity, url); @@ -187,7 +187,7 @@ public class Utils { } public static int getDuration(Event event) { - long millis = event.getStop().getTime() - event.getStart().getTime(); + long millis = event.getDuration(); int minuts = (int) (millis / 1000 / 60); return minuts; } |