added delete option to user notes on map

This commit is contained in:
Aran Zaiger 2016-07-08 15:21:04 +03:00
parent c30de5623a
commit c3d445c593
5 changed files with 78 additions and 67 deletions

View file

@ -4,6 +4,7 @@ import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@ -169,18 +170,10 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
// Defines the contents of the InfoWindow // Defines the contents of the InfoWindow
@Override @Override
public View getInfoContents(Marker args) { public View getInfoContents(Marker args) {
// LatLng clickMarkerLatLng = args.getPosition();
// Getting view from the layout file info_window_layout
// Getting the position from the marker
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker) { public void onInfoWindowClick(final Marker marker) {
Note note = eventMarkerMap.get(marker); final Note note = eventMarkerMap.get(marker);
final Dialog noteViewDialog = new Dialog(getActivity()); final Dialog noteViewDialog = new Dialog(getActivity());
noteViewDialog.setContentView(R.layout.note_display_full); noteViewDialog.setContentView(R.layout.note_display_full);
@ -193,8 +186,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
noteViewDialog.show(); noteViewDialog.show();
//get note_view_full layout elements //get note_view_full layout elements
final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview); final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview);
final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview); final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview);
@ -212,61 +203,61 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
time.setText(note.getTimestamp()); time.setText(note.getTimestamp());
location.setText("Address: " + note.getAddress()); location.setText("Address: " + note.getAddress());
likes.setText("Likes: " + note.getLikes()); likes.setText("Likes: " + note.getLikes());
tags.setText("Tags: "+note.getTags().toString()); tags.setText("Tags: " + note.getTags().toString());
Utils.URLtoImageView(avatar, note.getAvatar()); Utils.URLtoImageView(avatar, note.getAvatar());
if (isOwner) { if (isOwner) {
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
} } else {
else{
permission.setText(""); permission.setText("");
deleteBtn.setBackgroundResource(R.drawable.like_icon); deleteBtn.setBackgroundResource(R.drawable.like_icon);
} }
if (isOwner) {
deleteBtn.setOnClickListener(new View.OnClickListener() {
// deleteBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
// public void onClick(View v) { //Put up the Yes/No message box
// //Put up the Yes/No message box AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder
// builder .setTitle("Delete Note")
// .setTitle("Delete Note") .setMessage("Are you sure you want to delete the note?")
// .setMessage("Are you sure you want to delete the note?") .setIcon(android.R.drawable.ic_dialog_alert)
// .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {
// public void onClick(DialogInterface dialog, int which) { //Yes button clicked, do something
// //Yes button clicked, do something Toast.makeText(getActivity(), "Item Deleted!",
// Toast.makeText(getActivity(), "Item Deleted!", Toast.LENGTH_SHORT).show();
// Toast.LENGTH_SHORT).show(); //TODO send delete
// //TODO send delete JSONObject delNote = new JSONObject();
// JSONObject delNote = new JSONObject(); try {
// try { delNote.put("uid", mainActivity.getUserId());
// delNote.put("uid", userId); delNote.put("nid", note.getId());
// delNote.put("nid", note.getId()); VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
// VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener);
// listOfNotes.remove(position); // listOfNotes.remove(position);
// marker.remove();
// } catch (JSONException e) {
// Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show(); } catch (JSONException e) {
// e.printStackTrace(); Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show();
// } e.printStackTrace();
}
// noteList.setAdapter(noteListAdapter); // noteList.setAdapter(noteListAdapter);
// noteViewDialog.dismiss(); noteViewDialog.dismiss();
// } }
// }) })
// .setNegativeButton("No", new DialogInterface.OnClickListener() { .setNegativeButton("No", new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// //Yes button clicked, do something //Yes button clicked, do something
// Toast.makeText(getActivity(), "Canceled", Toast.makeText(getActivity(), "Canceled",
// Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
// noteViewDialog.dismiss(); noteViewDialog.dismiss();
// } }
// }) //Do nothing on no }) //Do nothing on no
// .show(); .show();
// } }
// }); });
}
} }
}); });
@ -300,6 +291,19 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
}; };
private View.OnClickListener cameraBtnListener = new View.OnClickListener()
{
public void onClick(View v)
{
Log.d(TAG, "in camera Button");
}
};
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> { private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> {
GoogleMap mMap; GoogleMap mMap;
HashMap<Marker, Note> eventMarkerMap; HashMap<Marker, Note> eventMarkerMap;

View file

@ -286,12 +286,9 @@ public class PersonalFragment extends Fragment {
return stringArray; return stringArray;
} }
Response.Listener<JSONObject> deleteNoteSuccessListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "deleteNoteSuccessListener: " + response.toString());
}
};
private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException { private void addNoteFromJsonObj(JSONObject noteObject, Date time) throws JSONException {
Note addNote = new Note( Note addNote = new Note(
@ -369,7 +366,7 @@ public class PersonalFragment extends Fragment {
try { try {
delNote.put("uid", userId); delNote.put("uid", userId);
delNote.put("nid", note.getId()); delNote.put("nid", note.getId());
VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener); VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
listOfNotes.remove(position); listOfNotes.remove(position);
} catch (JSONException e) { } catch (JSONException e) {

View file

@ -58,6 +58,13 @@ public class Utils {
} }
}; };
public static Response.Listener<JSONObject> deleteNoteSuccessListener = new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "deleteNoteSuccessListener: " + response.toString());
}
};
public static void showLoadingDialog(Context context, String title, String msg) { public static void showLoadingDialog(Context context, String title, String msg) {
progress = new ProgressDialog(context); progress = new ProgressDialog(context);
progress.setTitle(title); progress.setTitle(title);
@ -133,4 +140,6 @@ public class Utils {
} }
} }
} }

View file

@ -74,11 +74,12 @@
<ImageButton <ImageButton
android:id="@+id/ndf_delete_imagebutton" android:id="@+id/ndf_delete_imagebutton"
android:layout_width="wrap_content" android:layout_width="40dp"
android:layout_height="wrap_content" android:layout_height="40dp"
android:layout_gravity="right" android:layout_gravity="right"
android:background="@android:drawable/ic_menu_delete" /> android:background="@android:drawable/ic_menu_delete" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>