99import android .support .v7 .widget .GridLayoutManager ;
1010import android .support .v7 .widget .RecyclerView ;
1111import android .util .Log ;
12+ import android .view .KeyEvent ;
1213import android .view .LayoutInflater ;
1314import android .view .Menu ;
1415import android .view .MenuInflater ;
1516import android .view .MenuItem ;
1617import android .view .View ;
1718import android .view .ViewGroup ;
19+ import android .view .inputmethod .EditorInfo ;
1820import android .view .inputmethod .InputMethodManager ;
1921import android .widget .EditText ;
2022import android .widget .ImageButton ;
23+ import android .widget .TextView ;
2124import android .widget .Toast ;
2225
2326import com .parse .FindCallback ;
@@ -125,6 +128,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
125128
126129 addNotesButton = (FloatingActionButton ) rootView .findViewById (R .id .notes_button_add );
127130 searchEdTxt = (EditText ) rootView .findViewById (R .id .notes_search );
131+ searchEdTxt .setOnEditorActionListener (new TextView .OnEditorActionListener () {
132+ @ Override
133+ public boolean onEditorAction (TextView v , int actionId , KeyEvent event ) {
134+
135+ if (actionId == EditorInfo .IME_ACTION_SEARCH ) {
136+ performSearch (v .getText ().toString ());
137+ ((InputMethodManager ) getActivity ().getSystemService (Context .INPUT_METHOD_SERVICE ))
138+ .hideSoftInputFromWindow ((v ).getWindowToken (),0 );
139+ return true ;
140+ }
141+
142+ return false ;
143+ }
144+ });
128145 searchButton = (ImageButton ) rootView .findViewById (R .id .searchblahblah );
129146 searchButton .setOnClickListener (new View .OnClickListener () {
130147 @ Override
@@ -179,13 +196,55 @@ public void goToUploadFragment() {
179196 }
180197
181198 public void getNotes () {
182- ParseQuery <ParseObject > query = new ParseQuery <ParseObject >(
199+ clear_lists ();
200+ ParseQuery <ParseObject > query = new ParseQuery <>(
201+ "Notes" );
202+
203+ query .orderByDescending ("createdAt" );
204+ query .setCachePolicy (ParseQuery .CachePolicy .NETWORK_ELSE_CACHE );
205+ query .findInBackground (new FindCallback <ParseObject >() {
206+ @ Override
207+ public void done (List <ParseObject > parseObjects , ParseException e ) {
208+ for (ParseObject notes : parseObjects ) {
209+
210+ notesBranchName .add ((String ) notes .get ("branchName" ));
211+ notesSubjectName .add ((String ) notes .get ("subjectName" ));
212+ notesCollegeName .add ((String ) notes .get ("collegeName" ));
213+ notesTopicName .add ((String ) notes .get ("topicName" ));
214+ uploadedBy .add ((String ) notes .get ("userName" ));
215+ notesFirstImage .add ((ArrayList <ParseFile >) notes .get ("notesImages" ));
216+
217+
218+ }
219+ notesCustomGridViewAdapter = new NotesCustomGridViewAdapter (getActivity (), notesCollegeName ,
220+ notesBranchName , notesTopicName , notesSubjectName , notesFirstImage , uploadedBy );
221+
222+ mRecyclerView .setAdapter (notesCustomGridViewAdapter );
223+ }
224+
225+ });
226+ }
227+
228+ public void performSearch (final String s ) {
229+
230+ if (s .equals ("" )) {
231+ Toast .makeText (getActivity (),"Please Enter Something" ,Toast .LENGTH_SHORT ).show ();
232+ return ;
233+ }
234+ ParseQuery <ParseObject > query = new ParseQuery <>(
183235 "Notes" );
236+
237+ clear_lists ();
238+ query .whereContains ("topicName" ,s );
184239 query .orderByDescending ("createdAt" );
240+
185241 query .setCachePolicy (ParseQuery .CachePolicy .NETWORK_ELSE_CACHE );
186242 query .findInBackground (new FindCallback <ParseObject >() {
187243 @ Override
188244 public void done (List <ParseObject > parseObjects , ParseException e ) {
245+
246+ // Log.d("Search notes","result size : "+String.valueOf( parseObjects.size())+" "+s);
247+
189248 for (ParseObject notes : parseObjects ) {
190249
191250 notesBranchName .add ((String ) notes .get ("branchName" ));
@@ -201,11 +260,20 @@ public void done(List<ParseObject> parseObjects, ParseException e) {
201260 notesBranchName , notesTopicName , notesSubjectName , notesFirstImage , uploadedBy );
202261
203262 mRecyclerView .setAdapter (notesCustomGridViewAdapter );
263+ // notesCustomGridViewAdapter.notifyDataSetChanged();
204264 }
205265
206266 });
207267 }
208268
269+ private void clear_lists () {
270+ notesBranchName .clear ();
271+ notesSubjectName .clear ();
272+ notesCollegeName .clear ();
273+ notesTopicName .clear ();
274+ uploadedBy .clear ();
275+ notesFirstImage .clear ();
276+ }
209277 @ Override
210278 public void onCreateOptionsMenu (Menu menu , MenuInflater inflater ) {
211279 super .onCreateOptionsMenu (menu , inflater );
0 commit comments