Skip to content

Commit 385859a

Browse files
committed
Merge pull request #31 from teamOSC/notes
le wild rudimentay notes search appears
2 parents 93c6177 + 4e4bbfd commit 385859a

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

app/src/main/java/in/tosc/studddin/fragments/notes/NotesSearchFragment.java

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
import android.support.v7.widget.GridLayoutManager;
1010
import android.support.v7.widget.RecyclerView;
1111
import android.util.Log;
12+
import android.view.KeyEvent;
1213
import android.view.LayoutInflater;
1314
import android.view.Menu;
1415
import android.view.MenuInflater;
1516
import android.view.MenuItem;
1617
import android.view.View;
1718
import android.view.ViewGroup;
19+
import android.view.inputmethod.EditorInfo;
1820
import android.view.inputmethod.InputMethodManager;
1921
import android.widget.EditText;
2022
import android.widget.ImageButton;
23+
import android.widget.TextView;
2124
import android.widget.Toast;
2225

2326
import 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);

app/src/main/res/layout/fragment_notes_search.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848

4949
<EditText
5050
android:id="@+id/notes_search"
51+
android:imeOptions="actionSearch"
5152
android:layout_width="match_parent"
5253
android:layout_height="match_parent"
5354
android:layout_gravity="center_vertical"
5455
android:background="@android:color/transparent"
5556
android:gravity="center_vertical"
5657
android:hint="Search here"
57-
android:imeOptions="actionDone"
5858
android:paddingRight="60dp"
5959
android:singleLine="true" />
6060
</LinearLayout>

0 commit comments

Comments
 (0)