diff options
Diffstat (limited to 'vdrmanager/app/src')
9 files changed, 713 insertions, 672 deletions
diff --git a/vdrmanager/app/src/main/AndroidManifest.xml b/vdrmanager/app/src/main/AndroidManifest.xml index 6d56eac..6615b76 100644 --- a/vdrmanager/app/src/main/AndroidManifest.xml +++ b/vdrmanager/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.bjusystems.vdrmanager" - android:versionCode="12260" - android:versionName="12.26" > + android:versionCode="12270" + android:versionName="12.27" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java index b377144..9aaed58 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/BaseTimerEditActivity.java @@ -21,7 +21,6 @@ import de.bjusystems.vdrmanager.tasks.ToggleTimerTask; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; /** - * * This class is a base class for all the listings, which can deal with timers * * @author lado diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java index c1daefa..3b6bf94 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/EpgDetailsActivity.java @@ -51,718 +51,739 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; /** * This class is used for showing what's current running on all channels - * + * * @author bju */ public class EpgDetailsActivity extends ActionBarActivity implements - OnClickListener, OnPageChangeListener { + OnClickListener, OnPageChangeListener, View.OnLongClickListener { - public static final String TAG = "EpgDetailsActivity"; + public static final String TAG = "EpgDetailsActivity"; - public static String IMDB_BASE_URL = "http://%s"; + public static String IMDB_BASE_URL = "http://%s"; - public static String IMDB_URL_QUERY = "/find?s=tt&q=%s"; + public static String IMDB_URL_QUERY = "/find?s=tt&q=%s"; - public static String OMDB_URL = "http://www.omdb.org/search?search[text]=%s"; + public static String OMDB_URL = "http://www.omdb.org/search?search[text]=%s"; - private static final String IMDB_URL_ENCODING = "UTF-8"; + private static final String IMDB_URL_ENCODING = "UTF-8"; - private static final String OMDB_URL_ENCODING = "UTF-8"; + private static final String OMDB_URL_ENCODING = "UTF-8"; - private static final String TMDB_URL_ENCODING = "UTF-8"; + private static final String TMDB_URL_ENCODING = "UTF-8"; - public static String TMDB_URL = "http://www.themoviedb.org/search?search=%s"; + public static String TMDB_URL = "http://www.themoviedb.org/search?search=%s"; - private String highlight = null; + private String highlight = null; - // private Event cEvent; + // private Event cEvent; - // private ImageView state; + // private ImageView state; - private boolean modifed = false; + private boolean modifed = false; - // private int current; + // private int current; - private ViewPager pager; + private ViewPager pager; - private Adapter adapter; + private Adapter adapter; - // private Timerable timerable = null; + @Override + public boolean onLongClick(View v) { + if (v.getId() == R.id.epg_event_create_timer) { + final Event cEvent = epgs.get(pager.getCurrentItem()); + if (getTimer(cEvent) != null) { + say(R.string.timer_already_exists); + return true; + } - class Adapter extends PagerAdapter implements TitleProvider { + final Timer timer = new Timer(cEvent); + final CreateTimerTask task = new CreateTimerTask( + EpgDetailsActivity.this, timer) { + boolean error = false; + @Override + public void svdrpEvent(final SvdrpEvent event, Throwable th) { + if(event == SvdrpEvent.ERROR){ + error = true; + } + super.svdrpEvent(event, th); + } - public Adapter() { + @Override + public void finished(SvdrpEvent event) { + modifed = true; + EpgCache.CACHE.remove(timer + .getChannelId()); + if(error == false && event == SvdrpEvent.FINISHED_SUCCESS) { + say(R.string.timer_created); + } + } + }; + task.start(); + return true; - } - public String getTitle(int position) { - return epgs.get(position).getChannelName(); - } + } + return false; + } - public int getCount() { - return epgs.size(); - } + // private Timerable timerable = null; - public Object instantiateItem(View pager, int position) { - View view = getLayoutInflater().inflate(R.layout.epg_detail, null); - // Event e = epgs.get(position); - publishEPG(view, position); - ((ViewPager) pager).addView(view, 0); + class Adapter extends PagerAdapter implements TitleProvider { - return view; - } + public Adapter() { - public void destroyItem(View pager, int position, Object view) { - ((ViewPager) pager).removeView((View) view); - } + } - public boolean isViewFromObject(View view, Object object) { - return view.equals(object); - } + public String getTitle(int position) { + return epgs.get(position).getChannelName(); + } - public void finishUpdate(View view) { - } + public int getCount() { + return epgs.size(); + } - public void restoreState(Parcelable p, ClassLoader c) { - } + public Object instantiateItem(View pager, int position) { + View view = getLayoutInflater().inflate(R.layout.epg_detail, null); + // Event e = epgs.get(position); + publishEPG(view, position); + ((ViewPager) pager).addView(view, 0); - public Parcelable saveState() { - return null; - } + return view; + } - public void startUpdate(View view) { - } - } + public void destroyItem(View pager, int position, Object view) { + ((ViewPager) pager).removeView((View) view); + } - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getSupportActionBar().setHomeButtonEnabled(true); - // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); + public boolean isViewFromObject(View view, Object object) { + return view.equals(object); + } - Intent i = getIntent(); + public void finishUpdate(View view) { + } - highlight = i.getStringExtra(Intents.HIGHLIGHT); - final int preselect = i.getIntExtra(Intents.CURRENT_EPG, 0); + public void restoreState(Parcelable p, ClassLoader c) { + } - + public Parcelable saveState() { + return null; + } - // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); - // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, - // R.layout.titlebar); + public void startUpdate(View view) { + } + } - // Attach view - setContentView(R.layout.epgdetails); + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getSupportActionBar().setHomeButtonEnabled(true); + // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); - // detector = new SimpleGestureFilter(this, this); + Intent i = getIntent(); - // state = (ImageView) findViewById(R.id.epg_timer_state); + highlight = i.getStringExtra(Intents.HIGHLIGHT); + final int preselect = i.getIntExtra(Intents.CURRENT_EPG, 0); - final Event epg = getApp().getCurrentEvent(); - if (epg == null) { - finish(); - } - final Event cEvent = epg; + // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); + // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, + // R.layout.titlebar); - if (epg instanceof Timerable) { - // timerable = (Timerable) cEvent; - } + // Attach view + setContentView(R.layout.epgdetails); - - pager = (ViewPager) findViewById(R.id.viewpager); - pager.setOnPageChangeListener(this); - + // detector = new SimpleGestureFilter(this, this); - new VoidAsyncTask() { + // state = (ImageView) findViewById(R.id.epg_timer_state); - int counter = 0; + final Event epg = getApp().getCurrentEvent(); + if (epg == null) { + finish(); + } - @Override - protected void onPreExecute() { - setProgressBarIndeterminateVisibility(true); - } + final Event cEvent = epg; - @Override - protected Void doInBackground(Void... params) { - // current event - final VdrManagerApp app = (VdrManagerApp) getApplication(); - epgs = app.getCurrentEpgList(); - - if (epgs.isEmpty()) { - epgs.add(cEvent); - return (Void) null; - } - - // for (Event e : epgs) { - // if (epg.equals(e)) { - // break; - //} - //counter++; - //} - - //if (counter == epgs.size()) {// not found? - //epgs.add(0, cEvent); - //counter = 0; - //} - if(preselect < epgs.size()){ - counter = preselect; - } - return (Void) null; - } - - @Override - protected void onPostExecute(Void result) { - adapter = new Adapter(); - pager.setAdapter(adapter); - pager.setCurrentItem(counter); - onPageSelected(counter); - } - }.execute((Void) null); - - } - - private void setState(ImageView view, int res) { - view.setVisibility(View.VISIBLE); - view.setImageResource(res); - } - - private static String encode(String str, String enc) { - try { - return URLEncoder.encode(str, enc); - } catch (Exception ex) { - Log.w(TAG, ex); - return URLEncoder.encode(str); - } - } - - public void publishEPG(final View view, int position) { - - Event event = epgs.get(position); - - Timerable timerable = null; - - if (event instanceof Timerable) { - timerable = (Timerable) event; - } - - view.setTag(event); - // view.setTag(event); - - final EventFormatter formatter = new EventFormatter(event); - - final TextView title = (TextView) view - .findViewById(R.id.epg_detail_title); - String titleText = formatter.getTitle(); - title.setText(Utils.highlight(titleText, highlight)); - // title.setTextSize(TypedValue.COMPLEX_UNIT_PX, title.getTextSize() - // * (float) 1.3); - - ((TextView) view.findViewById(R.id.epg_detail_time)).setText(formatter - .getDate() + " " + formatter.getTime()); - - TextView dura = (TextView) view.findViewById(R.id.epg_detail_duration); - - ((TextView) view.findViewById(R.id.epg_detail_channel)).setText(event - .getChannelName()); - // ((TextView) findViewById(R.id.epg_detail_date)).setText(formatter - // .getLongDate()); - ImageView state = (ImageView) view.findViewById(R.id.epg_timer_state); - if (timerable == null) { - setState(state, R.drawable.timer_none); - } else { - - TimerMatch match = timerable.getTimerMatch(); - - switch (timerable.getTimerState()) { - case Active: - setState(state, Utils.getTimerStateDrawable(match, - R.drawable.timer_active, - R.drawable.timer_active_begin, - R.drawable.timer_active_end, - R.drawable.timer_active_conflict)); - break; - case Inactive: - setState(state, Utils.getTimerStateDrawable(match, - R.drawable.timer_inactive, - R.drawable.timer_inactive_begin, - R.drawable.timer_inactive_end, - R.drawable.timer_inactive)); - break; - case Recording: - setState(state, Utils.getTimerStateDrawable(match, - R.drawable.timer_recording, - R.drawable.timer_recording_begin, - R.drawable.timer_recording_end, - R.drawable.timer_recording_conflict)); - break; - default: - setState(state, R.drawable.timer_none); - } - } - final TextView shortText = (TextView) view - .findViewById(R.id.epg_detail_shorttext); - shortText.setText(Utils.highlight(formatter.getShortText(), highlight)); - - final TextView textView = (TextView) view - .findViewById(R.id.epg_detail_description); - textView.setText(Utils.highlight(formatter.getDescription(), highlight)); - - if (event.getAudio().isEmpty() == false) { - view.findViewById(R.id.audio_block).setVisibility(View.VISIBLE); - final TextView audioTracks = (TextView) view - .findViewById(R.id.epg_detail_audio); - audioTracks.setText(Utils.formatAudio(this, event.getAudio())); - } else { - view.findViewById(R.id.audio_block).setVisibility(View.GONE); - } - - TextView contentView = ((TextView) view - .findViewById(R.id.epg_detail_cats)); - if (event.getContent().length > 0) { - contentView.setVisibility(View.VISIBLE); - contentView - .setText(Utils.getContenString(this, event.getContent())); - } else { - contentView.setVisibility(View.GONE); - } - - // copy color for separator lines - // final int color = textView.getTextColors().getDefaultColor(); - // ((TextView) findViewById(R.id.epg_detail_separator_1)) - // .setBackgroundColor(color); - - int p = Utils.getProgress(event); - - ((ProgressBar) view.findViewById(R.id.epg_detail_progress)) - .setProgress(p); - int dm = Utils.getDuration(event); - if (Utils.isLive(event)) { - int rest = dm - (dm * p / 100); - dura.setText(getString(R.string.epg_duration_template_live, rest, - dm)); - } else { - dura.setText(getString(R.string.epg_duration_template, dm)); - } - - // ((TextView) view.findViewById(R.id.epg_detail_separator_2)) - // .setBackgroundColor(color); - - // register button handler - if (timerable == null) { - view.findViewById(R.id.epg_event_create_timer).setVisibility( - View.GONE); - } else { - setThisAsOnClickListener(view, R.id.epg_event_create_timer); - } - - View b = view.findViewById(R.id.epg_event_imdb); - - if (Preferences.get().isShowImdbButton() == false) { - b.setVisibility(View.GONE); - } else { - b.setVisibility(View.VISIBLE); - b.setOnClickListener(new OnClickListener() { - - public void onClick(View v) { - startFilmDatabaseBrowseIntent( - String.format(IMDB_BASE_URL, Preferences.get() - .getImdbUrl()) - + IMDB_URL_QUERY, view, IMDB_URL_ENCODING); - } - }); - } - - b = view.findViewById(R.id.epg_event_omdb); - - if (Preferences.get().isShowOmdbButton() == false) { - b.setVisibility(View.GONE); - } else { - b.setVisibility(View.VISIBLE); - b.setOnClickListener(new OnClickListener() { - - public void onClick(View v) { - startFilmDatabaseBrowseIntent(OMDB_URL, view, - OMDB_URL_ENCODING); - } - }); - } - - b = view.findViewById(R.id.epg_event_tmdb); - - if (Preferences.get().isShowTmdbButton() == false) { - b.setVisibility(View.GONE); - } else { - b.setVisibility(View.VISIBLE); - b.setOnClickListener(new OnClickListener() { - - public void onClick(View v) { - startFilmDatabaseBrowseIntent(TMDB_URL, view, - TMDB_URL_ENCODING); - } - }); - } - - b = view.findViewById(R.id.epg_event_livetv); - if (Utils.isLive(event) == false - && (event instanceof Recording == false || Preferences.get() - .isEnableRecStream() == false)) { - b.setVisibility(View.GONE); - } else { - b.setVisibility(View.VISIBLE); - setThisAsOnClickListener(b); - } - // setThisAsOnClickListener(view, R.id.epg_event_left); - // setThisAsOnClickListener(view, R.id.epg_event_right); - - // set button text - if (event instanceof Timer) { - // timeButton.setText(R.string.epg_event_create_timer_text); - } else { - // timeButton.setText(R.string.epg_event_modify_timer_text); - } - - } - - private void startFilmDatabaseBrowseIntent(String url, View view, - String encoding) { - final TextView title = (TextView) view - .findViewById(R.id.epg_detail_title); - url = String.format(url, - encode(String.valueOf(title.getText()), encoding)); - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse(url)); - i.addCategory(Intent.CATEGORY_BROWSABLE); - try { - startActivity(i); - } catch (ActivityNotFoundException anfe) { - Log.w(TAG, anfe); - say(anfe.getLocalizedMessage()); - } - } - - private void setThisAsOnClickListener(View v) { - if (v != null) { - v.setOnClickListener(this); - } - } - - private void setThisAsOnClickListener(View root, int view) { - setThisAsOnClickListener(root.findViewById(view)); - } - - @Override - protected void onResume() { - super.onResume(); - // TODO Check here whether the config has changed for imdb - } - - @Override - protected void onPause() { - super.onPause(); - } - - class Wrapper { - public int id; - public String value; - - public Wrapper(int id) { - this.id = id; - this.value = getString(id); - } - - public String toString() { - return value; - } - } - - public Timer getTimer(Event event) { - if (event instanceof Timer) { - return (Timer) event; - } - if (event instanceof Epg) { - return ((Epg) event).getTimer(); - } - return null; - } - - protected VdrManagerApp getApp() { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - return app; - } - - public void onClick(final View v) { - - final Event cEvent = epgs.get(pager.getCurrentItem()); - - switch (v.getId()) { - case R.id.epg_event_livetv: - if (cEvent instanceof Recording) { - Utils.streamRecording(this, (Recording) cEvent); - } else { - Utils.stream(this, String.valueOf(cEvent.getChannelNumber())); - } - break; - case R.id.epg_event_create_timer: - final ArrayAdapter<Wrapper> ada = new ArrayAdapter<Wrapper>(this, - android.R.layout.simple_dropdown_item_1line); - final Timer timer = getTimer(cEvent); - TimerMatch tm = Utils.getTimerMatch(cEvent, timer); - // remove unneeded menu items - if (timer != null && tm == TimerMatch.Full) { - ada.add(new Wrapper(R.string.epg_item_menu_timer_modify)); - ada.add(new Wrapper(R.string.epg_item_menu_timer_delete)); - if (timer.isEnabled()) { - ada.add(new Wrapper(R.string.epg_item_menu_timer_disable)); - } else { - ada.add(new Wrapper(R.string.epg_item_menu_timer_enable)); - } - } else if (cEvent instanceof Recording) { - ada.add(new Wrapper(R.string.epg_item_menu_timer_delete)); - } else { - - ada.add(new Wrapper(R.string.epg_item_menu_timer_add)); - if (Utils.isLive(cEvent) && (cEvent instanceof Timerable) - && ((Timerable) cEvent).getTimer() == null) { - ada.add(new Wrapper(R.string.epg_item_menu_timer_record)); - } - } - - final Timerable timerable; - - if (cEvent instanceof Timerable) { - timerable = (Timerable) cEvent; - } else { - return; - } - - new AlertDialog.Builder(this) - .setAdapter(ada, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - Wrapper w = ada.getItem(which); - switch (w.id) { - case R.string.epg_item_menu_timer_add: { - getApp().setCurrentTimer( - timerable.createTimer()); - final Intent intent = new Intent(); - intent.setClass(EpgDetailsActivity.this, - TimerDetailsActivity.class); - intent.putExtra(Intents.TIMER_OP, - Intents.ADD_TIMER); - startActivityForResult( - intent, - TimerDetailsActivity.REQUEST_CODE_TIMER_ADD); - break; - } - case R.string.epg_item_menu_timer_modify: { - getApp().setCurrentTimer(timer); - final Intent intent = new Intent(); - intent.setClass(EpgDetailsActivity.this, - TimerDetailsActivity.class); - intent.putExtra(Intents.TIMER_OP, - Intents.EDIT_TIMER); - startActivityForResult( - intent, - TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT); - break; - } - case R.string.epg_item_menu_timer_delete: { - deleteTimer(timer); - break; - } - case R.string.epg_item_menu_timer_enable: - case R.string.epg_item_menu_timer_disable: { - toggleTimer(timer); - break; - } - - case R.string.epg_item_menu_timer_record: { - final Timer timer = new Timer(cEvent); - final CreateTimerTask task = new CreateTimerTask( - EpgDetailsActivity.this, timer) { - @Override - public void finished(SvdrpEvent event) { - modifed = true; - EpgCache.CACHE.remove(timer - .getChannelId()); - say(R.string.recording_started); - } - }; - task.start(); - - } - } - } - }).create()// - .show();// - - break; - // case R.id.epg_event_imdb: - - // break; - - // case R.id.epg_event_share: - // shareEvent(cEvent); - // break; - } - } - - protected void toggleTimer(final Timer timer) { - final ToggleTimerTask task = new ToggleTimerTask(this, timer) { - @Override - public void finished(SvdrpEvent event) { - if (event == SvdrpEvent.FINISHED_SUCCESS) { - TimerState state = timer.getTimerState(); - TimerMatch match = timer.getTimerMatch(); - int res = -1; - if (state == TimerState.Active) { - res = Utils.getTimerStateDrawable(match, - R.drawable.timer_inactive, - R.drawable.timer_inactive_begin, - R.drawable.timer_inactive_end, + if (epg instanceof Timerable) { + // timerable = (Timerable) cEvent; + } + + + pager = (ViewPager) findViewById(R.id.viewpager); + pager.setOnPageChangeListener(this); + + + new VoidAsyncTask() { + + int counter = 0; + + @Override + protected void onPreExecute() { + setProgressBarIndeterminateVisibility(true); + } + + @Override + protected Void doInBackground(Void... params) { + // current event + final VdrManagerApp app = (VdrManagerApp) getApplication(); + epgs = app.getCurrentEpgList(); + + if (epgs.isEmpty()) { + epgs.add(cEvent); + return (Void) null; + } + + // for (Event e : epgs) { + // if (epg.equals(e)) { + // break; + //} + //counter++; + //} + + //if (counter == epgs.size()) {// not found? + //epgs.add(0, cEvent); + //counter = 0; + //} + if (preselect < epgs.size()) { + counter = preselect; + } + return (Void) null; + } + + @Override + protected void onPostExecute(Void result) { + adapter = new Adapter(); + pager.setAdapter(adapter); + pager.setCurrentItem(counter); + onPageSelected(counter); + } + }.execute((Void) null); + + } + + private void setState(ImageView view, int res) { + view.setVisibility(View.VISIBLE); + view.setImageResource(res); + } + + private static String encode(String str, String enc) { + try { + return URLEncoder.encode(str, enc); + } catch (Exception ex) { + Log.w(TAG, ex); + return URLEncoder.encode(str); + } + } + + public void publishEPG(final View view, int position) { + + Event event = epgs.get(position); + + Timerable timerable = null; + + if (event instanceof Timerable) { + timerable = (Timerable) event; + } + + view.setTag(event); + // view.setTag(event); + + final EventFormatter formatter = new EventFormatter(event); + + final TextView title = (TextView) view + .findViewById(R.id.epg_detail_title); + String titleText = formatter.getTitle(); + title.setText(Utils.highlight(titleText, highlight)); + // title.setTextSize(TypedValue.COMPLEX_UNIT_PX, title.getTextSize() + // * (float) 1.3); + + ((TextView) view.findViewById(R.id.epg_detail_time)).setText(formatter + .getDate() + " " + formatter.getTime()); + + TextView dura = (TextView) view.findViewById(R.id.epg_detail_duration); + + ((TextView) view.findViewById(R.id.epg_detail_channel)).setText(event + .getChannelName()); + // ((TextView) findViewById(R.id.epg_detail_date)).setText(formatter + // .getLongDate()); + ImageView state = (ImageView) view.findViewById(R.id.epg_timer_state); + if (timerable == null) { + setState(state, R.drawable.timer_none); + } else { + + TimerMatch match = timerable.getTimerMatch(); + + switch (timerable.getTimerState()) { + case Active: + setState(state, Utils.getTimerStateDrawable(match, + R.drawable.timer_active, + R.drawable.timer_active_begin, + R.drawable.timer_active_end, + R.drawable.timer_active_conflict)); + break; + case Inactive: + setState(state, Utils.getTimerStateDrawable(match, + R.drawable.timer_inactive, + R.drawable.timer_inactive_begin, + R.drawable.timer_inactive_end, + R.drawable.timer_inactive)); + break; + case Recording: + setState(state, Utils.getTimerStateDrawable(match, + R.drawable.timer_recording, + R.drawable.timer_recording_begin, + R.drawable.timer_recording_end, + R.drawable.timer_recording_conflict)); + break; + default: + setState(state, R.drawable.timer_none); + } + } + final TextView shortText = (TextView) view + .findViewById(R.id.epg_detail_shorttext); + shortText.setText(Utils.highlight(formatter.getShortText(), highlight)); + + final TextView textView = (TextView) view + .findViewById(R.id.epg_detail_description); + textView.setText(Utils.highlight(formatter.getDescription(), highlight)); + + if (event.getAudio().isEmpty() == false) { + view.findViewById(R.id.audio_block).setVisibility(View.VISIBLE); + final TextView audioTracks = (TextView) view + .findViewById(R.id.epg_detail_audio); + audioTracks.setText(Utils.formatAudio(this, event.getAudio())); + } else { + view.findViewById(R.id.audio_block).setVisibility(View.GONE); + } + + TextView contentView = ((TextView) view + .findViewById(R.id.epg_detail_cats)); + if (event.getContent().length > 0) { + contentView.setVisibility(View.VISIBLE); + contentView + .setText(Utils.getContenString(this, event.getContent())); + } else { + contentView.setVisibility(View.GONE); + } + + // copy color for separator lines + // final int color = textView.getTextColors().getDefaultColor(); + // ((TextView) findViewById(R.id.epg_detail_separator_1)) + // .setBackgroundColor(color); + + int p = Utils.getProgress(event); + + ((ProgressBar) view.findViewById(R.id.epg_detail_progress)) + .setProgress(p); + int dm = Utils.getDuration(event); + if (Utils.isLive(event)) { + int rest = dm - (dm * p / 100); + dura.setText(getString(R.string.epg_duration_template_live, rest, + dm)); + } else { + dura.setText(getString(R.string.epg_duration_template, dm)); + } + + // ((TextView) view.findViewById(R.id.epg_detail_separator_2)) + // .setBackgroundColor(color); + + // register button handler + if (timerable == null) { + view.findViewById(R.id.epg_event_create_timer).setVisibility( + View.GONE); + } else { + setThisAsOnClickListener(view, R.id.epg_event_create_timer); + view.findViewById(R.id.epg_event_create_timer).setOnLongClickListener(this); + } + + View b = view.findViewById(R.id.epg_event_imdb); + + if (Preferences.get().isShowImdbButton() == false) { + b.setVisibility(View.GONE); + } else { + b.setVisibility(View.VISIBLE); + b.setOnClickListener(new OnClickListener() { + + public void onClick(View v) { + startFilmDatabaseBrowseIntent( + String.format(IMDB_BASE_URL, Preferences.get() + .getImdbUrl()) + + IMDB_URL_QUERY, view, IMDB_URL_ENCODING); + } + }); + } + + b = view.findViewById(R.id.epg_event_omdb); + + if (Preferences.get().isShowOmdbButton() == false) { + b.setVisibility(View.GONE); + } else { + b.setVisibility(View.VISIBLE); + b.setOnClickListener(new OnClickListener() { + + public void onClick(View v) { + startFilmDatabaseBrowseIntent(OMDB_URL, view, + OMDB_URL_ENCODING); + } + }); + } + + b = view.findViewById(R.id.epg_event_tmdb); + + if (Preferences.get().isShowTmdbButton() == false) { + b.setVisibility(View.GONE); + } else { + b.setVisibility(View.VISIBLE); + b.setOnClickListener(new OnClickListener() { + + public void onClick(View v) { + startFilmDatabaseBrowseIntent(TMDB_URL, view, + TMDB_URL_ENCODING); + } + }); + } + + b = view.findViewById(R.id.epg_event_livetv); + if (Utils.isLive(event) == false + && (event instanceof Recording == false || Preferences.get() + .isEnableRecStream() == false)) { + b.setVisibility(View.GONE); + } else { + b.setVisibility(View.VISIBLE); + setThisAsOnClickListener(b); + } + // setThisAsOnClickListener(view, R.id.epg_event_left); + // setThisAsOnClickListener(view, R.id.epg_event_right); + + // set button text + if (event instanceof Timer) { + // timeButton.setText(R.string.epg_event_create_timer_text); + } else { + // timeButton.setText(R.string.epg_event_modify_timer_text); + } + + } + + private void startFilmDatabaseBrowseIntent(String url, View view, + String encoding) { + final TextView title = (TextView) view + .findViewById(R.id.epg_detail_title); + url = String.format(url, + encode(String.valueOf(title.getText()), encoding)); + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + i.addCategory(Intent.CATEGORY_BROWSABLE); + try { + startActivity(i); + } catch (ActivityNotFoundException anfe) { + Log.w(TAG, anfe); + say(anfe.getLocalizedMessage()); + } + } + + private void setThisAsOnClickListener(View v) { + if (v != null) { + v.setOnClickListener(this); + } + } + + private void setThisAsOnClickListener(View root, int view) { + setThisAsOnClickListener(root.findViewById(view)); + } + + @Override + protected void onResume() { + super.onResume(); + // TODO Check here whether the config has changed for imdb + } + + @Override + protected void onPause() { + super.onPause(); + } + + class Wrapper { + public int id; + public String value; + + public Wrapper(int id) { + this.id = id; + this.value = getString(id); + } + + public String toString() { + return value; + } + } + + public Timer getTimer(Event event) { + if (event instanceof Timer) { + return (Timer) event; + } + if (event instanceof Epg) { + return ((Epg) event).getTimer(); + } + return null; + } + + protected VdrManagerApp getApp() { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + return app; + } + + public void onClick(final View v) { + + final Event cEvent = epgs.get(pager.getCurrentItem()); + + + if (cEvent instanceof Timerable == false) { + return; + } + + final Timerable timerable = (Timerable) cEvent; + + + switch (v.getId()) { + case R.id.epg_event_livetv: + if (cEvent instanceof Recording) { + Utils.streamRecording(this, (Recording) cEvent); + } else { + Utils.stream(this, String.valueOf(cEvent.getChannelNumber())); + } + break; + case R.id.epg_event_create_timer: + final ArrayAdapter<Wrapper> ada = new ArrayAdapter<Wrapper>(this, + android.R.layout.simple_dropdown_item_1line); + final Timer timer = getTimer(cEvent); + TimerMatch tm = Utils.getTimerMatch(cEvent, timer); + // remove unneeded menu items + if (timer != null && tm == TimerMatch.Full) { + ada.add(new Wrapper(R.string.epg_item_menu_timer_modify)); + ada.add(new Wrapper(R.string.epg_item_menu_timer_delete)); + if (timer.isEnabled()) { + ada.add(new Wrapper(R.string.epg_item_menu_timer_disable)); + } else { + ada.add(new Wrapper(R.string.epg_item_menu_timer_enable)); + } + } else if (cEvent instanceof Recording) { + ada.add(new Wrapper(R.string.epg_item_menu_timer_delete)); + } else { + getApp().setCurrentTimer( + timerable.createTimer()); + final Intent intent = new Intent(); + intent.setClass(EpgDetailsActivity.this, + TimerDetailsActivity.class); + intent.putExtra(Intents.TIMER_OP, + Intents.ADD_TIMER); + startActivityForResult( + intent, + TimerDetailsActivity.REQUEST_CODE_TIMER_ADD); + return; + //ada.add(new Wrapper(R.string.epg_item_menu_timer_add)); + //if (Utils.isLive(cEvent) && (cEvent instanceof Timerable) + // && ((Timerable) cEvent).getTimer() == null) { + // ada.add(new Wrapper(R.string.epg_item_menu_timer_record)); + //} + } + + + new AlertDialog.Builder(this) + .setAdapter(ada, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Wrapper w = ada.getItem(which); + switch (w.id) { + case R.string.epg_item_menu_timer_modify: { + getApp().setCurrentTimer(timer); + final Intent intent = new Intent(); + intent.setClass(EpgDetailsActivity.this, + TimerDetailsActivity.class); + intent.putExtra(Intents.TIMER_OP, + Intents.EDIT_TIMER); + startActivityForResult( + intent, + TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT); + break; + } + case R.string.epg_item_menu_timer_delete: { + deleteTimer(timer); + break; + } + case R.string.epg_item_menu_timer_enable: + case R.string.epg_item_menu_timer_disable: { + toggleTimer(timer); + break; + } + } + } + }).create()// + .show();// + + break; + // case R.id.epg_event_imdb: + + // break; + + // case R.id.epg_event_share: + // shareEvent(cEvent); + // break; + } + } + + protected void toggleTimer(final Timer timer) { + final ToggleTimerTask task = new ToggleTimerTask(this, timer) { + @Override + public void finished(SvdrpEvent event) { + if (event == SvdrpEvent.FINISHED_SUCCESS) { + TimerState state = timer.getTimerState(); + TimerMatch match = timer.getTimerMatch(); + int res = -1; + if (state == TimerState.Active) { + res = Utils.getTimerStateDrawable(match, + R.drawable.timer_inactive, + R.drawable.timer_inactive_begin, + R.drawable.timer_inactive_end, R.drawable.timer_inactive); - } else if (state == TimerState.Inactive) { - res = Utils.getTimerStateDrawable(match, - R.drawable.timer_active, - R.drawable.timer_active_begin, - R.drawable.timer_active_end, + } else if (state == TimerState.Inactive) { + res = Utils.getTimerStateDrawable(match, + R.drawable.timer_active, + R.drawable.timer_active_begin, + R.drawable.timer_active_end, R.drawable.timer_active_conflict); - - } - if (res != -1) { - setState( - (ImageView) findViewById(R.id.epg_timer_state), - res); - } - } - } - }; - task.start(); - } - - private List<Event> epgs = new ArrayList<Event>(); - - protected void say(int res) { - Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); - } - - protected void say(String msg) { - Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); - } - - @Override - public final boolean onCreateOptionsMenu( - Menu menu) { - super.onCreateOptionsMenu(menu); - - final MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.epg_details, menu); - - // mShareActionProvider = (ShareActionProvider) - // menu.findItem(R.id.epg_details_menu_share).getActionProvider(); - // mShareActionProvider.setShareIntent(getDefaultShareIntent()); - - return true; - } - - private void shareEvent(Event event) { - Utils.shareEvent(this, event); - } - - @Override - public boolean onOptionsItemSelected( - MenuItem item) { - - Event cEvent = epgs.get(pager.getCurrentItem()); - - if (item.getItemId() == R.id.epg_details_menu_share) { - shareEvent(cEvent); - return true; - } - - if (item.getItemId() == R.id.epg_details_menu_add_to_cal) { - Utils.addCalendarEvent(this, cEvent); - } - - if (item.getItemId() == R.id.epg_details_menu_search_repeat) { - Intent intent = new Intent(this, EpgSearchListActivity.class); - intent.setAction(Intent.ACTION_SEARCH); - intent.putExtra(SearchManager.QUERY, cEvent.getTitle()); - startActivity(intent); - return true; - } - - if (item.getItemId() == R.id.epg_details_menu_switch) { - Utils.switchTo(this, cEvent.getChannelId(), cEvent.getChannelName()); - return true; - } - return super.onOptionsItemSelected(item); - } - - protected void deleteTimer(final Timer timer) { - final DeleteTimerTask task = new DeleteTimerTask(this, timer) { - @Override - public void finished(SvdrpEvent event) { - if (event == SvdrpEvent.FINISHED_SUCCESS) { - setState((ImageView) findViewById(R.id.epg_timer_state), - R.drawable.timer_none); - modifed = true; - EpgCache.CACHE.remove(timer.getChannelId()); - } - } - }; - task.start(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode != RESULT_OK) { - return; - } - - // View view = pager.getChildAt(current); - // ImageView state = (ImageView) - // view.findViewById(R.id.epg_timer_state); - - if (requestCode == TimerDetailsActivity.REQUEST_CODE_TIMER_ADD) { - modifed = true; - // setState( - // state, - // Utils.isLive(getApp().getCurrentEvent()) ? - // R.drawable.timer_recording - // : R.drawable.timer_active); - } else if (requestCode == TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT) { - modifed = true; - // ?? - } - adapter.notifyDataSetChanged(); - } - - @Override - public void onBackPressed() { - if (modifed) { - setResult(RESULT_OK); - finish(); - } else { - super.onBackPressed(); - } - } - - public void onPageScrollStateChanged(int state) { - } - - public void onPageScrolled(int position, float positionOffset, - int positionOffsetPixels) { - } - - public void onPageSelected(int position) { - - Event cEvent = epgs.get(position); - String cn = cEvent.getChannelName(); - // View view = pager.getChildAt(arg0); - // state = (ImageView) view.findViewById(R.id.epg_timer_state); - setTitle(getString(R.string.epg_of_a_channel, cn, position + 1, - epgs.size())); - } + + } + if (res != -1) { + setState( + (ImageView) findViewById(R.id.epg_timer_state), + res); + } + } + } + }; + task.start(); + } + + private List<Event> epgs = new ArrayList<Event>(); + + protected void say(int res) { + Toast.makeText(this, res, Toast.LENGTH_SHORT).show(); + } + + protected void say(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + @Override + public final boolean onCreateOptionsMenu( + Menu menu) { + super.onCreateOptionsMenu(menu); + + final MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.epg_details, menu); + + // mShareActionProvider = (ShareActionProvider) + // menu.findItem(R.id.epg_details_menu_share).getActionProvider(); + // mShareActionProvider.setShareIntent(getDefaultShareIntent()); + + return true; + } + + private void shareEvent(Event event) { + Utils.shareEvent(this, event); + } + + @Override + public boolean onOptionsItemSelected( + MenuItem item) { + + Event cEvent = epgs.get(pager.getCurrentItem()); + + if (item.getItemId() == R.id.epg_details_menu_share) { + shareEvent(cEvent); + return true; + } + + if (item.getItemId() == R.id.epg_details_menu_add_to_cal) { + Utils.addCalendarEvent(this, cEvent); + } + + if (item.getItemId() == R.id.epg_details_menu_search_repeat) { + Intent intent = new Intent(this, EpgSearchListActivity.class); + intent.setAction(Intent.ACTION_SEARCH); + intent.putExtra(SearchManager.QUERY, cEvent.getTitle()); + startActivity(intent); + return true; + } + + if (item.getItemId() == R.id.epg_details_menu_switch) { + Utils.switchTo(this, cEvent.getChannelId(), cEvent.getChannelName()); + return true; + } + return super.onOptionsItemSelected(item); + } + + protected void deleteTimer(final Timer timer) { + final DeleteTimerTask task = new DeleteTimerTask(this, timer) { + @Override + public void finished(SvdrpEvent event) { + if (event == SvdrpEvent.FINISHED_SUCCESS) { + setState((ImageView) findViewById(R.id.epg_timer_state), + R.drawable.timer_none); + modifed = true; + EpgCache.CACHE.remove(timer.getChannelId()); + } + } + }; + task.start(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (resultCode != RESULT_OK) { + return; + } + + // View view = pager.getChildAt(current); + // ImageView state = (ImageView) + // view.findViewById(R.id.epg_timer_state); + + if (requestCode == TimerDetailsActivity.REQUEST_CODE_TIMER_ADD) { + modifed = true; + // setState( + // state, + // Utils.isLive(getApp().getCurrentEvent()) ? + // R.drawable.timer_recording + // : R.drawable.timer_active); + } else if (requestCode == TimerDetailsActivity.REQUEST_CODE_TIMER_EDIT) { + modifed = true; + // ?? + } + adapter.notifyDataSetChanged(); + } + + @Override + public void onBackPressed() { + if (modifed) { + setResult(RESULT_OK); + finish(); + } else { + super.onBackPressed(); + } + } + + public void onPageScrollStateChanged(int state) { + } + + public void onPageScrolled(int position, float positionOffset, + int positionOffsetPixels) { + } + + public void onPageSelected(int position) { + + Event cEvent = epgs.get(position); + String cn = cEvent.getChannelName(); + // View view = pager.getChildAt(arg0); + // state = (ImageView) view.findViewById(R.id.epg_timer_state); + setTitle(getString(R.string.epg_of_a_channel, cn, position + 1, + epgs.size())); + } } diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java index 74cd502..1afab79 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/gui/SvdrpProgressDialog.java @@ -63,7 +63,7 @@ public class SvdrpProgressDialog<T> extends ProgressDialog implements @Override public void svdrpEvent(SvdrpEvent event, Throwable t) { - progress.dismiss(); + this.svdrpEvent(event); Utils.say(getContext(), t.getLocalizedMessage()); } } diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java index daeb2c7..022b479 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java @@ -5,6 +5,7 @@ import de.bjusystems.vdrmanager.gui.SvdrpProgressDialog; 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; public abstract class AsyncProgressTask<Result> { @@ -18,6 +19,7 @@ public abstract class AsyncProgressTask<Result> { @Override public void svdrpEvent(final SvdrpEvent event) { super.svdrpEvent(event); + AsyncProgressTask.this.svdrpEvent(event); switch (event) { case ABORTED: case CONNECT_ERROR: @@ -31,6 +33,12 @@ public abstract class AsyncProgressTask<Result> { break; } } + + @Override + public void svdrpEvent(SvdrpEvent event, Throwable th) { + super.svdrpEvent(event,th); + AsyncProgressTask.this.svdrpEvent(event, th); + } } Activity activity; @@ -59,5 +67,15 @@ public abstract class AsyncProgressTask<Result> { task.run(); } - public abstract void finished(SvdrpEvent event); + public void svdrpEvent(final SvdrpEvent event){ + + } + + + public void svdrpEvent(final SvdrpEvent event, Throwable th){ + + } + + + public abstract void finished(SvdrpEvent event); } diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java index 8daab75..f672791 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java @@ -86,5 +86,6 @@ public class SetTimerClient extends SvdrpClient<Timer> { public int getProgressTextId() { return R.string.progress_timer_save; } + } diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index 0198bb0..6efee8b 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -462,7 +462,7 @@ public abstract class SvdrpClient<Result> { msg = line; } disconnect(); - informListener(SvdrpEvent.ERROR, new SvdrpException(msg)); + informListener(SvdrpEvent.ERROR, new SvdrpException(SvdrpEvent.ERROR,msg)); break; } diff --git a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java index fe0824e..8deb8e1 100644 --- a/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java +++ b/vdrmanager/app/src/main/java/de/bjusystems/vdrmanager/utils/svdrp/SvdrpException.java @@ -20,9 +20,7 @@ public class SvdrpException extends Exception { public SvdrpException(SvdrpEvent event, String text) { super(text); - } - public SvdrpException(String text) { - this(null,text); + this.event = event; } public SvdrpException(String text, Throwable cause) { diff --git a/vdrmanager/app/src/main/res/values/strings.xml b/vdrmanager/app/src/main/res/values/strings.xml index 0fd460c..2c28997 100644 --- a/vdrmanager/app/src/main/res/values/strings.xml +++ b/vdrmanager/app/src/main/res/values/strings.xml @@ -190,6 +190,9 @@ <string name="timer_default_primary_limit_summary">Default primary limit</string> <string name="timer_default_lifetime_title">Default lifetime</string> <string name="timer_default_lifetime_summary">Default lifetime</string> + <string name="timer_already_exists">Timer already defined.</string> + <string name="timer_created">Timer created</string> + <!-- GUI --> <string name="gui_preferences">GUI Settings</string> @@ -536,4 +539,5 @@ What do you want to do?</string> <string name="menu_remapback">\'Back\' is \'Back\' HITK</string> <string name="remapback_hint">Longpress on Back Button to leave the remote.</string> <string name="not_yet_implemented">Not Yet Implemented</string> + <string name="timer_error" >Can not create timer: %1$s</string> </resources>
\ No newline at end of file |