diff options
author | Thialfihar <thialfihar@gmail.com> | 2010-05-28 07:04:01 +0000 |
---|---|---|
committer | Thialfihar <thialfihar@gmail.com> | 2010-05-28 07:04:01 +0000 |
commit | eed42b2e34d6ba7e6eda43640eb3bb1555d9e24f (patch) | |
tree | 768ceeb8a27bf1c850b9ac986506461f8e3c271e /src/org/thialfihar/android/apg/MainActivity.java | |
parent | b943f706b60538bc343e643879a607b389ebb1ca (diff) | |
download | open-keychain-eed42b2e34d6ba7e6eda43640eb3bb1555d9e24f.tar.gz open-keychain-eed42b2e34d6ba7e6eda43640eb3bb1555d9e24f.tar.bz2 open-keychain-eed42b2e34d6ba7e6eda43640eb3bb1555d9e24f.zip |
fully removed old DataProvider for now, manage queries, clean up old database stuff
Diffstat (limited to 'src/org/thialfihar/android/apg/MainActivity.java')
-rw-r--r-- | src/org/thialfihar/android/apg/MainActivity.java | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/org/thialfihar/android/apg/MainActivity.java b/src/org/thialfihar/android/apg/MainActivity.java index a4d584304..cdb79f1bf 100644 --- a/src/org/thialfihar/android/apg/MainActivity.java +++ b/src/org/thialfihar/android/apg/MainActivity.java @@ -47,6 +47,8 @@ import android.widget.AdapterView.OnItemClickListener; public class MainActivity extends BaseActivity { private ListView mAccounts = null; + private AccountListAdapter mListAdapter = null; + private Cursor mAccountCursor; @Override public void onCreate(Bundle savedInstanceState) { @@ -95,22 +97,22 @@ public class MainActivity extends BaseActivity { } }); - Cursor accountCursor = managedQuery(Accounts.CONTENT_URI, null, null, null, null); + mAccountCursor = + Apg.getDatabase().db().query(Accounts.TABLE_NAME, + new String[] { + Accounts._ID, + Accounts.NAME, + }, null, null, null, null, Accounts.NAME + " ASC"); + startManagingCursor(mAccountCursor); - mAccounts.setAdapter(new AccountListAdapter(this, accountCursor)); + mListAdapter = new AccountListAdapter(this, mAccountCursor); + mAccounts.setAdapter(mListAdapter); mAccounts.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int index, long id) { - Cursor cursor = - managedQuery(Uri.withAppendedPath(Accounts.CONTENT_URI, "" + id), null, - null, null, null); - if (cursor != null && cursor.getCount() > 0) { - cursor.moveToFirst(); - int nameIndex = cursor.getColumnIndex(Accounts.NAME); - String accountName = cursor.getString(nameIndex); - startActivity(new Intent(MainActivity.this, MailListActivity.class) + String accountName = (String) mAccounts.getSelectedItem(); + startActivity(new Intent(MainActivity.this, MailListActivity.class) .putExtra("account", accountName)); - } } }); registerForContextMenu(mAccounts); @@ -154,9 +156,10 @@ public class MainActivity extends BaseActivity { ContentValues values = new ContentValues(); values.put(Accounts.NAME, accountName); try { - MainActivity.this.getContentResolver() - .insert(Accounts.CONTENT_URI, - values); + Apg.getDatabase().db().insert(Accounts.TABLE_NAME, + Accounts.NAME, values); + mAccountCursor.requery(); + mListAdapter.notifyDataSetChanged(); } catch (SQLException e) { Toast.makeText(MainActivity.this, getString(R.string.errorMessage, @@ -277,8 +280,11 @@ public class MainActivity extends BaseActivity { switch (menuItem.getItemId()) { case Id.menu.delete: { - Uri uri = Uri.withAppendedPath(Accounts.CONTENT_URI, "" + info.id); - this.getContentResolver().delete(uri, null, null); + Apg.getDatabase().db().delete(Accounts.TABLE_NAME, + Accounts._ID + " = ?", + new String[] { "" + info.id }); + mAccountCursor.requery(); + mListAdapter.notifyDataSetChanged(); return true; } @@ -298,6 +304,13 @@ public class MainActivity extends BaseActivity { } @Override + public Object getItem(int position) { + Cursor c = getCursor(); + c.moveToPosition(position); + return c.getString(c.getColumnIndex(Accounts.NAME)); + } + + @Override public int getCount() { return super.getCount(); } |