diff options
32 files changed, 4468 insertions, 4235 deletions
diff --git a/vdrmanager/res/values/strings.xml b/vdrmanager/res/values/strings.xml index 177b0bb..dd12a14 100644 --- a/vdrmanager/res/values/strings.xml +++ b/vdrmanager/res/values/strings.xml @@ -393,5 +393,20 @@ <string name="probing">Probing %1$s …</string> <string name="no_results">No results…</string> <string name="recording_started">Recording started</string> - <!-- … --> + + <!-- + SSL related messages + --> + + <string name="certificate_problem_message_title">Certificate warning</string> + <string name="certificate_problem_message_text" formatted="false"> + The server certificate was not accepted:\n + Hostname: %s\n + Fingerprint: %s\n + Issuer: %s + </string> + <string name="certificate_accept_once">Continue</string> + <string name="certificate_accepted_forever">Remember certificate</string> + <string name="certificate_not_accepted">Abort</string> + </resources>
\ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java index de3d42e..cdf0842 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java @@ -29,474 +29,483 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpFinishedListener; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpListener; public abstract class BaseActivity<Result, T extends ListView> extends - ICSBaseActivity implements OnClickListener, SvdrpListener, - SvdrpExceptionListener, SvdrpFinishedListener<Result> { - - public static final String TAG = BaseActivity.class.getName(); - - public static final int MENU_GROUP_REFRESH = 99; - - public static final int MENU_REFRESH = 99; - - protected T listView; +ICSBaseActivity implements OnClickListener, SvdrpListener, +SvdrpExceptionListener, SvdrpFinishedListener<Result> { + + public static final String TAG = BaseActivity.class.getName(); + + public static final int MENU_GROUP_REFRESH = 99; + + public static final int MENU_REFRESH = 99; + + protected T listView; - protected ViewFlipper flipper; - - private Button retry; + protected ViewFlipper flipper; + + private Button retry; - private ProgressDialog progress; + private ProgressDialog progress; - // protected SvdrpProgressDialog progress; + // protected SvdrpProgressDialog progress; - abstract protected String getWindowTitle(); + abstract protected String getWindowTitle(); - abstract protected int getMainLayout(); + abstract protected int getMainLayout(); - protected void noInternetConnection() { - alert(R.string.no_internet_connection); - } + protected void noInternetConnection() { + alert(R.string.no_internet_connection); + } - abstract protected boolean displayingResults(); + abstract protected boolean displayingResults(); - protected boolean isForceRefresh() { - if (forceRefresh == false) { - return false; - } - forceRefresh = false; - return true; - } + protected boolean isForceRefresh() { + if (forceRefresh == false) { + return false; + } + forceRefresh = false; + return true; + } - protected boolean forceRefresh = false; - - protected void switchNoConnection() { - if (flipper == null) { - say(R.string.no_connection); - return; - } - - if (displayingResults()) { - say(R.string.no_connection); - } else { - flipper.setDisplayedChild(1); - } - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - Preferences.setLocale(this); - super.onConfigurationChanged(newConfig); - } - - @Override - protected void onResume() { - Preferences.setLocale(this); - // Preferences.init(this); - super.onResume(); - } - - protected void initFlipper() { - this.flipper = (ViewFlipper) findViewById(R.id.flipper); - retry = (Button) findViewById(R.id.retry_button); - retry.setOnClickListener(this); - } - - public void onClick(View v) { - if (v.getId() == R.id.retry_button) { - 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); - // } - - abstract protected int getListNavigationIndex(); - - public static final int LIST_NAVIGATION_CHANNELS = 0; - public static final int LIST_NAVIGATION_EPG_BY_TIME = 1; - public static final int LIST_NAVIGATION_EPG_BY_CHANNEL = 2; - public static final int LIST_NAVIGATION_RECORDINGS = 3; - public static final int LIST_NAVIGATION_TIMERS = 4; - - protected boolean hasListNavigation() { - return true; - } - - protected void initListNavigation() { - - if (hasListNavigation() == false) { - return; - } - - getSupportActionBar().setDisplayShowTitleEnabled(false); - - getSupportActionBar().setNavigationMode( - getSupportActionBar().NAVIGATION_MODE_LIST); - - ArrayAdapter<CharSequence> mSpinnerAdapter = ArrayAdapter - .createFromResource(this, R.array.navigation_array, - android.R.layout.simple_spinner_dropdown_item); - - getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, - new OnNavigationListener() { - - private boolean firstHit = true; - - @Override - public boolean onNavigationItemSelected(int itemPosition, - long itemId) { - - if (firstHit == true) { - firstHit = false; - return false; - } - switch (itemPosition) { - - case LIST_NAVIGATION_CHANNELS: { - startActivity(ChannelListActivity.class); - return true; - } - case LIST_NAVIGATION_EPG_BY_TIME: { - startActivity(TimeEpgListActivity.class); - return true; - } - - case LIST_NAVIGATION_EPG_BY_CHANNEL: { - startActivity(EventEpgListActivity.class); - return true; - } - - case LIST_NAVIGATION_RECORDINGS: { - startActivity(RecordingListActivity.class); - return true; - } - - case LIST_NAVIGATION_TIMERS: { - startActivity(TimerListActivity.class); - return true; - } - - } - return false; - } - }); - getSupportActionBar().setSelectedNavigationItem( - getListNavigationIndex()); - - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Preferences.setLocale(this); - progress = new ProgressDialog(this); - - - initActionBar(); - - initListNavigation(); - - // new OnNavigationListener() { - // @Override - // public boolean onNavigationItemSelected(int itemPosition, long - // itemId) { - // System.err.println("itemPosition: "+ itemPosition +", itemId:" + - // itemId); - // rturn false; - // } - // }); - - // your logic for click listner - // setListenerForActionBarCustomView(actionBarView); - - // private void setListenerForActionBarCustomView(View actionBarView) { - // ActionBarCustomViewOnClickListener actionBarCustomViewOnClickListener - // = new ActionBarCustomViewOnClickListener(); - // actionBarView.findViewById(R.id.text_view_title).setOnClickListener(actionBarCustomViewOnClickListener); - // } - - } - - public void startActivity(Class<?> clazz) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setClass(this, clazz); - startActivity(intent); - finish(); - } - - protected int getBaseMenu() { - return R.menu.refresh_filter_menu; - } - - @Override - public boolean onCreateOptionsMenu( - final com.actionbarsherlock.view.Menu menu) { - - // MenuItem item; - // item = menu.add(MENU_GROUP_REFRESH, MENU_REFRESH, 0, - // R.string.refresh); - // item.setIcon(R.drawable.ic_menu_refresh); - // item.setAlphabeticShortcut('r'); - com.actionbarsherlock.view.MenuInflater inf = getSupportMenuInflater(); - inf.inflate(getBaseMenu(), menu); - - // SearchView searchView = (SearchView) - // menu.findItem(R.id.menu_search).getActionView(); - // searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); - - return true; - } - - abstract protected void refresh(); - - abstract protected void retry(); - - // abstract protected SvdrpClient<Result> getClient(); - - @Override - public boolean onOptionsItemSelected( - final com.actionbarsherlock.view.MenuItem item) { - switch (item.getItemId()) { - case R.id.list_refresh: - backupViewSelection(); - refresh(); - return true; - case R.id.list_filter: { - onSearchRequested(); - return true; - } - case android.R.id.home: - Intent intent = new Intent(this, VdrManagerActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - return true; - default: - return false; - } - } - - protected void setCurrent(Channel channel) { - getApp().setCurrentChannel(channel); - } - - protected VdrManagerApp getApp() { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - return app; - } - - // protected Channel getCurrentChannel(){ - // final Channel channel = ((VdrManagerApp) getApplication()) - // .getCurrentChannel(); - // return channel; - // } - - protected void say(int res) { - say(this.getString(res)); - } - - protected void say(String msg) { - Utils.say(this, msg); - } - - protected boolean noConnection(SvdrpEvent event) { - switch (event) { - case CONNECTION_TIMEOUT: - say(R.string.progress_connect_timeout); - switchNoConnection(); - case CONNECT_ERROR: - say(R.string.progress_connect_error); - switchNoConnection(); - break; - case FINISHED_ABNORMALY: - alert(R.string.progress_connect_finished_abnormal); - switchNoConnection(); - break; - case LOGIN_ERROR: - say(R.string.progress_login_error); - switchNoConnection(); - break; - default: - return false; - } - return true; - } - - protected void alert(String msg) { - if (isFinishing()) { - return; - } - new AlertDialog.Builder(this)// - .setMessage(msg)// - .setPositiveButton(android.R.string.ok, null)// - .create()// - .show();// - } - - protected void alert(int resId) { - alert(getString(resId)); - } - - protected void restoreViewSelection() { - listView.setSelectionFromTop(index, top); - } - - protected void backupViewSelection() { - index = listView.getFirstVisiblePosition(); - View v = listView.getChildAt(0); - top = (v == null) ? 0 : v.getTop(); - } - - int index; - int top; - - protected boolean checkInternetConnection() { - if (Utils.checkInternetConnection(this)) { - return true; - } - noInternetConnection(); - return false; - } - - // public void svdrpEvent(Result result) { - // resultReceived(result); - // } - - @Override - public void svdrpEvent(SvdrpEvent event, Throwable t) { - Utils.say(this, t.getLocalizedMessage()); - } - - protected void addListener(SvdrpAsyncTask<Result, SvdrpClient<Result>> task) { - task.addSvdrpExceptionListener(this); - task.addSvdrpListener(this); - task.addSvdrpFinishedListener(this); - } - - @Override - public void svdrpEvent(final SvdrpEvent event) { - - switch (event) { - case LOGIN: - break; - case COMMAND_SENDING: - break; - case CONNECTING: - progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); - setMessage(R.string.progress_connect); - if (!isFinishing()) { - progress.show(); - } - break; - case LOGGED_IN: - setMessage(R.string.progress_login); - break; - case COMMAND_SENT: - setMessage(getProgressTextId()); - break; - case DISCONNECTING: - setMessage(R.string.progress_disconnect); - break; - case DISCONNECTED: - break; - case ABORTED: - progress.dismiss(); - say(R.string.aborted); - break; - case ERROR: - progress.dismiss(); - alert(R.string.epg_client_errors); - break; - case CONNECTED: - connected(); - break; - case CONNECTION_TIMEOUT: - case CONNECT_ERROR: - case FINISHED_ABNORMALY: - case LOGIN_ERROR: - progress.dismiss(); - noConnection(event); - break; - case CACHE_HIT: - progress.dismiss(); - cacheHit(); - return; - case FINISHED_SUCCESS: - progress.dismiss(); - break; - } - // case RESULT_RECEIVED: - // resultReceived(result); - // break; - // } - } - - protected int getProgressTextId() { - return R.string.progress_loading; - } - - private void setMessage(int progressConnect) { - progress.setMessage(getString(progressConnect)); - } - - protected boolean finishedSuccess = false; - - protected void cacheHit() { - - } - - /** - * @return false, if no results found - */ - protected abstract boolean finishedSuccess(List<Result> results); - - // /** - // * @param result - // */ - // protected abstract void resultReceived(Result result); - - protected void connected() { - if (flipper != null) { - flipper.setDisplayedChild(0); - } - } - - public void svdrpException(final 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(); - } - - @Override - public void finished(List<Result> results) { - if (finishedSuccess(results)) { - finishedSuccess = true; - restoreViewSelection(); - } else { - say(R.string.epg_no_items); - } - } + protected boolean forceRefresh = false; + protected void switchNoConnection() { + if (flipper == null) { + say(R.string.no_connection); + return; + } + + if (displayingResults()) { + say(R.string.no_connection); + } else { + flipper.setDisplayedChild(1); + } + } + + @Override + public void onConfigurationChanged(final Configuration newConfig) { + Preferences.setLocale(this); + super.onConfigurationChanged(newConfig); + } + + @Override + protected void onResume() { + Preferences.setLocale(this); + // Preferences.init(this); + super.onResume(); + } + + protected void initFlipper() { + this.flipper = (ViewFlipper) findViewById(R.id.flipper); + retry = (Button) findViewById(R.id.retry_button); + retry.setOnClickListener(this); + } + + @Override + public void onClick(final View v) { + if (v.getId() == R.id.retry_button) { + 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); + // } + + abstract protected int getListNavigationIndex(); + + public static final int LIST_NAVIGATION_CHANNELS = 0; + public static final int LIST_NAVIGATION_EPG_BY_TIME = 1; + public static final int LIST_NAVIGATION_EPG_BY_CHANNEL = 2; + public static final int LIST_NAVIGATION_RECORDINGS = 3; + public static final int LIST_NAVIGATION_TIMERS = 4; + + protected boolean hasListNavigation() { + return true; + } + + protected void initListNavigation() { + + if (hasListNavigation() == false) { + return; + } + + getSupportActionBar().setDisplayShowTitleEnabled(false); + + getSupportActionBar().setNavigationMode( + getSupportActionBar().NAVIGATION_MODE_LIST); + + final ArrayAdapter<CharSequence> mSpinnerAdapter = ArrayAdapter + .createFromResource(this, R.array.navigation_array, + android.R.layout.simple_spinner_dropdown_item); + + getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, + new OnNavigationListener() { + + private boolean firstHit = true; + + @Override + public boolean onNavigationItemSelected(final int itemPosition, + final long itemId) { + + if (firstHit == true) { + firstHit = false; + return false; + } + switch (itemPosition) { + + case LIST_NAVIGATION_CHANNELS: { + startActivity(ChannelListActivity.class); + return true; + } + case LIST_NAVIGATION_EPG_BY_TIME: { + startActivity(TimeEpgListActivity.class); + return true; + } + + case LIST_NAVIGATION_EPG_BY_CHANNEL: { + startActivity(EventEpgListActivity.class); + return true; + } + + case LIST_NAVIGATION_RECORDINGS: { + startActivity(RecordingListActivity.class); + return true; + } + + case LIST_NAVIGATION_TIMERS: { + startActivity(TimerListActivity.class); + return true; + } + + } + return false; + } + }); + getSupportActionBar().setSelectedNavigationItem( + getListNavigationIndex()); + + } + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Preferences.setLocale(this); + progress = new ProgressDialog(this); + + + initActionBar(); + + initListNavigation(); + + // new OnNavigationListener() { + // @Override + // public boolean onNavigationItemSelected(int itemPosition, long + // itemId) { + // System.err.println("itemPosition: "+ itemPosition +", itemId:" + + // itemId); + // rturn false; + // } + // }); + + // your logic for click listner + // setListenerForActionBarCustomView(actionBarView); + + // private void setListenerForActionBarCustomView(View actionBarView) { + // ActionBarCustomViewOnClickListener actionBarCustomViewOnClickListener + // = new ActionBarCustomViewOnClickListener(); + // actionBarView.findViewById(R.id.text_view_title).setOnClickListener(actionBarCustomViewOnClickListener); + // } + + } + + public void startActivity(final Class<?> clazz) { + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setClass(this, clazz); + startActivity(intent); + finish(); + } + + protected int getBaseMenu() { + return R.menu.refresh_filter_menu; + } + + @Override + public boolean onCreateOptionsMenu( + final com.actionbarsherlock.view.Menu menu) { + + // MenuItem item; + // item = menu.add(MENU_GROUP_REFRESH, MENU_REFRESH, 0, + // R.string.refresh); + // item.setIcon(R.drawable.ic_menu_refresh); + // item.setAlphabeticShortcut('r'); + final com.actionbarsherlock.view.MenuInflater inf = getSupportMenuInflater(); + inf.inflate(getBaseMenu(), menu); + + // SearchView searchView = (SearchView) + // menu.findItem(R.id.menu_search).getActionView(); + // searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + + return true; + } + + abstract protected void refresh(); + + abstract protected void retry(); + + // abstract protected SvdrpClient<Result> getClient(); + + @Override + public boolean onOptionsItemSelected( + final com.actionbarsherlock.view.MenuItem item) { + switch (item.getItemId()) { + case R.id.list_refresh: + backupViewSelection(); + refresh(); + return true; + case R.id.list_filter: { + onSearchRequested(); + return true; + } + case android.R.id.home: + final Intent intent = new Intent(this, VdrManagerActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + return true; + default: + return false; + } + } + + protected void setCurrent(final Channel channel) { + getApp().setCurrentChannel(channel); + } + + protected VdrManagerApp getApp() { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + return app; + } + + // protected Channel getCurrentChannel(){ + // final Channel channel = ((VdrManagerApp) getApplication()) + // .getCurrentChannel(); + // return channel; + // } + + protected void say(final int res) { + say(this.getString(res)); + } + + protected void say(final String msg) { + Utils.say(this, msg); + } + + protected boolean noConnection(final SvdrpEvent event) { + switch (event) { + case CONNECTION_TIMEOUT: + say(R.string.progress_connect_timeout); + switchNoConnection(); + case CONNECT_ERROR: + say(R.string.progress_connect_error); + switchNoConnection(); + break; + case FINISHED_ABNORMALY: + alert(R.string.progress_connect_finished_abnormal); + switchNoConnection(); + break; + case LOGIN_ERROR: + say(R.string.progress_login_error); + switchNoConnection(); + break; + default: + return false; + } + return true; + } + + protected void alert(final String msg) { + if (isFinishing()) { + return; + } + new AlertDialog.Builder(this)// + .setMessage(msg)// + .setPositiveButton(android.R.string.ok, null)// + .create()// + .show();// + } + + protected void alert(final int resId) { + alert(getString(resId)); + } + + protected void restoreViewSelection() { + listView.setSelectionFromTop(index, top); + } + + protected void backupViewSelection() { + index = listView.getFirstVisiblePosition(); + final View v = listView.getChildAt(0); + top = (v == null) ? 0 : v.getTop(); + } + + int index; + int top; + + protected boolean checkInternetConnection() { + if (Utils.checkInternetConnection(this)) { + return true; + } + noInternetConnection(); + return false; + } + + // public void svdrpEvent(Result result) { + // resultReceived(result); + // } + + @Override + public void svdrpEvent(final SvdrpEvent event, final Throwable t) { + Utils.say(this, t.getLocalizedMessage()); + } + + protected void addListener(final SvdrpAsyncTask<Result, SvdrpClient<Result>> task) { + task.addSvdrpExceptionListener(this); + task.addSvdrpListener(this); + task.addSvdrpFinishedListener(this); + } + + @Override + public void svdrpEvent(final SvdrpEvent event) { + + switch (event) { + case LOGIN: + break; + case COMMAND_SENDING: + break; + case CONNECTING: + progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); + setMessage(R.string.progress_connect); + if (!isFinishing()) { + progress.show(); + } + break; + case LOGGED_IN: + setMessage(R.string.progress_login); + break; + case COMMAND_SENT: + setMessage(getProgressTextId()); + break; + case DISCONNECTING: + setMessage(R.string.progress_disconnect); + break; + case DISCONNECTED: + break; + case ABORTED: + progress.dismiss(); + say(R.string.aborted); + break; + case ERROR: + progress.dismiss(); + alert(R.string.epg_client_errors); + break; + case CONNECTED: + connected(); + break; + case CONNECTION_TIMEOUT: + case CONNECT_ERROR: + case FINISHED_ABNORMALY: + case LOGIN_ERROR: + progress.dismiss(); + noConnection(event); + break; + case CACHE_HIT: + progress.dismiss(); + cacheHit(); + return; + case FINISHED_SUCCESS: + progress.dismiss(); + break; + } + // case RESULT_RECEIVED: + // resultReceived(result); + // break; + // } + } + + protected int getProgressTextId() { + return R.string.progress_loading; + } + + private void setMessage(final int progressConnect) { + progress.setMessage(getString(progressConnect)); + } + + protected boolean finishedSuccess = false; + + protected void cacheHit() { + + } + + /** + * @return false, if no results found + */ + protected abstract boolean finishedSuccess(List<Result> results); + + // /** + // * @param result + // */ + // protected abstract void resultReceived(Result result); + + protected void connected() { + if (flipper != null) { + flipper.setDisplayedChild(0); + } + } + + public void svdrpException(final 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(); + } + + @Override + public void finished(final List<Result> results) { + if (finishedSuccess(results)) { + finishedSuccess = true; + restoreViewSelection(); + } else { + say(R.string.epg_no_items); + } + } + + /** + * Creates a dialog for showing certificate problems + * @return dialog + */ + @Override + protected CertificateProblemDialog getCertificateProblemDialog() { + return new CertificateProblemDialog(this); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java index be1e17d..2723d41 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseEventListActivity.java @@ -36,511 +36,523 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; * */ public abstract class BaseEventListActivity<T extends Event> extends - BaseActivity<T, ListView> implements OnItemClickListener, - SimpleGestureListener { +BaseActivity<T, ListView> implements OnItemClickListener, +SimpleGestureListener { - public static final String TAG = BaseEventListActivity.class.getName(); + public static final String TAG = BaseEventListActivity.class.getName(); - public static final int MENU_GROUP_SHARE = 90; + public static final int MENU_GROUP_SHARE = 90; - public static final int MENU_SHARE = 90; + public static final int MENU_SHARE = 90; - public static final int MENU_GROUP_TO_CAL = 91; + public static final int MENU_GROUP_TO_CAL = 91; - public static final int MENU_TO_CAL = 91; + public static final int MENU_TO_CAL = 91; - private SimpleGestureFilter detector; + private SimpleGestureFilter detector; - protected EventAdapter adapter; + protected EventAdapter adapter; - protected String highlight = null; + protected String highlight = null; - protected Date lastUpdate = null; + protected Date lastUpdate = null; - protected static final Date FUTURE = new Date(Long.MAX_VALUE); + protected static final Date FUTURE = new Date(Long.MAX_VALUE); - // private static final Date BEGIN = new Date(0); + // private static final Date BEGIN = new Date(0); - protected Channel currentChannel = null; + protected Channel currentChannel = null; - //protected List<T> results = new ArrayList<T>(); + //protected List<T> results = new ArrayList<T>(); - AlertDialog sortByDialog = null; + AlertDialog sortByDialog = null; - public static final int MENU_GROUP_DEFAULT = 0; + public static final int MENU_GROUP_DEFAULT = 0; - public static final int MENU_GROUP_ALPHABET = 1; + public static final int MENU_GROUP_ALPHABET = 1; - protected int sortBy; + protected int sortBy; - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - sortBy = Preferences.get(this, getViewID() + "_" - + P.EPG_LAST_SORT, MENU_GROUP_DEFAULT); - // Attach view - setContentView(getMainLayout()); - setTitle(getWindowTitle()); - initFlipper(); - detector = new SimpleGestureFilter(this, this); + sortBy = Preferences.get(this, getViewID() + "_" + + P.EPG_LAST_SORT, MENU_GROUP_DEFAULT); + // Attach view + setContentView(getMainLayout()); + setTitle(getWindowTitle()); + initFlipper(); + detector = new SimpleGestureFilter(this, this); - initChannel(); - } + initChannel(); + } - private void initChannel() { - currentChannel = getApp().getCurrentChannel(); - // currentChannel = getIntent() - // .getParcelableExtra(Intents.CURRENT_CHANNEL); - } + private void initChannel() { + currentChannel = getApp().getCurrentChannel(); + // currentChannel = getIntent() + // .getParcelableExtra(Intents.CURRENT_CHANNEL); + } - @Override - protected void onResume() { - super.onResume(); - if (notifyDataSetChangedOnResume()) { - adapter.notifyDataSetChanged(); - } - } + @Override + protected void onResume() { + super.onResume(); + if (notifyDataSetChangedOnResume()) { + adapter.notifyDataSetChanged(); + } + } - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseActivity#onCreateOptionsMenu(android - * .view.Menu) - */ - @Override - public boolean onCreateOptionsMenu( - final com.actionbarsherlock.view.Menu menu) { - super.onCreateOptionsMenu(menu); - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.epg_list_menu, menu); - return true; - } + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseActivity#onCreateOptionsMenu(android + * .view.Menu) + */ + @Override + public boolean onCreateOptionsMenu( + final com.actionbarsherlock.view.Menu menu) { + super.onCreateOptionsMenu(menu); + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.epg_list_menu, menu); + return true; + } - /** - * Prepare the current event and the chained events for - * - * @param event - */ - protected void prepareDetailsViewData(EventListItem event) { + /** + * Prepare the current event and the chained events for + * + * @param event + */ + protected void prepareDetailsViewData(final EventListItem event) { - } + } - /* - * (non-Javadoc) - * - * @see android.app.Activity#onContextItemSelected(android.view.MenuItem) - */ - @Override - public boolean onContextItemSelected(final MenuItem item) { + /* + * (non-Javadoc) + * + * @see android.app.Activity#onContextItemSelected(android.view.MenuItem) + */ + @Override + public boolean onContextItemSelected(final MenuItem item) { - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item - .getMenuInfo(); - final EventListItem event = adapter.getItem(info.position); + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item + .getMenuInfo(); + final EventListItem event = adapter.getItem(info.position); - int itemId = item.getItemId(); + final int itemId = item.getItemId(); - switch (itemId) { + switch (itemId) { - case R.id.epg_item_menu_live_tv: { - Utils.stream(this, event); - break; - } - - - case MENU_SHARE: { - Utils.shareEvent(this, event); - break; - } - - case MENU_TO_CAL: { - Utils.addCalendarEvent(this, event); - break; - } - - case R.id.epg_item_menu_switchto: { - Utils.switchTo(this, event.getChannelId(), event.getChannelName()); - break; - } - - default: - return super.onContextItemSelected(item); - } - - return true; - } - - - - protected int getAvailableSortByEntries() { - return 0; - } - - protected void fillAdapter() { - - } - - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseActivity#onOptionsItemSelected(android - * .view.MenuItem) - */ - public boolean onOptionsItemSelected( - final com.actionbarsherlock.view.MenuItem item) { - - switch (item.getItemId()) { - - case R.id.epg_list_sort_menu: { - - if (sortByDialog == null) { - sortByDialog = new AlertDialog.Builder(this) - .setTitle(R.string.sort) - .setIcon(android.R.drawable.ic_menu_sort_alphabetically) - .setSingleChoiceItems(getAvailableSortByEntries(), - sortBy, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int which) { - - if (sortBy == which) { - sortByDialog.dismiss(); - return; - } - - sortBy = which; - - new VoidAsyncTask() { - - @Override - protected Void doInBackground( - Void... params) { - Preferences - .set(BaseEventListActivity.this, - getViewID() - + "_" - + P.EPG_LAST_SORT, - sortBy); - return null; - } - }.execute(); - - sortByDialog.dismiss(); - fillAdapter(); - } - - }).create(); - } - - sortByDialog.show(); - - return true; - } - - // switch (item.getItemId()) { - // case R.id.epg_menu_search: - // startSearchManager(); - // super.onSearchRequested(); - // break; - // case R.id.epg_menu_times: - // intent = new Intent(); - // /intent.setClass(this, EpgSearchTimesListActivity.class); - // startActivity(intent); - // break; - } - return super.onOptionsItemSelected(item); - } - - /* - * (non-Javadoc) - * - * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, - * android.view.View, android.view.ContextMenu.ContextMenuInfo) - */ - @Override - public void onCreateContextMenu(final ContextMenu menu, final View v, - final ContextMenuInfo menuInfo) { - - // if (v.getId() == R.id.whatson_list) { - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - - // set menu title - final EventListItem item = adapter.getItem(info.position); - - if (item.isHeader()) { - return; - } - - MenuItem mi = menu.findItem(R.id.epg_item_menu_live_tv); - if (item.isLive() && item.getStreamId() != null) { - - mi.setVisible(true); - - } else { - - mi.setVisible(false); - } - menu.add(MENU_GROUP_SHARE, MENU_SHARE, 0, R.string.share); - menu.add(MENU_GROUP_TO_CAL, MENU_TO_CAL, 0, R.string.addtocal); - super.onCreateContextMenu(menu, v, menuInfo); - - } - - /** - * @param parent - * @param view - * @param position - * @param id - */ - public void onItemClick(final AdapterView<?> parent, final View view, - final int position, final long id) { - - // find and remember item - final EventListItem item = adapter.getItem(position); - - if (item.isHeader()) { - return; - } - - prepareDetailsViewData(item); - - // show details - final Intent intent = new Intent(this, EpgDetailsActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - | Intent.FLAG_ACTIVITY_SINGLE_TOP); - if (highlight != null) { - intent.putExtra(Intents.HIGHLIGHT, highlight); - } - startActivityForResult(intent, - TimerDetailsActivity.REQUEST_CODE_TIMER_MODIFIED); - } - - protected boolean notifyDataSetChangedOnResume() { - return true; - } - - @Override - protected void onPause() { - super.onPause(); - // if (epgClient != null) { - // epgClient.abort(); - // } - // if (progress != null) { - // progress.dismiss(); - // progress = null; - // } - } - -// protected void resultReceived(T result) { -// results.add(result); -// } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - int index = savedInstanceState.getInt("INDEX"); - int top = savedInstanceState.getInt("TOP"); - listView.setSelectionFromTop(index, top); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - int index = listView.getFirstVisiblePosition(); - View v = listView.getChildAt(0); - int top = (v == null) ? 0 : v.getTop(); - outState.putInt("INDEX", index); - outState.putInt("TOP", top); - super.onSaveInstanceState(outState); - } - - protected void dismiss(AlertDialog dialog) { - if (dialog == null) { - return; - } - dialog.dismiss(); - } - - public boolean onSearchRequested() { - InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - inputMgr.toggleSoftInput(0, 0); - return true; - } - - protected void startSearchManager() { - Bundle appData = new Bundle(); - startSearch(highlight, false, appData, false); - } - - @Override - public boolean dispatchTouchEvent(MotionEvent me) { - this.detector.onTouchEvent(me); - return super.dispatchTouchEvent(me); - } - - public void onSwipe(int direction) { - - } - - public void onDoubleTap() { - - } - - protected void sortItemsByChannel(List<Event> result) { - final Comparator<Event> comparator = new Comparator<Event>() { - - public int compare(final Event item1, final Event item2) { - return item1.getChannelNumber().compareTo( - item2.getChannelNumber()); - } - }; - Collections.sort(result, comparator); - } - - protected void sortItemsByTime(List<T> result) { - sortItemsByTime(result, false); - } - - protected void sortItemsByTime(List<T> result, final boolean reverse) { - Collections.sort(result, new TimeAndChannelComparator(reverse)); - } - - public void svdrpException(final SvdrpException exception) { - Log.w(TAG, exception); - alert(getString(R.string.vdr_error_text, exception.getMessage())); - } - - abstract protected boolean finishedSuccessImpl(List<T> results); - - protected String getViewID(){ - return this.getClass().getSimpleName(); - } - - protected void pushResultCountToTitle(){ - setTitle(getString(R.string.epg_window_title_count, getWindowTitle(), - getCACHE().size())); - } - - - synchronized protected final boolean finishedSuccess(List<T> results) { - //ProgressDialog dialog = new ProgressDialog(this); - //dialog.setMessage("Loading"); - //dialog.show(); - try { - lastUpdate = new Date(); - boolean r = finishedSuccessImpl(results); - if(r == false){ - adapter.clear(); - adapter.notifyDataSetChanged(); - } - return r; - } finally { -// dialog.dismiss(); - //results.clear(); - } - } - - @Override - protected boolean displayingResults() { - return getCACHE().isEmpty() == false; - } - - class TitleComparator implements Comparator<Event> { - - @Override - public int compare(Event lhs, Event rhs) { - if (lhs == null || lhs.getTitle() == null) { - return 1; - } - if (rhs == null || rhs.getTitle() == null) { - return 0; - } - return lhs.getTitle().compareToIgnoreCase(rhs.getTitle()); - } - }; - - class TimeAndChannelComparator implements Comparator<Event> { - boolean r = false; - - TimeAndChannelComparator() { - this(false); - } - TimeAndChannelComparator(boolean r) { - this.r = r; - } - - public int compare(final Event item1, final Event item2) { - - int c = item1.getStart().compareTo(item2.getStart()); - if (c != 0) { - if (r == false) - return c; - return -1 * c; - } - if (item1.getChannelNumber() == null - && item2.getChannelNumber() == null) { - return 0; - } - if (item1.getChannelNumber() == null) { - return 1; - } - if (item2.getChannelNumber() == null) { - return -1; - } - return item1.getChannelNumber().compareTo(item2.getChannelNumber()); - } - } - - - class TimeComparator implements Comparator<Event> { - boolean r = false; - - TimeComparator(boolean r) { - this.r = r; - } - - public int compare(final Event item1, final Event item2) { - - int c = item1.getStart().compareTo(item2.getStart()); - if (c == 0) { - return c; - } - if (r == false) - return c; - return -1 * c; - } - } - - class ChannelComparator implements Comparator<Event> { - - public int compare(final Event item1, final Event item2) { - - if (item1.getChannelNumber() == null - && item2.getChannelNumber() == null) { - return 0; - } - if (item1.getChannelNumber() == null) { - return 1; - } - if (item2.getChannelNumber() == null) { - return -1; - } - return item1.getChannelNumber().compareTo(item2.getChannelNumber()); - } - } - - - - public void clearCache() { - getCACHE().clear(); - } - - protected abstract List<T> getCACHE(); - -// @Override -// protected void connected() { -// super.connected(); -// results.clear(); -// } + case R.id.epg_item_menu_live_tv: { + Utils.stream(this, event); + break; + } + + + case MENU_SHARE: { + Utils.shareEvent(this, event); + break; + } + + case MENU_TO_CAL: { + Utils.addCalendarEvent(this, event); + break; + } + + case R.id.epg_item_menu_switchto: { + Utils.switchTo(this, event.getChannelId(), event.getChannelName()); + break; + } + + default: + return super.onContextItemSelected(item); + } + + return true; + } + + + + protected int getAvailableSortByEntries() { + return 0; + } + + protected void fillAdapter() { + + } + + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseActivity#onOptionsItemSelected(android + * .view.MenuItem) + */ + public boolean onOptionsItemSelected( + final com.actionbarsherlock.view.MenuItem item) { + + switch (item.getItemId()) { + + case R.id.epg_list_sort_menu: { + + if (sortByDialog == null) { + sortByDialog = new AlertDialog.Builder(this) + .setTitle(R.string.sort) + .setIcon(android.R.drawable.ic_menu_sort_alphabetically) + .setSingleChoiceItems(getAvailableSortByEntries(), + sortBy, new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, + final int which) { + + if (sortBy == which) { + sortByDialog.dismiss(); + return; + } + + sortBy = which; + + new VoidAsyncTask() { + + @Override + protected Void doInBackground( + final Void... params) { + Preferences + .set(BaseEventListActivity.this, + getViewID() + + "_" + + P.EPG_LAST_SORT, + sortBy); + return null; + } + }.execute(); + + sortByDialog.dismiss(); + fillAdapter(); + } + + }).create(); + } + + sortByDialog.show(); + + return true; + } + + // switch (item.getItemId()) { + // case R.id.epg_menu_search: + // startSearchManager(); + // super.onSearchRequested(); + // break; + // case R.id.epg_menu_times: + // intent = new Intent(); + // /intent.setClass(this, EpgSearchTimesListActivity.class); + // startActivity(intent); + // break; + } + return super.onOptionsItemSelected(item); + } + + /* + * (non-Javadoc) + * + * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, + * android.view.View, android.view.ContextMenu.ContextMenuInfo) + */ + @Override + public void onCreateContextMenu(final ContextMenu menu, final View v, + final ContextMenuInfo menuInfo) { + + // if (v.getId() == R.id.whatson_list) { + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + + // set menu title + final EventListItem item = adapter.getItem(info.position); + + if (item.isHeader()) { + return; + } + + final MenuItem mi = menu.findItem(R.id.epg_item_menu_live_tv); + if (item.isLive() && item.getStreamId() != null) { + + mi.setVisible(true); + + } else { + + mi.setVisible(false); + } + menu.add(MENU_GROUP_SHARE, MENU_SHARE, 0, R.string.share); + menu.add(MENU_GROUP_TO_CAL, MENU_TO_CAL, 0, R.string.addtocal); + super.onCreateContextMenu(menu, v, menuInfo); + + } + + /** + * @param parent + * @param view + * @param position + * @param id + */ + @Override + public void onItemClick(final AdapterView<?> parent, final View view, + final int position, final long id) { + + // find and remember item + final EventListItem item = adapter.getItem(position); + + if (item.isHeader()) { + return; + } + + prepareDetailsViewData(item); + + // show details + final Intent intent = new Intent(this, EpgDetailsActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT + | Intent.FLAG_ACTIVITY_SINGLE_TOP); + if (highlight != null) { + intent.putExtra(Intents.HIGHLIGHT, highlight); + } + startActivityForResult(intent, + TimerDetailsActivity.REQUEST_CODE_TIMER_MODIFIED); + } + + protected boolean notifyDataSetChangedOnResume() { + return true; + } + + @Override + protected void onPause() { + super.onPause(); + // if (epgClient != null) { + // epgClient.abort(); + // } + // if (progress != null) { + // progress.dismiss(); + // progress = null; + // } + } + + // protected void resultReceived(T result) { + // results.add(result); + // } + + @Override + protected void onRestoreInstanceState(final Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + final int index = savedInstanceState.getInt("INDEX"); + final int top = savedInstanceState.getInt("TOP"); + listView.setSelectionFromTop(index, top); + } + + @Override + protected void onSaveInstanceState(final Bundle outState) { + final int index = listView.getFirstVisiblePosition(); + final View v = listView.getChildAt(0); + final int top = (v == null) ? 0 : v.getTop(); + outState.putInt("INDEX", index); + outState.putInt("TOP", top); + super.onSaveInstanceState(outState); + } + + protected void dismiss(final AlertDialog dialog) { + if (dialog == null) { + return; + } + dialog.dismiss(); + } + + public boolean onSearchRequested() { + final InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputMgr.toggleSoftInput(0, 0); + return true; + } + + protected void startSearchManager() { + final Bundle appData = new Bundle(); + startSearch(highlight, false, appData, false); + } + + @Override + public boolean dispatchTouchEvent(final MotionEvent me) { + this.detector.onTouchEvent(me); + return super.dispatchTouchEvent(me); + } + + @Override + public void onSwipe(final int direction) { + + } + + @Override + public void onDoubleTap() { + + } + + protected void sortItemsByChannel(final List<Event> result) { + final Comparator<Event> comparator = new Comparator<Event>() { + + @Override + public int compare(final Event item1, final Event item2) { + return item1.getChannelNumber().compareTo( + item2.getChannelNumber()); + } + }; + Collections.sort(result, comparator); + } + + protected void sortItemsByTime(final List<T> result) { + sortItemsByTime(result, false); + } + + protected void sortItemsByTime(final List<T> result, final boolean reverse) { + Collections.sort(result, new TimeAndChannelComparator(reverse)); + } + + @Override + public void svdrpException(final SvdrpException exception) { + Log.w(TAG, exception); + alert(getString(R.string.vdr_error_text, exception.getMessage())); + } + + abstract protected boolean finishedSuccessImpl(List<T> results); + + protected String getViewID(){ + return this.getClass().getSimpleName(); + } + + protected void pushResultCountToTitle(){ + setTitle(getString(R.string.epg_window_title_count, getWindowTitle(), + getCACHE().size())); + } + + + @Override + synchronized protected final boolean finishedSuccess(final List<T> results) { + //ProgressDialog dialog = new ProgressDialog(this); + //dialog.setMessage("Loading"); + //dialog.show(); + try { + lastUpdate = new Date(); + final boolean r = finishedSuccessImpl(results); + if(r == false){ + adapter.clear(); + adapter.notifyDataSetChanged(); + } + return r; + } finally { + // dialog.dismiss(); + //results.clear(); + } + } + + @Override + protected boolean displayingResults() { + return getCACHE().isEmpty() == false; + } + + class TitleComparator implements Comparator<Event> { + + @Override + public int compare(final Event lhs, final Event rhs) { + if (lhs == null || lhs.getTitle() == null) { + return 1; + } + if (rhs == null || rhs.getTitle() == null) { + return 0; + } + return lhs.getTitle().compareToIgnoreCase(rhs.getTitle()); + } + }; + + class TimeAndChannelComparator implements Comparator<Event> { + boolean r = false; + + TimeAndChannelComparator() { + this(false); + } + TimeAndChannelComparator(final boolean r) { + this.r = r; + } + + @Override + public int compare(final Event item1, final Event item2) { + + final int c = item1.getStart().compareTo(item2.getStart()); + if (c != 0) { + if (r == false) { + return c; + } + return -1 * c; + } + if (item1.getChannelNumber() == null + && item2.getChannelNumber() == null) { + return 0; + } + if (item1.getChannelNumber() == null) { + return 1; + } + if (item2.getChannelNumber() == null) { + return -1; + } + return item1.getChannelNumber().compareTo(item2.getChannelNumber()); + } + } + + + class TimeComparator implements Comparator<Event> { + boolean r = false; + + TimeComparator(final boolean r) { + this.r = r; + } + + @Override + public int compare(final Event item1, final Event item2) { + + final int c = item1.getStart().compareTo(item2.getStart()); + if (c == 0) { + return c; + } + if (r == false) { + return c; + } + return -1 * c; + } + } + + class ChannelComparator implements Comparator<Event> { + + @Override + public int compare(final Event item1, final Event item2) { + + if (item1.getChannelNumber() == null + && item2.getChannelNumber() == null) { + return 0; + } + if (item1.getChannelNumber() == null) { + return 1; + } + if (item2.getChannelNumber() == null) { + return -1; + } + return item1.getChannelNumber().compareTo(item2.getChannelNumber()); + } + } + + + + public void clearCache() { + getCACHE().clear(); + } + + protected abstract List<T> getCACHE(); + + // @Override + // protected void connected() { + // super.connected(); + // results.clear(); + // } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/CertificateProblemDialog.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/CertificateProblemDialog.java new file mode 100644 index 0000000..1d685b4 --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/CertificateProblemDialog.java @@ -0,0 +1,94 @@ +package de.bjusystems.vdrmanager.gui; + +import java.security.cert.X509Certificate; +import java.util.concurrent.Semaphore; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import de.bjusystems.vdrmanager.R; +import de.bjusystems.vdrmanager.utils.svdrp.CertificateProblemListener; + +public class CertificateProblemDialog implements CertificateProblemListener { + + /** Context */ + private final Activity activity; + /** User wanted action */ + CertificateProblemAction action; + + /** + * Constructor + * @param activity Context + */ + public CertificateProblemDialog(final Activity activity) { + this.activity = activity; + } + + @Override + public CertificateProblemAction reportProblem(final X509Certificate[] chain, final String authType) { + + // Semaphore to implement a modal dialog + final Semaphore semaphore = new Semaphore(0, true); + + // certificate properties + final String host = "myhost.de"; + final String key = "Key"; + final String fingerprint = "Fingerprint"; + final String issuer = "Issuer"; + + // message + final CharSequence message = String.format(activity.getString(R.string.certificate_problem_message_text), host, key, fingerprint, issuer); + + // create dialog builder + final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); + alertDialogBuilder.setTitle(R.string.certificate_problem_message_title); + alertDialogBuilder.setMessage(message); + alertDialogBuilder.setCancelable(false); + + // buttons + alertDialogBuilder.setNegativeButton(R.string.certificate_not_accepted, new OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + action = CertificateProblemAction.ABORT; + dialog.cancel(); + semaphore.release(); + } + }); + alertDialogBuilder.setNeutralButton(R.string.certificate_accept_once, new OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + action = CertificateProblemAction.ACCEPT_ONCE; + dialog.cancel(); + semaphore.release(); + } + }); + alertDialogBuilder.setPositiveButton(R.string.certificate_accepted_forever, new OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + action = CertificateProblemAction.ACCEPT_FOREVER; + dialog.cancel(); + semaphore.release(); + } + }); + + // show the dialog + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + final AlertDialog dialog = alertDialogBuilder.create(); + dialog.show(); + } + }); + + + try { + semaphore.acquire(); + } catch (final InterruptedException e) { + // NOP + } + + return action; + } +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java index 990488d..e6ad0e0 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java @@ -42,566 +42,573 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; * @author bju */ public class ChannelListActivity extends - BaseActivity<Channel, ExpandableListView> implements - OnChildClickListener, OnGroupClickListener { +BaseActivity<Channel, ExpandableListView> implements +OnChildClickListener, OnGroupClickListener { - private static final String TAG = ChannelListActivity.class.getName(); + private static final String TAG = ChannelListActivity.class.getName(); - ChannelAdapter adapter; + ChannelAdapter adapter; - Preferences prefs; + Preferences prefs; - // private static final LinkedList<Channel> RECENT = new - // LinkedList<Channel>(); + // private static final LinkedList<Channel> RECENT = new + // LinkedList<Channel>(); - public static final int MENU_GROUP = 0; - public static final int MENU_PROVIDER = 1; - public static final int MENU_SOURCE = 2; - public static final int MENU_NAME = 3; + public static final int MENU_GROUP = 0; + public static final int MENU_PROVIDER = 1; + public static final int MENU_SOURCE = 2; + public static final int MENU_NAME = 3; - public static final boolean GROUP_NATURAL = false; + public static final boolean GROUP_NATURAL = false; - public static final boolean GROUP_REVERSE = true; + public static final boolean GROUP_REVERSE = true; - private int groupBy; + private int groupBy; - private boolean groupByReverse; + private boolean groupByReverse; - final static ArrayList<String> ALL_CHANNELS_GROUP = new ArrayList<String>(1); + final static ArrayList<String> ALL_CHANNELS_GROUP = new ArrayList<String>(1); - @Override - protected void onResume() { - super.onResume(); - } + @Override + protected void onResume() { + super.onResume(); + } - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - // Attach view - setContentView(getMainLayout()); - setTitle(getWindowTitle()); - initFlipper(); + // Attach view + setContentView(getMainLayout()); + setTitle(getWindowTitle()); + initFlipper(); - groupBy = Preferences.get(this, P.CHANNELS_LAST_ORDER, MENU_GROUP); - groupByReverse = Preferences.get(this, P.CHANNELS_LAST_ORDER_REVERSE, - GROUP_NATURAL); + groupBy = Preferences.get(this, P.CHANNELS_LAST_ORDER, MENU_GROUP); + groupByReverse = Preferences.get(this, P.CHANNELS_LAST_ORDER_REVERSE, + GROUP_NATURAL); - adapter = new ChannelAdapter(this); + adapter = new ChannelAdapter(this); - listView = (ExpandableListView) findViewById(R.id.channel_list); - listView.setOnChildClickListener(this); - listView.setTextFilterEnabled(true); - listView.setFastScrollEnabled(true); - listView.setAdapter(adapter); - // register context menu - registerForContextMenu(listView); - startChannelQuery(); + listView = (ExpandableListView) findViewById(R.id.channel_list); + listView.setOnChildClickListener(this); + listView.setTextFilterEnabled(true); + listView.setFastScrollEnabled(true); + listView.setAdapter(adapter); + // register context menu + registerForContextMenu(listView); + startChannelQuery(); - } + } - // + // - @Override - protected void onPause() { - super.onPause(); - } + @Override + protected void onPause() { + super.onPause(); + } - private void startChannelQuery() { - backupViewSelection(); - startChannelQuery(true); - } - - private void startChannelQuery(boolean useCache) { - - if (checkInternetConnection() == false) { - return; - } - - ChannelClient channelClient = new ChannelClient(); - - if (useCache == false) { - ChannelClient.clearCache(); - } - - // create background task - final SvdrpAsyncTask<Channel, SvdrpClient<Channel>> task = new SvdrpAsyncTask<Channel, SvdrpClient<Channel>>( - channelClient); - - addListener(task); - //task.addSvdrpExceptionListener(this); - //task.addSvdrpResultListener(this); - //task.addSvdrpListener(this); - //task.addSvdrpFinishedListener(this); - - // start task - task.run(); - } - - static RecentChannelsAdapter RECENT_ADAPTER = null; - - static class RecentChannelsAdapter extends ArrayAdapter<Channel> { - private Activity context; - int resId; - - public RecentChannelsAdapter(Activity context) { - super(context, android.R.layout.simple_list_item_1); - this.context = context; - showChannelNumbers = Preferences.get().isShowChannelNumbers(); - - if (Build.VERSION.SDK_INT < 11) { - resId = android.R.layout.select_dialog_item; - } else { - resId = android.R.layout.simple_list_item_1; - } - } - - public boolean showChannelNumbers; - - public View getView(int position, View convertView, ViewGroup parent) { - // recycle view? - TextView text1; - View view = convertView; - if (view == null) { - view = this.context.getLayoutInflater().inflate(resId, null); - text1 = (TextView) view.findViewById(android.R.id.text1); - view.setTag(text1); - } else { - text1 = (TextView) view.getTag(); - } - - Channel c = getItem(position); - String text = showChannelNumbers ? text = c.toString() : c - .getName(); - text1.setText(text); - return view; - - } - } - - private ArrayAdapter<Channel> getRecentAdapter() { - if (RECENT_ADAPTER != null) { - RECENT_ADAPTER.showChannelNumbers = Preferences.get() - .isShowChannelNumbers(); - RECENT_ADAPTER.notifyDataSetChanged(); - return RECENT_ADAPTER; - } - - RECENT_ADAPTER = new RecentChannelsAdapter(this); - return RECENT_ADAPTER; - - } - - private void fillAdapter() { - switch (groupBy) { - case MENU_GROUP: - ArrayList<String> cgs = ChannelClient.getChannelGroups(); - adapter.fill(cgs, ChannelClient.getGroupChannels(), groupBy, - groupByReverse); - if (cgs.size() == 1) {// one group or first no first group - listView.expandGroup(0); - } else if ((cgs.size() > 1 && TextUtils.isEmpty(cgs.get(0)))) { - listView.expandGroup(0); - } - updateWindowTitle(); - break; - - case MENU_SOURCE: - ArrayList<String> css = ChannelClient.getChannelSources(); - adapter.fill(css, ChannelClient.getSourceChannels(), groupBy, - groupByReverse); - if (css.size() == 1) {// one group or first no first group - listView.expandGroup(0); - } else if ((css.size() > 1 && TextUtils.isEmpty(css.get(0)))) { - listView.expandGroup(0); - } - updateWindowTitle(); - break; - - - case MENU_PROVIDER: - ArrayList<String> gs = new ArrayList<String>(ChannelClient - .getProviderChannels().keySet()); - adapter.fill(gs, ChannelClient.getProviderChannels(), groupBy, - groupByReverse); - if (gs.size() == 1) { - listView.expandGroup(0); - } - updateWindowTitle(); - break; - case MENU_NAME: - if (ALL_CHANNELS_GROUP.isEmpty()) { - ALL_CHANNELS_GROUP - .add(getString(R.string.groupby_name_all_channels_group)); - } - HashMap<String, ArrayList<Channel>> channels = new HashMap<String, ArrayList<Channel>>( - 1); - channels.put(getString(R.string.groupby_name_all_channels_group), - ChannelClient.getChannels()); - adapter.fill(ALL_CHANNELS_GROUP, channels, groupBy, groupByReverse); - listView.expandGroup(0); - updateWindowTitle(); - } - adapter.notifyDataSetChanged(); - } - - public boolean onPrepareOptionsMenu(com.actionbarsherlock.view.Menu menu) { - return super.onPrepareOptionsMenu(menu); - } - - @Override - public final boolean onCreateOptionsMenu( - final com.actionbarsherlock.view.Menu menu) { - super.onCreateOptionsMenu(menu); - - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.channellist, menu); - - return true; - } - - private int getAvailableGroupByEntries() { - return R.array.channels_group_by; - } - - AlertDialog groupByDialog = null; - - @Override - public boolean onOptionsItemSelected( - final com.actionbarsherlock.view.MenuItem item) { - - switch (item.getItemId()) { - case R.id.channels_groupby: - // case MENU_PROVIDER: - // case MENU_NAME: - if (groupByDialog == null) { - groupByDialog = new AlertDialog.Builder(this) - .setTitle(R.string.menu_groupby) - .setIcon(android.R.drawable.ic_menu_sort_alphabetically) - .setSingleChoiceItems(getAvailableGroupByEntries(), - groupBy, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int which) { - - final boolean reversed = which == groupBy ? true - : false; - groupBy = which; - new VoidAsyncTask() { - - @Override - protected Void doInBackground( - Void... params) { - - if (reversed) { - if (groupByReverse == true) { - groupByReverse = false; - } else { - groupByReverse = true; - } - Preferences - .set(ChannelListActivity.this, - P.CHANNELS_LAST_ORDER_REVERSE, - groupByReverse); - - } else { - Preferences - .set(ChannelListActivity.this, - P.CHANNELS_LAST_ORDER, - groupBy); - } - return null; - } - }.execute(); - - fillAdapter(); - groupByDialog.dismiss(); - } - }).create(); - } - - groupByDialog.show(); - - return true; - case R.id.channels_recent_channels: - - String order = Preferences.get(ChannelListActivity.this, - "gui_recent_channels_order", "most"); - - List<RecenteChannel> rcs = null; - - if (order.equals("most")) { - rcs = DBAccess - .get(ChannelListActivity.this) - .getRecentChannelDAO() - .loadByRecentUse( - Preferences.get().getMaxRecentChannels()); - } else if (order.equals("last")) { - rcs = DBAccess - .get(ChannelListActivity.this) - .getRecentChannelDAO() - .loadByLastAccess( - Preferences.get().getMaxRecentChannels()); - } else { - return true; - } - - if (rcs.isEmpty()) { - say(R.string.recent_channels_no_history); - return true; - } - - if (Preferences.get().getMaxRecentChannels() <= 0) { - say(R.string.recent_channels_no_history); - return true; - } - - final ArrayAdapter<Channel> recentAdapter = getRecentAdapter(); - - recentAdapter.clear(); - for (Channel c : DBAccess.get(ChannelListActivity.this) - .getRecentChannelDAO() - .getRecentChannels(ChannelClient.getIdChannels(), rcs)) { - recentAdapter.add(c); - } - - new AlertDialog.Builder(this) - .setTitle(R.string.recent_channels) - .setAdapter(getRecentAdapter(), - new DialogInterface.OnClickListener() { - - public void onClick(DialogInterface dialog, - int which) { - Channel c = recentAdapter.getItem(which); - startChannelEPG(c); - } - })// - .create().show(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - - @Override - public void onCreateContextMenu(final ContextMenu menu, final View v, - final ContextMenuInfo menuInfo) { - ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; - int type = ExpandableListView - .getPackedPositionType(info.packedPosition); - int group = ExpandableListView - .getPackedPositionGroup(info.packedPosition); - int child = ExpandableListView - .getPackedPositionChild(info.packedPosition); - // Only create a context menu for child items - if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { - // Array created earlier when we built the expandable list - Channel item = (Channel) adapter.getChild(group, child); - // if (v.getId() == R.id.channel_list) { - - final MenuInflater inflater = getMenuInflater(); - menu.setHeaderTitle(item.getName()); - inflater.inflate(R.menu.channel_list_item_menu, menu); - - - } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { - /* - * http://projects.vdr-developer.org/issues/722 String grp = - * adapter.getGroup(group); final MenuInflater infl = - * getMenuInflater(); menu.setHeaderTitle(grp); - * infl.inflate(R.menu.channel_list_group_menu, menu); - */ - } - } - - @Override - public boolean onContextItemSelected(MenuItem item) { - - ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item - .getMenuInfo(); - - // String title = ((TextView) info.targetView).getText().toString(); - - int type = ExpandableListView - .getPackedPositionType(info.packedPosition); - - Channel channel = null; - if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { - int groupPos = ExpandableListView - .getPackedPositionGroup(info.packedPosition); - int childPos = ExpandableListView - .getPackedPositionChild(info.packedPosition); - channel = (Channel) adapter.getChild(groupPos, childPos); - switch (item.getItemId()) { - //case R.id.channel_item_menu_epg: - //startChannelEPG(channel); - //break; - case R.id.channel_item_menu_stream: - // show live stream - Utils.stream(this, channel); - break; - - //case R.id.channel_item_menu_hide: - // TODO http://projects.vdr-developer.org/issues/722 - //break; - //case R.id.channel_item_menu_hide_permanent: - // TODO http://projects.vdr-developer.org/issues/722 - //break; - - case R.id.channel_item_menu_switch: - Utils.switchTo(this, channel); - break; - } - - return true; - } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { - int groupPos = ExpandableListView - .getPackedPositionGroup(info.packedPosition); - - return true; - } - - return false; - - } - - @Override - public boolean onSearchRequested() { - InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - inputMgr.toggleSoftInput(0, 0); - return true; - } - - public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2, - long arg3) { - return true; - } - - private void startChannelEPG(final Channel channel) { - new VoidAsyncTask() { - - @Override - protected Void doInBackground(Void... arg0) { - int max = Preferences.get().getMaxRecentChannels(); - if (max <= 0) { - return null; - } - - DBAccess.get(ChannelListActivity.this).getRecentChannelDAO() - .hit(channel.getId()); - - return (Void) null; - } - }.execute((Void) null); - // for(int i = 0; i < recent) - // find and remember item - // final Channel channel = adapter.getItem(position); - // final VdrManagerApp app = (VdrManagerApp) getApplication(); - // app.setCurrentChannel(channel); - - // show details - final Intent intent = new Intent(); - getApp().setCurrentChannel(channel); - // intent.putExtra(Intents.CURRENT_CHANNEL, channel); - intent.setClass(this, EventEpgListActivity.class); - startActivity(intent); - } - - public boolean onChildClick(ExpandableListView parent, View v, - int groupPosition, int childPosition, long id) { - Channel channel = (Channel) adapter.getChild(groupPosition, - childPosition); - startChannelEPG(channel); - return false; - } - - @Override - protected void refresh() { - backupViewSelection(); - startChannelQuery(false); - } - - @Override - protected void retry() { - refresh(); - } - - @Override - protected int getMainLayout() { - 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; - - case MENU_SOURCE: { - sb.append(getString(R.string.action_menu_channels)) - .append(" > ") - .append(getString(R.string.groupby_window_title_templte, - getString(R.string.groupby_source))); - break; - } - } - - return sb.toString(); - } - - private void updateWindowTitle() { - setTitle(getString(R.string.channels_window_title_count, - resolveWindowTitle(), adapter.groups.size(), ChannelClient - .getChannels().size())); - } - - @Override - protected synchronized boolean finishedSuccess(List<Channel> results) { - fillAdapter(); - restoreViewSelection(); - updateWindowTitle(); - return ChannelClient.getChannels().isEmpty() == false; - } - - protected void cacheHit() { - fillAdapter(); - restoreViewSelection(); - } - - @Override - protected String getWindowTitle() { - return resolveWindowTitle(); - } - - protected boolean displayingResults() { - return ChannelClient.getChannels().isEmpty() == false; - } - - @Override - protected int getProgressTextId() { - return R.string.progress_channels_loading; - } - - - @Override - protected int getListNavigationIndex() { - return LIST_NAVIGATION_CHANNELS; - } + private void startChannelQuery() { + backupViewSelection(); + startChannelQuery(true); + } + + private void startChannelQuery(final boolean useCache) { + + if (checkInternetConnection() == false) { + return; + } + + final ChannelClient channelClient = new ChannelClient(getCertificateProblemDialog()); + + if (useCache == false) { + ChannelClient.clearCache(); + } + + // create background task + final SvdrpAsyncTask<Channel, SvdrpClient<Channel>> task = new SvdrpAsyncTask<Channel, SvdrpClient<Channel>>( + channelClient); + + addListener(task); + //task.addSvdrpExceptionListener(this); + //task.addSvdrpResultListener(this); + //task.addSvdrpListener(this); + //task.addSvdrpFinishedListener(this); + + // start task + task.run(); + } + + static RecentChannelsAdapter RECENT_ADAPTER = null; + + static class RecentChannelsAdapter extends ArrayAdapter<Channel> { + private final Activity context; + int resId; + + public RecentChannelsAdapter(final Activity context) { + super(context, android.R.layout.simple_list_item_1); + this.context = context; + showChannelNumbers = Preferences.get().isShowChannelNumbers(); + + if (Build.VERSION.SDK_INT < 11) { + resId = android.R.layout.select_dialog_item; + } else { + resId = android.R.layout.simple_list_item_1; + } + } + + public boolean showChannelNumbers; + + @Override + public View getView(final int position, final View convertView, final ViewGroup parent) { + // recycle view? + TextView text1; + View view = convertView; + if (view == null) { + view = this.context.getLayoutInflater().inflate(resId, null); + text1 = (TextView) view.findViewById(android.R.id.text1); + view.setTag(text1); + } else { + text1 = (TextView) view.getTag(); + } + + final Channel c = getItem(position); + String text = showChannelNumbers ? text = c.toString() : c + .getName(); + text1.setText(text); + return view; + + } + } + + private ArrayAdapter<Channel> getRecentAdapter() { + if (RECENT_ADAPTER != null) { + RECENT_ADAPTER.showChannelNumbers = Preferences.get() + .isShowChannelNumbers(); + RECENT_ADAPTER.notifyDataSetChanged(); + return RECENT_ADAPTER; + } + + RECENT_ADAPTER = new RecentChannelsAdapter(this); + return RECENT_ADAPTER; + + } + + private void fillAdapter() { + switch (groupBy) { + case MENU_GROUP: + final ArrayList<String> cgs = ChannelClient.getChannelGroups(); + adapter.fill(cgs, ChannelClient.getGroupChannels(), groupBy, + groupByReverse); + if (cgs.size() == 1) {// one group or first no first group + listView.expandGroup(0); + } else if ((cgs.size() > 1 && TextUtils.isEmpty(cgs.get(0)))) { + listView.expandGroup(0); + } + updateWindowTitle(); + break; + + case MENU_SOURCE: + final ArrayList<String> css = ChannelClient.getChannelSources(); + adapter.fill(css, ChannelClient.getSourceChannels(), groupBy, + groupByReverse); + if (css.size() == 1) {// one group or first no first group + listView.expandGroup(0); + } else if ((css.size() > 1 && TextUtils.isEmpty(css.get(0)))) { + listView.expandGroup(0); + } + updateWindowTitle(); + break; + + + case MENU_PROVIDER: + final ArrayList<String> gs = new ArrayList<String>(ChannelClient + .getProviderChannels().keySet()); + adapter.fill(gs, ChannelClient.getProviderChannels(), groupBy, + groupByReverse); + if (gs.size() == 1) { + listView.expandGroup(0); + } + updateWindowTitle(); + break; + case MENU_NAME: + if (ALL_CHANNELS_GROUP.isEmpty()) { + ALL_CHANNELS_GROUP + .add(getString(R.string.groupby_name_all_channels_group)); + } + final HashMap<String, ArrayList<Channel>> channels = new HashMap<String, ArrayList<Channel>>( + 1); + channels.put(getString(R.string.groupby_name_all_channels_group), + ChannelClient.getChannels()); + adapter.fill(ALL_CHANNELS_GROUP, channels, groupBy, groupByReverse); + listView.expandGroup(0); + updateWindowTitle(); + } + adapter.notifyDataSetChanged(); + } + + public boolean onPrepareOptionsMenu(final com.actionbarsherlock.view.Menu menu) { + return super.onPrepareOptionsMenu(menu); + } + + @Override + public final boolean onCreateOptionsMenu( + final com.actionbarsherlock.view.Menu menu) { + super.onCreateOptionsMenu(menu); + + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.channellist, menu); + + return true; + } + + private int getAvailableGroupByEntries() { + return R.array.channels_group_by; + } + + AlertDialog groupByDialog = null; + + @Override + public boolean onOptionsItemSelected( + final com.actionbarsherlock.view.MenuItem item) { + + switch (item.getItemId()) { + case R.id.channels_groupby: + // case MENU_PROVIDER: + // case MENU_NAME: + if (groupByDialog == null) { + groupByDialog = new AlertDialog.Builder(this) + .setTitle(R.string.menu_groupby) + .setIcon(android.R.drawable.ic_menu_sort_alphabetically) + .setSingleChoiceItems(getAvailableGroupByEntries(), + groupBy, new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, + final int which) { + + final boolean reversed = which == groupBy ? true + : false; + groupBy = which; + new VoidAsyncTask() { + + @Override + protected Void doInBackground( + final Void... params) { + + if (reversed) { + if (groupByReverse == true) { + groupByReverse = false; + } else { + groupByReverse = true; + } + Preferences + .set(ChannelListActivity.this, + P.CHANNELS_LAST_ORDER_REVERSE, + groupByReverse); + + } else { + Preferences + .set(ChannelListActivity.this, + P.CHANNELS_LAST_ORDER, + groupBy); + } + return null; + } + }.execute(); + + fillAdapter(); + groupByDialog.dismiss(); + } + }).create(); + } + + groupByDialog.show(); + + return true; + case R.id.channels_recent_channels: + + final String order = Preferences.get(ChannelListActivity.this, + "gui_recent_channels_order", "most"); + + List<RecenteChannel> rcs = null; + + if (order.equals("most")) { + rcs = DBAccess + .get(ChannelListActivity.this) + .getRecentChannelDAO() + .loadByRecentUse( + Preferences.get().getMaxRecentChannels()); + } else if (order.equals("last")) { + rcs = DBAccess + .get(ChannelListActivity.this) + .getRecentChannelDAO() + .loadByLastAccess( + Preferences.get().getMaxRecentChannels()); + } else { + return true; + } + + if (rcs.isEmpty()) { + say(R.string.recent_channels_no_history); + return true; + } + + if (Preferences.get().getMaxRecentChannels() <= 0) { + say(R.string.recent_channels_no_history); + return true; + } + + final ArrayAdapter<Channel> recentAdapter = getRecentAdapter(); + + recentAdapter.clear(); + for (final Channel c : DBAccess.get(ChannelListActivity.this) + .getRecentChannelDAO() + .getRecentChannels(ChannelClient.getIdChannels(), rcs)) { + recentAdapter.add(c); + } + + new AlertDialog.Builder(this) + .setTitle(R.string.recent_channels) + .setAdapter(getRecentAdapter(), + new DialogInterface.OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, + final int which) { + final Channel c = recentAdapter.getItem(which); + startChannelEPG(c); + } + })// + .create().show(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + + @Override + public void onCreateContextMenu(final ContextMenu menu, final View v, + final ContextMenuInfo menuInfo) { + final ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; + final int type = ExpandableListView + .getPackedPositionType(info.packedPosition); + final int group = ExpandableListView + .getPackedPositionGroup(info.packedPosition); + final int child = ExpandableListView + .getPackedPositionChild(info.packedPosition); + // Only create a context menu for child items + if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { + // Array created earlier when we built the expandable list + final Channel item = (Channel) adapter.getChild(group, child); + // if (v.getId() == R.id.channel_list) { + + final MenuInflater inflater = getMenuInflater(); + menu.setHeaderTitle(item.getName()); + inflater.inflate(R.menu.channel_list_item_menu, menu); + + + } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { + /* + * http://projects.vdr-developer.org/issues/722 String grp = + * adapter.getGroup(group); final MenuInflater infl = + * getMenuInflater(); menu.setHeaderTitle(grp); + * infl.inflate(R.menu.channel_list_group_menu, menu); + */ + } + } + + @Override + public boolean onContextItemSelected(final MenuItem item) { + + final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item + .getMenuInfo(); + + // String title = ((TextView) info.targetView).getText().toString(); + + final int type = ExpandableListView + .getPackedPositionType(info.packedPosition); + + Channel channel = null; + if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { + final int groupPos = ExpandableListView + .getPackedPositionGroup(info.packedPosition); + final int childPos = ExpandableListView + .getPackedPositionChild(info.packedPosition); + channel = (Channel) adapter.getChild(groupPos, childPos); + switch (item.getItemId()) { + //case R.id.channel_item_menu_epg: + //startChannelEPG(channel); + //break; + case R.id.channel_item_menu_stream: + // show live stream + Utils.stream(this, channel); + break; + + //case R.id.channel_item_menu_hide: + // TODO http://projects.vdr-developer.org/issues/722 + //break; + //case R.id.channel_item_menu_hide_permanent: + // TODO http://projects.vdr-developer.org/issues/722 + //break; + + case R.id.channel_item_menu_switch: + Utils.switchTo(this, channel); + break; + } + + return true; + } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { + final int groupPos = ExpandableListView + .getPackedPositionGroup(info.packedPosition); + + return true; + } + + return false; + + } + + @Override + public boolean onSearchRequested() { + final InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + inputMgr.toggleSoftInput(0, 0); + return true; + } + + @Override + public boolean onGroupClick(final ExpandableListView arg0, final View arg1, final int arg2, + final long arg3) { + return true; + } + + private void startChannelEPG(final Channel channel) { + new VoidAsyncTask() { + + @Override + protected Void doInBackground(final Void... arg0) { + final int max = Preferences.get().getMaxRecentChannels(); + if (max <= 0) { + return null; + } + + DBAccess.get(ChannelListActivity.this).getRecentChannelDAO() + .hit(channel.getId()); + + return null; + } + }.execute((Void) null); + // for(int i = 0; i < recent) + // find and remember item + // final Channel channel = adapter.getItem(position); + // final VdrManagerApp app = (VdrManagerApp) getApplication(); + // app.setCurrentChannel(channel); + + // show details + final Intent intent = new Intent(); + getApp().setCurrentChannel(channel); + // intent.putExtra(Intents.CURRENT_CHANNEL, channel); + intent.setClass(this, EventEpgListActivity.class); + startActivity(intent); + } + + @Override + public boolean onChildClick(final ExpandableListView parent, final View v, + final int groupPosition, final int childPosition, final long id) { + final Channel channel = (Channel) adapter.getChild(groupPosition, + childPosition); + startChannelEPG(channel); + return false; + } + + @Override + protected void refresh() { + backupViewSelection(); + startChannelQuery(false); + } + + @Override + protected void retry() { + refresh(); + } + + @Override + protected int getMainLayout() { + return R.layout.channel_list; + } + + private String resolveWindowTitle() { + final 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; + + case MENU_SOURCE: { + sb.append(getString(R.string.action_menu_channels)) + .append(" > ") + .append(getString(R.string.groupby_window_title_templte, + getString(R.string.groupby_source))); + break; + } + } + + return sb.toString(); + } + + private void updateWindowTitle() { + setTitle(getString(R.string.channels_window_title_count, + resolveWindowTitle(), adapter.groups.size(), ChannelClient + .getChannels().size())); + } + + @Override + protected synchronized boolean finishedSuccess(final List<Channel> results) { + fillAdapter(); + restoreViewSelection(); + updateWindowTitle(); + return ChannelClient.getChannels().isEmpty() == false; + } + + @Override + protected void cacheHit() { + fillAdapter(); + restoreViewSelection(); + } + + @Override + protected String getWindowTitle() { + return resolveWindowTitle(); + } + + @Override + protected boolean displayingResults() { + return ChannelClient.getChannels().isEmpty() == false; + } + + @Override + protected int getProgressTextId() { + return R.string.progress_channels_loading; + } + + + @Override + protected int getListNavigationIndex() { + return LIST_NAVIGATION_CHANNELS; + } }
\ 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 86df035..0185390 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EpgSearchListActivity.java @@ -37,244 +37,248 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; * @author bju */ public class EpgSearchListActivity extends BaseTimerEditActivity<Epg> implements - OnItemClickListener { - - protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); - - protected List<Epg> getCACHE() { - return CACHE; - } - - private void initSearch(Intent intent) { - if (Intent.ACTION_SEARCH.equals(intent.getAction())) { - String query = intent.getStringExtra(SearchManager.QUERY); - if (TextUtils.isEmpty(query) == false) { - highlight = query.trim(); - SearchRecentSuggestions suggestions = new SearchRecentSuggestions( - this, EPGSearchSuggestionsProvider.AUTHORITY, - EPGSearchSuggestionsProvider.MODE); - suggestions.saveRecentQuery(query, null); - } - } - } - - @Override - protected void onNewIntent(Intent intent) { - initSearch(intent); - startSearch(); - } - - private void startSearch() { - startEpgQuery(); - } - - protected String getViewID(){ - return this.getClass().getSimpleName(); - } - - - @Override - protected void onCreate(final Bundle savedInstanceState) { - Preferences.setLocale(this); - // Preferences.init(this); - - super.onCreate(savedInstanceState); - - sortBy = Preferences.get(this, getViewID() + "_" - + P.EPG_LAST_SORT, MENU_GROUP_DEFAULT); - - - Intent intent = getIntent(); - initSearch(intent); - adapter = new TimeEventAdapter(this); - - // Create adapter for EPG list - adapter.setHideDescription(false); - listView = (ListView) findViewById(R.id.whatson_list); - listView.setAdapter(adapter); - listView.setTextFilterEnabled(true); - registerForContextMenu(listView); - // register EPG item click - listView.setOnItemClickListener(this); - startSearch(); - } - - public void onNothingSelected(final AdapterView<?> arg0) { - // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); - } - - // - - private void startEpgQuery() { - - if (checkInternetConnection() == false) { - return; - } - - EpgSearchParams sp = new EpgSearchParams(); - sp.setTitle(highlight); - setTitle(getWindowTitle()); - EpgClient epgClient = new EpgClient(sp); - // remove old listeners - // epgClient.clearSvdrpListener(); - - // create background task - final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( - epgClient); - - // create progress - addListener(task); - - // start task - task.run(); - } - - protected void sort() { - /* */ - switch (sortBy) { - case MENU_GROUP_DEFAULT: { - //Collections.sort(CACHE, getTimeComparator(false)); - break; - } - case MENU_GROUP_ALPHABET: { - Collections.sort(CACHE, new TitleComparator()); - break; - } - //case MENU_GROUP_CHANNEL: { - //sortItemsByChannel(results); - //} - } - } - - - @Override - protected int getBaseMenu() { - return R.menu.refresh_menu; - } - - @Override - protected synchronized void fillAdapter() { - - adapter.highlight = this.highlight; - - adapter.clear(); - - if(CACHE.isEmpty()){ - return; - } - - Calendar cal = Calendar.getInstance(); - int day = -1; - for (Event e : CACHE) { - cal.setTime(e.getStart()); - int eday = cal.get(Calendar.DAY_OF_YEAR); - if (eday != day) { - day = eday; - adapter.add(new EventListItem(new DateFormatter(cal) - .getDailyHeader())); - } - adapter.add(new EventListItem((Epg) e)); - } - adapter.notifyDataSetChanged(); - } - - - @Override - protected int getAvailableSortByEntries() { - return R.array.epg_sort_by_time_alpha; - } - - - /* - * (non-Javadoc) TODO this method also should be used in startEpgQuery on - * cache hit - * - * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess() - */ - @Override - protected boolean finishedSuccessImpl(List<Epg> results) { - - clearCache(); - for(Epg e : results){ - CACHE.add(e); - } - pushResultCountToTitle(); - fillAdapter(); - listView.setSelectionAfterHeaderView(); - return adapter.getCount() > 0; - } - - protected void prepareDetailsViewData(final EventListItem item) { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - app.setCurrentEvent(item.getEvent()); - app.setCurrentEpgList(CACHE); - } - - @Override - protected int getMainLayout() { - return R.layout.search_epg_list; - } - - @Override - protected void refresh() { - startEpgQuery(); - } - - @Override - protected void retry() { - startEpgQuery(); - } - - public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.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'); - - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.epg_search_menu, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if(item.getItemId() == R.id.epg_search){ - startSearchManager(); - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - protected String getWindowTitle() { - if (TextUtils.isEmpty(highlight)) { - return getString(R.string.epg_by_search); - } - - return getString(R.string.epg_by_search_param, highlight); - } - - //@Override - //public boolean onSearchRequested() { - //startSearchManager(); - //return true; - //} - - @Override - protected int getListNavigationIndex() { - return -1; - } - - @Override - protected boolean hasListNavigation() { - return false; - } - - @Override - protected void timerModified(Timer timer) { - clearCache(); - super.timerModified(timer); - } +OnItemClickListener { + + protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); + + @Override + protected List<Epg> getCACHE() { + return CACHE; + } + + private void initSearch(final Intent intent) { + if (Intent.ACTION_SEARCH.equals(intent.getAction())) { + final String query = intent.getStringExtra(SearchManager.QUERY); + if (TextUtils.isEmpty(query) == false) { + highlight = query.trim(); + final SearchRecentSuggestions suggestions = new SearchRecentSuggestions( + this, EPGSearchSuggestionsProvider.AUTHORITY, + EPGSearchSuggestionsProvider.MODE); + suggestions.saveRecentQuery(query, null); + } + } + } + + @Override + protected void onNewIntent(final Intent intent) { + initSearch(intent); + startSearch(); + } + + private void startSearch() { + startEpgQuery(); + } + + @Override + protected String getViewID(){ + return this.getClass().getSimpleName(); + } + + + @Override + protected void onCreate(final Bundle savedInstanceState) { + Preferences.setLocale(this); + // Preferences.init(this); + + super.onCreate(savedInstanceState); + + sortBy = Preferences.get(this, getViewID() + "_" + + P.EPG_LAST_SORT, MENU_GROUP_DEFAULT); + + + final Intent intent = getIntent(); + initSearch(intent); + adapter = new TimeEventAdapter(this); + + // Create adapter for EPG list + adapter.setHideDescription(false); + listView = (ListView) findViewById(R.id.whatson_list); + listView.setAdapter(adapter); + listView.setTextFilterEnabled(true); + registerForContextMenu(listView); + // register EPG item click + listView.setOnItemClickListener(this); + startSearch(); + } + + public void onNothingSelected(final AdapterView<?> arg0) { + // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); + } + + // + + private void startEpgQuery() { + + if (checkInternetConnection() == false) { + return; + } + + final EpgSearchParams sp = new EpgSearchParams(); + sp.setTitle(highlight); + setTitle(getWindowTitle()); + final EpgClient epgClient = new EpgClient(sp, getCertificateProblemDialog()); + // remove old listeners + // epgClient.clearSvdrpListener(); + + // create background task + final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( + epgClient); + + // create progress + addListener(task); + + // start task + task.run(); + } + + protected void sort() { + /* */ + switch (sortBy) { + case MENU_GROUP_DEFAULT: { + //Collections.sort(CACHE, getTimeComparator(false)); + break; + } + case MENU_GROUP_ALPHABET: { + Collections.sort(CACHE, new TitleComparator()); + break; + } + //case MENU_GROUP_CHANNEL: { + //sortItemsByChannel(results); + //} + } + } + + + @Override + protected int getBaseMenu() { + return R.menu.refresh_menu; + } + + @Override + protected synchronized void fillAdapter() { + + adapter.highlight = this.highlight; + + adapter.clear(); + + if(CACHE.isEmpty()){ + return; + } + + final Calendar cal = Calendar.getInstance(); + int day = -1; + for (final Event e : CACHE) { + cal.setTime(e.getStart()); + final int eday = cal.get(Calendar.DAY_OF_YEAR); + if (eday != day) { + day = eday; + adapter.add(new EventListItem(new DateFormatter(cal) + .getDailyHeader())); + } + adapter.add(new EventListItem(e)); + } + adapter.notifyDataSetChanged(); + } + + + @Override + protected int getAvailableSortByEntries() { + return R.array.epg_sort_by_time_alpha; + } + + + /* + * (non-Javadoc) TODO this method also should be used in startEpgQuery on + * cache hit + * + * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess() + */ + @Override + protected boolean finishedSuccessImpl(final List<Epg> results) { + + clearCache(); + for(final Epg e : results){ + CACHE.add(e); + } + pushResultCountToTitle(); + fillAdapter(); + listView.setSelectionAfterHeaderView(); + return adapter.getCount() > 0; + } + + @Override + protected void prepareDetailsViewData(final EventListItem item) { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + app.setCurrentEvent(item.getEvent()); + app.setCurrentEpgList(CACHE); + } + + @Override + protected int getMainLayout() { + return R.layout.search_epg_list; + } + + @Override + protected void refresh() { + startEpgQuery(); + } + + @Override + protected void retry() { + startEpgQuery(); + } + + @Override + public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.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'); + + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.epg_search_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if(item.getItemId() == R.id.epg_search){ + startSearchManager(); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + protected String getWindowTitle() { + if (TextUtils.isEmpty(highlight)) { + return getString(R.string.epg_by_search); + } + + return getString(R.string.epg_by_search_param, highlight); + } + + //@Override + //public boolean onSearchRequested() { + //startSearchManager(); + //return true; + //} + + @Override + protected int getListNavigationIndex() { + return -1; + } + + @Override + protected boolean hasListNavigation() { + return false; + } + + @Override + protected void timerModified(final Timer timer) { + clearCache(); + super.timerModified(timer); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java index 689fb34..bb0125a 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventEpgListActivity.java @@ -5,10 +5,6 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.WeakHashMap; - -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuItem; import android.content.Intent; import android.os.Bundle; @@ -21,14 +17,17 @@ import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; + +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; + import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.app.VdrManagerApp; -import de.bjusystems.vdrmanager.data.EpgCache; import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.data.Epg; +import de.bjusystems.vdrmanager.data.EpgCache; import de.bjusystems.vdrmanager.data.Event; import de.bjusystems.vdrmanager.data.EventListItem; -import de.bjusystems.vdrmanager.data.Timer; import de.bjusystems.vdrmanager.tasks.ChannelsTask; import de.bjusystems.vdrmanager.utils.date.DateFormatter; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; @@ -43,427 +42,433 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; * @author bju */ public class EventEpgListActivity extends BaseTimerEditActivity<Epg> implements - OnItemClickListener, OnItemSelectedListener { - - private static final String TAG = EventEpgListActivity.class - .getSimpleName(); +OnItemClickListener, OnItemSelectedListener { - // protected static Date nextForceCache = null; + private static final String TAG = EventEpgListActivity.class + .getSimpleName(); - // private static Channel cachedChannel = null; + // protected static Date nextForceCache = null; - Spinner channelSpinner; + // private static Channel cachedChannel = null; - View switcher; + Spinner channelSpinner; - ArrayAdapter<Channel> channelSpinnerAdapter; + View switcher; + + ArrayAdapter<Channel> channelSpinnerAdapter; - // protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); + // protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); - private TextView audio; + private TextView audio; - private View channelInfo; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // - // - // create adapter for channel spinner - channelSpinnerAdapter = new ArrayAdapter<Channel>(this, - android.R.layout.simple_spinner_item); - channelSpinnerAdapter - .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - channelSpinner = (Spinner) findViewById(R.id.epg_list_channel_spinner); - channelSpinner.setAdapter(channelSpinnerAdapter); - - switcher = findViewById(R.id.switch_epg_view); - switcher.setOnClickListener(this); - - // add channel values - // boolean useChannelNumber = Preferences.get().isShowChannelNumbers(); - - // show needed items - - channelInfo = findViewById(R.id.channel_info); - - channelInfo.setOnClickListener(this); - - audio = (TextView) channelInfo.findViewById(R.id.channel_audio); - - adapter = new ChannelEventAdapter(this); - - // if (currentChannel != null) { - - // } - // startChannelEpgQuery(channel); - // findViewById(R.id.timer_item_channel).setVisibility(View.GONE); - // break; - - // Create adapter for EPG list - listView = (ListView) findViewById(R.id.whatson_list); - listView.setAdapter(adapter); - // listView.setFastScrollEnabled(true); - listView.setTextFilterEnabled(true); - registerForContextMenu(listView); - - // register EPG item click - listView.setOnItemClickListener(this); - - if (checkInternetConnection() == false) { - return; - } - - startQuery(); - - } - - @Override - protected int getAvailableSortByEntries() { - return R.array.epg_sort_by_time_alpha; - } - - protected String getViewID() { - return EventEpgListActivity.class.getSimpleName(); - } - - private void startQuery() { - new ChannelsTask(this, new ChannelClient()) { - public void finished(SvdrpEvent event) { - if (event == SvdrpEvent.CACHE_HIT - || event == SvdrpEvent.FINISHED_SUCCESS) { - ArrayList<Channel> channels = ChannelClient.getChannels(); - currentChannel = getApp().getCurrentChannel(); - boolean found = false; - int count = 0; - for (final Channel c : channels) { - channelSpinnerAdapter.add(c); - if (currentChannel != null && !found) { - if (currentChannel.equals(c)) { - found = true; - } else { - count++; - } - } - } - channelSpinner.setSelection(count); - channelSpinner - .setOnItemSelectedListener(EventEpgListActivity.this); - } else { - noConnection(event); - } - } - }.start(); - - } - - void sort() { - if (sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) { - Collections.sort(getCache(), new TitleComparator()); - } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) { - Collections.sort(getCache(), new TimeComparator(false)); - } - } - - @Override - protected void onPause() { - super.onPause(); - } - - @Override - protected void onResume() { - super.onResume(); - } - - public void onItemSelected(final AdapterView<?> parent, final View view, - final int position, final long id) { - // get spinner value - final Channel channel = (Channel) channelSpinner.getSelectedItem(); - currentChannel = channel; - setCurrent(channel); - // setAsCurrent(channel); - // update search - if (channel.getAudio().isEmpty() == false) { - audio.setText(Utils.formatAudio(this, channel.getAudio())); - } else { - audio.setText(""); - } - - startEpgQuery(false); - } - - public void onNothingSelected(final AdapterView<?> arg0) { - // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); - } - - public void clearCache() { - getCache().clear(); - EpgCache.CACHE.remove(currentChannel.getId()); - EpgCache.NEXT_REFRESH.remove(currentChannel.getId()); - } - - private boolean useCache() { - - if (currentChannel == null) { - return false; - } - - ArrayList<Epg> cachedChannel = EpgCache.CACHE.get(currentChannel.getId()); - - if (cachedChannel == null) { - return false; - } - - Date nextForceCache = EpgCache.NEXT_REFRESH.get(currentChannel.getId()); - - if (nextForceCache == null) { - return false; - } - Date now = new Date(); - if (nextForceCache.before(now)) { - return false; - } - return true; - } - - @Override - public void onClick(View view) { - - if (view == switcher) { - final Intent intent = new Intent(); - intent.setClass(this, TimeEpgListActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - | Intent.FLAG_ACTIVITY_SINGLE_TOP); - startActivity(intent); - } else if (view == channelInfo) { - Utils.stream(this, currentChannel); - } else { - super.onClick(view); - } - } - - private void startEpgQuery(final boolean force) { - if (useCache() && !force) { - fillAdapter(); - return; - } - - if (checkInternetConnection() == false) { - return; - } - - // clearCache(); - - EpgClient epgClient = new EpgClient(currentChannel); - - // remove old listeners - // epgClient.clearSvdrpListener(); - - // create background task - final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( - epgClient); - - // create progress - - addListener(task); - - // start task - task.run(); - } - - private static final ArrayList<Epg> EMPTY = new ArrayList<Epg>(0); - - private ArrayList<Epg> getCache() { - ArrayList<Epg> arrayList = EpgCache.CACHE.get(currentChannel.getId()); - if (arrayList == null) { - return EMPTY; - } - return arrayList; - } - - @Override - protected void fillAdapter() { - - adapter.clear(); - - ArrayList<Epg> cache = getCache(); - - if (cache.isEmpty()) { - return; - } - - sort(); - - Calendar cal = Calendar.getInstance(); - int day = -1; - for (Event e : cache) { - cal.setTime(e.getStart()); - int eday = cal.get(Calendar.DAY_OF_YEAR); - if (eday != day) { - day = eday; - adapter.add(new EventListItem(new DateFormatter(cal) - .getDailyHeader())); - } - adapter.add(new EventListItem((Epg) e)); - } - - adapter.notifyDataSetChanged(); - - } - - /* - * (non-Javadoc) TODO this method also should be used in startEpgQuery on - * cache hit - * - * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess() - */ - @Override - protected boolean finishedSuccessImpl(List<Epg> results) { - // adapter.clear(); - // CACHE.clear(); - - clearCache(); - - if (results.isEmpty()) { - return false; - } - - Date now = new Date(); - - EpgCache.NEXT_REFRESH.put(currentChannel.getId(), FUTURE); - - Date nextForceCache = FUTURE; - - // Calendar cal = Calendar.getInstance(); - // int day = -1; - // sortItemsByTime(results); - ArrayList<Epg> cache = new ArrayList<Epg>(); - for (Epg e : results) { - cache.add(e); - // cal.setTime(e.getStart()); - // int eday = cal.get(Calendar.DAY_OF_YEAR); - // if (eday != day) { - // day = eday; - // adapter.add(new EventListItem(new DateFormatter(cal) - // .getDailyHeader())); - // } - // adapter.add(new EventListItem((Epg) e)); - if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { - nextForceCache = e.getStop(); - } - } - - EpgCache.NEXT_REFRESH.put(currentChannel.getId(), nextForceCache); - EpgCache.CACHE.put(currentChannel.getId(), cache); - - fillAdapter(); - listView.setSelectionAfterHeaderView(); - return results.isEmpty() == false; - - // /////////////// - - // // get spinner value - // final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner - // .getSelectedItem(); - // nextForceCache = FUTURE; - // cachedTime = selection.getValue(); - // Date now = new Date(); - // - // //adapter.add(new EventListItem(new DateFormatter(results.get(0) - // // .getStart()).getDailyHeader())); - // - // for (Event e : results) { - // CACHE.add(e); - // if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { - // nextForceCache = e.getStop(); - // } - // } - // - - } - - protected void prepareDetailsViewData(final EventListItem item) { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - app.setCurrentEvent(item.getEvent()); - app.setCurrentEpgList(getCache()); - } - - @Override - protected int getMainLayout() { - return R.layout.event_epg_list; - } - - @Override - protected void refresh() { - startEpgQuery(true); - } - - @Override - protected void retry() { - refresh(); - } - - @Override - protected String getWindowTitle() { - return getString(R.string.epg_by_channel); - } - - private void nextEvent() { - int pos = channelSpinner.getSelectedItemPosition(); - if (pos + 1 >= channelSpinnerAdapter.getCount()) { - Toast.makeText(this, R.string.navigae_at_the_end, - Toast.LENGTH_SHORT).show(); - return; - } - channelSpinner.setSelection(pos + 1, true); - } - - private void prevEvent() { - int pos = channelSpinner.getSelectedItemPosition(); - if (pos <= 0) { - say(R.string.navigae_at_the_start); - return; - } - channelSpinner.setSelection(pos - 1, true); - } - - @Override - public void onSwipe(int direction) { - switch (direction) { - case SimpleGestureFilter.SWIPE_RIGHT: - prevEvent(); - break; - case SimpleGestureFilter.SWIPE_LEFT: - nextEvent(); - break; - } - } - - @Override - protected int getListNavigationIndex() { - return LIST_NAVIGATION_EPG_BY_CHANNEL; - } - - @Override - protected List<Epg> getCACHE() { - return getCache(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.epg_event_list_menu, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.epg_list_stream) { - Utils.stream(this, currentChannel); - return true; - } - return super.onOptionsItemSelected(item); - } + private View channelInfo; + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // + // + // create adapter for channel spinner + channelSpinnerAdapter = new ArrayAdapter<Channel>(this, + android.R.layout.simple_spinner_item); + channelSpinnerAdapter + .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + channelSpinner = (Spinner) findViewById(R.id.epg_list_channel_spinner); + channelSpinner.setAdapter(channelSpinnerAdapter); + + switcher = findViewById(R.id.switch_epg_view); + switcher.setOnClickListener(this); + + // add channel values + // boolean useChannelNumber = Preferences.get().isShowChannelNumbers(); + + // show needed items + + channelInfo = findViewById(R.id.channel_info); + + channelInfo.setOnClickListener(this); + + audio = (TextView) channelInfo.findViewById(R.id.channel_audio); + + adapter = new ChannelEventAdapter(this); + + // if (currentChannel != null) { + + // } + // startChannelEpgQuery(channel); + // findViewById(R.id.timer_item_channel).setVisibility(View.GONE); + // break; + + // Create adapter for EPG list + listView = (ListView) findViewById(R.id.whatson_list); + listView.setAdapter(adapter); + // listView.setFastScrollEnabled(true); + listView.setTextFilterEnabled(true); + registerForContextMenu(listView); + + // register EPG item click + listView.setOnItemClickListener(this); + + if (checkInternetConnection() == false) { + return; + } + + startQuery(); + + } + + @Override + protected int getAvailableSortByEntries() { + return R.array.epg_sort_by_time_alpha; + } + + @Override + protected String getViewID() { + return EventEpgListActivity.class.getSimpleName(); + } + + private void startQuery() { + new ChannelsTask(this, new ChannelClient(getCertificateProblemDialog())) { + @Override + public void finished(final SvdrpEvent event) { + if (event == SvdrpEvent.CACHE_HIT + || event == SvdrpEvent.FINISHED_SUCCESS) { + final ArrayList<Channel> channels = ChannelClient.getChannels(); + currentChannel = getApp().getCurrentChannel(); + boolean found = false; + int count = 0; + for (final Channel c : channels) { + channelSpinnerAdapter.add(c); + if (currentChannel != null && !found) { + if (currentChannel.equals(c)) { + found = true; + } else { + count++; + } + } + } + channelSpinner.setSelection(count); + channelSpinner + .setOnItemSelectedListener(EventEpgListActivity.this); + } else { + noConnection(event); + } + } + }.start(); + + } + + void sort() { + if (sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) { + Collections.sort(getCache(), new TitleComparator()); + } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) { + Collections.sort(getCache(), new TimeComparator(false)); + } + } + + @Override + protected void onPause() { + super.onPause(); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + public void onItemSelected(final AdapterView<?> parent, final View view, + final int position, final long id) { + // get spinner value + final Channel channel = (Channel) channelSpinner.getSelectedItem(); + currentChannel = channel; + setCurrent(channel); + // setAsCurrent(channel); + // update search + if (channel.getAudio().isEmpty() == false) { + audio.setText(Utils.formatAudio(this, channel.getAudio())); + } else { + audio.setText(""); + } + + startEpgQuery(false); + } + + @Override + public void onNothingSelected(final AdapterView<?> arg0) { + // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); + } + + @Override + public void clearCache() { + getCache().clear(); + EpgCache.CACHE.remove(currentChannel.getId()); + EpgCache.NEXT_REFRESH.remove(currentChannel.getId()); + } + + private boolean useCache() { + + if (currentChannel == null) { + return false; + } + + final ArrayList<Epg> cachedChannel = EpgCache.CACHE.get(currentChannel.getId()); + + if (cachedChannel == null) { + return false; + } + + final Date nextForceCache = EpgCache.NEXT_REFRESH.get(currentChannel.getId()); + + if (nextForceCache == null) { + return false; + } + final Date now = new Date(); + if (nextForceCache.before(now)) { + return false; + } + return true; + } + + @Override + public void onClick(final View view) { + + if (view == switcher) { + final Intent intent = new Intent(); + intent.setClass(this, TimeEpgListActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT + | Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(intent); + } else if (view == channelInfo) { + Utils.stream(this, currentChannel); + } else { + super.onClick(view); + } + } + + private void startEpgQuery(final boolean force) { + if (useCache() && !force) { + fillAdapter(); + return; + } + + if (checkInternetConnection() == false) { + return; + } + + // clearCache(); + + final EpgClient epgClient = new EpgClient(currentChannel, getCertificateProblemDialog()); + + // remove old listeners + // epgClient.clearSvdrpListener(); + + // create background task + final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( + epgClient); + + // create progress + + addListener(task); + + // start task + task.run(); + } + + private static final ArrayList<Epg> EMPTY = new ArrayList<Epg>(0); + + private ArrayList<Epg> getCache() { + final ArrayList<Epg> arrayList = EpgCache.CACHE.get(currentChannel.getId()); + if (arrayList == null) { + return EMPTY; + } + return arrayList; + } + + @Override + protected void fillAdapter() { + + adapter.clear(); + + final ArrayList<Epg> cache = getCache(); + + if (cache.isEmpty()) { + return; + } + + sort(); + + final Calendar cal = Calendar.getInstance(); + int day = -1; + for (final Event e : cache) { + cal.setTime(e.getStart()); + final int eday = cal.get(Calendar.DAY_OF_YEAR); + if (eday != day) { + day = eday; + adapter.add(new EventListItem(new DateFormatter(cal) + .getDailyHeader())); + } + adapter.add(new EventListItem(e)); + } + + adapter.notifyDataSetChanged(); + + } + + /* + * (non-Javadoc) TODO this method also should be used in startEpgQuery on + * cache hit + * + * @see de.bjusystems.vdrmanager.gui.BaseEpgListActivity#finishedSuccess() + */ + @Override + protected boolean finishedSuccessImpl(final List<Epg> results) { + // adapter.clear(); + // CACHE.clear(); + + clearCache(); + + if (results.isEmpty()) { + return false; + } + + final Date now = new Date(); + + EpgCache.NEXT_REFRESH.put(currentChannel.getId(), FUTURE); + + Date nextForceCache = FUTURE; + + // Calendar cal = Calendar.getInstance(); + // int day = -1; + // sortItemsByTime(results); + final ArrayList<Epg> cache = new ArrayList<Epg>(); + for (final Epg e : results) { + cache.add(e); + // cal.setTime(e.getStart()); + // int eday = cal.get(Calendar.DAY_OF_YEAR); + // if (eday != day) { + // day = eday; + // adapter.add(new EventListItem(new DateFormatter(cal) + // .getDailyHeader())); + // } + // adapter.add(new EventListItem((Epg) e)); + if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { + nextForceCache = e.getStop(); + } + } + + EpgCache.NEXT_REFRESH.put(currentChannel.getId(), nextForceCache); + EpgCache.CACHE.put(currentChannel.getId(), cache); + + fillAdapter(); + listView.setSelectionAfterHeaderView(); + return results.isEmpty() == false; + + // /////////////// + + // // get spinner value + // final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner + // .getSelectedItem(); + // nextForceCache = FUTURE; + // cachedTime = selection.getValue(); + // Date now = new Date(); + // + // //adapter.add(new EventListItem(new DateFormatter(results.get(0) + // // .getStart()).getDailyHeader())); + // + // for (Event e : results) { + // CACHE.add(e); + // if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { + // nextForceCache = e.getStop(); + // } + // } + // + + } + + @Override + protected void prepareDetailsViewData(final EventListItem item) { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + app.setCurrentEvent(item.getEvent()); + app.setCurrentEpgList(getCache()); + } + + @Override + protected int getMainLayout() { + return R.layout.event_epg_list; + } + + @Override + protected void refresh() { + startEpgQuery(true); + } + + @Override + protected void retry() { + refresh(); + } + + @Override + protected String getWindowTitle() { + return getString(R.string.epg_by_channel); + } + + private void nextEvent() { + final int pos = channelSpinner.getSelectedItemPosition(); + if (pos + 1 >= channelSpinnerAdapter.getCount()) { + Toast.makeText(this, R.string.navigae_at_the_end, + Toast.LENGTH_SHORT).show(); + return; + } + channelSpinner.setSelection(pos + 1, true); + } + + private void prevEvent() { + final int pos = channelSpinner.getSelectedItemPosition(); + if (pos <= 0) { + say(R.string.navigae_at_the_start); + return; + } + channelSpinner.setSelection(pos - 1, true); + } + + @Override + public void onSwipe(final int direction) { + switch (direction) { + case SimpleGestureFilter.SWIPE_RIGHT: + prevEvent(); + break; + case SimpleGestureFilter.SWIPE_LEFT: + nextEvent(); + break; + } + } + + @Override + protected int getListNavigationIndex() { + return LIST_NAVIGATION_EPG_BY_CHANNEL; + } + + @Override + protected List<Epg> getCACHE() { + return getCache(); + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + super.onCreateOptionsMenu(menu); + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.epg_event_list_menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + if (item.getItemId() == R.id.epg_list_stream) { + Utils.stream(this, currentChannel); + return true; + } + return super.onOptionsItemSelected(item); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ICSBaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ICSBaseActivity.java index ce44ef0..b34219f 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ICSBaseActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ICSBaseActivity.java @@ -2,17 +2,21 @@ package de.bjusystems.vdrmanager.gui; import com.actionbarsherlock.app.SherlockActivity; -public abstract class ICSBaseActivity extends SherlockActivity{ +public abstract class ICSBaseActivity extends SherlockActivity { - public void initActionBar() { -// int api = Build.VERSION.SDK_INT; - // if (api < 14) { - // return; - //} - com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar(); - if(actionBar == null){ - return; - } - actionBar.setHomeButtonEnabled(true); - } + public void initActionBar() { + // int api = Build.VERSION.SDK_INT; + // if (api < 14) { + // return; + //} + final com.actionbarsherlock.app.ActionBar actionBar = getSupportActionBar(); + if(actionBar == null){ + return; + } + actionBar.setHomeButtonEnabled(true); + } + + protected CertificateProblemDialog getCertificateProblemDialog() { + return new CertificateProblemDialog(this); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java index 27ec91b..d369ca5 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/RecordingListActivity.java @@ -33,288 +33,292 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; * @author bju */ public class RecordingListActivity extends BaseEventListActivity<Recording> - implements OnItemLongClickListener { - - //RecordingClient recordingClient; - - //public static final int MENU_GROUP_CHANNEL = 2; - - public static final int ASC = 0; - - public static final int DESC = 1; - - protected static ArrayList<Recording> CACHE = new ArrayList<Recording>(); - - - private int ASC_DESC = ASC; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // create an adapter - adapter = new RecordingAdapter(this); - - // attach adapter to ListView - listView = (ListView) findViewById(R.id.recording_list); - listView.setAdapter(adapter); - - // set click listener - listView.setOnItemLongClickListener(this); - // register EPG item click - listView.setOnItemClickListener(this); - // context menu wanted - registerForContextMenu(listView); - listView.setFastScrollEnabled(true); - listView.setTextFilterEnabled(true); - // start query - startRecordingQuery(); - } - - protected int getAvailableSortByEntries() { - return R.array.recordings_group_by; - }; - - // AlertDialog groupByDialog = null; - - // @Override - // public boolean onOptionsItemSelected( - // final com.actionbarsherlock.view.MenuItem item) { - // - // switch (item.getItemId()) { - // case R.id.menu_groupby: - // // case MENU_PROVIDER: - // // case MENU_NAME: - // if (groupByDialog == null) { - // groupByDialog = new AlertDialog.Builder(this) - // .setTitle(R.string.menu_groupby) - // .setIcon(android.R.drawable.ic_menu_sort_alphabetically) - // .setSingleChoiceItems(getAvailableGroupByEntries(), - // groupBy, new DialogInterface.OnClickListener() { - // public void onClick(DialogInterface dialog, - // int which) { - // if (groupBy == which) { - // ASC_DESC = ASC_DESC == ASC ? DESC - // : ASC; - // } else { - // groupBy = which; - // ASC_DESC = ASC; - // } - // // fillAdapter(); - // groupByDialog.dismiss(); - // say("Comming soon..."); - // } - // }).create(); - // } - // - // groupByDialog.show(); - // - // return true; - // default: - // return super.onOptionsItemSelected(item); - // } - // } - - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseActivity#onCreateOptionsMenu(android - * .view.Menu) - */ - @Override - public boolean onCreateOptionsMenu( - final com.actionbarsherlock.view.Menu menu) { - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.recording_list_menu, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - protected void onPause() { - super.onPause(); - } - - @Override - protected void prepareDetailsViewData(EventListItem event) { - getApp().setCurrentEvent(event.getEvent()); - getApp().setCurrentEpgList(CACHE); - } - - @Override - public void onCreateContextMenu(final ContextMenu menu, final View v, - final ContextMenuInfo menuInfo) { - - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - final EventListItem item = adapter.getItem(info.position); - if (item.isHeader()) { - return; - } - - if (v.getId() == R.id.recording_list) { - final MenuInflater inflater = getMenuInflater(); - // set menu title - final EventFormatter formatter = new EventFormatter(item); - menu.setHeaderTitle(formatter.getTitle()); - - inflater.inflate(R.menu.recording_list_item_menu, menu); - if (Preferences.get().isEnableRecStream() == false) { - menu.removeItem(R.id.recording_item_menu_stream); - } - - } - - super.onCreateContextMenu(menu, v, menuInfo); - // - // http://projects.vdr-developer.org/issues/863 - //if (Utils.isLive(item)) { - menu.removeItem(R.id.epg_item_menu_live_tv); - //} - } - - @Override - public boolean onContextItemSelected(final MenuItem item) { - - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item - .getMenuInfo(); - final EventListItem event = adapter.getItem(info.position); - Recording rec = (Recording) event.getEvent(); - switch (item.getItemId()) { - case R.id.recording_item_menu_delete: { - DeleteRecordingTask drt = new DeleteRecordingTask(this, rec) { - @Override - public void finished(SvdrpEvent event) { - if (event == SvdrpEvent.FINISHED_SUCCESS) { - backupViewSelection(); - refresh(); - } - } - }; - drt.start(); - break; - } - case R.id.recording_item_menu_stream: { - Utils.streamRecording(this, rec); - // say("Sorry, not yet. It would be. File -> " + rec.getFileName()); - break; - } - - default: - return super.onContextItemSelected(item); - } - return true; - } - - private void startRecordingQuery() { - - if (checkInternetConnection() == false) { - return; - } - - // get timer client - RecordingClient recordingClient = new RecordingClient(); - - // create backgound task - final SvdrpAsyncTask<Recording, SvdrpClient<Recording>> task = new SvdrpAsyncTask<Recording, SvdrpClient<Recording>>( - recordingClient); - - // create progress dialog - - addListener(task); - - // start task - task.run(); - } - - protected void retry() { - startRecordingQuery(); - } - - protected void refresh() { - startRecordingQuery(); - } - - @Override - protected int getMainLayout() { - return R.layout.recording_list; - } - - @Override - protected String getWindowTitle() { - return getString(R.string.action_menu_recordings); - } - - protected void sort() { - /* */ - switch (sortBy) { - case MENU_GROUP_DEFAULT: { - sortItemsByTime(CACHE, true); - break; - } - case MENU_GROUP_ALPHABET: { - Collections.sort(CACHE, new TitleComparator()); - break; - } - //case MENU_GROUP_CHANNEL: { - //sortItemsByChannel(results); - //} - } - } - - @Override - protected void fillAdapter() { - - adapter.clear(); - - if (CACHE.isEmpty()) { - return; - } - - sort(); - - Calendar cal = Calendar.getInstance(); - int day = -1; - - for (final Event rec : CACHE) { - cal.setTime(rec.getStart()); - int eday = cal.get(Calendar.DAY_OF_YEAR); - if (eday != day) { - day = eday; - adapter.add(new EventListItem(new DateFormatter(cal) - .getDailyHeader())); - } - adapter.add(new EventListItem((Recording) rec)); - adapter.notifyDataSetChanged(); - } - - } - - @Override - protected boolean finishedSuccessImpl(List<Recording> results) { - clearCache(); - for(Recording r :results){ - CACHE.add(r); - } - pushResultCountToTitle(); - fillAdapter(); - return adapter.isEmpty() == false; - - } - - public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, - long arg3) { - - return false; - } - - @Override - protected int getListNavigationIndex() { - return LIST_NAVIGATION_RECORDINGS; - } - - @Override - protected List<Recording> getCACHE() { - return CACHE; - } +implements OnItemLongClickListener { + + //RecordingClient recordingClient; + + //public static final int MENU_GROUP_CHANNEL = 2; + + public static final int ASC = 0; + + public static final int DESC = 1; + + protected static ArrayList<Recording> CACHE = new ArrayList<Recording>(); + + + private final int ASC_DESC = ASC; + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // create an adapter + adapter = new RecordingAdapter(this); + + // attach adapter to ListView + listView = (ListView) findViewById(R.id.recording_list); + listView.setAdapter(adapter); + + // set click listener + listView.setOnItemLongClickListener(this); + // register EPG item click + listView.setOnItemClickListener(this); + // context menu wanted + registerForContextMenu(listView); + listView.setFastScrollEnabled(true); + listView.setTextFilterEnabled(true); + // start query + startRecordingQuery(); + } + + @Override + protected int getAvailableSortByEntries() { + return R.array.recordings_group_by; + }; + + // AlertDialog groupByDialog = null; + + // @Override + // public boolean onOptionsItemSelected( + // final com.actionbarsherlock.view.MenuItem item) { + // + // switch (item.getItemId()) { + // case R.id.menu_groupby: + // // case MENU_PROVIDER: + // // case MENU_NAME: + // if (groupByDialog == null) { + // groupByDialog = new AlertDialog.Builder(this) + // .setTitle(R.string.menu_groupby) + // .setIcon(android.R.drawable.ic_menu_sort_alphabetically) + // .setSingleChoiceItems(getAvailableGroupByEntries(), + // groupBy, new DialogInterface.OnClickListener() { + // public void onClick(DialogInterface dialog, + // int which) { + // if (groupBy == which) { + // ASC_DESC = ASC_DESC == ASC ? DESC + // : ASC; + // } else { + // groupBy = which; + // ASC_DESC = ASC; + // } + // // fillAdapter(); + // groupByDialog.dismiss(); + // say("Comming soon..."); + // } + // }).create(); + // } + // + // groupByDialog.show(); + // + // return true; + // default: + // return super.onOptionsItemSelected(item); + // } + // } + + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseActivity#onCreateOptionsMenu(android + * .view.Menu) + */ + @Override + public boolean onCreateOptionsMenu( + final com.actionbarsherlock.view.Menu menu) { + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.recording_list_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + protected void onPause() { + super.onPause(); + } + + @Override + protected void prepareDetailsViewData(final EventListItem event) { + getApp().setCurrentEvent(event.getEvent()); + getApp().setCurrentEpgList(CACHE); + } + + @Override + public void onCreateContextMenu(final ContextMenu menu, final View v, + final ContextMenuInfo menuInfo) { + + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + final EventListItem item = adapter.getItem(info.position); + if (item.isHeader()) { + return; + } + + if (v.getId() == R.id.recording_list) { + final MenuInflater inflater = getMenuInflater(); + // set menu title + final EventFormatter formatter = new EventFormatter(item); + menu.setHeaderTitle(formatter.getTitle()); + + inflater.inflate(R.menu.recording_list_item_menu, menu); + if (Preferences.get().isEnableRecStream() == false) { + menu.removeItem(R.id.recording_item_menu_stream); + } + + } + + super.onCreateContextMenu(menu, v, menuInfo); + // + // http://projects.vdr-developer.org/issues/863 + //if (Utils.isLive(item)) { + menu.removeItem(R.id.epg_item_menu_live_tv); + //} + } + + @Override + public boolean onContextItemSelected(final MenuItem item) { + + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item + .getMenuInfo(); + final EventListItem event = adapter.getItem(info.position); + final Recording rec = (Recording) event.getEvent(); + switch (item.getItemId()) { + case R.id.recording_item_menu_delete: { + final DeleteRecordingTask drt = new DeleteRecordingTask(this, rec) { + @Override + public void finished(final SvdrpEvent event) { + if (event == SvdrpEvent.FINISHED_SUCCESS) { + backupViewSelection(); + refresh(); + } + } + }; + drt.start(); + break; + } + case R.id.recording_item_menu_stream: { + Utils.streamRecording(this, rec); + // say("Sorry, not yet. It would be. File -> " + rec.getFileName()); + break; + } + + default: + return super.onContextItemSelected(item); + } + return true; + } + + private void startRecordingQuery() { + + if (checkInternetConnection() == false) { + return; + } + + // get timer client + final RecordingClient recordingClient = new RecordingClient(getCertificateProblemDialog()); + + // create backgound task + final SvdrpAsyncTask<Recording, SvdrpClient<Recording>> task = new SvdrpAsyncTask<Recording, SvdrpClient<Recording>>( + recordingClient); + + // create progress dialog + + addListener(task); + + // start task + task.run(); + } + + @Override + protected void retry() { + startRecordingQuery(); + } + + @Override + protected void refresh() { + startRecordingQuery(); + } + + @Override + protected int getMainLayout() { + return R.layout.recording_list; + } + + @Override + protected String getWindowTitle() { + return getString(R.string.action_menu_recordings); + } + + protected void sort() { + /* */ + switch (sortBy) { + case MENU_GROUP_DEFAULT: { + sortItemsByTime(CACHE, true); + break; + } + case MENU_GROUP_ALPHABET: { + Collections.sort(CACHE, new TitleComparator()); + break; + } + //case MENU_GROUP_CHANNEL: { + //sortItemsByChannel(results); + //} + } + } + + @Override + protected void fillAdapter() { + + adapter.clear(); + + if (CACHE.isEmpty()) { + return; + } + + sort(); + + final Calendar cal = Calendar.getInstance(); + int day = -1; + + for (final Event rec : CACHE) { + cal.setTime(rec.getStart()); + final int eday = cal.get(Calendar.DAY_OF_YEAR); + if (eday != day) { + day = eday; + adapter.add(new EventListItem(new DateFormatter(cal) + .getDailyHeader())); + } + adapter.add(new EventListItem(rec)); + adapter.notifyDataSetChanged(); + } + + } + + @Override + protected boolean finishedSuccessImpl(final List<Recording> results) { + clearCache(); + for(final Recording r :results){ + CACHE.add(r); + } + pushResultCountToTitle(); + fillAdapter(); + return adapter.isEmpty() == false; + + } + + @Override + public boolean onItemLongClick(final AdapterView<?> arg0, final View arg1, final int arg2, + final long arg3) { + + return false; + } + + @Override + protected int getListNavigationIndex() { + return LIST_NAVIGATION_RECORDINGS; + } + + @Override + protected List<Recording> getCACHE() { + return CACHE; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java index caa97f0..ed323d0 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimeEpgListActivity.java @@ -9,7 +9,6 @@ import java.util.TimeZone; import android.app.TimePickerDialog; import android.app.TimePickerDialog.OnTimeSetListener; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -40,374 +39,380 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; * @author bju */ public class TimeEpgListActivity extends BaseTimerEditActivity<Epg> implements - OnItemClickListener, OnItemSelectedListener, OnTimeSetListener { +OnItemClickListener, OnItemSelectedListener, OnTimeSetListener { - protected Spinner timeSpinner; + protected Spinner timeSpinner; + + protected View switcher; - protected View switcher; - - protected View clock; - - ArrayAdapter<EpgSearchTimeValue> timeSpinnerAdapter; - - protected static Date nextForceCache = null; - - private static String cachedTime = null; - - int selectedIndex = 0; - - protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); - - @Override - public int getProgressTextId() { - return R.string.progress_whatson_loading; - } - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // create adapter for time spinner - timeSpinnerAdapter = new ArrayAdapter<EpgSearchTimeValue>(this, - android.R.layout.simple_spinner_item); - timeSpinnerAdapter - .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - timeSpinner = (Spinner) findViewById(R.id.epg_list_time_spinner); - timeSpinner.setAdapter(timeSpinnerAdapter); - - switcher = findViewById(R.id.switch_epg_view); - switcher.setOnClickListener(this); - - clock = findViewById(R.id.epg_list_times); - clock.setOnClickListener(this); - - // update gui - adapter = new TimeEventAdapter(this); - // searchLabel.setVisibility(View.GONE); - timeSpinner.setOnItemSelectedListener(this); - - fillTimeSpinnerValues(); - - // Create adapter for EPG list - listView = (ListView) findViewById(R.id.whatson_list); - listView.setFastScrollEnabled(true); - listView.setTextFilterEnabled(true); - - listView.setAdapter(adapter); - registerForContextMenu(listView); - - // register EPG item click - listView.setOnItemClickListener(this); - - } - - private void fillTimeSpinnerValues() { - final EpgSearchTimeValues values = new EpgSearchTimeValues(this); - timeSpinnerAdapter.clear(); - for (final EpgSearchTimeValue value : values.getValues()) { - timeSpinnerAdapter.add(value); - } - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - - } - - @Override - public void onClick(View view) { - if (view == switcher) { - final Intent intent = new Intent(); - intent.setClass(this, EventEpgListActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - | Intent.FLAG_ACTIVITY_SINGLE_TOP); - startActivity(intent); - finish(); - } else if (view == clock) { - Intent intent = new Intent(); - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT - | Intent.FLAG_ACTIVITY_SINGLE_TOP); - intent.setClass(this, EpgSearchTimesListActivity.class); - startActivity(intent); - } else { - super.onClick(view); - } - } - - public void onTimeSet(final TimePicker view, final int hourOfDay, - final int minute) { - String tm = String.format("%02d:%02d", hourOfDay, minute); - - // timeSpinnerAdapter.add(time); - final EpgSearchTimeValues values = new EpgSearchTimeValues(this); - List<EpgSearchTimeValue> vs = values.getValues(); - final EpgSearchTimeValue time = new EpgSearchTimeValue(3, tm); - vs.add(vs.size() - 1, time); - timeSpinnerAdapter.clear(); - int select = -1; - int counter = 0; - for (final EpgSearchTimeValue value : vs) { - timeSpinnerAdapter.add(value); - if (select == -1 && value.getText().equals(tm)) { - select = counter; - } - counter++; - } - timeSpinner.setSelection(select); - 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) { - - // get spinner value - final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner - .getSelectedItem(); - - if (selection.getValue().equals("adhoc")) { - final Calendar cal = Calendar.getInstance(TimeZone.getDefault()); - // show time selection - final TimePickerDialog dialog = new TimePickerDialog(this, this, - cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), - Preferences.get().isUse24hFormat()); -// dialog.setOnDismissListener(new OnDismissListener() { - - // @Override - // public void onDismiss(DialogInterface dialog) { - - - // } - //}); - - dialog.show(); - } else { - // update search - setTitle(getString(R.string.epg_by_time_args, selection.getText())); - startEpgQuery(selection.getValue(), false); - } - } - - public void onNothingSelected(final AdapterView<?> arg0) { - // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); - } - - public void clearCache() { - super.clearCache(); - cachedTime = null; - } - - private boolean useCache(String time) { - - if (cachedTime == null) { - return false; - } - - if (cachedTime.equals(time) == false) { - return false; - } - - if (nextForceCache == null) { - return false; - } - Date now = new Date(); - if (nextForceCache.before(now)) { - return false; - } - return true; - } - - private void startEpgQuery(String time, boolean force) { - - if (useCache(time) && !force) { - fillAdapter(); - return; - } - - if (checkInternetConnection() == false) { - return; - } - - EpgClient epgClient = new EpgClient(time); - - // remove old listeners - // epgClient.clearSvdrpListener(); - - // create background task - final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( - epgClient); - - // create progress - addListener(task); - - // start task - task.run(); - } - - @Override - protected synchronized void fillAdapter() { - - adapter.clear(); - - if (CACHE.isEmpty()) { - return; - } - - sort(); - listView.setFastScrollEnabled(false); - adapter.add(new EventListItem( - new DateFormatter(CACHE.get(0).getStart()).getDailyHeader())); - - for (Event e : CACHE) { - adapter.add(new EventListItem((Epg) e)); - } - adapter.notifyDataSetChanged(); - listView.setFastScrollEnabled(true); - } - - void sort() { - if (sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) { - Collections.sort(CACHE, new TitleComparator()); - } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) { - Collections.sort(CACHE, new ChannelComparator()); - } - } - - @Override - protected int getAvailableSortByEntries() { - return R.array.epg_sort_by_channels_alpha; - } - - protected String getViewID() { - return TimeEpgListActivity.class.getSimpleName(); - } - - @Override - protected boolean finishedSuccessImpl(List<Epg> results) { - clearCache(); - - if (results.isEmpty()) { - return false; - } - - // get spinner value - final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner - .getSelectedItem(); - nextForceCache = FUTURE; - cachedTime = selection.getValue(); - Date now = new Date(); - - // adapter.add(new EventListItem(new DateFormatter(results.get(0) - // .getStart()).getDailyHeader())); - - for (Epg e : results) { - CACHE.add(e); - if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { - nextForceCache = e.getStop(); - } - } - fillAdapter(); - pushResultCountToTitle(); - listView.setSelectionAfterHeaderView(); - return results.isEmpty() == false; - - } - - protected void prepareDetailsViewData(final EventListItem item) { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - - // remember event for details view and timer things - app.setCurrentEvent(item.getEvent()); - app.setCurrentEpgList(CACHE); - } - - @Override - protected int getMainLayout() { - return R.layout.time_epg_list; - } - - @Override - protected void refresh() { - // get spi - final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner - .getSelectedItem(); - // update search - startEpgQuery(selection.getValue(), true); - } - - @Override - protected void retry() { - refresh(); - } - - @Override - protected String getWindowTitle() { - return resolveWindowTitle(); - } - - private void nextEvent() { - int pos = timeSpinner.getSelectedItemPosition(); - if (pos + 1 >= timeSpinnerAdapter.getCount()) { - say(R.string.navigae_at_the_end); - return; - } - timeSpinner.setSelection(pos + 1, true); - } - - private void prevEvent() { - int pos = timeSpinner.getSelectedItemPosition(); - if (pos <= 0) { - say(R.string.navigae_at_the_start); - return; - } - timeSpinner.setSelection(pos - 1, true); - } - - @Override - public void onSwipe(int direction) { - switch (direction) { - case SimpleGestureFilter.SWIPE_RIGHT: - prevEvent(); - break; - case SimpleGestureFilter.SWIPE_LEFT: - nextEvent(); - break; - } - } - - @Override - protected int getListNavigationIndex() { - return LIST_NAVIGATION_EPG_BY_TIME; - } - - @Override - protected List<Epg> getCACHE() { - return CACHE; - } - - @Override - protected void timerModified(Timer timer) { - clearCache(); - super.timerModified(timer); - } + protected View clock; + + ArrayAdapter<EpgSearchTimeValue> timeSpinnerAdapter; + + protected static Date nextForceCache = null; + + private static String cachedTime = null; + + int selectedIndex = 0; + + protected static ArrayList<Epg> CACHE = new ArrayList<Epg>(); + + @Override + public int getProgressTextId() { + return R.string.progress_whatson_loading; + } + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // create adapter for time spinner + timeSpinnerAdapter = new ArrayAdapter<EpgSearchTimeValue>(this, + android.R.layout.simple_spinner_item); + timeSpinnerAdapter + .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + timeSpinner = (Spinner) findViewById(R.id.epg_list_time_spinner); + timeSpinner.setAdapter(timeSpinnerAdapter); + + switcher = findViewById(R.id.switch_epg_view); + switcher.setOnClickListener(this); + + clock = findViewById(R.id.epg_list_times); + clock.setOnClickListener(this); + + // update gui + adapter = new TimeEventAdapter(this); + // searchLabel.setVisibility(View.GONE); + timeSpinner.setOnItemSelectedListener(this); + + fillTimeSpinnerValues(); + + // Create adapter for EPG list + listView = (ListView) findViewById(R.id.whatson_list); + listView.setFastScrollEnabled(true); + listView.setTextFilterEnabled(true); + + listView.setAdapter(adapter); + registerForContextMenu(listView); + + // register EPG item click + listView.setOnItemClickListener(this); + + } + + private void fillTimeSpinnerValues() { + final EpgSearchTimeValues values = new EpgSearchTimeValues(this); + timeSpinnerAdapter.clear(); + for (final EpgSearchTimeValue value : values.getValues()) { + timeSpinnerAdapter.add(value); + } + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + + } + + @Override + public void onClick(final View view) { + if (view == switcher) { + final Intent intent = new Intent(); + intent.setClass(this, EventEpgListActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT + | Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(intent); + finish(); + } else if (view == clock) { + final Intent intent = new Intent(); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT + | Intent.FLAG_ACTIVITY_SINGLE_TOP); + intent.setClass(this, EpgSearchTimesListActivity.class); + startActivity(intent); + } else { + super.onClick(view); + } + } + + @Override + public void onTimeSet(final TimePicker view, final int hourOfDay, + final int minute) { + final String tm = String.format("%02d:%02d", hourOfDay, minute); + + // timeSpinnerAdapter.add(time); + final EpgSearchTimeValues values = new EpgSearchTimeValues(this); + final List<EpgSearchTimeValue> vs = values.getValues(); + final EpgSearchTimeValue time = new EpgSearchTimeValue(3, tm); + vs.add(vs.size() - 1, time); + timeSpinnerAdapter.clear(); + int select = -1; + int counter = 0; + for (final EpgSearchTimeValue value : vs) { + timeSpinnerAdapter.add(value); + if (select == -1 && value.getText().equals(tm)) { + select = counter; + } + counter++; + } + timeSpinner.setSelection(select); + setTitle(resolveWindowTitle()); + // update search + startEpgQuery(time.getValue(), false); + } + + private String resolveWindowTitle() { + if (timeSpinner == null) { + return getString(R.string.epg_by_time); + } + final 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()); + } + + @Override + public void onItemSelected(final AdapterView<?> parent, final View view, + final int position, final long id) { + + // get spinner value + final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner + .getSelectedItem(); + + if (selection.getValue().equals("adhoc")) { + final Calendar cal = Calendar.getInstance(TimeZone.getDefault()); + // show time selection + final TimePickerDialog dialog = new TimePickerDialog(this, this, + cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), + Preferences.get().isUse24hFormat()); + // dialog.setOnDismissListener(new OnDismissListener() { + + // @Override + // public void onDismiss(DialogInterface dialog) { + + + // } + //}); + + dialog.show(); + } else { + // update search + setTitle(getString(R.string.epg_by_time_args, selection.getText())); + startEpgQuery(selection.getValue(), false); + } + } + + @Override + public void onNothingSelected(final AdapterView<?> arg0) { + // startTimeEpgQuery(((EpgTimeSpinnerValue)timeSpinner.getAdapter().getItem(0)).getValue()); + } + + @Override + public void clearCache() { + super.clearCache(); + cachedTime = null; + } + + private boolean useCache(final String time) { + + if (cachedTime == null) { + return false; + } + + if (cachedTime.equals(time) == false) { + return false; + } + + if (nextForceCache == null) { + return false; + } + final Date now = new Date(); + if (nextForceCache.before(now)) { + return false; + } + return true; + } + + private void startEpgQuery(final String time, final boolean force) { + + if (useCache(time) && !force) { + fillAdapter(); + return; + } + + if (checkInternetConnection() == false) { + return; + } + + final EpgClient epgClient = new EpgClient(time, getCertificateProblemDialog()); + + // remove old listeners + // epgClient.clearSvdrpListener(); + + // create background task + final SvdrpAsyncTask<Epg, SvdrpClient<Epg>> task = new SvdrpAsyncTask<Epg, SvdrpClient<Epg>>( + epgClient); + + // create progress + addListener(task); + + // start task + task.run(); + } + + @Override + protected synchronized void fillAdapter() { + + adapter.clear(); + + if (CACHE.isEmpty()) { + return; + } + + sort(); + listView.setFastScrollEnabled(false); + adapter.add(new EventListItem( + new DateFormatter(CACHE.get(0).getStart()).getDailyHeader())); + + for (final Event e : CACHE) { + adapter.add(new EventListItem(e)); + } + adapter.notifyDataSetChanged(); + listView.setFastScrollEnabled(true); + } + + void sort() { + if (sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET) { + Collections.sort(CACHE, new TitleComparator()); + } else if (sortBy == BaseEventListActivity.MENU_GROUP_DEFAULT) { + Collections.sort(CACHE, new ChannelComparator()); + } + } + + @Override + protected int getAvailableSortByEntries() { + return R.array.epg_sort_by_channels_alpha; + } + + @Override + protected String getViewID() { + return TimeEpgListActivity.class.getSimpleName(); + } + + @Override + protected boolean finishedSuccessImpl(final List<Epg> results) { + clearCache(); + + if (results.isEmpty()) { + return false; + } + + // get spinner value + final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner + .getSelectedItem(); + nextForceCache = FUTURE; + cachedTime = selection.getValue(); + final Date now = new Date(); + + // adapter.add(new EventListItem(new DateFormatter(results.get(0) + // .getStart()).getDailyHeader())); + + for (final Epg e : results) { + CACHE.add(e); + if (e.getStop().before(nextForceCache) && e.getStop().after(now)) { + nextForceCache = e.getStop(); + } + } + fillAdapter(); + pushResultCountToTitle(); + listView.setSelectionAfterHeaderView(); + return results.isEmpty() == false; + + } + + @Override + protected void prepareDetailsViewData(final EventListItem item) { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + + // remember event for details view and timer things + app.setCurrentEvent(item.getEvent()); + app.setCurrentEpgList(CACHE); + } + + @Override + protected int getMainLayout() { + return R.layout.time_epg_list; + } + + @Override + protected void refresh() { + // get spi + final EpgSearchTimeValue selection = (EpgSearchTimeValue) timeSpinner + .getSelectedItem(); + // update search + startEpgQuery(selection.getValue(), true); + } + + @Override + protected void retry() { + refresh(); + } + + @Override + protected String getWindowTitle() { + return resolveWindowTitle(); + } + + private void nextEvent() { + final int pos = timeSpinner.getSelectedItemPosition(); + if (pos + 1 >= timeSpinnerAdapter.getCount()) { + say(R.string.navigae_at_the_end); + return; + } + timeSpinner.setSelection(pos + 1, true); + } + + private void prevEvent() { + final int pos = timeSpinner.getSelectedItemPosition(); + if (pos <= 0) { + say(R.string.navigae_at_the_start); + return; + } + timeSpinner.setSelection(pos - 1, true); + } + + @Override + public void onSwipe(final int direction) { + switch (direction) { + case SimpleGestureFilter.SWIPE_RIGHT: + prevEvent(); + break; + case SimpleGestureFilter.SWIPE_LEFT: + nextEvent(); + break; + } + } + + @Override + protected int getListNavigationIndex() { + return LIST_NAVIGATION_EPG_BY_TIME; + } + + @Override + protected List<Epg> getCACHE() { + return CACHE; + } + + @Override + protected void timerModified(final Timer timer) { + clearCache(); + super.timerModified(timer); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java index 45a75ca..9bb2361 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/TimerListActivity.java @@ -24,255 +24,256 @@ import de.bjusystems.vdrmanager.utils.svdrp.TimerClient; * @author bju */ public class TimerListActivity extends BaseTimerEditActivity<Timer> implements - OnItemClickListener { - - private static final int MENU_NEW_TIMER = 2; - - private static final int MENU_GROUP_NEW_TIMER = 2; - - protected static ArrayList<Timer> CACHE = new ArrayList<Timer>(); - - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseEventListActivity#onCreate(android.os - * .Bundle) - */ - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Attach view - // setContentView(getMainLayout()); - - // create an adapter - adapter = new TimeEventAdapter(this); - - // attach adapter to ListView - listView = (ListView) findViewById(R.id.timer_list); - listView.setAdapter(adapter); - listView.setFastScrollEnabled(true); - listView.setTextFilterEnabled(true); - - // set click listener - listView.setOnItemClickListener(this); - - // context menu wanted - registerForContextMenu(listView); - - // start query - startTimerQuery(); - } - - @Override - protected void onPause() { - super.onPause(); - } - - private void startTimerQuery() { - - if (checkInternetConnection() == false) { - return; - } - - // get timer client - TimerClient timerClient = new TimerClient(); - - // create backgound task - final SvdrpAsyncTask<Timer, SvdrpClient<Timer>> task = new SvdrpAsyncTask<Timer, SvdrpClient<Timer>>( - timerClient); - - // create progress dialog - // progress = new SvdrpProgressDialog(this, timerClient); - - // attach listener - // task.addListener(progress); - addListener(task); - - // start task - task.run(); - } - - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseTimerEditActivity#getTimer(de.bjusystems - * .vdrmanager.data.EventListItem) - */ - @Override - protected Timer getTimer(EventListItem item) { - return (Timer) item.getEvent(); - } - - /* - * (non-Javadoc) - * - * @see - * de.bjusystems.vdrmanager.gui.BaseEventListActivity#prepareTimer(de.bjusystems - * .vdrmanager.data.EventListItem) - */ - protected void prepareDetailsViewData(final EventListItem item) { - final VdrManagerApp app = (VdrManagerApp) getApplication(); - // remember event for details view and timer things - app.setCurrentEvent(item.getEvent()); - app.setCurrentEpgList(CACHE); - } - - protected Comparator<Timer> getTimeComparator(boolean reverse) { - return new Comparator<Timer>() { - TimeAndChannelComparator c = new TimeAndChannelComparator(); - @Override - public int compare(Timer item1, Timer item2) { - if (item1.isRecurring()) { - return 1; - } - if (item2.isRecurring()) { - return -1; - } - return c.compare(item1, item2); - } - - }; - } - - - - @Override - protected boolean finishedSuccessImpl(List<Timer> results) { - clearCache(); - for(Timer r :results){ - CACHE.add(r); - } - pushResultCountToTitle(); - fillAdapter(); - return adapter.isEmpty() == false; - - } - - - protected void sort() { - /* */ - switch (sortBy) { - case MENU_GROUP_DEFAULT: { - Collections.sort(CACHE, getTimeComparator(false)); - break; - } - case MENU_GROUP_ALPHABET: { - Collections.sort(CACHE, new TitleComparator()); - break; - } - //case MENU_GROUP_CHANNEL: { - //sortItemsByChannel(results); - //} - } - } - - - @Override - protected void fillAdapter() { - - adapter.clear(); - - if (CACHE.isEmpty()) { - return; - } - - sort(); - - int day = -1; - Calendar cal = Calendar.getInstance(); - - for (Timer e : CACHE) { - if (e.isRecurring()) { - adapter.add(new EventListItem(e.getWeekdays())); - } else { - cal.setTime(e.getStart()); - int eday = cal.get(Calendar.DAY_OF_YEAR); - if (eday != day) { - day = eday; - adapter.add(new EventListItem(new DateFormatter(cal) - .getDailyHeader())); - } - } - adapter.add(new EventListItem(e)); - } - adapter.notifyDataSetChanged(); - } - -// protected boolean finishedSuccessImpl() { -// adapter.clear(); -// sortItemsByTime(results); -// int day = -1; -// Calendar cal = Calendar.getInstance(); -// for (Timer e : results) { -// if (e.isRecurring()) { -// adapter.add(new EventListItem(e.getWeekdays())); -// } else { -// cal.setTime(e.getStart()); -// int eday = cal.get(Calendar.DAY_OF_YEAR); -// if (eday != day) { -// day = eday; -// adapter.add(new EventListItem(new DateFormatter(cal) -// .getDailyHeader())); -// } -// } -// adapter.add(new EventListItem(e)); -// } -// listView.setSelectionAfterHeaderView(); -// return adapter.isEmpty() == false; -// } - - @Override - protected boolean notifyDataSetChangedOnResume() { - return true; - } - - @Override - protected String getWindowTitle() { - return getString(R.string.action_menu_timers); - } - - @Override - protected int getMainLayout() { - return R.layout.timer_list; - } - - @Override - protected void refresh() { - startTimerQuery(); - } - - @Override - protected void retry() { - refresh(); - } - - @Override - protected int getAvailableSortByEntries() { - return R.array.epg_sort_by_time_alpha; - } - - public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.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'); - - final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.timer_list_menu, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - protected int getListNavigationIndex() { - return LIST_NAVIGATION_TIMERS; - } - - @Override - protected List<Timer> getCACHE() { - return CACHE; - } +OnItemClickListener { + + private static final int MENU_NEW_TIMER = 2; + + private static final int MENU_GROUP_NEW_TIMER = 2; + + protected static ArrayList<Timer> CACHE = new ArrayList<Timer>(); + + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseEventListActivity#onCreate(android.os + * .Bundle) + */ + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Attach view + // setContentView(getMainLayout()); + + // create an adapter + adapter = new TimeEventAdapter(this); + + // attach adapter to ListView + listView = (ListView) findViewById(R.id.timer_list); + listView.setAdapter(adapter); + listView.setFastScrollEnabled(true); + listView.setTextFilterEnabled(true); + + // set click listener + listView.setOnItemClickListener(this); + + // context menu wanted + registerForContextMenu(listView); + + // start query + startTimerQuery(); + } + + @Override + protected void onPause() { + super.onPause(); + } + + private void startTimerQuery() { + + if (checkInternetConnection() == false) { + return; + } + + // get timer client + final TimerClient timerClient = new TimerClient(getCertificateProblemDialog()); + + // create backgound task + final SvdrpAsyncTask<Timer, SvdrpClient<Timer>> task = new SvdrpAsyncTask<Timer, SvdrpClient<Timer>>( + timerClient); + + // create progress dialog + // progress = new SvdrpProgressDialog(this, timerClient); + + // attach listener + // task.addListener(progress); + addListener(task); + + // start task + task.run(); + } + + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseTimerEditActivity#getTimer(de.bjusystems + * .vdrmanager.data.EventListItem) + */ + @Override + protected Timer getTimer(final EventListItem item) { + return (Timer) item.getEvent(); + } + + /* + * (non-Javadoc) + * + * @see + * de.bjusystems.vdrmanager.gui.BaseEventListActivity#prepareTimer(de.bjusystems + * .vdrmanager.data.EventListItem) + */ + @Override + protected void prepareDetailsViewData(final EventListItem item) { + final VdrManagerApp app = (VdrManagerApp) getApplication(); + // remember event for details view and timer things + app.setCurrentEvent(item.getEvent()); + app.setCurrentEpgList(CACHE); + } + + protected Comparator<Timer> getTimeComparator(final boolean reverse) { + return new Comparator<Timer>() { + TimeAndChannelComparator c = new TimeAndChannelComparator(); + @Override + public int compare(final Timer item1, final Timer item2) { + if (item1.isRecurring()) { + return 1; + } + if (item2.isRecurring()) { + return -1; + } + return c.compare(item1, item2); + } + + }; + } + + + + @Override + protected boolean finishedSuccessImpl(final List<Timer> results) { + clearCache(); + for(final Timer r :results){ + CACHE.add(r); + } + pushResultCountToTitle(); + fillAdapter(); + return adapter.isEmpty() == false; + + } + + + protected void sort() { + /* */ + switch (sortBy) { + case MENU_GROUP_DEFAULT: { + Collections.sort(CACHE, getTimeComparator(false)); + break; + } + case MENU_GROUP_ALPHABET: { + Collections.sort(CACHE, new TitleComparator()); + break; + } + //case MENU_GROUP_CHANNEL: { + //sortItemsByChannel(results); + //} + } + } + + + @Override + protected void fillAdapter() { + + adapter.clear(); + + if (CACHE.isEmpty()) { + return; + } + + sort(); + + int day = -1; + final Calendar cal = Calendar.getInstance(); + + for (final Timer e : CACHE) { + if (e.isRecurring()) { + adapter.add(new EventListItem(e.getWeekdays())); + } else { + cal.setTime(e.getStart()); + final int eday = cal.get(Calendar.DAY_OF_YEAR); + if (eday != day) { + day = eday; + adapter.add(new EventListItem(new DateFormatter(cal) + .getDailyHeader())); + } + } + adapter.add(new EventListItem(e)); + } + adapter.notifyDataSetChanged(); + } + + // protected boolean finishedSuccessImpl() { + // adapter.clear(); + // sortItemsByTime(results); + // int day = -1; + // Calendar cal = Calendar.getInstance(); + // for (Timer e : results) { + // if (e.isRecurring()) { + // adapter.add(new EventListItem(e.getWeekdays())); + // } else { + // cal.setTime(e.getStart()); + // int eday = cal.get(Calendar.DAY_OF_YEAR); + // if (eday != day) { + // day = eday; + // adapter.add(new EventListItem(new DateFormatter(cal) + // .getDailyHeader())); + // } + // } + // adapter.add(new EventListItem(e)); + // } + // listView.setSelectionAfterHeaderView(); + // return adapter.isEmpty() == false; + // } + + @Override + protected boolean notifyDataSetChangedOnResume() { + return true; + } + + @Override + protected String getWindowTitle() { + return getString(R.string.action_menu_timers); + } + + @Override + protected int getMainLayout() { + return R.layout.timer_list; + } + + @Override + protected void refresh() { + startTimerQuery(); + } + + @Override + protected void retry() { + refresh(); + } + + @Override + protected int getAvailableSortByEntries() { + return R.array.epg_sort_by_time_alpha; + } + + public boolean onCreateOptionsMenu(final com.actionbarsherlock.view.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'); + + final com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.timer_list_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + protected int getListNavigationIndex() { + return LIST_NAVIGATION_TIMERS; + } + + @Override + protected List<Timer> getCACHE() { + return CACHE; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java index 06e2522..b0aae06 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/Utils.java @@ -44,422 +44,425 @@ import de.bjusystems.vdrmanager.utils.svdrp.SwitchChannelClient; public class Utils { - public static final String TAG = Utils.class.getName(); - - public static final List EMPTY_LIST = new ArrayList(0); - public static final String[] EMPTY = new String[] {}; - public static final ForegroundColorSpan HIGHLIGHT_TEXT = new ForegroundColorSpan( - - Color.RED); - - public static CharSequence highlight(String where, String what) { - if (TextUtils.isEmpty(what)) { - return where; - } - - String str = where.toLowerCase(); - what = what.toLowerCase(); - int idx = str.indexOf(what); - if (idx == -1) { - return where; - } - SpannableString ss = new SpannableString(where); - ss.setSpan(HIGHLIGHT_TEXT, idx, idx + what.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - return ss; - } - - public static Pair<Boolean, CharSequence> highlight2(String where, - String what) { - if (TextUtils.isEmpty(what)) { - return Pair.create(Boolean.FALSE, (CharSequence) where); - } - - String str = where.toLowerCase(); - what = what.toLowerCase(); - int idx = str.indexOf(what); - if (idx == -1) { - return Pair.create(Boolean.FALSE, (CharSequence) where); - } - SpannableString ss = new SpannableString(where); - ss.setSpan(HIGHLIGHT_TEXT, idx, idx + what.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - return Pair.create(Boolean.TRUE, (CharSequence) ss); - } - - public static int getProgress(Date start, Date stop) { - long now = System.currentTimeMillis(); - return getProgress(now, start.getTime(), stop.getTime()); - } - - public static int getProgress(Event e) { - if(e instanceof Recording == false){ - return getProgress(e.getStart(), e.getStop()); - } - Recording r = ((Recording)e); - if(r.getTimerStopTime() == null){ - return getProgress(e.getStart(), e.getStop()); - } - return getProgress(r.getStart(), r.getTimerStopTime()); - - } - - /** - * @param now - * @param time - * @param time2 - * @return -1, is not not between start stop, - */ - private static int getProgress(long now, long start, long stop) { - if (now >= start && now <= stop) { - long dura = stop - start; - long prog = now - start; - return (int) (prog * 100 / dura); - } - return -1; - } - - public static boolean isLive(Event event) { - long now = System.currentTimeMillis(); - return now >= event.getStart().getTime() - && now <= event.getStop().getTime(); - } - - private static String trimToEmpty(String str) { - if (str == null) { - return ""; - } - if (TextUtils.isEmpty(str)) { - return ""; - } - return str; - } - - private static String getBaseUrl() { - StringBuilder sb = new StringBuilder(); - Preferences p = Preferences.getPreferences(); - String auth = trimToEmpty(p.getStreamingUsername()) + ":" - + trimToEmpty(p.getStreamingPassword()); - if (auth.length() == 1) { - auth = ""; - } else { - auth += "@"; - } - - sb.append("http://").append(auth).append(p.getSvdrpHost()).append(":") - .append(p.getStreamPort()); - return sb.toString(); - } - - private static String getStreamUrl(String chn) { - // "http://192.168.1.119:3000/TS/" - Preferences p = Preferences.getPreferences(); - StringBuilder sb = new StringBuilder(); - sb.append(getBaseUrl()).append("/").append(p.getStreamFormat()) - .append("/").append(chn); - - return sb.toString(); - } - - private static String getRemuxStreamUrl(String chn) { - // "http://192.168.1.119:3000/TS/" - StringBuilder sb = new StringBuilder(); - Preferences p = Preferences.getPreferences(); - sb.append(getBaseUrl()).append("/").append(p.getRemuxCommand()) - .append(";").append(p.getRemuxParameter()).append("/") - .append(chn); - return sb.toString(); - } - - public static void stream(final Activity activity, Event event) { - stream(activity, event.getStreamId()); - } - - public static void stream(final Activity activity, Channel channel) { - stream(activity, channel.getId()); - } - - public static void stream(final Activity activity, final String idornr) { - - if (Preferences.get().isEnableRemux() == false) { - String url = getStreamUrl(idornr); - startStream(activity, url); - return; - } - - String sf = Preferences.get().getStreamFormat(); - String ext = activity.getString(R.string.remux_title); - new AlertDialog.Builder(activity) - .setTitle(R.string.stream_via_as) - // - .setItems( - new String[] { - activity.getString(R.string.stream_as, sf), - activity.getString(R.string.stream_via, ext) },// TODO - // add - // here - // what - // will - // be - // used - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, - int which) { - String url = null; - switch (which) { - case 0: - url = getStreamUrl(idornr); - break; - case 1: - url = getRemuxStreamUrl(idornr); - break; - } - startStream(activity, url); - } - }).create().show(); - } - - public static void startStream(Activity activity, String url) { - try { - final Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(url.toString()), "video/*"); - activity.startActivityForResult(intent, 1); - } catch (ActivityNotFoundException anfe) { - Log.w(TAG, anfe); - Toast.makeText(activity, anfe.getLocalizedMessage(), - Toast.LENGTH_SHORT).show(); - } - } - - public static final String md5(final String s) { - try { - // Create MD5 Hash - MessageDigest digest = java.security.MessageDigest - .getInstance("MD5"); - digest.update(s.getBytes()); - byte messageDigest[] = digest.digest(); - - // Create Hex String - StringBuffer hexString = new StringBuffer(); - for (int i = 0; i < messageDigest.length; i++) { - String h = Integer.toHexString(0xFF & messageDigest[i]); - while (h.length() < 2) - h = "0" + h; - hexString.append(h); - } - return hexString.toString(); - - } catch (NoSuchAlgorithmException e) { - Log.w(TAG, e); - } - return ""; - } - - public static int getDuration(Event event) { - long millis = event.getDuration(); - int minuts = (int) (millis / 1000 / 60); - return minuts; - } - - public static void shareEvent(Activity activity, Event event) { - final Intent share = new Intent(android.content.Intent.ACTION_SEND); - share.setType("text/plain"); - StringBuilder sb = new StringBuilder(); - sb.append(event.getTitle()); - sb.append("\n"); - EventFormatter ef = new EventFormatter(event, false); - sb.append(ef.getDate()).append(" ").append(ef.getTime()); - String title = sb.toString(); - share.putExtra(android.content.Intent.EXTRA_SUBJECT, sb.toString()); - sb = new StringBuilder(); - sb.append(title).append("\n\n"); - sb.append(event.getChannelNumber() + " " + event.getChannelName()); - sb.append("\n\n"); - sb.append(ef.getShortText()); - sb.append("\n\n"); - sb.append(ef.getDescription()); - sb.append("\n"); - share.putExtra(android.content.Intent.EXTRA_TEXT, sb.toString()); - activity.startActivity(Intent.createChooser(share, - activity.getString(R.string.share_chooser))); - } - - public static void addCalendarEvent(Activity activity, Event event) { - Intent intent = new Intent(Intent.ACTION_EDIT); - intent.setType("vnd.android.cursor.item/event"); - intent.putExtra("title", event.getTitle()); - intent.putExtra("description", event.getShortText()); - intent.putExtra("beginTime", event.getStart().getTime()); - intent.putExtra("endTime", event.getStop().getTime()); - activity.startActivity(intent); - } - - public static String mapSpecialChars(String src) { - if (src == null) { - return ""; - } - return src.replace("|##", C.DATA_SEPARATOR).replace("||#", "\n"); - } - - public static String unMapSpecialChars(String src) { - if (src == null) { - return ""; - } - return src.replace(C.DATA_SEPARATOR, "|##").replace("\n", "||#"); - } - - public static PackageInfo getPackageInfo(Context ctx) { - PackageInfo pi = null; - try { - pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), - PackageManager.GET_ACTIVITIES); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - return pi; - } - - public static boolean checkInternetConnection(Context ctx) { - ConnectivityManager cm = (ConnectivityManager) ctx - .getSystemService(Context.CONNECTIVITY_SERVICE); - // test for connection - if (cm.getActiveNetworkInfo() != null - && cm.getActiveNetworkInfo().isConnectedOrConnecting()) { - return true; - } - return false; - } - - private static String getRecordingStream(Activity ctx, Recording rec) { - - String m = Preferences.get().getRecStreamMethod(); - - StringBuilder url = new StringBuilder(); - - if (StringUtils.equals(m, "vdr-live")) { - url.append("http://") - .append(Preferences.get().getSvdrpHost()) - // - .append(":") - .append(Integer.valueOf(Preferences.get().getLivePort())) - // - .append("/recstream.html?recid=recording_") - .append(Utils.md5(rec.getFileName())); - // http://192.168.1.119:8008/b0cdedeed2d36508dfd924f0876a851b - String urlstring = url.toString(); - return urlstring; - } else if (StringUtils.equals(m, "vdr-streamdev")) { - url.append("http://").append(Preferences.get().getSvdrpHost()) - // - .append(":") - .append(Integer.valueOf(Preferences.get().getStreamPort())) - // - .append("/").append(rec.getDevInode()); - } - return url.toString(); - } - - public static void streamRecording(Activity ctx, Recording rec) { - String urlstring = getRecordingStream(ctx, rec); - Log.d(TAG, "try stream: " + urlstring); - Utils.startStream(ctx, urlstring); - } - - public static void switchTo(final Context ctx, final Channel channel) { - switchTo(ctx, channel.getId(), channel.getName()); - } - - /** - * @param ctx - * @param id - * @param name - * Optional für die Anzeige - */ - public static void switchTo(final Context ctx, final String id, - final String name) { - - final SwitchChannelClient scc = new SwitchChannelClient(id); - SvdrpAsyncTask<String, SwitchChannelClient> task = new SvdrpAsyncTask<String, SwitchChannelClient>( - scc); - task.addSvdrpListener(new SvdrpListener() { - public void svdrpEvent(SvdrpEvent event) { - if (event == SvdrpEvent.FINISHED_SUCCESS) { - Utils.say(ctx, ctx.getString(R.string.switching_success, - (name != null ? name : id))); - } else if (event == SvdrpEvent.CONNECT_ERROR - || event == SvdrpEvent.FINISHED_ABNORMALY - || event == SvdrpEvent.ABORTED - || event == SvdrpEvent.ERROR - || event == SvdrpEvent.CACHE_HIT) { - Utils.say(ctx, ctx.getString(R.string.switching_failed, - (name != null ? name : id), event.name())); - } - } - - public void svdrpException(SvdrpException e) { - Log.w(TAG, e.getMessage(), e); - Utils.say(ctx, e.getMessage()); - } - }); - task.run(); - } - - public static void say(Context ctx, String msg) { - Toast t = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); - t.setGravity(Gravity.CENTER, 0, 0); - t.show(); - } - - public static void say(Context ctx, int msg) { - Toast t = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); - t.setGravity(Gravity.CENTER, 0, 0); - t.show(); - } - - /** - * Formats the date and time based on user's phone date/time preferences. - * - * @param context - * the context - * @param time - * the time in milliseconds - */ - - public static String formatDateTime(Context context, long time) { - return android.text.format.DateFormat.getDateFormat(context).format( - time) - + " " - + DateUtils.formatDateTime(context, time, - DateUtils.FORMAT_SHOW_TIME).toString(); - } - - public static int getTimerStateDrawable(TimerMatch match, int full, - int begin, int end) { - if (match == TimerMatch.Full) { - return full; - } - - if (match == TimerMatch.Begin) { - return begin; - } - - return end; - } - - public static String formatAudio(Context context, List<AudioTrack> tracks){ - - StringBuilder sb = new StringBuilder(); - - String sep = ""; - for(AudioTrack a : tracks){ - sb.append(sep).append(a.display); - if(a.type.equals("d")){ - sb.append(" (").append(context.getString(R.string.audio_track_dolby)).append(")"); - } - sep = ", "; - } - return sb.toString(); - - } + public static final String TAG = Utils.class.getName(); + + public static final List EMPTY_LIST = new ArrayList(0); + public static final String[] EMPTY = new String[] {}; + public static final ForegroundColorSpan HIGHLIGHT_TEXT = new ForegroundColorSpan( + + Color.RED); + + public static CharSequence highlight(final String where, String what) { + if (TextUtils.isEmpty(what)) { + return where; + } + + final String str = where.toLowerCase(); + what = what.toLowerCase(); + final int idx = str.indexOf(what); + if (idx == -1) { + return where; + } + final SpannableString ss = new SpannableString(where); + ss.setSpan(HIGHLIGHT_TEXT, idx, idx + what.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return ss; + } + + public static Pair<Boolean, CharSequence> highlight2(final String where, + String what) { + if (TextUtils.isEmpty(what)) { + return Pair.create(Boolean.FALSE, (CharSequence) where); + } + + final String str = where.toLowerCase(); + what = what.toLowerCase(); + final int idx = str.indexOf(what); + if (idx == -1) { + return Pair.create(Boolean.FALSE, (CharSequence) where); + } + final SpannableString ss = new SpannableString(where); + ss.setSpan(HIGHLIGHT_TEXT, idx, idx + what.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + return Pair.create(Boolean.TRUE, (CharSequence) ss); + } + + public static int getProgress(final Date start, final Date stop) { + final long now = System.currentTimeMillis(); + return getProgress(now, start.getTime(), stop.getTime()); + } + + public static int getProgress(final Event e) { + if(e instanceof Recording == false){ + return getProgress(e.getStart(), e.getStop()); + } + final Recording r = ((Recording)e); + if(r.getTimerStopTime() == null){ + return getProgress(e.getStart(), e.getStop()); + } + return getProgress(r.getStart(), r.getTimerStopTime()); + + } + + /** + * @param now + * @param time + * @param time2 + * @return -1, is not not between start stop, + */ + private static int getProgress(final long now, final long start, final long stop) { + if (now >= start && now <= stop) { + final long dura = stop - start; + final long prog = now - start; + return (int) (prog * 100 / dura); + } + return -1; + } + + public static boolean isLive(final Event event) { + final long now = System.currentTimeMillis(); + return now >= event.getStart().getTime() + && now <= event.getStop().getTime(); + } + + private static String trimToEmpty(final String str) { + if (str == null) { + return ""; + } + if (TextUtils.isEmpty(str)) { + return ""; + } + return str; + } + + private static String getBaseUrl() { + final StringBuilder sb = new StringBuilder(); + final Preferences p = Preferences.getPreferences(); + String auth = trimToEmpty(p.getStreamingUsername()) + ":" + + trimToEmpty(p.getStreamingPassword()); + if (auth.length() == 1) { + auth = ""; + } else { + auth += "@"; + } + + sb.append("http://").append(auth).append(p.getSvdrpHost()).append(":") + .append(p.getStreamPort()); + return sb.toString(); + } + + private static String getStreamUrl(final String chn) { + // "http://192.168.1.119:3000/TS/" + final Preferences p = Preferences.getPreferences(); + final StringBuilder sb = new StringBuilder(); + sb.append(getBaseUrl()).append("/").append(p.getStreamFormat()) + .append("/").append(chn); + + return sb.toString(); + } + + private static String getRemuxStreamUrl(final String chn) { + // "http://192.168.1.119:3000/TS/" + final StringBuilder sb = new StringBuilder(); + final Preferences p = Preferences.getPreferences(); + sb.append(getBaseUrl()).append("/").append(p.getRemuxCommand()) + .append(";").append(p.getRemuxParameter()).append("/") + .append(chn); + return sb.toString(); + } + + public static void stream(final Activity activity, final Event event) { + stream(activity, event.getStreamId()); + } + + public static void stream(final Activity activity, final Channel channel) { + stream(activity, channel.getId()); + } + + public static void stream(final Activity activity, final String idornr) { + + if (Preferences.get().isEnableRemux() == false) { + final String url = getStreamUrl(idornr); + startStream(activity, url); + return; + } + + final String sf = Preferences.get().getStreamFormat(); + final String ext = activity.getString(R.string.remux_title); + new AlertDialog.Builder(activity) + .setTitle(R.string.stream_via_as) + // + .setItems( + new String[] { + activity.getString(R.string.stream_as, sf), + activity.getString(R.string.stream_via, ext) },// TODO + // add + // here + // what + // will + // be + // used + new DialogInterface.OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, + final int which) { + String url = null; + switch (which) { + case 0: + url = getStreamUrl(idornr); + break; + case 1: + url = getRemuxStreamUrl(idornr); + break; + } + startStream(activity, url); + } + }).create().show(); + } + + public static void startStream(final Activity activity, final String url) { + try { + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(url.toString()), "video/*"); + activity.startActivityForResult(intent, 1); + } catch (final ActivityNotFoundException anfe) { + Log.w(TAG, anfe); + Toast.makeText(activity, anfe.getLocalizedMessage(), + Toast.LENGTH_SHORT).show(); + } + } + + public static final String md5(final String s) { + try { + // Create MD5 Hash + final MessageDigest digest = java.security.MessageDigest + .getInstance("MD5"); + digest.update(s.getBytes()); + final byte messageDigest[] = digest.digest(); + + // Create Hex String + final StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < messageDigest.length; i++) { + String h = Integer.toHexString(0xFF & messageDigest[i]); + while (h.length() < 2) { + h = "0" + h; + } + hexString.append(h); + } + return hexString.toString(); + + } catch (final NoSuchAlgorithmException e) { + Log.w(TAG, e); + } + return ""; + } + + public static int getDuration(final Event event) { + final long millis = event.getDuration(); + final int minuts = (int) (millis / 1000 / 60); + return minuts; + } + + public static void shareEvent(final Activity activity, final Event event) { + final Intent share = new Intent(android.content.Intent.ACTION_SEND); + share.setType("text/plain"); + StringBuilder sb = new StringBuilder(); + sb.append(event.getTitle()); + sb.append("\n"); + final EventFormatter ef = new EventFormatter(event, false); + sb.append(ef.getDate()).append(" ").append(ef.getTime()); + final String title = sb.toString(); + share.putExtra(android.content.Intent.EXTRA_SUBJECT, sb.toString()); + sb = new StringBuilder(); + sb.append(title).append("\n\n"); + sb.append(event.getChannelNumber() + " " + event.getChannelName()); + sb.append("\n\n"); + sb.append(ef.getShortText()); + sb.append("\n\n"); + sb.append(ef.getDescription()); + sb.append("\n"); + share.putExtra(android.content.Intent.EXTRA_TEXT, sb.toString()); + activity.startActivity(Intent.createChooser(share, + activity.getString(R.string.share_chooser))); + } + + public static void addCalendarEvent(final Activity activity, final Event event) { + final Intent intent = new Intent(Intent.ACTION_EDIT); + intent.setType("vnd.android.cursor.item/event"); + intent.putExtra("title", event.getTitle()); + intent.putExtra("description", event.getShortText()); + intent.putExtra("beginTime", event.getStart().getTime()); + intent.putExtra("endTime", event.getStop().getTime()); + activity.startActivity(intent); + } + + public static String mapSpecialChars(final String src) { + if (src == null) { + return ""; + } + return src.replace("|##", C.DATA_SEPARATOR).replace("||#", "\n"); + } + + public static String unMapSpecialChars(final String src) { + if (src == null) { + return ""; + } + return src.replace(C.DATA_SEPARATOR, "|##").replace("\n", "||#"); + } + + public static PackageInfo getPackageInfo(final Context ctx) { + PackageInfo pi = null; + try { + pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), + PackageManager.GET_ACTIVITIES); + } catch (final PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return pi; + } + + public static boolean checkInternetConnection(final Context ctx) { + final ConnectivityManager cm = (ConnectivityManager) ctx + .getSystemService(Context.CONNECTIVITY_SERVICE); + // test for connection + if (cm.getActiveNetworkInfo() != null + && cm.getActiveNetworkInfo().isConnectedOrConnecting()) { + return true; + } + return false; + } + + private static String getRecordingStream(final Activity ctx, final Recording rec) { + + final String m = Preferences.get().getRecStreamMethod(); + + final StringBuilder url = new StringBuilder(); + + if (StringUtils.equals(m, "vdr-live")) { + url.append("http://") + .append(Preferences.get().getSvdrpHost()) + // + .append(":") + .append(Integer.valueOf(Preferences.get().getLivePort())) + // + .append("/recstream.html?recid=recording_") + .append(Utils.md5(rec.getFileName())); + // http://192.168.1.119:8008/b0cdedeed2d36508dfd924f0876a851b + final String urlstring = url.toString(); + return urlstring; + } else if (StringUtils.equals(m, "vdr-streamdev")) { + url.append("http://").append(Preferences.get().getSvdrpHost()) + // + .append(":") + .append(Integer.valueOf(Preferences.get().getStreamPort())) + // + .append("/").append(rec.getDevInode()); + } + return url.toString(); + } + + public static void streamRecording(final Activity ctx, final Recording rec) { + final String urlstring = getRecordingStream(ctx, rec); + Log.d(TAG, "try stream: " + urlstring); + Utils.startStream(ctx, urlstring); + } + + public static void switchTo(final Activity activity, final Channel channel) { + switchTo(activity, channel.getId(), channel.getName()); + } + + /** + * @param ctx + * @param id + * @param name + * Optional für die Anzeige + */ + public static void switchTo(final Activity activity, final String id, + final String name) { + + final SwitchChannelClient scc = new SwitchChannelClient(id, new CertificateProblemDialog(activity)); + final SvdrpAsyncTask<String, SwitchChannelClient> task = new SvdrpAsyncTask<String, SwitchChannelClient>( + scc); + task.addSvdrpListener(new SvdrpListener() { + @Override + public void svdrpEvent(final SvdrpEvent event) { + if (event == SvdrpEvent.FINISHED_SUCCESS) { + Utils.say(activity, activity.getString(R.string.switching_success, + (name != null ? name : id))); + } else if (event == SvdrpEvent.CONNECT_ERROR + || event == SvdrpEvent.FINISHED_ABNORMALY + || event == SvdrpEvent.ABORTED + || event == SvdrpEvent.ERROR + || event == SvdrpEvent.CACHE_HIT) { + Utils.say(activity, activity.getString(R.string.switching_failed, + (name != null ? name : id), event.name())); + } + } + + public void svdrpException(final SvdrpException e) { + Log.w(TAG, e.getMessage(), e); + Utils.say(activity, e.getMessage()); + } + }); + task.run(); + } + + public static void say(final Context ctx, final String msg) { + final Toast t = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); + t.setGravity(Gravity.CENTER, 0, 0); + t.show(); + } + + public static void say(final Context ctx, final int msg) { + final Toast t = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); + t.setGravity(Gravity.CENTER, 0, 0); + t.show(); + } + + /** + * Formats the date and time based on user's phone date/time preferences. + * + * @param context + * the context + * @param time + * the time in milliseconds + */ + + public static String formatDateTime(final Context context, final long time) { + return android.text.format.DateFormat.getDateFormat(context).format( + time) + + " " + + DateUtils.formatDateTime(context, time, + DateUtils.FORMAT_SHOW_TIME).toString(); + } + + public static int getTimerStateDrawable(final TimerMatch match, final int full, + final int begin, final int end) { + if (match == TimerMatch.Full) { + return full; + } + + if (match == TimerMatch.Begin) { + return begin; + } + + return end; + } + + public static String formatAudio(final Context context, final List<AudioTrack> tracks){ + + final StringBuilder sb = new StringBuilder(); + + String sep = ""; + for(final AudioTrack a : tracks){ + sb.append(sep).append(a.display); + if(a.type.equals("d")){ + sb.append(" (").append(context.getString(R.string.audio_track_dolby)).append(")"); + } + sep = ", "; + } + return sb.toString(); + + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java index 870bc70..daeb2c7 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/AsyncProgressTask.java @@ -8,55 +8,56 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; public abstract class AsyncProgressTask<Result> { - class AsyncProgress extends SvdrpProgressDialog<Result> { - - public AsyncProgress(final Activity activity, - final SvdrpClient<Result> client) { - super(activity, client); - } - - public void svdrpEvent(final SvdrpEvent event) { - super.svdrpEvent(event); - switch (event) { - case ABORTED: - case CONNECT_ERROR: - case CONNECTION_TIMEOUT: - case ERROR: - case LOGIN_ERROR: - case FINISHED_ABNORMALY: - case FINISHED_SUCCESS: - case CACHE_HIT: - AsyncProgressTask.this.finished(event); - break; - } - } - } - - Activity activity; - SvdrpClient<Result> client; - - public AsyncProgressTask(final Activity activity, - final SvdrpClient<Result> client) { - this.activity = activity; - this.client = client; - } - - public void start() { - - // delete timer - /* - * final SetTimerClient client = new SetTimerClient(timer, true) { - * - * @Override public int getProgressTextId() { return - * R.string.progress_timer_delete; } }; - */ - final SvdrpAsyncTask<Result, SvdrpClient<Result>> task = new SvdrpAsyncTask<Result, SvdrpClient<Result>>( - client); - final AsyncProgress progress = new AsyncProgress(activity, client); - task.addSvdrpListener(progress); - task.addSvdrpExceptionListener(progress); - task.run(); - } - - public abstract void finished(SvdrpEvent event); + class AsyncProgress extends SvdrpProgressDialog<Result> { + + public AsyncProgress(final Activity activity, + final SvdrpClient<Result> client) { + super(activity, client); + } + + @Override + public void svdrpEvent(final SvdrpEvent event) { + super.svdrpEvent(event); + switch (event) { + case ABORTED: + case CONNECT_ERROR: + case CONNECTION_TIMEOUT: + case ERROR: + case LOGIN_ERROR: + case FINISHED_ABNORMALY: + case FINISHED_SUCCESS: + case CACHE_HIT: + AsyncProgressTask.this.finished(event); + break; + } + } + } + + Activity activity; + SvdrpClient<Result> client; + + public AsyncProgressTask(final Activity activity, + final SvdrpClient<Result> client) { + this.activity = activity; + this.client = client; + } + + public void start() { + + // delete timer + /* + * final SetTimerClient client = new SetTimerClient(timer, true) { + * + * @Override public int getProgressTextId() { return + * R.string.progress_timer_delete; } }; + */ + final SvdrpAsyncTask<Result, SvdrpClient<Result>> task = new SvdrpAsyncTask<Result, SvdrpClient<Result>>( + client); + final AsyncProgress progress = new AsyncProgress(activity, client); + task.addSvdrpListener(progress); + task.addSvdrpExceptionListener(progress); + task.run(); + } + + public abstract void finished(SvdrpEvent event); } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java index bd4a679..1623575 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ChannelsTask.java @@ -5,7 +5,7 @@ import de.bjusystems.vdrmanager.data.Channel; import de.bjusystems.vdrmanager.utils.svdrp.ChannelClient; public abstract class ChannelsTask extends AsyncProgressTask<Channel> { - public ChannelsTask(final Activity activity, final ChannelClient client) { - super(activity, client); - } + public ChannelsTask(final Activity activity, final ChannelClient client) { + super(activity, client); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java index f9ab94b..fa7dc43 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/CreateTimerTask.java @@ -3,17 +3,18 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.gui.CertificateProblemDialog; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; public abstract class CreateTimerTask extends AsyncProgressTask<Timer> { - public CreateTimerTask(final Activity activity, final Timer timer) { - super(activity, new SetTimerClient(timer, TimerOperation.CREATE) { - @Override - public int getProgressTextId() { - return R.string.progress_timer_save; - } - }); - } + public CreateTimerTask(final Activity activity, final Timer timer) { + super(activity, new SetTimerClient(timer, TimerOperation.CREATE, new CertificateProblemDialog(activity)) { + @Override + public int getProgressTextId() { + return R.string.progress_timer_save; + } + }); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteRecordingTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteRecordingTask.java index 255a6a6..b9f5f75 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteRecordingTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteRecordingTask.java @@ -3,15 +3,16 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Recording; +import de.bjusystems.vdrmanager.gui.CertificateProblemDialog; import de.bjusystems.vdrmanager.utils.svdrp.DelRecordingClient; public abstract class DeleteRecordingTask extends AsyncProgressTask<Recording> { - public DeleteRecordingTask(final Activity activity, final Recording r) { - super(activity, new DelRecordingClient(r) { - @Override - public int getProgressTextId() { - return R.string.progress_recording_delete; - } - }); - } + public DeleteRecordingTask(final Activity activity, final Recording r) { + super(activity, new DelRecordingClient(r, new CertificateProblemDialog(activity)) { + @Override + public int getProgressTextId() { + return R.string.progress_recording_delete; + } + }); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java index f4ea149..b3314d2 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/DeleteTimerTask.java @@ -3,17 +3,18 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.gui.CertificateProblemDialog; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; public abstract class DeleteTimerTask extends AsyncProgressTask<Timer> { - public DeleteTimerTask(final Activity activity, final Timer timer) { - super(activity, new SetTimerClient(timer, TimerOperation.DELETE) { - @Override - public int getProgressTextId() { - return R.string.progress_timer_delete; - } - }); - } + public DeleteTimerTask(final Activity activity, final Timer timer) { + super(activity, new SetTimerClient(timer, TimerOperation.DELETE, new CertificateProblemDialog(activity)) { + @Override + public int getProgressTextId() { + return R.string.progress_timer_delete; + } + }); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java index 14e7b1a..80aae53 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ModifyTimerTask.java @@ -3,21 +3,22 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.gui.CertificateProblemDialog; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; public abstract class ModifyTimerTask extends AsyncProgressTask<Timer> { - - public ModifyTimerTask(final Activity activity, final Timer newTimer, final Timer oldTimer) { - super(activity, new SetTimerClient(newTimer, oldTimer, TimerOperation.MODIFY) { - @Override - public int getProgressTextId() { - return R.string.progress_timer_modify; - } - - - }); - - - } + + public ModifyTimerTask(final Activity activity, final Timer newTimer, final Timer oldTimer) { + super(activity, new SetTimerClient(newTimer, oldTimer, TimerOperation.MODIFY, new CertificateProblemDialog(activity)) { + @Override + public int getProgressTextId() { + return R.string.progress_timer_modify; + } + + + }); + + + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java index 0f96926..82daae4 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/tasks/ToggleTimerTask.java @@ -3,24 +3,25 @@ package de.bjusystems.vdrmanager.tasks; import android.app.Activity; import de.bjusystems.vdrmanager.R; import de.bjusystems.vdrmanager.data.Timer; +import de.bjusystems.vdrmanager.gui.CertificateProblemDialog; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient; import de.bjusystems.vdrmanager.utils.svdrp.SetTimerClient.TimerOperation; public abstract class ToggleTimerTask extends AsyncProgressTask<Timer> { - public ToggleTimerTask(final Activity activity, final Timer timer) { - super(activity, new SetTimerClient(timer, TimerOperation.TOGGLE) { - boolean enabled = timer.isEnabled(); + public ToggleTimerTask(final Activity activity, final Timer timer) { + super(activity, new SetTimerClient(timer, TimerOperation.TOGGLE, new CertificateProblemDialog(activity)) { + boolean enabled = timer.isEnabled(); - @Override - public int getProgressTextId() { - if (enabled) { - return R.string.progress_timer_disable; - } else { - return R.string.progress_timer_enable; - } - } - }); - timer.setEnabled(!timer.isEnabled()); - } + @Override + public int getProgressTextId() { + if (enabled) { + return R.string.progress_timer_disable; + } else { + return R.string.progress_timer_enable; + } + } + }); + timer.setEnabled(!timer.isEnabled()); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java index ebaee8c..0d5dca9 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/AliveClient.java @@ -9,41 +9,39 @@ import de.bjusystems.vdrmanager.data.AliveState; */ public class AliveClient extends SvdrpClient<AliveState> { - /** - * Constructor - * @param host host - * @param port port - * @param ssl use ssl - */ - public AliveClient() { - super(); - } - - /** - * Starts the EPG request - * @param parameter parameter for lste - */ - @Override - public void run() { - runCommand("aliv"); - } - - @Override - public AliveState parseAnswer(final String line) { - - if (line.startsWith("200")) { - return AliveState.ALIVE; - } - if (line.startsWith("400")) { - return AliveState.DEAD; - } - return AliveState.UNKNOWN; - } - - @Override - public int getProgressTextId() { - return 0; - } + /** + * Constructor + * @param certificateProblemListener + */ + public AliveClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + } + + /** + * Starts the EPG request + * @param parameter parameter for lste + */ + @Override + public void run() { + runCommand("aliv"); + } + + @Override + public AliveState parseAnswer(final String line) { + + if (line.startsWith("200")) { + return AliveState.ALIVE; + } + if (line.startsWith("400")) { + return AliveState.DEAD; + } + return AliveState.UNKNOWN; + } + + @Override + public int getProgressTextId() { + return 0; + } }
\ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/CertificateProblemListener.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/CertificateProblemListener.java new file mode 100644 index 0000000..4af370e --- /dev/null +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/CertificateProblemListener.java @@ -0,0 +1,31 @@ +package de.bjusystems.vdrmanager.utils.svdrp; + +import java.security.cert.X509Certificate; + +/** + * Interface for reporting problems with the SSL certificate + * @author bju + * + */ +public interface CertificateProblemListener { + + /** + * Possible user decisions on certificate problems + */ + public enum CertificateProblemAction { + + /** Abort the connection */ + ABORT, + /** Accept the certificate this time */ + ACCEPT_ONCE, + /** Accept the certificate forever */ + ACCEPT_FOREVER + } + + /** + * Reports the certificate problem and waits for a user decision + * @param chain Certificate trust chain + * @param authType authentication type + */ + CertificateProblemAction reportProblem(final X509Certificate[] chain, final String authType); +} diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java index 3b524c7..c3761c4 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/ChannelClient.java @@ -17,168 +17,168 @@ import de.bjusystems.vdrmanager.data.Preferences; * */ public class ChannelClient extends SvdrpClient<Channel> implements - SvdrpListener, SvdrpResultListener<Channel> { - - private static final ArrayList<String> channelGroups = new ArrayList<String>(); - - private static final ArrayList<String> channelSources = new ArrayList<String>(); - - private static LinkedHashMap<String, ArrayList<Channel>> groupChannels = new LinkedHashMap<String, ArrayList<Channel>>(); - - private static TreeMap<String, ArrayList<Channel>> providerChannels = new TreeMap<String, ArrayList<Channel>>(); - - private static TreeMap<String, ArrayList<Channel>> sourceChannels = new TreeMap<String, ArrayList<Channel>>(); - - private static ArrayList<Channel> channels = new ArrayList<Channel>(); - - private static Map<String, Channel> idChannels = new HashMap<String, Channel>(); - - public static Map<String, Channel> getIdChannels() { - return idChannels; - } - - private static boolean inited = false; - - public ChannelClient() { - super(); - // if (useCache == false) { - // clearCache(); - // } - addSvdrpListener(this); - addSvdrpResultListener(this); - } - - public static void clearCache() { - channelSources.clear(); - sourceChannels.clear(); - channelGroups.clear(); - groupChannels.clear(); - providerChannels.clear(); - channels.clear(); - idChannels.clear(); - inited = false; - } - - public static ArrayList<String> getChannelGroups() { - return channelGroups; - } - - public static ArrayList<String> getChannelSources() { - return channelSources; - } - - - public static HashMap<String, ArrayList<Channel>> getGroupChannels() { - return groupChannels; - } - - public static TreeMap<String, ArrayList<Channel>> getProviderChannels() { - return providerChannels; - } - - public static TreeMap<String, ArrayList<Channel>> getSourceChannels() { - return sourceChannels; - } - - public static ArrayList<Channel> getChannels() { - return channels; - } - - /** - * Constructor - * - * @param host - * host - * @param port - * port - * @param ssl - * use ssl - */ - // public ChannelClient() { - // this(true); - // - // } - - /** - * Starts the EPG request - * - * @param parameter - * parameter for lste - */ - @Override - synchronized public void run() { - if (inited == true) { - informListener(SvdrpEvent.CACHE_HIT); - } else { - runCommand("channels " + Preferences.get().getChannels()); - } - } - - @Override - public Channel parseAnswer(final String line) { - return new Channel(line); - } - - @Override - public int getProgressTextId() { - return R.string.progress_channels_loading; - } - - ArrayList<Channel> currentChannels = new ArrayList<Channel>(); - - String currentGroup; - - private void addSourceChannel(Channel c){ - ArrayList<Channel> channels = sourceChannels.get(c.getSource()); - - if(channels == null){ - channels = new ArrayList<Channel>(); - sourceChannels.put(c.getSource(), channels); - channelSources.add(c.getSource()); - } - channels.add(c); - } - - private void received(Channel c) { - - if (c.isGroupSeparator()) { - currentGroup = c.getName(); - channelGroups.add(currentGroup); - currentChannels = new ArrayList<Channel>(); - groupChannels.put(c.getName(), currentChannels); - } else { - - addSourceChannel(c); - - if (channelGroups.isEmpty()) {// receiver channel with no previous - // group - channelGroups.add(""); - groupChannels.put("", currentChannels); - } - - c.setGroup(currentGroup); - channels.add(c); - idChannels.put(c.getId(), c); - currentChannels.add(c); - String provider = c.getProvider(); - ArrayList<Channel> pchannels = providerChannels.get(provider); - if (pchannels == null) { - pchannels = new ArrayList<Channel>(); - providerChannels.put(provider, pchannels); - } - pchannels.add(c); - } - } - - @Override - public void svdrpEvent(Channel c) { - received(c); - } - - @Override - public void svdrpEvent(SvdrpEvent event) { - if (event == SvdrpEvent.FINISHED_SUCCESS) { - inited = true; - } - } +SvdrpListener, SvdrpResultListener<Channel> { + + private static final ArrayList<String> channelGroups = new ArrayList<String>(); + + private static final ArrayList<String> channelSources = new ArrayList<String>(); + + private static LinkedHashMap<String, ArrayList<Channel>> groupChannels = new LinkedHashMap<String, ArrayList<Channel>>(); + + private static TreeMap<String, ArrayList<Channel>> providerChannels = new TreeMap<String, ArrayList<Channel>>(); + + private static TreeMap<String, ArrayList<Channel>> sourceChannels = new TreeMap<String, ArrayList<Channel>>(); + + private static ArrayList<Channel> channels = new ArrayList<Channel>(); + + private static Map<String, Channel> idChannels = new HashMap<String, Channel>(); + + public static Map<String, Channel> getIdChannels() { + return idChannels; + } + + private static boolean inited = false; + + public ChannelClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + // if (useCache == false) { + // clearCache(); + // } + addSvdrpListener(this); + addSvdrpResultListener(this); + } + + public static void clearCache() { + channelSources.clear(); + sourceChannels.clear(); + channelGroups.clear(); + groupChannels.clear(); + providerChannels.clear(); + channels.clear(); + idChannels.clear(); + inited = false; + } + + public static ArrayList<String> getChannelGroups() { + return channelGroups; + } + + public static ArrayList<String> getChannelSources() { + return channelSources; + } + + + public static HashMap<String, ArrayList<Channel>> getGroupChannels() { + return groupChannels; + } + + public static TreeMap<String, ArrayList<Channel>> getProviderChannels() { + return providerChannels; + } + + public static TreeMap<String, ArrayList<Channel>> getSourceChannels() { + return sourceChannels; + } + + public static ArrayList<Channel> getChannels() { + return channels; + } + + /** + * Constructor + * + * @param host + * host + * @param port + * port + * @param ssl + * use ssl + */ + // public ChannelClient() { + // this(true); + // + // } + + /** + * Starts the EPG request + * + * @param parameter + * parameter for lste + */ + @Override + synchronized public void run() { + if (inited == true) { + informListener(SvdrpEvent.CACHE_HIT); + } else { + runCommand("channels " + Preferences.get().getChannels()); + } + } + + @Override + public Channel parseAnswer(final String line) { + return new Channel(line); + } + + @Override + public int getProgressTextId() { + return R.string.progress_channels_loading; + } + + ArrayList<Channel> currentChannels = new ArrayList<Channel>(); + + String currentGroup; + + private void addSourceChannel(final Channel c){ + ArrayList<Channel> channels = sourceChannels.get(c.getSource()); + + if(channels == null){ + channels = new ArrayList<Channel>(); + sourceChannels.put(c.getSource(), channels); + channelSources.add(c.getSource()); + } + channels.add(c); + } + + private void received(final Channel c) { + + if (c.isGroupSeparator()) { + currentGroup = c.getName(); + channelGroups.add(currentGroup); + currentChannels = new ArrayList<Channel>(); + groupChannels.put(c.getName(), currentChannels); + } else { + + addSourceChannel(c); + + if (channelGroups.isEmpty()) {// receiver channel with no previous + // group + channelGroups.add(""); + groupChannels.put("", currentChannels); + } + + c.setGroup(currentGroup); + channels.add(c); + idChannels.put(c.getId(), c); + currentChannels.add(c); + final String provider = c.getProvider(); + ArrayList<Channel> pchannels = providerChannels.get(provider); + if (pchannels == null) { + pchannels = new ArrayList<Channel>(); + providerChannels.put(provider, pchannels); + } + pchannels.add(c); + } + } + + @Override + public void svdrpEvent(final Channel c) { + received(c); + } + + @Override + public void svdrpEvent(final SvdrpEvent event) { + if (event == SvdrpEvent.FINISHED_SUCCESS) { + inited = true; + } + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java index efd5c6d..522e285 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/DelRecordingClient.java @@ -10,40 +10,40 @@ import de.bjusystems.vdrmanager.data.Recording; */ public class DelRecordingClient extends SvdrpClient<Recording> { - /** current recording */ - Recording recording; - - /** - * Constructor - * Recording - */ - public DelRecordingClient(final Recording recording) { - super(); - this.recording = recording; - } - - /** - * Starts the request - */ - @Override - public void run() { - - final StringBuilder command = new StringBuilder(); - - command.append("drecording "); - command.append(recording.toCommandLine()); - runCommand(command.toString()); - } - - - @Override - public int getProgressTextId() { - return R.string.progress_timer_save; - } - - @Override - protected Recording parseAnswer(String line) { - return null; - } + /** current recording */ + Recording recording; + + /** + * Constructor + * Recording + */ + public DelRecordingClient(final Recording recording, final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + this.recording = recording; + } + + /** + * Starts the request + */ + @Override + public void run() { + + final StringBuilder command = new StringBuilder(); + + command.append("drecording "); + command.append(recording.toCommandLine()); + runCommand(command.toString()); + } + + + @Override + public int getProgressTextId() { + return R.string.progress_timer_save; + } + + @Override + protected Recording parseAnswer(final String line) { + return null; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java index 88c1801..a3d5b7e 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/EpgClient.java @@ -14,79 +14,79 @@ import de.bjusystems.vdrmanager.data.Timer; */ public class EpgClient extends SvdrpClient<Epg> { - /** Time to retrieve EPG for */ - private String time; - /** Channel to retrieve EPG for */ - private Channel channel; - /** Search parameters to retrieve EPG for */ - private EpgSearchParams search; - /** Last read EPG */ - private Epg lastEpg; + /** Time to retrieve EPG for */ + private String time; + /** Channel to retrieve EPG for */ + private Channel channel; + /** Search parameters to retrieve EPG for */ + private EpgSearchParams search; + /** Last read EPG */ + private Epg lastEpg; - /** - * Constructor - */ - private EpgClient() { - super(); - this.time = null; - this.channel = null; - this.search = null; - } + /** + * Constructor + */ + private EpgClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + this.time = null; + this.channel = null; + this.search = null; + } - /** - * Constructor - * @param time time to search for epg events - */ - public EpgClient(final String time) { - this(); - this.time = time; - } + /** + * Constructor + * @param time time to search for epg events + */ + public EpgClient(final String time, final CertificateProblemListener certificateProblemListener) { + this(certificateProblemListener); + this.time = time; + } - /** - * Constructor - * @param channel channel to search for epg events - */ - public EpgClient(final Channel channel) { - this(); - this.channel = channel; - } + /** + * Constructor + * @param channel channel to search for epg events + */ + public EpgClient(final Channel channel, final CertificateProblemListener certificateProblemListener) { + this(certificateProblemListener); + this.channel = channel; + } - public EpgClient(final EpgSearchParams search) { - this(); - this.search = search; - } + public EpgClient(final EpgSearchParams search, final CertificateProblemListener certificateProblemListener) { + this(certificateProblemListener); + this.search = search; + } - /** - * Starts the EPG request - * @param parameter parameter for lste - */ - @Override - public void run() { - if (time != null) { - runCommand(String.format("tevents %s %s", time, Preferences.getPreferences().getChannels())); - } else if (channel != null) { - runCommand(String.format("cevents %s", channel.getNumber())); - } else if (search != null) { - runCommand(String.format("search %s:%s", Preferences.get().getChannels(), search.toCommandLine())); - } - } + /** + * Starts the EPG request + * @param parameter parameter for lste + */ + @Override + public void run() { + if (time != null) { + runCommand(String.format("tevents %s %s", time, Preferences.getPreferences().getChannels())); + } else if (channel != null) { + runCommand(String.format("cevents %s", channel.getNumber())); + } else if (search != null) { + runCommand(String.format("search %s:%s", Preferences.get().getChannels(), search.toCommandLine())); + } + } - @Override - public Epg parseAnswer(final String line) { + @Override + public Epg parseAnswer(final String line) { - if (line.startsWith("E")) { - lastEpg = new Epg(line); - return lastEpg; - } else if (line.startsWith("T")) { - lastEpg.setTimer(new Timer(line)); - } - return null; - } + if (line.startsWith("E")) { + lastEpg = new Epg(line); + return lastEpg; + } else if (line.startsWith("T")) { + lastEpg.setTimer(new Timer(line)); + } + return null; + } - @Override - public int getProgressTextId() { - return R.string.progress_whatson_loading; - } + @Override + public int getProgressTextId() { + return R.string.progress_whatson_loading; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/MySSLSocketFactory.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/MySSLSocketFactory.java index 9ef0788..3f1f2be 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/MySSLSocketFactory.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/MySSLSocketFactory.java @@ -35,7 +35,7 @@ public class MySSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactor /** the trust managers */ private X509TrustManager[] trustManagers; - public MySSLSocketFactory(final boolean acceptAllCertificates) + public MySSLSocketFactory(final boolean acceptAllCertificates, final CertificateProblemListener certProblemListener) throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException { super(null); @@ -50,7 +50,7 @@ public class MySSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactor if (acceptAllCertificates) { initInsecureTrustManagers(); } else { - initSecureTrustManagers(); + initSecureTrustManagers(certProblemListener); } // create SSL context @@ -81,10 +81,11 @@ public class MySSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactor /** * initialize the trust managers validating certificates * @param acceptAllCertificates accept all certificates + * @param certProblemListener listener to inform about certificate problems * @throws NoSuchAlgorithmException * @throws KeyStoreException */ - private void initSecureTrustManagers() throws NoSuchAlgorithmException, KeyStoreException { + private void initSecureTrustManagers(final CertificateProblemListener certProblemListener) throws NoSuchAlgorithmException, KeyStoreException { final List<X509TrustManager> trustManagerList = new ArrayList<X509TrustManager>(); @@ -123,10 +124,21 @@ public class MySSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactor lastException = e; } } - if (lastException != null) { - throw lastException; + + switch (certProblemListener.reportProblem(chain, authType)) { + case ACCEPT_ONCE: + return; + case ACCEPT_FOREVER: + saveCertificate(chain, authType); + return; + default: + if (lastException != null) { + throw lastException; + } + break; } + throw new CertificateException("Certificate not validated"); } @@ -175,4 +187,12 @@ public class MySSLSocketFactory extends org.apache.http.conn.ssl.SSLSocketFactor } return null; } + + /** + * Saves the certificate + * @param chain certificate chain + * @param authType authentication type + */ + private void saveCertificate(final X509Certificate[] chain, final String authType) { + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java index 025dcf9..f201ed9 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/RecordingClient.java @@ -5,19 +5,27 @@ import de.bjusystems.vdrmanager.data.Recording; public class RecordingClient extends SvdrpClient<Recording> { - @Override - protected Recording parseAnswer(String line) { - return new Recording(line); - } + /** + * Constructor + * @param certificateProblemListener + */ + public RecordingClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + } - @Override - public int getProgressTextId() { - return R.string.progress_recordings_loading; - } + @Override + protected Recording parseAnswer(final String line) { + return new Recording(line); + } - @Override - public synchronized void run() { - runCommand("recordings"); - } + @Override + public int getProgressTextId() { + return R.string.progress_recordings_loading; + } + + @Override + public synchronized void run() { + runCommand("recordings"); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java index 72ca70e..8daab75 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SetTimerClient.java @@ -10,81 +10,81 @@ import de.bjusystems.vdrmanager.data.Timer; */ public class SetTimerClient extends SvdrpClient<Timer> { - public enum TimerOperation { - CREATE("C"),// - DELETE("D"),// - MODIFY("M"),// - TOGGLE("T"),// - ; - private String command; - private TimerOperation(String command){ - this.command = command; - } - public String getCommand(){ - return this.command; - } - - } - - /** channel names for timer */ - Timer newTimer; - - Timer oldTimer; - - /** timer should be deleted */ - private TimerOperation timerOperation; - - /** - * @param newTimer Das was modifiziert angelegt wird - */ - public SetTimerClient(final Timer newTimer, TimerOperation op) { - this(newTimer, null, op); - } - - /** - * @param newTimer - * @param oldTimer this is original Timer, if any (modify) - * @param op - */ - public SetTimerClient(final Timer newTimer, final Timer oldTimer, TimerOperation op) { - super(); - this.newTimer = newTimer; - this.oldTimer = oldTimer; - this.timerOperation = op; - } - - - /** - * Starts the request - */ - @Override - public void run() { - - final StringBuilder command = new StringBuilder(); - - command.append("timer "); - command.append(timerOperation.getCommand()); - //command.append(oldTimer.getNumber()); - command.append(" "); - command.append(newTimer.toCommandLine()); - if(timerOperation == TimerOperation.MODIFY){ - command.append("#|#|#").append(oldTimer.toCommandLine()); - } - //timer D 1:1:2011-11-11:1513:1710:50:99:Mirrors 2 - //timer C 1:1:2011-11-11:2223:2250:50:99:Zapping - //timer T 0:1:2011-11-11:2013:2230:50:99:So spielt das Leben - //timer M - runCommand(command.toString()); - } - - @Override - public Timer parseAnswer(final String line) { - return new Timer(line); - } - - @Override - public int getProgressTextId() { - return R.string.progress_timer_save; - } + public enum TimerOperation { + CREATE("C"),// + DELETE("D"),// + MODIFY("M"),// + TOGGLE("T"),// + ; + private String command; + private TimerOperation(final String command){ + this.command = command; + } + public String getCommand(){ + return this.command; + } + + } + + /** channel names for timer */ + Timer newTimer; + + Timer oldTimer; + + /** timer should be deleted */ + private final TimerOperation timerOperation; + + /** + * @param newTimer Das was modifiziert angelegt wird + */ + public SetTimerClient(final Timer newTimer, final TimerOperation op, final CertificateProblemListener certificateProblemListener) { + this(newTimer, null, op, certificateProblemListener); + } + + /** + * @param newTimer + * @param oldTimer this is original Timer, if any (modify) + * @param op + */ + public SetTimerClient(final Timer newTimer, final Timer oldTimer, final TimerOperation op, final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + this.newTimer = newTimer; + this.oldTimer = oldTimer; + this.timerOperation = op; + } + + + /** + * Starts the request + */ + @Override + public void run() { + + final StringBuilder command = new StringBuilder(); + + command.append("timer "); + command.append(timerOperation.getCommand()); + //command.append(oldTimer.getNumber()); + command.append(" "); + command.append(newTimer.toCommandLine()); + if(timerOperation == TimerOperation.MODIFY){ + command.append("#|#|#").append(oldTimer.toCommandLine()); + } + //timer D 1:1:2011-11-11:1513:1710:50:99:Mirrors 2 + //timer C 1:1:2011-11-11:2223:2250:50:99:Zapping + //timer T 0:1:2011-11-11:2013:2230:50:99:So spielt das Leben + //timer M + runCommand(command.toString()); + } + + @Override + public Timer parseAnswer(final String line) { + return new Timer(line); + } + + @Override + public int getProgressTextId() { + return R.string.progress_timer_save; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java index 0a7e539..224ca48 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpAsyncTask.java @@ -4,155 +4,159 @@ import java.util.ArrayList; import java.util.List; import android.os.AsyncTask; +import de.bjusystems.vdrmanager.utils.svdrp.CertificateProblemListener.CertificateProblemAction; public class SvdrpAsyncTask<Result, Client extends SvdrpClient<Result>> extends - AsyncTask<Void, Object, Void> implements SvdrpListener, - SvdrpExceptionListener, SvdrpResultListener<Result> { - - Client client; - - Throwable ex; - - SvdrpEvent event; - - List<SvdrpListener> eventListeners = new ArrayList<SvdrpListener>(); - - List<SvdrpExceptionListener> exceptionListeners = new ArrayList<SvdrpExceptionListener>(); - - List<SvdrpFinishedListener<Result>> finishedListeners = new ArrayList<SvdrpFinishedListener<Result>>(); - - public SvdrpAsyncTask(final Client client) { - this.client = client; - this.client.addSvdrpListener(this); - this.client.addSvdrpExceptionListener(this); - this.client.addSvdrpResultListener(this); - } - - protected List<Result> results = new ArrayList<Result>(); - - - public List<Result> getResults() { - return results; - } - - - /** - * Adds the listener to the list of listeners - * - * @param listener - * listener - */ - public void addSvdrpListener(final SvdrpListener listener) { - // client.addSvdrpListener(listener); - eventListeners.add(listener); - } - - /** - * Adds the listener to the list of listeners - * - * @param listener - * listener - */ - public void addSvdrpResultListener( - final SvdrpResultListener<Result> listener) { - client.addSvdrpResultListener(listener); - } - - public void addSvdrpFinishedListener(final SvdrpFinishedListener<Result> liste) { - finishedListeners.add(liste); - } - - /** - * Adds the listener to the list of listeners - * - * @param listener - * listener - */ - public void addSvdrpExceptionListener(final SvdrpExceptionListener listener) { - // client.addSvdrpExceptionListener(listener); - exceptionListeners.add(listener); - } - - public void run() { - execute(); - } - - @Override - protected Void doInBackground(final Void... params) { - client.run(); - return null; - } - - @Override - protected void onProgressUpdate(final Object... values) { - - if (values.length == 1) { - - if (List.class.isAssignableFrom(values[0].getClass())) { - for (final SvdrpFinishedListener<Result> listener : finishedListeners) { - listener.finished((List<Result>) values[0]); - } - return; - } - - for (final SvdrpListener listener : eventListeners) { - listener.svdrpEvent((SvdrpEvent) values[0]); - } - - } else if (values.length == 2) { - for (final SvdrpExceptionListener listener : exceptionListeners) { - listener.svdrpEvent((SvdrpEvent) values[0], - (Throwable) values[1]); - } - } - - /* - * switch (event) { case CONNECTING: { - * setMessage(R.string.progress_connect); progress.show(); break; } - * - * case LOGGED_IN: { setMessage(R.string.progress_login); break; } - * - * case COMMAND_SENT: { setMessage(client.getProgressTextId()); break; } - * - * case DISCONNECTING: { setMessage(R.string.progress_disconnect); - * break; } - * - * case ERROR: case CONNECTION_TIMEOUT: case CONNECT_ERROR: case - * FINISHED_ABNORMALY: case CACHE_HIT: case FINISHED_SUCCESS: case - * LOGIN_ERROR: { progress.dismiss(); } - * - * } - */ - } - - // @Override - // protected void onPostExecute(SvdrpException exception) { - // for (SvdrpExceptionListener l : exceptionListeners) { - // l.svdrpEvent(exception.getEvent(), ex); - // } - // } - - @Override - public void svdrpEvent(SvdrpEvent event) { - publishProgress(event);; - if(event == SvdrpEvent.FINISHED_SUCCESS){ - publishProgress(results); - } - } - -// @Override -// public void finished(ListResult> results) { -// publishProgress(results); -// } - - @Override - public void svdrpEvent(SvdrpEvent event, Throwable t) { - publishProgress(event, t); - } - - - @Override - public void svdrpEvent(Result result) { - results.add(result); - } +AsyncTask<Void, Object, Void> implements SvdrpListener, +SvdrpExceptionListener, SvdrpResultListener<Result> { + + Client client; + + Throwable ex; + + SvdrpEvent event; + + List<SvdrpListener> eventListeners = new ArrayList<SvdrpListener>(); + + List<SvdrpExceptionListener> exceptionListeners = new ArrayList<SvdrpExceptionListener>(); + + List<SvdrpFinishedListener<Result>> finishedListeners = new ArrayList<SvdrpFinishedListener<Result>>(); + + CertificateProblemListener certificateProblemListener = null; + + CertificateProblemAction certificateProblemAction; + + public SvdrpAsyncTask(final Client client) { + this.client = client; + this.client.addSvdrpListener(this); + this.client.addSvdrpExceptionListener(this); + this.client.addSvdrpResultListener(this); + } + + protected List<Result> results = new ArrayList<Result>(); + + + public List<Result> getResults() { + return results; + } + + + /** + * Adds the listener to the list of listeners + * + * @param listener + * listener + */ + public void addSvdrpListener(final SvdrpListener listener) { + // client.addSvdrpListener(listener); + eventListeners.add(listener); + } + + /** + * Adds the listener to the list of listeners + * + * @param listener + * listener + */ + public void addSvdrpResultListener( + final SvdrpResultListener<Result> listener) { + client.addSvdrpResultListener(listener); + } + + public void addSvdrpFinishedListener(final SvdrpFinishedListener<Result> liste) { + finishedListeners.add(liste); + } + + /** + * Adds the listener to the list of listeners + * + * @param listener + * listener + */ + public void addSvdrpExceptionListener(final SvdrpExceptionListener listener) { + // client.addSvdrpExceptionListener(listener); + exceptionListeners.add(listener); + } + + public void run() { + execute(); + } + + @Override + protected Void doInBackground(final Void... params) { + client.run(); + return null; + } + + @Override + protected void onProgressUpdate(final Object... values) { + + if (values.length == 1) { + + if (List.class.isAssignableFrom(values[0].getClass())) { + for (final SvdrpFinishedListener<Result> listener : finishedListeners) { + listener.finished((List<Result>) values[0]); + } + return; + } + + for (final SvdrpListener listener : eventListeners) { + listener.svdrpEvent((SvdrpEvent) values[0]); + } + + } else if (values.length == 2) { + for (final SvdrpExceptionListener listener : exceptionListeners) { + listener.svdrpEvent((SvdrpEvent) values[0], (Throwable) values[1]); + } + } + + /* + * switch (event) { case CONNECTING: { + * setMessage(R.string.progress_connect); progress.show(); break; } + * + * case LOGGED_IN: { setMessage(R.string.progress_login); break; } + * + * case COMMAND_SENT: { setMessage(client.getProgressTextId()); break; } + * + * case DISCONNECTING: { setMessage(R.string.progress_disconnect); + * break; } + * + * case ERROR: case CONNECTION_TIMEOUT: case CONNECT_ERROR: case + * FINISHED_ABNORMALY: case CACHE_HIT: case FINISHED_SUCCESS: case + * LOGIN_ERROR: { progress.dismiss(); } + * + * } + */ + } + + // @Override + // protected void onPostExecute(SvdrpException exception) { + // for (SvdrpExceptionListener l : exceptionListeners) { + // l.svdrpEvent(exception.getEvent(), ex); + // } + // } + + @Override + public void svdrpEvent(final SvdrpEvent event) { + publishProgress(event);; + if(event == SvdrpEvent.FINISHED_SUCCESS){ + publishProgress(results); + } + } + + // @Override + // public void finished(ListResult> results) { + // publishProgress(results); + // } + + @Override + public void svdrpEvent(final SvdrpEvent event, final Throwable t) { + publishProgress(event, t); + } + + + @Override + public void svdrpEvent(final Result result) { + results.add(result); + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java index fcdf585..ba87100 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SvdrpClient.java @@ -35,14 +35,16 @@ public abstract class SvdrpClient<Result> { private InputStream inputStream; /** flag for stopping the current request */ private boolean abort; - /** listener */ + /** listener for events */ private final List<SvdrpListener> svdrpListeners = new ArrayList<SvdrpListener>(); - + /** listeners for results */ private final List<SvdrpResultListener<Result>> svdrpResultListeners = new ArrayList<SvdrpResultListener<Result>>(); - + /** listeners for exceptions */ private final List<SvdrpExceptionListener> svdrpExceptionListeners = new ArrayList<SvdrpExceptionListener>(); - + /** listeners for finished job */ private final List<SvdrpFinishedListener<Result>> svdrpFinishedListeners = new ArrayList<SvdrpFinishedListener<Result>>(); + /** listener for certificate problems set by caller */ + private final CertificateProblemListener certificateProblemListener; /** list of results */ // private final List<Result> results = new ArrayList<Result>(); @@ -85,8 +87,9 @@ public abstract class SvdrpClient<Result> { * @param prefs * Preferences */ - protected SvdrpClient() { + protected SvdrpClient(final CertificateProblemListener certificateProblemListener) { // results.clear(); + this.certificateProblemListener = certificateProblemListener; } /** @@ -206,7 +209,7 @@ public abstract class SvdrpClient<Result> { informListener(SvdrpEvent.CONNECTING); if (Preferences.get().isSecure()) { - socket = new MySSLSocketFactory(true).createSocket(); + socket = new MySSLSocketFactory(false, certificateProblemListener).createSocket(); } else { socket = new Socket(); } @@ -236,6 +239,11 @@ public abstract class SvdrpClient<Result> { } }, delay); informListener(SvdrpEvent.CONNECTED); + + // create streams + outputStream = socket.getOutputStream(); + inputStream = socket.getInputStream(); + } catch (final SocketTimeoutException sote) { Log.w(TAG, sote); if (abort) { @@ -255,12 +263,6 @@ public abstract class SvdrpClient<Result> { return false; } - // create streams - outputStream = socket.getOutputStream(); - inputStream = socket.getInputStream(); - // TODO http://projects.vdr-developer.org/issues/790 - // inputStream = new InflaterInputStream(socket.getInputStream()) - // password needed? informListener(SvdrpEvent.LOGIN); writeLine("passwd " + prefs.getPassword()); @@ -471,5 +473,4 @@ public abstract class SvdrpClient<Result> { listener.svdrpEvent(result); } } - } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java index e5b2b68..65a4d59 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/SwitchChannelClient.java @@ -11,45 +11,47 @@ import de.bjusystems.vdrmanager.R; */ public class SwitchChannelClient extends SvdrpClient<String> { - private Integer nr; - - private String chid; - - public SwitchChannelClient(Integer nr){ - this.nr = nr; - } - - public SwitchChannelClient(String chid){ - this.chid = chid; - } - - /** - * Constructor - */ - public SwitchChannelClient() { - super(); - } - - /** - * Starts the wakeup request - */ - @Override - public void run() { - if(nr != null){ - runCommand("SETCHANNEL " + String.valueOf(nr)); - } else { - runCommand("SETCHANNEL " + chid); - } - } - - @Override - public String parseAnswer(final String line) { - return line; - } - - @Override - public int getProgressTextId() { - return R.string.progress_switching; - } + private Integer nr; + + private String chid; + + public SwitchChannelClient(final Integer nr, final CertificateProblemListener certificateProblemListener){ + this(certificateProblemListener); + this.nr = nr; + } + + public SwitchChannelClient(final String chid, final CertificateProblemListener certificateProblemListener){ + this(certificateProblemListener); + this.chid = chid; + } + + /** + * Constructor + */ + public SwitchChannelClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + } + + /** + * Starts the wakeup request + */ + @Override + public void run() { + if(nr != null){ + runCommand("SETCHANNEL " + String.valueOf(nr)); + } else { + runCommand("SETCHANNEL " + chid); + } + } + + @Override + public String parseAnswer(final String line) { + return line; + } + + @Override + public int getProgressTextId() { + return R.string.progress_switching; + } }
\ No newline at end of file diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java index 6417541..4983745 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/svdrp/TimerClient.java @@ -14,37 +14,37 @@ import de.bjusystems.vdrmanager.data.Timer; */ public class TimerClient extends SvdrpClient<Timer> { - /** channel names for timer */ - Map<String, Channel> channels; - - /** - * Constructor - * @param host host - * @param port port - * @param ssl use ssl - */ - public TimerClient() { - super(); - this.channels = new HashMap<String, Channel>(); - } - - /** - * Starts the EPG request - * @param parameter parameter for lste - */ - @Override - public synchronized void run() { - runCommand("timers"); - } - - @Override - public Timer parseAnswer(final String line) { - return new Timer(line); - } - - @Override - public int getProgressTextId() { - return R.string.progress_timers_loading; - } + /** channel names for timer */ + Map<String, Channel> channels; + + /** + * Constructor + * @param host host + * @param port port + * @param ssl use ssl + */ + public TimerClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + this.channels = new HashMap<String, Channel>(); + } + + /** + * Starts the EPG request + * @param parameter parameter for lste + */ + @Override + public synchronized void run() { + runCommand("timers"); + } + + @Override + public Timer parseAnswer(final String line) { + return new Timer(line); + } + + @Override + public int getProgressTextId() { + return R.string.progress_timers_loading; + } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java index 12068fc..231554a 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/utils/wakeup/WakeupUrlClient.java @@ -1,8 +1,8 @@ package de.bjusystems.vdrmanager.utils.wakeup; import de.bjusystems.vdrmanager.data.WakeupState; +import de.bjusystems.vdrmanager.utils.svdrp.CertificateProblemListener; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpClient; -import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; /** * Class for retrieving informations about the running program @@ -11,43 +11,43 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; */ public class WakeupUrlClient extends SvdrpClient<WakeupState> { - private WakeupState state; - - /** - * Constructor - */ - public WakeupUrlClient() { - super(); - } - - /** - * Starts the wakeup request - */ - @Override - public void run() { - runCommand("wake"); - } - - @Override - public WakeupState parseAnswer(final String line) { - - if (line.startsWith("200")) { - state = WakeupState.OK; - } else if (line.startsWith("400")) { - state = WakeupState.FAILED; - } else { - state = WakeupState.ERROR; - } - return state; - } - - @Override - public int getProgressTextId() { - return 0; - } - - public WakeupState getState() { - return state; - } + private WakeupState state; + + /** + * Constructor + */ + public WakeupUrlClient(final CertificateProblemListener certificateProblemListener) { + super(certificateProblemListener); + } + + /** + * Starts the wakeup request + */ + @Override + public void run() { + runCommand("wake"); + } + + @Override + public WakeupState parseAnswer(final String line) { + + if (line.startsWith("200")) { + state = WakeupState.OK; + } else if (line.startsWith("400")) { + state = WakeupState.FAILED; + } else { + state = WakeupState.ERROR; + } + return state; + } + + @Override + public int getProgressTextId() { + return 0; + } + + public WakeupState getState() { + return state; + } }
\ No newline at end of file |