Skip to content

Commit

Permalink
made the filters work
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Jun 30, 2011
1 parent ac382fb commit 8326162
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/org/splitbrain/giraffe/MainActivity.java
Expand Up @@ -30,18 +30,15 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
this.context = this;

prefs = PreferenceManager.getDefaultSharedPreferences(this);
setFilter(0);


db = new DBAdapter(this);
db.openReadOnly();
Cursor cursor = db.getEventsCursor(null);
startManagingCursor(cursor);


prefs = PreferenceManager.getDefaultSharedPreferences(this);
Cursor cursor = null;
EventItemCursorAdapter listAdapter = new EventItemCursorAdapter(this,cursor);
setListAdapter(listAdapter);
setFilter(0);


ImageView iv;
iv = (ImageView) findViewById(R.id.filterbtn_fav);
Expand All @@ -58,13 +55,16 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onResume() {
EventItemCursorAdapter eica = (EventItemCursorAdapter) getListAdapter();
eica.getCursor().requery();
Cursor cursor = eica.getCursor();
if(cursor != null){
cursor.requery();
}
super.onResume();
}


/**
* Set the filter state
* Set the filter state and initialize the appropriate cursor
*
* @param filter 0 (for init) 1 (for favs) 2 (for future)
*/
Expand Down Expand Up @@ -108,16 +108,20 @@ private void setFilter(int filter){
// create WHERE clause
String where = "";
if((filterstate & 1) > 0){
where += db.FAVORITE+" > 0 ";
where += DBAdapter.FAVORITE+" > 0 ";
}
if((filterstate & 2) > 0){
if(where.length() > 0){
where += " AND ";
}
where += "("+db.STARTS+" > NOW() OR "+db.ENDS+" > NOW() )";
where += "(datetime("+DBAdapter.STARTS+",'unixexpoch') > datetime('now') OR datetime("+DBAdapter.ENDS+",'unixepoch') > datetime('now') )";
}

// FIXME find out how to apply filter
// apply the filter
Cursor cursor = db.getEventsCursor(where);
startManagingCursor(cursor);
EventItemCursorAdapter eica = (EventItemCursorAdapter) getListAdapter();
eica.changeCursor(cursor);
}


Expand Down

0 comments on commit 8326162

Please sign in to comment.