Skip to content

Commit

Permalink
Checked enzymes are stored in adapter now and correctly retrieved - n…
Browse files Browse the repository at this point in the history
…o more missing enzymes
  • Loading branch information
lpfann committed Jul 10, 2015
1 parent 4ab5881 commit 0d9de5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
15 changes: 9 additions & 6 deletions app/src/main/java/unibi/com/medicapp/ui/MainSearchFragment.java
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Set;

import butterknife.ButterKnife;
import butterknife.InjectView;
Expand Down Expand Up @@ -169,16 +170,18 @@ private void initSubstanceList() {

/**
* Retrieves the selected Enzymes in the list for the main search
*
* uses data from enzyme list adapter
* @return checked Enzyme IDs
*/
public ArrayList<Enzyme> getCheckedEnzymes() {
long[] checkedItemIds = enzymeListView.getCheckedItemIds();
Set<Long> ids = adapter.getChecked().keySet();
selectedEnzymeIDs = new ArrayList<>();
for (long checkedItemId : checkedItemIds) {
Cursor c = db.getEnzyme(checkedItemId);
Enzyme enz = new Enzyme(c.getString(c.getColumnIndex(DatabaseHelperClass.ISOENZYME.NAME)), checkedItemId);
selectedEnzymeIDs.add(enz);
for (long id : ids) {
if (adapter.getChecked().get(id)) {
Cursor c = db.getEnzyme(id);
Enzyme enz = new Enzyme(c.getString(c.getColumnIndex(DatabaseHelperClass.ISOENZYME.NAME)), id);
selectedEnzymeIDs.add(enz);
}
}
return selectedEnzymeIDs;

Expand Down
Expand Up @@ -17,7 +17,7 @@
* Enzymes can be selected which is handled here.
*/
public class EnzymeCursorAdapter extends SimpleCursorAdapter {
HashMap<Long, Boolean> checked;
private HashMap<Long, Boolean> checked;
private Cursor c;

public EnzymeCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags, ArrayList<Enzyme> checkedList) {
Expand All @@ -28,6 +28,7 @@ public EnzymeCursorAdapter(Context context, int layout, Cursor c, String[] from,
// Set local field to selected items
for (Enzyme e : checkedList) {
checked.put(e.id, true);

}

}
Expand Down Expand Up @@ -68,4 +69,13 @@ public void enzymeClicked(int pos) {
checked.put(getItemId(pos), true);
}
}

/**
* Getting Checked items from adapter
*
* @return
*/
public HashMap<Long, Boolean> getChecked() {
return checked;
}
}

0 comments on commit 0d9de5b

Please sign in to comment.