fully removed old DataProvider for now, manage queries, clean up old database stuff

This commit is contained in:
Thialfihar
2010-05-28 07:04:01 +00:00
parent b943f706b6
commit eed42b2e34
19 changed files with 53 additions and 713 deletions

View File

@@ -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;
}
@@ -297,6 +303,13 @@ public class MainActivity extends BaseActivity {
minflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@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();