summaryrefslogtreecommitdiff
path: root/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
diff options
context:
space:
mode:
authorlado <herrlado@gmail.com>2011-11-01 16:07:12 +0100
committerlado <herrlado@gmail.com>2011-11-01 16:07:12 +0100
commit22805607a538bd4df422242e2725c1c02807dd8a (patch)
tree545813c47685273e7f0368a06e03d96c0c9e07a7 /vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
parent70185fdadd3573dcd30b5daf9d7895a6e25bf536 (diff)
downloadvdr-manager-22805607a538bd4df422242e2725c1c02807dd8a.tar.gz
vdr-manager-22805607a538bd4df422242e2725c1c02807dd8a.tar.bz2
big refactoring
Diffstat (limited to 'vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java')
-rw-r--r--vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java144
1 files changed, 117 insertions, 27 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
index 5e2e49c..f4633b5 100644
--- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
+++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/BaseActivity.java
@@ -2,6 +2,8 @@ package de.bjusystems.vdrmanager.gui;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.Context;
+import android.net.ConnectivityManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -13,51 +15,46 @@ import android.widget.ViewFlipper;
import de.bjusystems.vdrmanager.R;
import de.bjusystems.vdrmanager.app.VdrManagerApp;
import de.bjusystems.vdrmanager.data.Channel;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpAsyncListener;
+import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent;
import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException;
-public abstract class BaseActivity<T extends ListView> extends Activity
- implements OnClickListener {
+public abstract class BaseActivity<Result, T extends ListView> extends Activity
+ implements OnClickListener, SvdrpAsyncListener<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 SvdrpProgressDialog progress;
+
abstract protected int getMainLayout();
- public void svdrpException(final SvdrpException exception) {
- // Log.w(TAG, exception);
- alert(getString(R.string.vdr_error_text, exception.getMessage()));
- }
-
+
protected void switchNoConnection() {
- View view = findViewById(R.id.main_content);
- if (view != null) {
- view.setVisibility(View.GONE);
+ if (flipper == null) {
+ return;
}
- view = findViewById(R.id.no_connection_layout);
- if (view != null) {
- view.setVisibility(View.VISIBLE);
- }
- Button b = (Button) findViewById(R.id.retry_button);
- b.setOnClickListener(this);
+ flipper.setDisplayedChild(1);
+ }
+
+ 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) {
- View view = findViewById(R.id.no_connection_layout);
- if (view != null) {
- view.setVisibility(View.GONE);
- }
- view = findViewById(R.id.main_content);
- if (view != null) {
- view.setVisibility(View.VISIBLE);
- }
retry();
}
}
@@ -83,7 +80,7 @@ public abstract class BaseActivity<T extends ListView> extends Activity
public boolean onCreateOptionsMenu(final Menu menu) {
MenuItem item;
item = menu.add(MENU_GROUP_REFRESH, MENU_REFRESH, 0, R.string.refresh);
- item.setIcon(android.R.drawable.ic_menu_rotate);
+ item.setIcon(R.drawable.ic_menu_refresh);
item.setAlphabeticShortcut('r');
return true;
}
@@ -104,7 +101,7 @@ public abstract class BaseActivity<T extends ListView> extends Activity
}
}
- protected void setAsCurrent(Channel channel) {
+ protected void setCurrent(Channel channel) {
getApp().setCurrentChannel(channel);
}
@@ -127,6 +124,26 @@ public abstract class BaseActivity<T extends ListView> extends Activity
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
+ protected boolean noConnection(SvdrpEvent event) {
+ switch (event) {
+ 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) {
new AlertDialog.Builder(this)//
.setMessage(msg)//
@@ -152,4 +169,77 @@ public abstract class BaseActivity<T extends ListView> extends Activity
int index;
int top;
+ protected boolean checkInternetConnection() {
+ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+ // test for connection
+ if (cm.getActiveNetworkInfo() != null
+ && cm.getActiveNetworkInfo().isAvailable()
+ && cm.getActiveNetworkInfo().isConnected()) {
+ return true;
+ }
+ return false;
+ }
+
+ public void svdrpEvent(final SvdrpEvent event, final Result result) {
+
+ switch (event) {
+
+ case ABORTED:
+ alert(R.string.aborted);
+ break;
+ case ERROR:
+ alert(R.string.epg_client_errors);
+ // say(R.string.epg_client_errors);
+ // dismiss(progress);
+ break;
+ case CONNECTING:
+ break;
+ case CONNECTED:
+ connected();
+ break;
+ case CONNECT_ERROR:
+ case FINISHED_ABNORMALY:
+ case LOGIN_ERROR:
+ noConnection(event);
+ break;
+ case CACHE_HIT:
+ cacheHit();
+ return;
+ case FINISHED_SUCCESS:
+ if (finishedSuccess() == false) {
+ say(R.string.epg_no_items);
+ } else {
+ restoreViewSelection();
+ }
+ break;
+ case RESULT_RECEIVED:
+ resultReceived(result);
+ break;
+ }
+ }
+
+ protected void cacheHit() {
+
+ }
+
+ /**
+ * @return false, if no results found
+ */
+ protected abstract boolean finishedSuccess();
+
+ /**
+ * @param result
+ */
+ protected abstract void resultReceived(Result result);
+
+ protected void connected() {
+
+ }
+
+ public void svdrpException(final SvdrpException exception) {
+ progress.svdrpException(exception);
+ // Log.w(TAG, exception);
+ alert(getString(R.string.vdr_error_text, exception.getMessage()));
+ }
+
}