Merge branch 'master' of github.com:sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
6cd2624ec2
3 changed files with 48 additions and 63 deletions
|
@ -43,6 +43,7 @@ import java.util.ListIterator;
|
|||
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;
|
||||
|
@ -76,7 +77,14 @@ public class ExploreFragment extends Fragment {
|
|||
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 View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
|
@ -84,9 +92,7 @@ public class ExploreFragment extends Fragment {
|
|||
// Inflate the layout for this fragment
|
||||
View view = inflater.inflate(R.layout.fragment_explore, container, false);
|
||||
|
||||
parent = (MainActivity) getActivity();
|
||||
gpsUtils = parent.getGPSUtils();
|
||||
user = parent.getUser();
|
||||
|
||||
notes = new ArrayList<>();
|
||||
//Get Views
|
||||
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) {
|
||||
//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);
|
||||
|
@ -235,57 +242,42 @@ public class ExploreFragment extends Fragment {
|
|||
date.setText(note.getDate());
|
||||
time.setText(note.getTime());
|
||||
location.setText(note.getAddress());
|
||||
if (likes != null) likes.setText("" + note.getLikes());
|
||||
|
||||
if (likes != null) {
|
||||
likeBtn.setBackgroundResource(R.drawable.like_icon);
|
||||
// tags.setText("Tags: "+ note.getTags().toString());
|
||||
// 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);
|
||||
Utils.URLtoImageView(avatar, note.getAvatar());
|
||||
permission_image.setVisibility(View.GONE);
|
||||
|
||||
likeBtn.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, 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();
|
||||
// }
|
||||
// });
|
||||
//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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -338,7 +338,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
permissionImg.setVisibility(View.INVISIBLE);
|
||||
permission.setText("");
|
||||
deleteBtn.setBackgroundResource(R.drawable.unlike_icon);
|
||||
int filterColor;
|
||||
if (mainActivity.getUser().getLiked_notes().contains(note.getId())) {
|
||||
deleteBtn.setBackgroundResource(R.drawable.like_icon);
|
||||
} else {
|
||||
|
@ -404,7 +403,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
} catch (JSONException e) {
|
||||
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().updateUser(mainActivity);
|
||||
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> {
|
||||
GoogleMap mMap;
|
||||
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) {
|
||||
progress = new ProgressDialog(context);
|
||||
progress.setTitle(title);
|
||||
|
@ -240,8 +248,4 @@ public class Utils {
|
|||
editor.remove("UserData");
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue