From 867dc7d877d1916e8c5c61351121ec50cd06582f Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Fri, 8 Jul 2016 03:20:03 +0300 Subject: [PATCH] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java --- .../animated_vector_drawable_23_4_0.xml | 3 +- .idea/libraries/appcompat_v7_23_4_0.xml | 6 +- .idea/libraries/design_23_4_0.xml | 6 +- .idea/libraries/firebase_auth_9_2_0.xml | 2 +- .idea/libraries/firebase_common_9_2_0.xml | 2 +- .idea/libraries/firebase_messaging_9_2_0.xml | 2 +- .idea/libraries/mediarouter_v7_23_0_0.xml | 6 +- .../play_services_ads_lite_9_2_0.xml | 2 +- .../play_services_analytics_9_2_0.xml | 2 +- .../play_services_appinvite_9_2_0.xml | 2 +- .idea/libraries/play_services_base_9_2_0.xml | 2 +- .../play_services_basement_9_2_0.xml | 2 +- .idea/libraries/play_services_cast_9_2_0.xml | 2 +- .../play_services_clearcut_9_2_0.xml | 2 +- .../play_services_contextmanager_9_2_0.xml | 2 +- .idea/libraries/play_services_drive_9_2_0.xml | 2 +- .../libraries/play_services_fitness_9_2_0.xml | 2 +- .idea/libraries/play_services_gcm_9_2_0.xml | 2 +- .../play_services_identity_9_2_0.xml | 2 +- .../play_services_panorama_9_2_0.xml | 2 +- .../play_services_safetynet_9_2_0.xml | 2 +- .../play_services_tagmanager_9_2_0.xml | 2 +- .idea/libraries/recyclerview_v7_23_4_0.xml | 4 + .../libraries/support_annotations_23_4_0.xml | 3 +- .idea/libraries/support_v4_23_4_0.xml | 6 +- .../support_vector_drawable_23_4_0.xml | 3 +- .idea/libraries/volley_1_0_0.xml | 2 +- .idea/misc.xml | 2 +- .../sagi/thesocialnotework/GmapFragment.java | 9 +- .../thesocialnotework/PersonalFragment.java | 565 +++++++++--------- .../ara/sagi/thesocialnotework/Utils.java | 1 + 31 files changed, 339 insertions(+), 313 deletions(-) diff --git a/.idea/libraries/animated_vector_drawable_23_4_0.xml b/.idea/libraries/animated_vector_drawable_23_4_0.xml index f3749a7..08d7899 100644 --- a/.idea/libraries/animated_vector_drawable_23_4_0.xml +++ b/.idea/libraries/animated_vector_drawable_23_4_0.xml @@ -1,11 +1,12 @@ - + + diff --git a/.idea/libraries/appcompat_v7_23_4_0.xml b/.idea/libraries/appcompat_v7_23_4_0.xml index c9db6e3..6391448 100644 --- a/.idea/libraries/appcompat_v7_23_4_0.xml +++ b/.idea/libraries/appcompat_v7_23_4_0.xml @@ -1,11 +1,15 @@ + + + - + + diff --git a/.idea/libraries/design_23_4_0.xml b/.idea/libraries/design_23_4_0.xml index 2b72087..5d90be8 100644 --- a/.idea/libraries/design_23_4_0.xml +++ b/.idea/libraries/design_23_4_0.xml @@ -1,11 +1,15 @@ + + + - + + 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_common_9_2_0.xml b/.idea/libraries/firebase_common_9_2_0.xml index 2aa6d7c..317d346 100644 --- a/.idea/libraries/firebase_common_9_2_0.xml +++ b/.idea/libraries/firebase_common_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/mediarouter_v7_23_0_0.xml b/.idea/libraries/mediarouter_v7_23_0_0.xml index 2e8eb2f..39b8fc6 100644 --- a/.idea/libraries/mediarouter_v7_23_0_0.xml +++ b/.idea/libraries/mediarouter_v7_23_0_0.xml @@ -1,12 +1,16 @@ + + + - + + diff --git a/.idea/libraries/play_services_ads_lite_9_2_0.xml b/.idea/libraries/play_services_ads_lite_9_2_0.xml index ccc96e0..8674fb1 100644 --- a/.idea/libraries/play_services_ads_lite_9_2_0.xml +++ b/.idea/libraries/play_services_ads_lite_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_analytics_9_2_0.xml b/.idea/libraries/play_services_analytics_9_2_0.xml index c6e4b62..2b08c1c 100644 --- a/.idea/libraries/play_services_analytics_9_2_0.xml +++ b/.idea/libraries/play_services_analytics_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_appinvite_9_2_0.xml b/.idea/libraries/play_services_appinvite_9_2_0.xml index 57aca98..6b9e8d2 100644 --- a/.idea/libraries/play_services_appinvite_9_2_0.xml +++ b/.idea/libraries/play_services_appinvite_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_base_9_2_0.xml b/.idea/libraries/play_services_base_9_2_0.xml index 8ec9e71..a1981fd 100644 --- a/.idea/libraries/play_services_base_9_2_0.xml +++ b/.idea/libraries/play_services_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_clearcut_9_2_0.xml b/.idea/libraries/play_services_clearcut_9_2_0.xml index fde64de..491f374 100644 --- a/.idea/libraries/play_services_clearcut_9_2_0.xml +++ b/.idea/libraries/play_services_clearcut_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_drive_9_2_0.xml b/.idea/libraries/play_services_drive_9_2_0.xml index 98828c3..d4461f8 100644 --- a/.idea/libraries/play_services_drive_9_2_0.xml +++ b/.idea/libraries/play_services_drive_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_fitness_9_2_0.xml b/.idea/libraries/play_services_fitness_9_2_0.xml index 2c270ce..e78f832 100644 --- a/.idea/libraries/play_services_fitness_9_2_0.xml +++ b/.idea/libraries/play_services_fitness_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_gcm_9_2_0.xml b/.idea/libraries/play_services_gcm_9_2_0.xml index 5662aa1..842e61c 100644 --- a/.idea/libraries/play_services_gcm_9_2_0.xml +++ b/.idea/libraries/play_services_gcm_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_identity_9_2_0.xml b/.idea/libraries/play_services_identity_9_2_0.xml index ad29331..7443980 100644 --- a/.idea/libraries/play_services_identity_9_2_0.xml +++ b/.idea/libraries/play_services_identity_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_panorama_9_2_0.xml b/.idea/libraries/play_services_panorama_9_2_0.xml index 9a61b57..ed921cc 100644 --- a/.idea/libraries/play_services_panorama_9_2_0.xml +++ b/.idea/libraries/play_services_panorama_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_safetynet_9_2_0.xml b/.idea/libraries/play_services_safetynet_9_2_0.xml index 8685efc..9c5b023 100644 --- a/.idea/libraries/play_services_safetynet_9_2_0.xml +++ b/.idea/libraries/play_services_safetynet_9_2_0.xml @@ -1,8 +1,8 @@ - + diff --git a/.idea/libraries/play_services_tagmanager_9_2_0.xml b/.idea/libraries/play_services_tagmanager_9_2_0.xml index 59cfde9..705e858 100644 --- a/.idea/libraries/play_services_tagmanager_9_2_0.xml +++ b/.idea/libraries/play_services_tagmanager_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 c911745..c26f835 100644 --- a/.idea/libraries/recyclerview_v7_23_4_0.xml +++ b/.idea/libraries/recyclerview_v7_23_4_0.xml @@ -1,11 +1,15 @@ + + + + diff --git a/.idea/libraries/support_annotations_23_4_0.xml b/.idea/libraries/support_annotations_23_4_0.xml index f678226..fbf30c6 100644 --- a/.idea/libraries/support_annotations_23_4_0.xml +++ b/.idea/libraries/support_annotations_23_4_0.xml @@ -1,10 +1,11 @@ - + + diff --git a/.idea/libraries/support_v4_23_4_0.xml b/.idea/libraries/support_v4_23_4_0.xml index 96fd1a8..027c10d 100644 --- a/.idea/libraries/support_v4_23_4_0.xml +++ b/.idea/libraries/support_v4_23_4_0.xml @@ -1,12 +1,16 @@ + + + - + + diff --git a/.idea/libraries/support_vector_drawable_23_4_0.xml b/.idea/libraries/support_vector_drawable_23_4_0.xml index 32cf50b..4cdec89 100644 --- a/.idea/libraries/support_vector_drawable_23_4_0.xml +++ b/.idea/libraries/support_vector_drawable_23_4_0.xml @@ -1,11 +1,12 @@ - + + 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/.idea/misc.xml b/.idea/misc.xml index 1a3eaff..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + 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 2e899d1..80af83a 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 @@ -184,9 +184,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { final Dialog noteViewDialog = new Dialog(getActivity()); noteViewDialog.setContentView(R.layout.note_display_full); - boolean isOwner = note.getOwnerId() == mainActivity.getUserId(); + boolean isOwner = note.getOwnerId().equals(mainActivity.getUserId()); if (isOwner) - noteViewDialog.setTitle("I wrote..."); + noteViewDialog.setTitle("You wrote..."); else noteViewDialog.setTitle("Someone wrote..."); @@ -210,14 +210,15 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { title.setText(note.getTitle()); body.setText(note.getBody()); time.setText(note.getTimestamp()); - location.setText("Tags: " + note.getAddress()); + location.setText("Address: " + note.getAddress()); likes.setText("Likes: " + note.getLikes()); tags.setText(note.getTags().toString()); -// avatar.setImageBitmap(); + Utils.URLtoImageView(avatar, note.getAvatar()); if (isOwner) { permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); } else{ + permission.setText(""); deleteBtn.setBackgroundResource(R.drawable.like_icon); } 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 529fb60..52ee9a6 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 @@ -50,173 +50,173 @@ import java.util.List; */ public class PersonalFragment extends Fragment { - protected ListView noteList; - private final int FINE_PERM = 0; - private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; - private GPSUtils gpsUtils; - private List listOfNotes; - private ListAdapter noteListAdapter; - private String userId; - private final String TAG = "[TSN/PersonalFragment]"; - private MainActivity activity; + protected ListView noteList; + private final int FINE_PERM = 0; + private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; + private GPSUtils gpsUtils; + private List listOfNotes; + private ListAdapter noteListAdapter; + private String userId; + private final String TAG = "[TSN/PersonalFragment]"; + private MainActivity activity; - public PersonalFragment() { - // Required empty public constructor - } + public PersonalFragment() { + // Required empty public constructor + } - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_personal, container, false); - // Inflate the layout for this fragment - activity = (MainActivity) getActivity(); - Bundle bundle = getArguments(); - this.userId = activity.getUserId(); - Log.d(TAG, "onCreateView: userID: " + userId); - //check for permission - ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, FINE_PERM); + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_personal, container, false); + // Inflate the layout for this fragment + activity = (MainActivity) getActivity(); + Bundle bundle = getArguments(); + this.userId = activity.getUserId(); + Log.d(TAG, "onCreateView: userID: " + userId); + //check for permission + ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, FINE_PERM); - this.noteList = (ListView) view.findViewById(R.id.ps_list_listview); - gpsUtils = activity.getGPSUtils(); - gpsUtils.getLocation(); - listOfNotes = new ArrayList<>(); - noteListAdapter = new ListAdapter(getContext(), listOfNotes); - noteList.setAdapter(noteListAdapter); - noteList.setOnItemClickListener(new ItemClickedListener()); - Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes"); - getAllNotes(); + this.noteList = (ListView) view.findViewById(R.id.ps_list_listview); + gpsUtils = activity.getGPSUtils(); + gpsUtils.getLocation(); + listOfNotes = new ArrayList<>(); + noteListAdapter = new ListAdapter(getContext(), listOfNotes); + noteList.setAdapter(noteListAdapter); + noteList.setOnItemClickListener(new ItemClickedListener()); + Utils.showLoadingDialog(getActivity(), "Fetching..", "getting your notes"); + getAllNotes(); //https://thesocialnotework-api.appspot.com/api/note/all?uid= - // The New "Add Button" - FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); - fab.setOnClickListener(addNewNoteDialog); - - return view; - } - - - @Override - public void onAttach(Context context) { - super.onAttach(context); - Utils.dismissLoadingDialog(); - Log.d(TAG, "onAttach"); - } - - @Override - public void onDetach() { - super.onDetach(); - Utils.dismissLoadingDialog(); - } - - public void getAllNotes() { - Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId); - VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); - } - - private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { - public void onClick(View v) { - - //create and configure dialog - final Dialog dialog = new Dialog(getActivity()); - dialog.setContentView(R.layout.note_view_full); - dialog.setTitle("New Note"); - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - lp.height = WindowManager.LayoutParams.MATCH_PARENT; - dialog.setCancelable(false); - dialog.show(); - dialog.getWindow().setAttributes(lp); - - - //get note_view_full layout elements - final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission); - final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title); - final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content); - Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn); - Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn); - - cancelBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - dialog.dismiss(); - } - }); - - saveBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - - //title too short - if (newTitle.getText().length() == 0) { - Toast toast = Toast.makeText(getActivity(), "Title too short.", Toast.LENGTH_LONG); - toast.show(); - return; - } - - //title too long - if (newTitle.getText().length() > 20) { - Toast toast = Toast.makeText(getActivity(), "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG); - toast.show(); - return; - } - //volley post - final JSONObject noteJson = new JSONObject(); - try { - - //TODO need to get owner id from login screen - noteJson.put("owner_id", userId); - noteJson.put("title", newTitle.getText()); - noteJson.put("lat", gpsUtils.getLatitude()); - noteJson.put("lng", gpsUtils.getLongitude()); - noteJson.put("address", gpsUtils.getAddress()); - noteJson.put("body", newBody.getText()); - noteJson.put("is_public", permissionSwitch.isChecked()); -// noteJson.put("tags",); - Log.d(TAG, "Json: " + noteJson.toString()); - - - } catch (Exception e) { - Log.d(TAG, "saveBtn: " + e.toString()); - } - - //send request and close dialog - VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener); - dialog.dismiss(); - } - }); - - //change text of switch according to state. - permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) - permissionSwitch.setText(R.string.nvf_public_label); - else - permissionSwitch.setText(R.string.nvf_private_label); - } - }); - + // The New "Add Button" + FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); + fab.setOnClickListener(addNewNoteDialog); + return view; } - }; - //response listener for adding new note - Response.Listener newNoteSuccessListener = new Response.Listener() { + @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "newNoteSuccess: response - " + response.toString()); - try { - Date time = new Date(); - JSONObject noteObject = response.getJSONObject("note"); - time.setTime(noteObject.getLong("created_at")); - addNoteFromJsonObj(noteObject, time); - noteList.setAdapter(noteListAdapter); - } catch (Exception e) { - Log.e(TAG, "newNoteSuccess:" + e.getMessage()); - } - + public void onAttach(Context context) { + super.onAttach(context); + Utils.dismissLoadingDialog(); + Log.d(TAG, "onAttach"); } - }; + + @Override + public void onDetach() { + super.onDetach(); + Utils.dismissLoadingDialog(); + } + + public void getAllNotes() { + Log.d(TAG, "url: " + BASE_URL + "/note/all?uid=" + userId); + VolleyUtilSingleton.getInstance(getActivity()).get(BASE_URL + "/note/all?uid=" + userId, getNotesSuccessListener, Utils.genericErrorListener); + } + + private View.OnClickListener addNewNoteDialog = new View.OnClickListener() { + public void onClick(View v) { + + //create and configure dialog + final Dialog dialog = new Dialog(getActivity()); + dialog.setContentView(R.layout.note_view_full); + dialog.setTitle("New Note"); + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.MATCH_PARENT; + lp.height = WindowManager.LayoutParams.MATCH_PARENT; + dialog.setCancelable(false); + dialog.show(); + dialog.getWindow().setAttributes(lp); + + + //get note_view_full layout elements + final Switch permissionSwitch = (Switch) dialog.findViewById(R.id.nvf_note_permission); + final EditText newTitle = (EditText) dialog.findViewById(R.id.nvf_note_title); + final EditText newBody = (EditText) dialog.findViewById(R.id.nvf_note_content); + Button saveBtn = (Button) dialog.findViewById(R.id.nvf_note_submit_btn); + Button cancelBtn = (Button) dialog.findViewById(R.id.nvf_note_cancel_btn); + + cancelBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + dialog.dismiss(); + } + }); + + saveBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + + //title too short + if (newTitle.getText().length() == 0) { + Toast toast = Toast.makeText(getActivity(), "Title too short.", Toast.LENGTH_LONG); + toast.show(); + return; + } + + //title too long + if (newTitle.getText().length() > 20) { + Toast toast = Toast.makeText(getActivity(), "Title too long.\n Use up to 20 notes.", Toast.LENGTH_LONG); + toast.show(); + return; + } + //volley post + final JSONObject noteJson = new JSONObject(); + try { + + //TODO need to get owner id from login screen + noteJson.put("owner_id", userId); + noteJson.put("title", newTitle.getText()); + noteJson.put("lat", gpsUtils.getLatitude()); + noteJson.put("lng", gpsUtils.getLongitude()); + noteJson.put("address", gpsUtils.getAddress()); + noteJson.put("body", newBody.getText()); + noteJson.put("is_public", permissionSwitch.isChecked()); +// noteJson.put("tags",); + Log.d(TAG, "Json: " + noteJson.toString()); + + + } catch (Exception e) { + Log.d(TAG, "saveBtn: " + e.toString()); + } + + //send request and close dialog + VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/upsert", noteJson, newNoteSuccessListener, Utils.genericErrorListener); + dialog.dismiss(); + } + }); + + //change text of switch according to state. + permissionSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) + permissionSwitch.setText(R.string.nvf_public_label); + else + permissionSwitch.setText(R.string.nvf_private_label); + } + }); + + + } + }; + + //response listener for adding new note + Response.Listener newNoteSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "newNoteSuccess: response - " + response.toString()); + try { + Date time = new Date(); + JSONObject noteObject = response.getJSONObject("note"); + time.setTime(noteObject.getLong("created_at")); + addNoteFromJsonObj(noteObject, time); + noteList.setAdapter(noteListAdapter); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } + + } + }; // //response Error listener for adding new note @@ -228,29 +228,29 @@ public class PersonalFragment extends Fragment { // }; - //response listener for getting all user notes - 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"); - Date time = new Date(); - for (int i = 0; i < noteObjectsArray.length(); i++) { - JSONObject noteObject = noteObjectsArray.getJSONObject(i); - time.setTime(noteObject.getLong("created_at")); + //response listener for getting all user notes + 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"); + Date time = new Date(); + for (int i = 0; i < noteObjectsArray.length(); i++) { + JSONObject noteObject = noteObjectsArray.getJSONObject(i); + time.setTime(noteObject.getLong("created_at")); + + addNoteFromJsonObj(noteObject, time); + } + noteList.setAdapter(noteListAdapter); + } catch (Exception e) { + Log.e(TAG, "newNoteSuccess:" + e.getMessage()); + } - addNoteFromJsonObj(noteObject, time); } - noteList.setAdapter(noteListAdapter); - } catch (Exception e) { - Log.e(TAG, "newNoteSuccess:" + e.getMessage()); - } - - } - }; + }; // //response ErrorListener for getting all user notes @@ -273,127 +273,128 @@ public class PersonalFragment extends Fragment { // }; - private ArrayList jsonArrayToStringArray(JSONArray jArray) { - ArrayList stringArray = new ArrayList(); - for (int i = 0, count = jArray.length(); i < count; i++) { - try { - JSONObject jsonObject = jArray.getJSONObject(i); - stringArray.add(jsonObject.toString()); - } catch (JSONException e) { - e.printStackTrace(); - } + private ArrayList jsonArrayToStringArray(JSONArray jArray) { + ArrayList stringArray = new ArrayList(); + for (int i = 0, count = jArray.length(); i < count; i++) { + try { + JSONObject jsonObject = jArray.getJSONObject(i); + stringArray.add(jsonObject.toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + return stringArray; } - return stringArray; - } - Response.Listener deleteNoteSuccessListener = new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - Log.d(TAG, "deleteNoteSuccessListener: " + response.toString()); + Response.Listener deleteNoteSuccessListener = new Response.Listener() { + @Override + public void onResponse(JSONObject response) { + Log.d(TAG, "deleteNoteSuccessListener: " + response.toString()); + } + }; + + private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException { + Note addNote = new Note( + noteObject.getString("id"), + Float.parseFloat(noteObject.getJSONObject("location").getString("lat")), + Float.parseFloat(noteObject.getJSONObject("location").getString("lng")), + noteObject.getJSONObject("location").getString("address"), + noteObject.getString("title"), + noteObject.getString("body"), + time.toString(), + noteObject.getBoolean("is_public"), + noteObject.getInt("likes"), + noteObject.getString("avatar"), + noteObject.getString("owner_id"), + jsonArrayToStringArray(noteObject.getJSONArray("tags")) + ); + listOfNotes.add(addNote); + } - }; - private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException { - Note addNote = new Note( - noteObject.getString("id"), - Float.parseFloat(noteObject.getJSONObject("location").getString("lat")), - Float.parseFloat(noteObject.getJSONObject("location").getString("lng")), - noteObject.getJSONObject("location").getString("address"), - noteObject.getString("title"), - noteObject.getString("body"), - time.toString(), - noteObject.getBoolean("is_public"), - noteObject.getInt("likes"), - noteObject.getString("avatar"), - jsonArrayToStringArray(noteObject.getJSONArray("tags")) - ); - listOfNotes.add(addNote); + // 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 = listOfNotes.get(position); + final Dialog noteViewDialog = new Dialog(getActivity()); + noteViewDialog.setContentView(R.layout.note_display_full); + noteViewDialog.setTitle("You wrote..."); - } - - // 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 = listOfNotes.get(position); - final Dialog noteViewDialog = new Dialog(getActivity()); - 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(); + 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 location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); - final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); - final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview); - final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); - final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); - final ImageView avatar = (ImageView)noteViewDialog.findViewById(R.id.note_user_avatar); + //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 location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview); + final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview); + final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview); + final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); + final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); + final ImageView avatar = (ImageView) noteViewDialog.findViewById(R.id.note_user_avatar); - title.setText(note.getTitle()); - body.setText(note.getBody()); - time.setText(note.getTimestamp()); - location.setText("Tags: " + note.getAddress()); - likes.setText("Likes: " + note.getLikes()); - tags.setText(note.getTags().toString()); - permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); - Utils.URLtoImageView(avatar, note.getAvatar()); + title.setText(note.getTitle()); + body.setText(note.getBody()); + time.setText(note.getTimestamp()); + location.setText("Address: " + note.getAddress()); + likes.setText("Likes: " + note.getLikes()); + tags.setText(note.getTags().toString()); + permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); + Utils.URLtoImageView(avatar, note.getAvatar()); - deleteBtn.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - //Put up the Yes/No message box - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder - .setTitle("Delete Note") - .setMessage("Are you sure you want to delete the note?") - .setIcon(android.R.drawable.ic_dialog_alert) - .setPositiveButton("Yes", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //Yes button clicked, do something - Toast.makeText(getActivity(), "Item Deleted!", - Toast.LENGTH_SHORT).show(); - //TODO send delete - JSONObject delNote = new JSONObject(); - try { - delNote.put("uid", userId); - delNote.put("nid", note.getId()); - VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener); - listOfNotes.remove(position); + deleteBtn.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + //Put up the Yes/No message box + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder + .setTitle("Delete Note") + .setMessage("Are you sure you want to delete the note?") + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton("Yes", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(getActivity(), "Item Deleted!", + Toast.LENGTH_SHORT).show(); + //TODO send delete + JSONObject delNote = new JSONObject(); + try { + delNote.put("uid", userId); + delNote.put("nid", note.getId()); + VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener); + listOfNotes.remove(position); - } catch (JSONException e) { - Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); - e.printStackTrace(); + } catch (JSONException e) { + Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + noteList.setAdapter(noteListAdapter); + noteViewDialog.dismiss(); + } + }) + .setNegativeButton("No", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Yes button clicked, do something + Toast.makeText(getActivity(), "Canceled", + Toast.LENGTH_SHORT).show(); + noteViewDialog.dismiss(); + } + }) //Do nothing on no + .show(); } - noteList.setAdapter(noteListAdapter); - noteViewDialog.dismiss(); - } - }) - .setNegativeButton("No", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - //Yes button clicked, do something - Toast.makeText(getActivity(), "Canceled", - Toast.LENGTH_SHORT).show(); - noteViewDialog.dismiss(); - } - }) //Do nothing on no - .show(); + }); + } - }); + } - - } - } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java index 03dfd85..1aea4ca 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java @@ -88,6 +88,7 @@ public class Utils { noteObject.getBoolean("is_public"), noteObject.getInt("likes"), noteObject.getString("avatar"), + noteObject.getString("owner_id"), jsonArrayToStringArray(noteObject.getJSONArray("tags")) ); return note;