ExplorFragment Doc

This commit is contained in:
Sagi Dayan 2016-07-10 17:24:15 +03:00
parent 22bb04b0d2
commit 1e092db5f7

View file

@ -31,21 +31,18 @@ import java.util.List;
/**
* A simple {@link Fragment} subclass.
* The Explore Fragment - See all public notes
*/
public class ExploreFragment extends Fragment {
private static final String TAG = "[TSN/Explore]";
// protected final User user = ((MainActivity) getActivity()).getUser();
protected User user;
protected MainActivity parent;
private ListAdapter noteListAdapter;
private List<Note> notes;
protected ListView list_notes;
private ImageButton dateFilter;
private ImageButton locationFilter;
// private ImageButton userFilter;
private Button map_small_filter;
private Button map_medium_filter;
private Button map_large_filter;
@ -59,6 +56,7 @@ public class ExploreFragment extends Fragment {
public ExploreFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -82,16 +80,11 @@ public class ExploreFragment extends Fragment {
list_notes.setOnItemClickListener(new ItemClickedListener());
dateFilterSelection = Utils.MONTH_MILI;
locationFilterSelection = Utils.DISTANCE_LONG;
dateFilter = (ImageButton) view.findViewById(R.id.explore_date_filter);
locationFilter = (ImageButton) view.findViewById(R.id.explore_location_filter);
map_small_filter = (Button) view.findViewById(R.id.explore_small_filter);
map_medium_filter = (Button) view.findViewById(R.id.explore_medium_filter);
map_large_filter = (Button) view.findViewById(R.id.explore_large_filter);
map_small_filter.setOnClickListener(button1ClickListener);
map_medium_filter.setOnClickListener(button2ClickListener);
map_large_filter.setOnClickListener(button3ClickListener);
@ -108,8 +101,6 @@ public class ExploreFragment extends Fragment {
exploreFilters.setVisibility(View.VISIBLE);
dateFilterIsVisible = true;
locationFilterIsVisible = false;
// userFilterIsVisible = false;
// set text button in the right filter string
map_small_filter.setText(R.string.day);
map_medium_filter.setText(R.string.week);
@ -129,8 +120,6 @@ public class ExploreFragment extends Fragment {
exploreFilters.setVisibility(View.VISIBLE);
locationFilterIsVisible = true;
dateFilterIsVisible = false;
// userFilterIsVisible = false;
// set text button in the right filter string
map_small_filter.setText(R.string.shortDistance);
map_medium_filter.setText(R.string.mediumDistance);
@ -139,10 +128,6 @@ public class ExploreFragment extends Fragment {
setButtonsColor();
}
});
// TODO: choose a default filter for openning explore mode
try {
getAllNotes();
} catch (JSONException e) {
@ -151,7 +136,11 @@ public class ExploreFragment extends Fragment {
return view;
}
/**
* This function will retrieve all the Public Notes from our Server.
* And will throw JSON exception on error
* @throws JSONException
*/
public void getAllNotes() throws JSONException {
Utils.showLoadingDialog(parent, "Exploring...", "Finding some new interesting notes just for you");
Log.d(TAG, "url: " + Utils.BASE_URL + "/note/getPublic");
@ -161,6 +150,9 @@ public class ExploreFragment extends Fragment {
VolleyUtilSingleton.getInstance(getActivity()).post(url, payload, getNotesSuccessListener, Utils.genericErrorListener);
}
/**
* The Success callback for our HTTP API call
*/
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
@ -176,7 +168,6 @@ public class ExploreFragment extends Fragment {
time.setTime(noteObject.getLong("created_at"));
notes.add(Utils.getNoteFromJsonObj(noteObject, time));
}
// list_notes.setAdapter(noteListAdapter);
updateShowedNotes();
Utils.dismissLoadingDialog();
} catch (Exception e) {
@ -197,15 +188,12 @@ public class ExploreFragment extends Fragment {
final Dialog noteViewDialog = new Dialog(getActivity());
noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
noteViewDialog.setContentView(R.layout.note_display_full);
// noteViewDialog.setTitle("You wrote...");
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(noteViewDialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
noteViewDialog.show();
// dialog.getWindow().setAttributes(lp);
//get note_view_full layout elements
final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview);
@ -372,6 +360,9 @@ public class ExploreFragment extends Fragment {
}
}
/**
* Will update the notes within the list view
*/
public void updateShowedNotes() {
List<Note> presentedNotes = new ArrayList<>();
long timeDifference;
@ -397,8 +388,6 @@ public class ExploreFragment extends Fragment {
}
}
noteListAdapter.updateList(presentedNotes);
list_notes.setAdapter(noteListAdapter);
}