From fd5c8d5ad38423d5e73121abdb9b58b85018d1a7 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 16:34:29 +0300 Subject: [PATCH 1/4] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java --- .idea/libraries/animated_vector_drawable_23_4_0.xml | 4 ++-- .idea/libraries/appcompat_v7_23_4_0.xml | 4 ++-- .idea/libraries/design_23_4_0.xml | 4 ++-- .idea/libraries/firebase_analytics_impl_9_2_0.xml | 2 +- .idea/libraries/firebase_auth_9_2_0.xml | 2 +- .idea/libraries/firebase_auth_common_9_2_0.xml | 2 +- .idea/libraries/firebase_auth_module_9_2_0.xml | 2 +- .idea/libraries/firebase_config_9_2_0.xml | 2 +- .idea/libraries/firebase_crash_9_2_0.xml | 2 +- .idea/libraries/firebase_database_9_2_0.xml | 2 +- .idea/libraries/firebase_messaging_9_2_0.xml | 2 +- .idea/libraries/firebase_storage_9_2_0.xml | 2 +- .idea/libraries/firebase_storage_common_9_2_0.xml | 2 +- .idea/libraries/mediarouter_v7_23_0_0.xml | 4 ++-- .idea/libraries/play_services_9_2_0.xml | 2 +- .idea/libraries/play_services_appindexing_9_2_0.xml | 2 +- .idea/libraries/play_services_auth_base_9_2_0.xml | 2 +- .idea/libraries/play_services_basement_9_2_0.xml | 2 +- .idea/libraries/play_services_cast_9_2_0.xml | 2 +- .../play_services_contextmanager_9_2_0.xml | 2 +- .idea/libraries/play_services_location_9_2_0.xml | 2 +- .idea/libraries/play_services_plus_9_2_0.xml | 2 +- .../play_services_tagmanager_api_9_2_0.xml | 2 +- .idea/libraries/play_services_tasks_9_2_0.xml | 2 +- .idea/libraries/play_services_vision_9_2_0.xml | 2 +- .idea/libraries/recyclerview_v7_23_4_0.xml | 4 ++-- .idea/libraries/support_annotations_23_4_0.xml | 4 ++-- .idea/libraries/support_v4_23_4_0.xml | 4 ++-- .idea/libraries/support_vector_drawable_23_4_0.xml | 2 +- .idea/libraries/volley_1_0_0.xml | 2 +- .../sagi/thesocialnotework/PersonalFragment.java | 13 +++++++++---- 31 files changed, 46 insertions(+), 41 deletions(-) diff --git a/.idea/libraries/animated_vector_drawable_23_4_0.xml b/.idea/libraries/animated_vector_drawable_23_4_0.xml index 4688c4a..581ec94 100644 --- a/.idea/libraries/animated_vector_drawable_23_4_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_4_0.xml @@ -1,13 +1,13 @@ - + - + diff --git a/.idea/libraries/appcompat_v7_23_4_0.xml b/.idea/libraries/appcompat_v7_23_4_0.xml index 215af43..7fc3be6 100644 --- a/.idea/libraries/appcompat_v7_23_4_0.xml +++ b/.idea/libraries/appcompat_v7_23_4_0.xml @@ -4,13 +4,13 @@ - + - + diff --git a/.idea/libraries/design_23_4_0.xml b/.idea/libraries/design_23_4_0.xml index da6f2ae..e917021 100644 --- a/.idea/libraries/design_23_4_0.xml +++ b/.idea/libraries/design_23_4_0.xml @@ -4,13 +4,13 @@ - + - + diff --git a/.idea/libraries/firebase_analytics_impl_9_2_0.xml b/.idea/libraries/firebase_analytics_impl_9_2_0.xml index 4993bce..6e0d7e2 100644 --- a/.idea/libraries/firebase_analytics_impl_9_2_0.xml +++ b/.idea/libraries/firebase_analytics_impl_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_auth_9_2_0.xml b/.idea/libraries/firebase_auth_9_2_0.xml index f4f9543..7185ab6 100644 --- a/.idea/libraries/firebase_auth_9_2_0.xml +++ b/.idea/libraries/firebase_auth_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_auth_common_9_2_0.xml b/.idea/libraries/firebase_auth_common_9_2_0.xml index 7a29d3c..86f4201 100644 --- a/.idea/libraries/firebase_auth_common_9_2_0.xml +++ b/.idea/libraries/firebase_auth_common_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_auth_module_9_2_0.xml b/.idea/libraries/firebase_auth_module_9_2_0.xml index 06c2d67..a45803b 100644 --- a/.idea/libraries/firebase_auth_module_9_2_0.xml +++ b/.idea/libraries/firebase_auth_module_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_config_9_2_0.xml b/.idea/libraries/firebase_config_9_2_0.xml index fc1bc23..d4a396e 100644 --- a/.idea/libraries/firebase_config_9_2_0.xml +++ b/.idea/libraries/firebase_config_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_crash_9_2_0.xml b/.idea/libraries/firebase_crash_9_2_0.xml index 5f6e0d0..7b7a413 100644 --- a/.idea/libraries/firebase_crash_9_2_0.xml +++ b/.idea/libraries/firebase_crash_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_database_9_2_0.xml b/.idea/libraries/firebase_database_9_2_0.xml index 2ce92c1..4cf8d04 100644 --- a/.idea/libraries/firebase_database_9_2_0.xml +++ b/.idea/libraries/firebase_database_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_messaging_9_2_0.xml b/.idea/libraries/firebase_messaging_9_2_0.xml index 036d0ad..f28a963 100644 --- a/.idea/libraries/firebase_messaging_9_2_0.xml +++ b/.idea/libraries/firebase_messaging_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_storage_9_2_0.xml b/.idea/libraries/firebase_storage_9_2_0.xml index d84dec2..111cccc 100644 --- a/.idea/libraries/firebase_storage_9_2_0.xml +++ b/.idea/libraries/firebase_storage_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/firebase_storage_common_9_2_0.xml b/.idea/libraries/firebase_storage_common_9_2_0.xml index 380abaf..206dd0b 100644 --- a/.idea/libraries/firebase_storage_common_9_2_0.xml +++ b/.idea/libraries/firebase_storage_common_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/mediarouter_v7_23_0_0.xml b/.idea/libraries/mediarouter_v7_23_0_0.xml index 9e4c862..d53bf7d 100644 --- a/.idea/libraries/mediarouter_v7_23_0_0.xml +++ b/.idea/libraries/mediarouter_v7_23_0_0.xml @@ -5,13 +5,13 @@ - + - + diff --git a/.idea/libraries/play_services_9_2_0.xml b/.idea/libraries/play_services_9_2_0.xml index c48c16f..7460e35 100644 --- a/.idea/libraries/play_services_9_2_0.xml +++ b/.idea/libraries/play_services_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_appindexing_9_2_0.xml b/.idea/libraries/play_services_appindexing_9_2_0.xml index 972539a..1f748dc 100644 --- a/.idea/libraries/play_services_appindexing_9_2_0.xml +++ b/.idea/libraries/play_services_appindexing_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_auth_base_9_2_0.xml b/.idea/libraries/play_services_auth_base_9_2_0.xml index 992cc4d..a6522a6 100644 --- a/.idea/libraries/play_services_auth_base_9_2_0.xml +++ b/.idea/libraries/play_services_auth_base_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_basement_9_2_0.xml b/.idea/libraries/play_services_basement_9_2_0.xml index d4ac257..0aec068 100644 --- a/.idea/libraries/play_services_basement_9_2_0.xml +++ b/.idea/libraries/play_services_basement_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_cast_9_2_0.xml b/.idea/libraries/play_services_cast_9_2_0.xml index db48fce..984c4b1 100644 --- a/.idea/libraries/play_services_cast_9_2_0.xml +++ b/.idea/libraries/play_services_cast_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_contextmanager_9_2_0.xml b/.idea/libraries/play_services_contextmanager_9_2_0.xml index 0c01383..f1795a0 100644 --- a/.idea/libraries/play_services_contextmanager_9_2_0.xml +++ b/.idea/libraries/play_services_contextmanager_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_location_9_2_0.xml b/.idea/libraries/play_services_location_9_2_0.xml index 53c7ebe..37fb730 100644 --- a/.idea/libraries/play_services_location_9_2_0.xml +++ b/.idea/libraries/play_services_location_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_plus_9_2_0.xml b/.idea/libraries/play_services_plus_9_2_0.xml index a1e9d21..13b2aef 100644 --- a/.idea/libraries/play_services_plus_9_2_0.xml +++ b/.idea/libraries/play_services_plus_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_tagmanager_api_9_2_0.xml b/.idea/libraries/play_services_tagmanager_api_9_2_0.xml index 0ccf9df..785dae0 100644 --- a/.idea/libraries/play_services_tagmanager_api_9_2_0.xml +++ b/.idea/libraries/play_services_tagmanager_api_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_tasks_9_2_0.xml b/.idea/libraries/play_services_tasks_9_2_0.xml index e7d0a1b..255cf7b 100644 --- a/.idea/libraries/play_services_tasks_9_2_0.xml +++ b/.idea/libraries/play_services_tasks_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_vision_9_2_0.xml b/.idea/libraries/play_services_vision_9_2_0.xml index 02a9a1e..d05e55f 100644 --- a/.idea/libraries/play_services_vision_9_2_0.xml +++ b/.idea/libraries/play_services_vision_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/recyclerview_v7_23_4_0.xml b/.idea/libraries/recyclerview_v7_23_4_0.xml index 0651040..af5c00a 100644 --- a/.idea/libraries/recyclerview_v7_23_4_0.xml +++ b/.idea/libraries/recyclerview_v7_23_4_0.xml @@ -4,13 +4,13 @@ - + - + diff --git a/.idea/libraries/support_annotations_23_4_0.xml b/.idea/libraries/support_annotations_23_4_0.xml index 4619479..92ae113 100644 --- a/.idea/libraries/support_annotations_23_4_0.xml +++ b/.idea/libraries/support_annotations_23_4_0.xml @@ -1,12 +1,12 @@ - + - + diff --git a/.idea/libraries/support_v4_23_4_0.xml b/.idea/libraries/support_v4_23_4_0.xml index b9606c9..550c072 100644 --- a/.idea/libraries/support_v4_23_4_0.xml +++ b/.idea/libraries/support_v4_23_4_0.xml @@ -5,13 +5,13 @@ - + - + diff --git a/.idea/libraries/support_vector_drawable_23_4_0.xml b/.idea/libraries/support_vector_drawable_23_4_0.xml index c4f8c3a..2f49a78 100644 --- a/.idea/libraries/support_vector_drawable_23_4_0.xml +++ b/.idea/libraries/support_vector_drawable_23_4_0.xml @@ -6,8 +6,8 @@ - + diff --git a/.idea/libraries/volley_1_0_0.xml b/.idea/libraries/volley_1_0_0.xml index 8e317b7..81a83dd 100644 --- a/.idea/libraries/volley_1_0_0.xml +++ b/.idea/libraries/volley_1_0_0.xml @@ -1,8 +1,8 @@ - + diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 337ab91..9190771 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -309,7 +309,7 @@ public class PersonalFragment extends Fragment { Date time = new Date(); JSONObject noteObject = response.getJSONObject("note"); time.setTime(noteObject.getLong("created_at")); - addNoteFromJsonObj(noteObject, time); + addNoteFromJsonObj(noteObject, time,0); updateShowedNotes(); // presentedNotes = listOfNotes; @@ -346,7 +346,7 @@ public class PersonalFragment extends Fragment { JSONObject noteObject = noteObjectsArray.getJSONObject(i); time.setTime(noteObject.getLong("created_at")); - addNoteFromJsonObj(noteObject, time); + addNoteFromJsonObj(noteObject, time,-1); } updateShowedNotes(); // presentedNotes = listOfNotes; @@ -393,7 +393,7 @@ public class PersonalFragment extends Fragment { } - private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException { + private void addNoteFromJsonObj(JSONObject noteObject, Date time, int position) throws JSONException { Note addNote = new Note( noteObject.getString("id"), Float.parseFloat(noteObject.getJSONObject("location").getString("lat")), @@ -408,7 +408,12 @@ public class PersonalFragment extends Fragment { noteObject.getString("owner_id"), jsonArrayToStringArray(noteObject.getJSONArray("tags")) ); - listOfNotes.add(addNote); + Log.d(TAG, "addNoteFromJsonObj: "+ addNote.getDate() + " " + addNote.getTime()); + if (position != 0) + listOfNotes.add(addNote); + else + listOfNotes.add(position,addNote); + } From 3a9df2db6844a08175414b11386209d832f75785 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 17:14:07 +0300 Subject: [PATCH 2/4] change zoom default --- .../matan/ara/sagi/thesocialnotework/GmapFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index 7e6ea91..756a78f 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -57,7 +57,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { private GoogleMap mMap; private GPSUtils gpsUtils; private MainActivity mainActivity; - private final int MAX_ZOOM = 16, MIN_ZOOM = 8, DEFAULT_ZOOM = 12; + private final int MAX_ZOOM = 16, MIN_ZOOM = 8, DEFAULT_ZOOM = 8; private HashMap eventMarkerMap; private ImageButton dateFilter; private ImageButton locationFilter; From 22bb04b0d23870d6e717da5d5779a3cc51c4d674 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 10 Jul 2016 17:19:30 +0300 Subject: [PATCH 3/4] Changed Update toast text --- .../matan/ara/sagi/thesocialnotework/MainActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index 4f7952c..e6c3de0 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -250,9 +250,8 @@ public class MainActivity extends AppCompatActivity public void updateNavAvatar() { //Change The Avatar - Log.d(TAG, "updateNavAvatar: PINPINPINPIN"); Utils.URLtoImageView(menu_avatar, user.getAvatar()); - Toast.makeText(this, "Profile Updated!", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "Success "+("\ud83d\ude01")+" !", Toast.LENGTH_LONG).show(); } } From 1e092db5f7e435f53283631ab1aff05aa52d8c33 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 10 Jul 2016 17:24:15 +0300 Subject: [PATCH 4/4] ExplorFragment Doc --- .../thesocialnotework/ExploreFragment.java | 683 +++++++++--------- 1 file changed, 336 insertions(+), 347 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java index d592c0d..62cee7a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java @@ -31,377 +31,366 @@ 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 notes; - protected ListView list_notes; + private static final String TAG = "[TSN/Explore]"; + protected User user; + protected MainActivity parent; + private ListAdapter noteListAdapter; + private List notes; + protected ListView list_notes; + private ImageButton dateFilter; + private ImageButton locationFilter; + private Button map_small_filter; + private Button map_medium_filter; + private Button map_large_filter; + private LinearLayout exploreFilters; + private boolean dateFilterIsVisible = false; + private boolean locationFilterIsVisible = false; + private Long dateFilterSelection; + private float locationFilterSelection; + private GPSUtils gpsUtils; - private ImageButton dateFilter; - private ImageButton locationFilter; -// private ImageButton userFilter; - private Button map_small_filter; - private Button map_medium_filter; - private Button map_large_filter; - private LinearLayout exploreFilters; - private boolean dateFilterIsVisible = false; - private boolean locationFilterIsVisible = false; - private Long dateFilterSelection; - private float locationFilterSelection; - private GPSUtils gpsUtils; + public ExploreFragment() { + // Required empty public constructor + } - public ExploreFragment() { - // Required empty public constructor - } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - parent = (MainActivity) getActivity(); - gpsUtils = parent.getGPSUtils(); - user = parent.getUser(); + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + parent = (MainActivity) getActivity(); + gpsUtils = parent.getGPSUtils(); + user = parent.getUser(); - } + } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_explore, container, false); + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_explore, container, false); - notes = new ArrayList<>(); - //Get Views - list_notes = (ListView) view.findViewById(R.id.list_notes); - noteListAdapter = new ListAdapter(parent, notes); - list_notes.setOnItemClickListener(new ItemClickedListener()); - dateFilterSelection = Utils.MONTH_MILI; - locationFilterSelection = Utils.DISTANCE_LONG; + notes = new ArrayList<>(); + //Get Views + list_notes = (ListView) view.findViewById(R.id.list_notes); + noteListAdapter = new ListAdapter(parent, notes); + 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); + exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options); - - 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); - - exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options); - - dateFilter.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (dateFilterIsVisible) { - dateFilterIsVisible = false; - exploreFilters.setVisibility(View.GONE); - } else { - 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); - map_large_filter.setText(R.string.month); - } - setButtonsColor(); - } - }); - - locationFilter.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (locationFilterIsVisible) { - locationFilterIsVisible = false; - exploreFilters.setVisibility(View.GONE); - } else { - 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); - map_large_filter.setText(R.string.longDistance); - } - setButtonsColor(); - } - }); - - - // TODO: choose a default filter for openning explore mode - - try { - getAllNotes(); - } catch (JSONException e) { - e.printStackTrace(); - } - return view; - } - - - 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"); - String url = Utils.BASE_URL + "/note/getPublic"; - JSONObject payload = new JSONObject(); - payload.put("id", user.getId()); - VolleyUtilSingleton.getInstance(getActivity()).post(url, payload, getNotesSuccessListener, Utils.genericErrorListener); - } - - Response.Listener getNotesSuccessListener = new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "getNotesSuccessListener: " + response.toString()); - Utils.dismissLoadingDialog(); - try { - //need to get all notes and add to listOfNotes - JSONArray noteObjectsArray = response.getJSONArray("notes"); - parent.getUser().setNumber_of_notes(noteObjectsArray.length()); - Date time = new Date(); - for (int i = 0; i < noteObjectsArray.length(); i++) { - JSONObject noteObject = noteObjectsArray.getJSONObject(i); - time.setTime(noteObject.getLong("created_at")); - notes.add(Utils.getNoteFromJsonObj(noteObject, time)); - } -// list_notes.setAdapter(noteListAdapter); - updateShowedNotes(); - Utils.dismissLoadingDialog(); - } catch (Exception e) { - Log.e(TAG, "newNoteSuccess:" + e.getMessage()); - } - - } - }; - - - // click on listView item - class ItemClickedListener implements AdapterView.OnItemClickListener { - @Override - public void onItemClick(AdapterView parent, View view, final int position, long id) { - //create and configure dialog - final Note note = notes.get(position); - final MainActivity localParent = (MainActivity)getActivity(); - 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); - final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); - final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_textview); - final TextView date = (TextView) noteViewDialog.findViewById(R.id.ndf_date_textview); - final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); - final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); - final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); - final ImageButton likeBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); - final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar); - final ImageView permission_image = (ImageView) noteViewDialog.findViewById(R.id.permission_image); - - title.setText(note.getTitle()); - body.setText(note.getBody()); - date.setText(note.getDate()); - time.setText(note.getTime()); - location.setText(note.getAddress()); - - if (likes != null) { - likeBtn.setBackgroundResource(R.drawable.like_icon); - if (localParent.getUser().getLiked_notes().contains(note.getId())) { - likeBtn.setBackgroundResource(R.drawable.like_icon); - } else { - likeBtn.setBackgroundResource(R.drawable.unlike_icon); - } - } - likes.setText("" + note.getLikes()); - - permission.setVisibility(View.GONE); - Utils.URLtoImageView(avatar, note.getAvatar()); - permission_image.setVisibility(View.GONE); - - likeBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - //add like only if user didnt like already - if (!user.getLiked_notes().contains(note.getId())) { - JSONObject jsonObj = new JSONObject(); - try { - jsonObj.put("uid", localParent.getUserId()); - jsonObj.put("nid", note.getId()); - - } catch (JSONException e) { - e.printStackTrace(); - } - VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, Utils.genericErrorListener); - user.getLiked_notes().add(note.getId()); - user.updateUser(localParent); - note.setLikes(note.getLikes()+1); - likes.setText("" + note.getLikes()); - noteListAdapter.updateList(notes); - list_notes.setAdapter(noteListAdapter); - likeBtn.setBackgroundResource(R.drawable.like_icon); - } - } - }); - } - } - - //all buttons listener - public View.OnClickListener button1ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - - //location filter - if (locationFilterIsVisible) { - locationFilterSelection = Utils.DISTANCE_SMALL; - } - - //date filters - else { - dateFilterSelection = Utils.DAY_MILI; - - } - //change colors of buttons and update visible notes - setButtonsColor(); - updateShowedNotes(); - } - }; - - //all buttons listener - public View.OnClickListener button2ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - - //location filter - if (locationFilterIsVisible) { - locationFilterSelection = Utils.DISTANCE_MEDIUM; - } - - //date filters - else { - dateFilterSelection = Utils.WEEK_MILI; - } - //change colors of buttons and update visible notes - setButtonsColor(); - updateShowedNotes(); - } - }; - - //all buttons listener - public View.OnClickListener button3ClickListener = new View.OnClickListener() { - @Override - public void onClick(final View v) { - - //location filter - if (locationFilterIsVisible) { - locationFilterSelection = Utils.DISTANCE_LONG; - } - - //date filters - else { - dateFilterSelection = Utils.MONTH_MILI; - } - //change colors of buttons and update visible notes - setButtonsColor(); - updateShowedNotes(); - } - }; - - - //set main filter colors - private void setButtonsColor() { - - Log.d(TAG, "setButtonsColor: start"); - //set date filter colors + dateFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { if (dateFilterIsVisible) { - dateFilter.setBackgroundColor(Utils.filterColor); - if (dateFilterSelection == Utils.DAY_MILI) { - map_small_filter.setBackgroundColor(Utils.filterColor); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else if (dateFilterSelection == Utils.WEEK_MILI) { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundColor(Utils.filterColor); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundColor(Utils.filterColor); - } + dateFilterIsVisible = false; + exploreFilters.setVisibility(View.GONE); } else { - dateFilter.setBackgroundResource(android.R.drawable.btn_default); + exploreFilters.setVisibility(View.VISIBLE); + dateFilterIsVisible = true; + locationFilterIsVisible = false; + // set text button in the right filter string + map_small_filter.setText(R.string.day); + map_medium_filter.setText(R.string.week); + map_large_filter.setText(R.string.month); } + setButtonsColor(); + } + }); - //set distance filter colors + locationFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { if (locationFilterIsVisible) { - locationFilter.setBackgroundColor(Utils.filterColor); - if (locationFilterSelection == Utils.DISTANCE_SMALL) { - map_small_filter.setBackgroundColor(Utils.filterColor); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else if (locationFilterSelection == Utils.DISTANCE_MEDIUM) { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundColor(Utils.filterColor); - map_large_filter.setBackgroundResource(android.R.drawable.btn_default); - } else { - map_small_filter.setBackgroundResource(android.R.drawable.btn_default); - map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); - map_large_filter.setBackgroundColor(Utils.filterColor); - } + locationFilterIsVisible = false; + exploreFilters.setVisibility(View.GONE); } else { - locationFilter.setBackgroundResource(android.R.drawable.btn_default); + exploreFilters.setVisibility(View.VISIBLE); + locationFilterIsVisible = true; + dateFilterIsVisible = false; + // set text button in the right filter string + map_small_filter.setText(R.string.shortDistance); + map_medium_filter.setText(R.string.mediumDistance); + map_large_filter.setText(R.string.longDistance); } + setButtonsColor(); + } + }); + try { + getAllNotes(); + } catch (JSONException e) { + e.printStackTrace(); } + return view; + } - public void updateShowedNotes() { - List presentedNotes = new ArrayList<>(); - long timeDifference; - float distance; - //get current date and location - Location currLocation = new Location(gpsUtils.getLocation()); - Date now = new Date(); - Location targetLocation = new Location("");//provider name is unecessary - Date targetDate; + /** + * 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"); + String url = Utils.BASE_URL + "/note/getPublic"; + JSONObject payload = new JSONObject(); + payload.put("id", user.getId()); + VolleyUtilSingleton.getInstance(getActivity()).post(url, payload, getNotesSuccessListener, Utils.genericErrorListener); + } - for (Note note : notes) { -// get note location and date - targetLocation.setLatitude(note.getLat());//your coords of course - targetLocation.setLongitude(note.getLon()); - targetDate = new Date(note.getTimestamp()); - //get time and date differences - timeDifference = now.getTime() - targetDate.getTime(); - distance = currLocation.distanceTo(targetLocation); - //add to currently presented list according to filters. - if (timeDifference <= dateFilterSelection - && distance <= locationFilterSelection){ - presentedNotes.add(note); + /** + * The Success callback for our HTTP API call + */ + Response.Listener getNotesSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "getNotesSuccessListener: " + response.toString()); + Utils.dismissLoadingDialog(); + try { + //need to get all notes and add to listOfNotes + JSONArray noteObjectsArray = response.getJSONArray("notes"); + parent.getUser().setNumber_of_notes(noteObjectsArray.length()); + Date time = new Date(); + for (int i = 0; i < noteObjectsArray.length(); i++) { + JSONObject noteObject = noteObjectsArray.getJSONObject(i); + time.setTime(noteObject.getLong("created_at")); + notes.add(Utils.getNoteFromJsonObj(noteObject, time)); + } + updateShowedNotes(); + Utils.dismissLoadingDialog(); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } + + } + }; + + + // click on listView item + class ItemClickedListener implements AdapterView.OnItemClickListener { + @Override + public void onItemClick(AdapterView parent, View view, final int position, long id) { + //create and configure dialog + final Note note = notes.get(position); + final MainActivity localParent = (MainActivity) getActivity(); + final Dialog noteViewDialog = new Dialog(getActivity()); + noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + noteViewDialog.setContentView(R.layout.note_display_full); + + 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(); + + //get note_view_full layout elements + final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview); + final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); + final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_textview); + final TextView date = (TextView) noteViewDialog.findViewById(R.id.ndf_date_textview); + final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); + final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); + final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); + final ImageButton likeBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); + final ImageView avatar = (RoundAvatarImageView) noteViewDialog.findViewById(R.id.note_user_avatar); + final ImageView permission_image = (ImageView) noteViewDialog.findViewById(R.id.permission_image); + + title.setText(note.getTitle()); + body.setText(note.getBody()); + date.setText(note.getDate()); + time.setText(note.getTime()); + location.setText(note.getAddress()); + + if (likes != null) { + likeBtn.setBackgroundResource(R.drawable.like_icon); + if (localParent.getUser().getLiked_notes().contains(note.getId())) { + likeBtn.setBackgroundResource(R.drawable.like_icon); + } else { + likeBtn.setBackgroundResource(R.drawable.unlike_icon); + } + } + likes.setText("" + note.getLikes()); + + permission.setVisibility(View.GONE); + Utils.URLtoImageView(avatar, note.getAvatar()); + permission_image.setVisibility(View.GONE); + + likeBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + //add like only if user didnt like already + if (!user.getLiked_notes().contains(note.getId())) { + JSONObject jsonObj = new JSONObject(); + try { + jsonObj.put("uid", localParent.getUserId()); + jsonObj.put("nid", note.getId()); + + } catch (JSONException e) { + e.printStackTrace(); } - + VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, Utils.genericErrorListener); + user.getLiked_notes().add(note.getId()); + user.updateUser(localParent); + note.setLikes(note.getLikes() + 1); + likes.setText("" + note.getLikes()); + noteListAdapter.updateList(notes); + list_notes.setAdapter(noteListAdapter); + likeBtn.setBackgroundResource(R.drawable.like_icon); + } } - - - noteListAdapter.updateList(presentedNotes); - list_notes.setAdapter(noteListAdapter); + }); } + } + + //all buttons listener + public View.OnClickListener button1ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_SMALL; + } + + //date filters + else { + dateFilterSelection = Utils.DAY_MILI; + + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + //all buttons listener + public View.OnClickListener button2ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_MEDIUM; + } + + //date filters + else { + dateFilterSelection = Utils.WEEK_MILI; + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + //all buttons listener + public View.OnClickListener button3ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_LONG; + } + + //date filters + else { + dateFilterSelection = Utils.MONTH_MILI; + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + + //set main filter colors + private void setButtonsColor() { + + Log.d(TAG, "setButtonsColor: start"); + //set date filter colors + if (dateFilterIsVisible) { + dateFilter.setBackgroundColor(Utils.filterColor); + if (dateFilterSelection == Utils.DAY_MILI) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (dateFilterSelection == Utils.WEEK_MILI) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + dateFilter.setBackgroundResource(android.R.drawable.btn_default); + } + + //set distance filter colors + if (locationFilterIsVisible) { + locationFilter.setBackgroundColor(Utils.filterColor); + if (locationFilterSelection == Utils.DISTANCE_SMALL) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (locationFilterSelection == Utils.DISTANCE_MEDIUM) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + locationFilter.setBackgroundResource(android.R.drawable.btn_default); + } + } + + /** + * Will update the notes within the list view + */ + public void updateShowedNotes() { + List presentedNotes = new ArrayList<>(); + long timeDifference; + float distance; + //get current date and location + Location currLocation = new Location(gpsUtils.getLocation()); + Date now = new Date(); + Location targetLocation = new Location("");//provider name is unecessary + Date targetDate; + + for (Note note : notes) { + // get note location and date + targetLocation.setLatitude(note.getLat());//your coords of course + targetLocation.setLongitude(note.getLon()); + targetDate = new Date(note.getTimestamp()); + //get time and date differences + timeDifference = now.getTime() - targetDate.getTime(); + distance = currLocation.distanceTo(targetLocation); + //add to currently presented list according to filters. + if (timeDifference <= dateFilterSelection + && distance <= locationFilterSelection) { + presentedNotes.add(note); + } + + } + noteListAdapter.updateList(presentedNotes); + list_notes.setAdapter(noteListAdapter); + } }