Skip to content

Commit

Permalink
user can now select and delete multiple quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
chan96 committed Dec 28, 2013
1 parent b3d5853 commit 7cc988e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/com/example/brainyquote/FavQuotesScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.util.SparseBooleanArray;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.Menu;
Expand Down Expand Up @@ -95,11 +96,23 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.delete:
String quoteText = ((TextView) findViewById(R.id.quoteTextView)).getText().toString();
//Finds all positions of selected items in listview and
//gets text at each position. Next, delete the quotes using
//their text and the quote directory.
SparseBooleanArray selectedItems = list.getCheckedItemPositions();
for (int i = 0; i < selectedItems.size(); i++) {
if (selectedItems.get(i)) {
String quoteText = (list.getItemAtPosition(i).toString());
String[] quoteAndDir = {quoteText, quotesDir};
DeleteFavTask favDelete = new DeleteFavTask();
favDelete.execute(quoteAndDir);
}
}
/*String quoteText = ((TextView) findViewById(R.id.quoteTextView)).getText().toString();
String[] quoteAndDir = {quoteText, quotesDir};
DeleteFavTask favDelete = new DeleteFavTask();
favDelete.execute(quoteAndDir);
new GetFavQuotesTask().execute();
favDelete.execute(quoteAndDir);*/

mode.finish(); // Action picked, so close the CAB
return true;
case R.id.deleteAll:
Expand All @@ -123,6 +136,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
public void onDestroyActionMode(ActionMode mode) {
// Here you can make any necessary updates to the activity when
// the CAB is removed. By default, selected items are deselected/unchecked.
new GetFavQuotesTask().execute();
}

@Override
Expand Down

0 comments on commit 7cc988e

Please sign in to comment.