added Documentation
This commit is contained in:
parent
2ca32ca356
commit
76f582d864
4 changed files with 87 additions and 88 deletions
|
@ -41,14 +41,10 @@ public class ExploreFragment extends Fragment {
|
||||||
private ListAdapter noteListAdapter;
|
private ListAdapter noteListAdapter;
|
||||||
private List<Note> notes;
|
private List<Note> notes;
|
||||||
protected ListView list_notes;
|
protected ListView list_notes;
|
||||||
private ImageButton dateFilter;
|
private ImageButton dateFilter, locationFilter;
|
||||||
private ImageButton locationFilter;
|
private Button map_small_filter, map_medium_filter, map_large_filter;
|
||||||
private Button map_small_filter;
|
|
||||||
private Button map_medium_filter;
|
|
||||||
private Button map_large_filter;
|
|
||||||
private LinearLayout exploreFilters;
|
private LinearLayout exploreFilters;
|
||||||
private boolean dateFilterIsVisible = false;
|
private boolean dateFilterIsVisible = false, locationFilterIsVisible = false;
|
||||||
private boolean locationFilterIsVisible = false;
|
|
||||||
private Long dateFilterSelection;
|
private Long dateFilterSelection;
|
||||||
private float locationFilterSelection;
|
private float locationFilterSelection;
|
||||||
private GPSUtils gpsUtils;
|
private GPSUtils gpsUtils;
|
||||||
|
@ -74,7 +70,7 @@ public class ExploreFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
notes = new ArrayList<>();
|
notes = new ArrayList<>();
|
||||||
//Get Views
|
//Get all Views from layout
|
||||||
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
list_notes = (ListView) view.findViewById(R.id.list_notes);
|
||||||
noteListAdapter = new ListAdapter(parent, notes);
|
noteListAdapter = new ListAdapter(parent, notes);
|
||||||
list_notes.setOnItemClickListener(new ItemClickedListener());
|
list_notes.setOnItemClickListener(new ItemClickedListener());
|
||||||
|
@ -88,12 +84,14 @@ public class ExploreFragment extends Fragment {
|
||||||
map_small_filter.setOnClickListener(button1ClickListener);
|
map_small_filter.setOnClickListener(button1ClickListener);
|
||||||
map_medium_filter.setOnClickListener(button2ClickListener);
|
map_medium_filter.setOnClickListener(button2ClickListener);
|
||||||
map_large_filter.setOnClickListener(button3ClickListener);
|
map_large_filter.setOnClickListener(button3ClickListener);
|
||||||
|
|
||||||
exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options);
|
exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options);
|
||||||
|
|
||||||
|
|
||||||
|
//set listener for date filter button
|
||||||
dateFilter.setOnClickListener(new View.OnClickListener() {
|
dateFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
//check if already pressed
|
||||||
if (dateFilterIsVisible) {
|
if (dateFilterIsVisible) {
|
||||||
dateFilterIsVisible = false;
|
dateFilterIsVisible = false;
|
||||||
exploreFilters.setVisibility(View.GONE);
|
exploreFilters.setVisibility(View.GONE);
|
||||||
|
@ -101,6 +99,7 @@ public class ExploreFragment extends Fragment {
|
||||||
exploreFilters.setVisibility(View.VISIBLE);
|
exploreFilters.setVisibility(View.VISIBLE);
|
||||||
dateFilterIsVisible = true;
|
dateFilterIsVisible = true;
|
||||||
locationFilterIsVisible = false;
|
locationFilterIsVisible = false;
|
||||||
|
|
||||||
// set text button in the right filter string
|
// set text button in the right filter string
|
||||||
map_small_filter.setText(R.string.day);
|
map_small_filter.setText(R.string.day);
|
||||||
map_medium_filter.setText(R.string.week);
|
map_medium_filter.setText(R.string.week);
|
||||||
|
@ -110,9 +109,12 @@ public class ExploreFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//set listener for location filter button
|
||||||
locationFilter.setOnClickListener(new View.OnClickListener() {
|
locationFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
//check if already pressed
|
||||||
if (locationFilterIsVisible) {
|
if (locationFilterIsVisible) {
|
||||||
locationFilterIsVisible = false;
|
locationFilterIsVisible = false;
|
||||||
exploreFilters.setVisibility(View.GONE);
|
exploreFilters.setVisibility(View.GONE);
|
||||||
|
@ -128,6 +130,7 @@ public class ExploreFragment extends Fragment {
|
||||||
setButtonsColor();
|
setButtonsColor();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getAllNotes();
|
getAllNotes();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import android.graphics.Bitmap;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
//import android.app.Fragment;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -49,8 +48,6 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
private static final String ARG_PARAM2 = "param2";
|
private static final String ARG_PARAM2 = "param2";
|
||||||
private static final String TAG = "[TSN / GmapFragment]";
|
private static final String TAG = "[TSN / GmapFragment]";
|
||||||
|
@ -62,13 +59,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
private ImageButton dateFilter;
|
private ImageButton dateFilter;
|
||||||
private ImageButton locationFilter;
|
private ImageButton locationFilter;
|
||||||
private ImageButton userFilter;
|
private ImageButton userFilter;
|
||||||
private Button map_small_filter;
|
private Button map_small_filter, map_medium_filter, map_large_filter;
|
||||||
private Button map_medium_filter;
|
|
||||||
private Button map_large_filter;
|
|
||||||
private LinearLayout mapFilters, mainMapFilters;
|
private LinearLayout mapFilters, mainMapFilters;
|
||||||
private boolean dateFilterIsVisible = false;
|
private boolean dateFilterIsVisible = false, locationFilterIsVisible = false, userFilterIsVisible = false;
|
||||||
private boolean locationFilterIsVisible = false;
|
|
||||||
private boolean userFilterIsVisible = false;
|
|
||||||
private int userFilterSelection;
|
private int userFilterSelection;
|
||||||
private Long dateFilterSelection;
|
private Long dateFilterSelection;
|
||||||
private float locationFilterSelection;
|
private float locationFilterSelection;
|
||||||
|
@ -108,18 +101,19 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View view = inflater.inflate(R.layout.fragment_personal, container, false);
|
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_gmap, container, false);
|
return inflater.inflate(R.layout.fragment_gmap, container, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
//initiate map
|
||||||
SupportMapFragment frag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
|
SupportMapFragment frag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFragment);
|
||||||
frag.getMapAsync(this);
|
frag.getMapAsync(this);
|
||||||
listOfNotes = new ArrayList<>();
|
|
||||||
|
|
||||||
|
//initialize arrays and get all layout views
|
||||||
|
listOfNotes = new ArrayList<>();
|
||||||
dateFilter = (ImageButton) view.findViewById(R.id.map_date_filter);
|
dateFilter = (ImageButton) view.findViewById(R.id.map_date_filter);
|
||||||
locationFilter = (ImageButton) view.findViewById(R.id.map_location_filter);
|
locationFilter = (ImageButton) view.findViewById(R.id.map_location_filter);
|
||||||
userFilter = (ImageButton) view.findViewById(R.id.map_user_filter);
|
userFilter = (ImageButton) view.findViewById(R.id.map_user_filter);
|
||||||
|
@ -128,6 +122,8 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
map_medium_filter = (Button) view.findViewById(R.id.map_medium_filter);
|
map_medium_filter = (Button) view.findViewById(R.id.map_medium_filter);
|
||||||
map_large_filter = (Button) view.findViewById(R.id.map_large_filter);
|
map_large_filter = (Button) view.findViewById(R.id.map_large_filter);
|
||||||
|
|
||||||
|
|
||||||
|
//set onClickListeners for all filter buttons
|
||||||
map_small_filter.setOnClickListener(button1ClickListener);
|
map_small_filter.setOnClickListener(button1ClickListener);
|
||||||
map_medium_filter.setOnClickListener(button2ClickListener);
|
map_medium_filter.setOnClickListener(button2ClickListener);
|
||||||
map_large_filter.setOnClickListener(button3ClickListener);
|
map_large_filter.setOnClickListener(button3ClickListener);
|
||||||
|
@ -135,9 +131,11 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
mapFilters = (LinearLayout) view.findViewById(R.id.map_filter_options);
|
mapFilters = (LinearLayout) view.findViewById(R.id.map_filter_options);
|
||||||
mainMapFilters = (LinearLayout) view.findViewById(R.id.map_filters_layout);
|
mainMapFilters = (LinearLayout) view.findViewById(R.id.map_filters_layout);
|
||||||
|
|
||||||
|
//set listener for date filter button
|
||||||
dateFilter.setOnClickListener(new View.OnClickListener() {
|
dateFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
//check if already pressed
|
||||||
if (dateFilterIsVisible) {
|
if (dateFilterIsVisible) {
|
||||||
dateFilterIsVisible = false;
|
dateFilterIsVisible = false;
|
||||||
mapFilters.setVisibility(View.GONE);
|
mapFilters.setVisibility(View.GONE);
|
||||||
|
@ -156,9 +154,11 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//set listener for location filter button
|
||||||
locationFilter.setOnClickListener(new View.OnClickListener() {
|
locationFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
//check if already pressed
|
||||||
if (locationFilterIsVisible) {
|
if (locationFilterIsVisible) {
|
||||||
locationFilterIsVisible = false;
|
locationFilterIsVisible = false;
|
||||||
mapFilters.setVisibility(View.GONE);
|
mapFilters.setVisibility(View.GONE);
|
||||||
|
@ -177,9 +177,11 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//set listener for user filter button
|
||||||
userFilter.setOnClickListener(new View.OnClickListener() {
|
userFilter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
//check if already pressed
|
||||||
if (userFilterIsVisible) {
|
if (userFilterIsVisible) {
|
||||||
userFilterIsVisible = false;
|
userFilterIsVisible = false;
|
||||||
mapFilters.setVisibility(View.GONE);
|
mapFilters.setVisibility(View.GONE);
|
||||||
|
@ -215,6 +217,8 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
public void onMapReady(GoogleMap googleMap) {
|
public void onMapReady(GoogleMap googleMap) {
|
||||||
|
|
||||||
mMap = googleMap;
|
mMap = googleMap;
|
||||||
|
|
||||||
|
//limit map zoom in\out options
|
||||||
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
|
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCameraChange(CameraPosition cameraPosition) {
|
public void onCameraChange(CameraPosition cameraPosition) {
|
||||||
|
@ -227,21 +231,26 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//add listener for clicking marker details on map
|
||||||
mMap.setInfoWindowAdapter(infoWindowAdapter);
|
mMap.setInfoWindowAdapter(infoWindowAdapter);
|
||||||
|
|
||||||
|
|
||||||
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
//check if permission to location is enabled - and show user location on map
|
||||||
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
|
||||||
if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateLocationCircle();
|
|
||||||
mMap.setMyLocationEnabled(true);
|
mMap.setMyLocationEnabled(true);
|
||||||
|
updateLocationCircle();
|
||||||
|
|
||||||
|
//set camera to user location
|
||||||
|
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
||||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM));
|
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM));
|
||||||
|
|
||||||
//get my notes
|
//get my notes
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener);
|
||||||
|
|
||||||
|
//put user id in Json with any wanted filters
|
||||||
JSONObject jsonObj = new JSONObject();
|
JSONObject jsonObj = new JSONObject();
|
||||||
try {
|
try {
|
||||||
jsonObj.put("id", mainActivity.getUserId());
|
jsonObj.put("id", mainActivity.getUserId());
|
||||||
|
@ -254,6 +263,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function draws a circle around the user location according to the distance filter
|
||||||
|
*/
|
||||||
private void updateLocationCircle() {
|
private void updateLocationCircle() {
|
||||||
if(onMapCircle!=null){
|
if(onMapCircle!=null){
|
||||||
onMapCircle.remove();
|
onMapCircle.remove();
|
||||||
|
@ -264,6 +276,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
.fillColor(Utils.circleColor));
|
.fillColor(Utils.circleColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This adapter is used for opening a dialog for user note when pressed associated marker
|
||||||
|
*/
|
||||||
GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter() { // Use default InfoWindow frame
|
GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter() { // Use default InfoWindow frame
|
||||||
@Override
|
@Override
|
||||||
public View getInfoWindow(Marker args) {
|
public View getInfoWindow(Marker args) {
|
||||||
|
@ -299,16 +314,16 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
final ImageView permissionImg = (ImageView) noteViewDialog.findViewById(R.id.permission_image);
|
final ImageView permissionImg = (ImageView) noteViewDialog.findViewById(R.id.permission_image);
|
||||||
final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton);
|
final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton);
|
||||||
|
|
||||||
|
//set all date to dialog fields
|
||||||
title.setText(note.getTitle());
|
title.setText(note.getTitle());
|
||||||
body.setText(note.getBody());
|
body.setText(note.getBody());
|
||||||
time.setText(note.getTime());
|
time.setText(note.getTime());
|
||||||
date.setText(note.getDate());
|
date.setText(note.getDate());
|
||||||
|
|
||||||
location.setText("" + note.getAddress());
|
location.setText("" + note.getAddress());
|
||||||
likes.setText("" + note.getLikes());
|
likes.setText("" + note.getLikes());
|
||||||
// tags.setText("Tags: " + note.getTags().toString());
|
|
||||||
Utils.URLtoImageView(avatar, note.getAvatar());
|
Utils.URLtoImageView(avatar, note.getAvatar());
|
||||||
|
|
||||||
|
//set delete\like icon according to user and note relation
|
||||||
if (isOwner) {
|
if (isOwner) {
|
||||||
permission.setText("" + (note.isPublic() ? "Public" : "Private"));
|
permission.setText("" + (note.isPublic() ? "Public" : "Private"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -322,6 +337,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if user is owner of note - set delete function
|
||||||
if (isOwner) {
|
if (isOwner) {
|
||||||
deleteBtn.setOnClickListener(new View.OnClickListener() {
|
deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -341,6 +357,8 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
try {
|
try {
|
||||||
delNote.put("uid", mainActivity.getUserId());
|
delNote.put("uid", mainActivity.getUserId());
|
||||||
delNote.put("nid", note.getId());
|
delNote.put("nid", note.getId());
|
||||||
|
|
||||||
|
//update server
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
|
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/delete", delNote, Utils.deleteNoteSuccessListener, Utils.genericErrorListener);
|
||||||
// listOfNotes.remove(position);
|
// listOfNotes.remove(position);
|
||||||
marker.remove();
|
marker.remove();
|
||||||
|
@ -365,7 +383,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//if user is NOT owner of note - set like function
|
||||||
} else {
|
} else {
|
||||||
//like Btn
|
//like Btn
|
||||||
deleteBtn.setOnClickListener(new View.OnClickListener() {
|
deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -380,6 +398,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
//update server and local data
|
||||||
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/like", jsonObj, Utils.genericSuccessListener, 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);
|
||||||
|
@ -400,7 +419,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//response listener for getting all user notes
|
/**
|
||||||
|
* response listener for getting all user notes
|
||||||
|
*/
|
||||||
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
|
@ -426,6 +447,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* async class in charge of getting image from server, and adding a note to the map when ready
|
||||||
|
*/
|
||||||
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;
|
||||||
|
@ -446,9 +470,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(List<Note>... listOfNotes) {
|
protected Void doInBackground(List<Note>... listOfNotes) {
|
||||||
Log.d(TAG, "in async BG");
|
Log.d(TAG, "in async BG");
|
||||||
|
|
||||||
BitmapDescriptor b;
|
BitmapDescriptor b;
|
||||||
|
|
||||||
|
//create new marker for each note
|
||||||
for (Note n : listOfNotes[0]) {
|
for (Note n : listOfNotes[0]) {
|
||||||
b = BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false));
|
b = BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false));
|
||||||
MarkerOptions mo = new MarkerOptions()
|
MarkerOptions mo = new MarkerOptions()
|
||||||
|
@ -457,6 +481,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
.snippet(n.getBody())
|
.snippet(n.getBody())
|
||||||
.icon(b);
|
.icon(b);
|
||||||
|
|
||||||
|
//update UI
|
||||||
publishProgress(new MarkerNoteStruct(n, mo));
|
publishProgress(new MarkerNoteStruct(n, mo));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -467,7 +492,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//set main filter colors
|
/**
|
||||||
|
* set all filter buttons colors
|
||||||
|
*/
|
||||||
private void setButtonsColor() {
|
private void setButtonsColor() {
|
||||||
|
|
||||||
Log.d(TAG, "setButtonsColor: start");
|
Log.d(TAG, "setButtonsColor: start");
|
||||||
|
@ -537,24 +564,30 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
mainMapFilters.setPadding(0, 8, 0, 0);
|
mainMapFilters.setPadding(0, 8, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the list of currently presented notes according to filters
|
||||||
|
*/
|
||||||
public void updateShowedNotes() {
|
public void updateShowedNotes() {
|
||||||
List<Note> presentedNotes = new ArrayList<>();
|
List<Note> presentedNotes = new ArrayList<>();
|
||||||
long timeDifference;
|
long timeDifference;
|
||||||
float distance;
|
float distance;
|
||||||
|
|
||||||
//get current date and location
|
//get current date and location
|
||||||
Location currLocation = new Location(gpsUtils.getLocation());
|
Location currLocation = new Location(gpsUtils.getLocation());
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Location targetLocation = new Location("");//provider name is unecessary
|
Location targetLocation = new Location("");//provider name is unecessary
|
||||||
Date targetDate;
|
Date targetDate;
|
||||||
|
|
||||||
|
//for each note - check if passes filter limitations
|
||||||
for (Note note : listOfNotes) {
|
for (Note note : listOfNotes) {
|
||||||
// get note location and date
|
//get note location and date
|
||||||
targetLocation.setLatitude(note.getLat());//your coords of course
|
targetLocation.setLatitude(note.getLat());
|
||||||
targetLocation.setLongitude(note.getLon());
|
targetLocation.setLongitude(note.getLon());
|
||||||
targetDate = new Date(note.getTimestamp());
|
targetDate = new Date(note.getTimestamp());
|
||||||
//get time and date differences
|
//get time and date differences
|
||||||
timeDifference = now.getTime() - targetDate.getTime();
|
timeDifference = now.getTime() - targetDate.getTime();
|
||||||
distance = currLocation.distanceTo(targetLocation);
|
distance = currLocation.distanceTo(targetLocation);
|
||||||
|
|
||||||
//add to currently presented list according to filters.
|
//add to currently presented list according to filters.
|
||||||
if (timeDifference <= dateFilterSelection
|
if (timeDifference <= dateFilterSelection
|
||||||
&& distance <= locationFilterSelection
|
&& distance <= locationFilterSelection
|
||||||
|
@ -563,14 +596,16 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Log.d(TAG, "updateShowedNotes: ======= markers presented: "+ presentedNotes.size()+"=============");
|
//clear map and re-add relevant notes
|
||||||
mMap.clear();
|
mMap.clear();
|
||||||
updateLocationCircle();
|
updateLocationCircle();
|
||||||
new getMarkersFromNotes(mMap, eventMarkerMap).execute(presentedNotes);
|
new getMarkersFromNotes(mMap, eventMarkerMap).execute(presentedNotes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//all buttons listener
|
/**
|
||||||
|
* first filter click listener
|
||||||
|
*/
|
||||||
public View.OnClickListener button1ClickListener = new View.OnClickListener() {
|
public View.OnClickListener button1ClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
|
@ -595,7 +630,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//all buttons listener
|
/**
|
||||||
|
* second filter click listener
|
||||||
|
*/
|
||||||
public View.OnClickListener button2ClickListener = new View.OnClickListener() {
|
public View.OnClickListener button2ClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
|
@ -619,7 +656,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//all buttons listener
|
/**
|
||||||
|
* first filter click listener
|
||||||
|
*/
|
||||||
public View.OnClickListener button3ClickListener = new View.OnClickListener() {
|
public View.OnClickListener button3ClickListener = new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by aranza on 7/2/2016.
|
|
||||||
*/
|
|
||||||
public class HeavyWorker extends AsyncTask<String, Context, Void> {
|
|
||||||
|
|
||||||
private ProgressDialog progressDialog;
|
|
||||||
private Context targetCtx;
|
|
||||||
|
|
||||||
public HeavyWorker(Context context) {
|
|
||||||
this.targetCtx = context;
|
|
||||||
progressDialog = new ProgressDialog(targetCtx);
|
|
||||||
progressDialog.setCancelable(false);
|
|
||||||
progressDialog.setMessage("Retrieving data...");
|
|
||||||
progressDialog.setTitle("Please wait");
|
|
||||||
progressDialog.setIndeterminate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
progressDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(String... params) {
|
|
||||||
// Do Your WORK here
|
|
||||||
|
|
||||||
// MainActivity ps = (MainActivity) targetCtx;
|
|
||||||
// ps.getAllNotes();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
if (progressDialog != null && progressDialog.isShowing()) {
|
|
||||||
progressDialog.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -58,22 +58,24 @@ public class ListAdapter extends BaseAdapter {
|
||||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
v = inflater.inflate(R.layout.note_view_mini , parent , false);
|
v = inflater.inflate(R.layout.note_view_mini , parent , false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get all layout views
|
||||||
TextView title = (TextView) v.findViewById(R.id.nvm_title_textview);
|
TextView title = (TextView) v.findViewById(R.id.nvm_title_textview);
|
||||||
TextView time = (TextView) v.findViewById(R.id.nvm_time_textview);
|
TextView time = (TextView) v.findViewById(R.id.nvm_time_textview);
|
||||||
TextView date = (TextView) v.findViewById(R.id.nvm_date_textview);
|
TextView date = (TextView) v.findViewById(R.id.nvm_date_textview);
|
||||||
TextView location = (TextView) v.findViewById(R.id.nvm_location_textview);
|
TextView location = (TextView) v.findViewById(R.id.nvm_location_textview);
|
||||||
TextView likes = (TextView) v.findViewById(R.id.nvm_likes_textview);
|
TextView likes = (TextView) v.findViewById(R.id.nvm_likes_textview);
|
||||||
ImageView permission = (RoundAvatarImageView) v.findViewById(R.id.nvm_permission_image_view);
|
ImageView permission = (RoundAvatarImageView) v.findViewById(R.id.nvm_permission_image_view);
|
||||||
// NetworkImageView thumbNail = (NetworkImageView) v.findViewById(R.id.infoImageImageView);
|
|
||||||
// String url = mVideos.get(position).getImgURL();
|
//set data from note
|
||||||
// thumbNail.setImageUrl(url, VolleyUtilSingleTone.getInstance(mContext).getImageLoader());
|
|
||||||
Note curNote = mNotes.get(position);
|
Note curNote = mNotes.get(position);
|
||||||
title.setText(curNote.getTitle());
|
title.setText(curNote.getTitle());
|
||||||
time.setText(curNote.getTime());
|
time.setText(curNote.getTime());
|
||||||
date.setText(curNote.getDate());
|
date.setText(curNote.getDate());
|
||||||
location.setText(curNote.getAddress());
|
location.setText(curNote.getAddress());
|
||||||
if(likes !=null )likes.setText(""+curNote.getLikes());
|
if(likes !=null )likes.setText(""+curNote.getLikes());
|
||||||
// permission.setText(curNote.isPublic() ? "Public":"Private");
|
|
||||||
|
//add permission icon only if user is owner
|
||||||
if(((MainActivity)mContext).getUser().getId().equals(curNote.ownerId)){// MY Note
|
if(((MainActivity)mContext).getUser().getId().equals(curNote.ownerId)){// MY Note
|
||||||
permission.setBackground(curNote.isPublic() ? v.getResources().getDrawable(R.drawable.public_icon): v.getResources().getDrawable(R.drawable.private_icon));
|
permission.setBackground(curNote.isPublic() ? v.getResources().getDrawable(R.drawable.public_icon): v.getResources().getDrawable(R.drawable.private_icon));
|
||||||
}else{
|
}else{
|
||||||
|
|
Loading…
Reference in a new issue