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.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -169,18 +170,10 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
// Defines the contents of the InfoWindow
@Override
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() {
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());
noteViewDialog.setContentView(R.layout.note_display_full);
@ -193,8 +186,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
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);
@ -212,61 +203,61 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
time.setText(note.getTimestamp());
location.setText("Address: " + note.getAddress());
likes.setText("Likes: " + note.getLikes());
tags.setText("Tags: "+note.getTags().toString());
tags.setText("Tags: " + note.getTags().toString());
Utils.URLtoImageView(avatar, note.getAvatar());
if (isOwner) {
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
}
else{
} else {
permission.setText("");
deleteBtn.setBackgroundResource(R.drawable.like_icon);
}
// 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);
if (isOwner) {
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", mainActivity.getUserId());
delNote.put("nid", note.getId());
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/delete", delNote, Utils.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();
// }
marker.remove();
} 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();
// }
// });
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();
}
});
}
}
});
@ -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> {
GoogleMap mMap;
HashMap<Marker, Note> eventMarkerMap;

View file

@ -286,14 +286,11 @@ public class PersonalFragment extends Fragment {
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(
noteObject.getString("id"),
Float.parseFloat(noteObject.getJSONObject("location").getString("lat")),
@ -369,7 +366,7 @@ public class PersonalFragment extends Fragment {
try {
delNote.put("uid", userId);
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);
} catch (JSONException e) {

View file

@ -107,8 +107,8 @@ public class SettingsFragment extends Fragment {
{
Log.d(TAG, "in camera Button");
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}

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) {
progress = new ProgressDialog(context);
progress.setTitle(title);
@ -133,4 +140,6 @@ public class Utils {
}
}
}

View file

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