diff options
author | lado <herrlado@gmail.com> | 2012-01-22 15:23:58 +0100 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2012-01-22 15:23:58 +0100 |
commit | f369f1621503bfec9b524dd7e8112a15a418c6a7 (patch) | |
tree | 83b42cacab35d0737b0f0c911153e84b4e943d0b /vdrmanager/src/de/bjusystems | |
parent | 72ccd948f28c90074b17a0fd7061a1d8f9917297 (diff) | |
download | vdr-manager-f369f1621503bfec9b524dd7e8112a15a418c6a7.tar.gz vdr-manager-f369f1621503bfec9b524dd7e8112a15a418c6a7.tar.bz2 |
better handling of settings. Perhaps a fix for a market fc with cursor
Diffstat (limited to 'vdrmanager/src/de/bjusystems')
3 files changed, 87 insertions, 53 deletions
diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/app/Intents.java b/vdrmanager/src/de/bjusystems/vdrmanager/app/Intents.java index ecac814..f5740e1 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/app/Intents.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/app/Intents.java @@ -12,4 +12,6 @@ public interface Intents { public static final int EDIT_VDR = 2; + public static final String EMPTY_CONFIG = "EMPTY_CONFIG"; + } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrListActivity.java index 0899ee2..0ce3d63 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrListActivity.java @@ -5,6 +5,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -18,81 +19,94 @@ import de.bjusystems.vdrmanager.app.Intents; import de.bjusystems.vdrmanager.data.Preferences; import de.bjusystems.vdrmanager.data.db.OrmDatabaseHelper; -public class VdrListActivity extends OrmLiteBaseListActivity<OrmDatabaseHelper> implements OnItemClickListener, OnItemLongClickListener { +public class VdrListActivity extends OrmLiteBaseListActivity<OrmDatabaseHelper> + implements OnItemClickListener, OnItemLongClickListener { + + private static final String TAG = VdrListActivity.class.getName(); SimpleCursorAdapter adapter = null; - + Cursor cursor; - + String[] listItems = {}; + private boolean emptyConfig = false; + private void initCursor() { - if(cursor != null){ - if(!cursor.isClosed()){ - cursor.close(); - } - } + //if (cursor != null) { + //if (!cursor.isClosed()) { + //cursor.close(); +// } + //} try { - cursor = getHelper().getVdrCursor();; + cursor = getHelper().getVdrCursor(); startManagingCursor(cursor); } catch (Exception ex) { - throw new RuntimeException(ex); + Log.w(TAG,ex); } } + private void populateIntent(){ + emptyConfig = getIntent().getBooleanExtra(Intents.EMPTY_CONFIG, Boolean.FALSE); + } + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - setContentView(R.layout.vdr_list_add_delete); - - findViewById(R.id.add_item).setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - editVdr(null); - } - }); - // PreparedQuery<Vdr> query = qb.prepare(); - // - // AndroidCompiledStatement compiledStatement = - // (AndroidCompiledStatement)query.compile(getHelper().getConnectionSource().getReadOnlyConnection()); - // Cursor cursor = compiledStatement.getCursor(); - // - // - // getHelper().getConnectionSource(). -// View view = findViewById(R.id.add_item); - + populateIntent(); + + setContentView(R.layout.vdr_list_add_delete); + findViewById(R.id.add_item).setOnClickListener( + new View.OnClickListener() { + public void onClick(View v) { + editVdr(null); + } + }); initCursor(); - adapter= new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2, cursor, new String[] {"name","host"}, new int[] { android.R.id.text1, android.R.id.text2 }); + adapter = new SimpleCursorAdapter(this, + android.R.layout.simple_list_item_2, cursor, new String[] { + "name", "host" }, new int[] { android.R.id.text1, + android.R.id.text2 }); setListAdapter(adapter); registerForContextMenu(getListView()); getListView().setOnItemClickListener(this); getListView().setOnItemLongClickListener(this); } - /* (non-Javadoc) - * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long) + /* + * (non-Javadoc) + * + * @see + * android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget + * .AdapterView, android.view.View, int, long) */ - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + public void onItemClick(AdapterView<?> parent, View view, int position, + long id) { editVdr(Long.valueOf(id).intValue()); } /** * Start {@link VdrPreferencesActivity} to create or edit a vdr - * @param id may be null. Then a new vdr is created + * + * @param id + * may be null. Then a new vdr is created */ - private void editVdr(Integer id){ + private void editVdr(Integer id) { Intent intent = new Intent(this, VdrPreferencesActivity.class); intent.putExtra(Intents.VDR_ID, id); startActivityForResult(intent, Intents.EDIT_VDR); } - - /* (non-Javadoc) - * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) + + /* + * (non-Javadoc) + * + * @see android.app.Activity#onActivityResult(int, int, + * android.content.Intent) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { @@ -104,14 +118,24 @@ public class VdrListActivity extends OrmLiteBaseListActivity<OrmDatabaseHelper> refresh(); return; } - + + } + + @Override + protected void onResume() { + super.onResume(); } - @Override public void onBackPressed() { Preferences.init(this); - super.onBackPressed(); + if (emptyConfig) { + Intent intent = new Intent(this, VdrManagerActivity.class); + startActivity(intent); + finish(); + } else { + super.onBackPressed(); + } } /** @@ -122,21 +146,25 @@ public class VdrListActivity extends OrmLiteBaseListActivity<OrmDatabaseHelper> adapter.changeCursor(cursor); } - public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) { + public boolean onItemLongClick(AdapterView<?> parent, View view, + final int position, final long id) { new AlertDialog.Builder(this) - .setMessage(R.string.vdr_device_delete_qeustion)// - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ - public void onClick(DialogInterface dialog, int which) { - if(getHelper().getVdrDAO().deleteById((int)id) > 0 ){ - initCursor(); - adapter.changeCursor(cursor); - } - - }})// - .setNegativeButton(android.R.string.cancel, null)// - .create()// - .show(); + .setMessage(R.string.vdr_device_delete_qeustion)// + .setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int which) { + if (getHelper().getVdrDAO() + .deleteById((int) id) > 0) { + refresh(); + } + + } + })// + .setNegativeButton(android.R.string.cancel, null)// + .create()// + .show(); return false; } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java index de70e2c..bb6173c 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VdrManagerActivity.java @@ -33,6 +33,10 @@ public class VdrManagerActivity extends Activity implements OnClickListener { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(Preferences.get().getCurrentVdr() == null){ + finish(); + return; + } Preferences.setLocale(this); // this.getActionBar().setDisplayShowCustomEnabled(true); // this.getActionBar().setDisplayShowTitleEnabled(false); |