- likes on explore implemented
- likes on explore update the list as well
This commit is contained in:
parent
b2c68a11a7
commit
58519d2431
3 changed files with 48 additions and 63 deletions
|
@ -43,6 +43,7 @@ import java.util.ListIterator;
|
||||||
public class ExploreFragment extends Fragment {
|
public class ExploreFragment extends Fragment {
|
||||||
|
|
||||||
private static final String TAG = "[TSN/Explore]";
|
private static final String TAG = "[TSN/Explore]";
|
||||||
|
// protected final User user = ((MainActivity) getActivity()).getUser();
|
||||||
protected User user;
|
protected User user;
|
||||||
protected MainActivity parent;
|
protected MainActivity parent;
|
||||||
private ListAdapter noteListAdapter;
|
private ListAdapter noteListAdapter;
|
||||||
|
@ -76,7 +77,14 @@ public class ExploreFragment extends Fragment {
|
||||||
public ExploreFragment() {
|
public ExploreFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
parent = (MainActivity) getActivity();
|
||||||
|
gpsUtils = parent.getGPSUtils();
|
||||||
|
user = parent.getUser();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -84,9 +92,7 @@ public class ExploreFragment extends Fragment {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
||||||
|
|
||||||
parent = (MainActivity) getActivity();
|
|
||||||
gpsUtils = parent.getGPSUtils();
|
|
||||||
user = parent.getUser();
|
|
||||||
notes = new ArrayList<>();
|
notes = new ArrayList<>();
|
||||||
//Get Views
|
//Get Views
|
||||||
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
||||||
|
@ -205,6 +211,7 @@ public class ExploreFragment extends Fragment {
|
||||||
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
//create and configure dialog
|
//create and configure dialog
|
||||||
final Note note = notes.get(position);
|
final Note note = notes.get(position);
|
||||||
|
final MainActivity localParent = (MainActivity)getActivity();
|
||||||
final Dialog noteViewDialog = new Dialog(getActivity());
|
final Dialog noteViewDialog = new Dialog(getActivity());
|
||||||
noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
noteViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
noteViewDialog.setContentView(R.layout.note_display_full);
|
noteViewDialog.setContentView(R.layout.note_display_full);
|
||||||
|
@ -235,57 +242,42 @@ public class ExploreFragment extends Fragment {
|
||||||
date.setText(note.getDate());
|
date.setText(note.getDate());
|
||||||
time.setText(note.getTime());
|
time.setText(note.getTime());
|
||||||
location.setText(note.getAddress());
|
location.setText(note.getAddress());
|
||||||
if (likes != null) likes.setText("" + note.getLikes());
|
|
||||||
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
if (likes != null) {
|
||||||
// tags.setText("Tags: "+ note.getTags().toString());
|
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
||||||
// permission.setText("" + (note.isPublic() ? "Public" : "Private"));
|
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);
|
permission.setVisibility(View.GONE);
|
||||||
Utils.URLtoImageView(avatar, note.getAvatar());
|
Utils.URLtoImageView(avatar, note.getAvatar());
|
||||||
permission_image.setVisibility(View.GONE);
|
permission_image.setVisibility(View.GONE);
|
||||||
|
|
||||||
likeBtn.setOnClickListener(new View.OnClickListener() {
|
likeBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// //Put up the Yes/No message box
|
//add like only if user didnt like already
|
||||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
if (!user.getLiked_notes().contains(note.getId())) {
|
||||||
// builder
|
JSONObject jsonObj = new JSONObject();
|
||||||
// .setTitle("Delete Note")
|
try {
|
||||||
// .setMessage("Are you sure you want to delete the note?")
|
jsonObj.put("uid", localParent.getUserId());
|
||||||
// .setIcon(android.R.drawable.ic_dialog_alert)
|
jsonObj.put("nid", note.getId());
|
||||||
// .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, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
|
|
||||||
// listOfNotes.remove(presentedNotes.get(position));
|
|
||||||
// presentedNotes.remove(position);
|
|
||||||
//
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show();
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// updateShowedNotes();
|
|
||||||
//// 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();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,7 +338,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
permissionImg.setVisibility(View.INVISIBLE);
|
permissionImg.setVisibility(View.INVISIBLE);
|
||||||
permission.setText("");
|
permission.setText("");
|
||||||
deleteBtn.setBackgroundResource(R.drawable.unlike_icon);
|
deleteBtn.setBackgroundResource(R.drawable.unlike_icon);
|
||||||
int filterColor;
|
|
||||||
if (mainActivity.getUser().getLiked_notes().contains(note.getId())) {
|
if (mainActivity.getUser().getLiked_notes().contains(note.getId())) {
|
||||||
deleteBtn.setBackgroundResource(R.drawable.like_icon);
|
deleteBtn.setBackgroundResource(R.drawable.like_icon);
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,7 +403,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, likeNotesSuccessListener, Utils.genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, Utils.genericErrorListener);
|
||||||
mainActivity.getUser().getLiked_notes().add(note.getId());
|
mainActivity.getUser().getLiked_notes().add(note.getId());
|
||||||
mainActivity.getUser().updateUser(mainActivity);
|
mainActivity.getUser().updateUser(mainActivity);
|
||||||
note.setLikes(note.getLikes()+1);
|
note.setLikes(note.getLikes()+1);
|
||||||
|
@ -450,16 +449,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//response listener for getting all user notes
|
|
||||||
Response.Listener<JSONObject> likeNotesSuccessListener = new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(JSONObject response) {
|
|
||||||
Log.d(TAG, "likeNotesSuccessListener: " + response.toString());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -96,6 +96,14 @@ public class Utils {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//response listener for getting all user notes
|
||||||
|
public static Response.Listener<JSONObject> genericSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(JSONObject response) {
|
||||||
|
Log.d(TAG, "likeNotesSuccessListener: " + 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);
|
||||||
|
@ -240,8 +248,4 @@ public class Utils {
|
||||||
editor.remove("UserData");
|
editor.remove("UserData");
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue