1010
1111package com .cmput301f17t11 .cupofjava .Views ;
1212
13+ import android .content .Context ;
1314import android .content .DialogInterface ;
1415import android .content .Intent ;
1516import android .location .Location ;
@@ -133,7 +134,7 @@ public void onClick(View v) {
133134 @ Override
134135 public void onClick (final View v ) {
135136 AlertDialog .Builder builder = new AlertDialog .Builder (getContext ());
136- builder .setTitle ("Filter Events by Comment " ).setMessage ("Enter Comment to search " );
137+ builder .setTitle ("Search events by comment " ).setMessage ("Enter comment: " );
137138
138139 final EditText input = new EditText (getContext ());
139140 LinearLayout .LayoutParams layoutParams = new LinearLayout .LayoutParams (
@@ -147,6 +148,20 @@ public void onClick(final View v) {
147148 public void onClick (DialogInterface dialog , int which ) {
148149
149150 String comment = input .getText ().toString ();
151+ if (comment .length () == 0 ){
152+ String text = "Error: Cannot search for empty string!" ;
153+ int length = Toast .LENGTH_SHORT ;
154+ Context context = getContext ();
155+ Toast toast = Toast .makeText (context ,text , length );
156+ toast .show ();
157+ dialog .dismiss ();
158+ }
159+
160+ events = EventFilteringHelper .filterByComment (events , comment );
161+ events = EventFilteringHelper .reverseChronological (events );
162+ updateTextView (events .size ());
163+ updateListView (events );
164+
150165 }
151166 })
152167 .setNegativeButton ("CANCEL" , new DialogInterface .OnClickListener () {
@@ -367,20 +382,4 @@ public int compare(HabitEvent o1, HabitEvent o2) {
367382 });
368383 return events ;
369384 }
370-
371-
372- /* Not Working
373- public ArrayList<HabitEvent> filterByComment(ArrayList<HabitEvent> events, String comment) {
374- ArrayList<HabitEvent> finalEvents = new ArrayList<>();
375-
376- for (int i=0; i < events.size(); i++) {
377- HabitEvent event = events.get(i);
378- String checkComment = event.getComment();
379- if (checkComment.contains(comment)) {
380- finalEvents.add(event);
381- }
382- }
383- return finalEvents;
384- }
385- */
386385}
0 commit comments