Merge branch 'master' of github.com:sagidayan/TheSocialNotework-Android

This commit is contained in:
Sagi Dayan 2016-07-10 15:35:50 +03:00
commit b2c68a11a7
3 changed files with 179 additions and 28 deletions

View file

@ -4,6 +4,7 @@ package com.android_app.matan.ara.sagi.thesocialnotework;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
@ -57,14 +58,17 @@ public class ExploreFragment extends Fragment {
private LinearLayout exploreFilters;
private boolean dateFilterIsVisible = false;
private boolean locationFilterIsVisible = false;
private Long dateFilterSelection;
private float locationFilterSelection;
private GPSUtils gpsUtils;
// private boolean userFilterIsVisible = false;
private final String day = "24 hours";
private final String week = "Week";
private final String month = "Month";
private final String hundredMeters = "100 meters";
private final String kilometer = "1 Km";
private final String threeKilometer = "3 Km";
private final String hundredMeters = "1 K";
private final String kilometer = "10 Km";
private final String threeKilometer = "100 Km";
// private final String mine = "Mine";
// private final String others = "Others";
// private final String all = "All";
@ -81,12 +85,16 @@ public class ExploreFragment extends 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);
noteListAdapter = new ListAdapter(parent, notes);
list_notes.setOnItemClickListener(new ItemClickedListener());
dateFilterSelection = Utils.MONTH_MILI;
locationFilterSelection = Utils.DISTANCE_LONG;
dateFilter = (ImageButton) view.findViewById(R.id.explore_date_filter);
@ -96,6 +104,10 @@ public class ExploreFragment extends Fragment {
map_medium_filter = (Button) view.findViewById(R.id.explore_medium_filter);
map_large_filter = (Button) view.findViewById(R.id.explore_large_filter);
map_small_filter.setOnClickListener(button1ClickListener);
map_medium_filter.setOnClickListener(button2ClickListener);
map_large_filter.setOnClickListener(button3ClickListener);
exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options);
dateFilter.setOnClickListener(new View.OnClickListener() {
@ -115,6 +127,7 @@ public class ExploreFragment extends Fragment {
map_medium_filter.setText(week);
map_large_filter.setText(month);
}
setButtonsColor();
}
});
@ -135,28 +148,10 @@ public class ExploreFragment extends Fragment {
map_medium_filter.setText(kilometer);
map_large_filter.setText(threeKilometer);
}
setButtonsColor();
}
});
// userFilter.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// if (userFilterIsVisible) {
// userFilterIsVisible = false;
// exploreFilters.setVisibility(View.GONE);
// } else {
// exploreFilters.setVisibility(View.VISIBLE);
// userFilterIsVisible = true;
// dateFilterIsVisible = false;
// locationFilterIsVisible = false;
//
// // set text button in the right filter string
// map_small_filter.setText(mine);
// map_medium_filter.setText(others);
// map_large_filter.setText(all);
// }
// }
// });
// TODO: choose a default filter for openning explore mode
@ -193,7 +188,8 @@ public class ExploreFragment extends Fragment {
time.setTime(noteObject.getLong("created_at"));
notes.add(Utils.getNoteFromJsonObj(noteObject, time));
}
list_notes.setAdapter(noteListAdapter);
// list_notes.setAdapter(noteListAdapter);
updateShowedNotes();
Utils.dismissLoadingDialog();
} catch (Exception e) {
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
@ -295,5 +291,143 @@ public class ExploreFragment extends Fragment {
}
}
//all buttons listener
public View.OnClickListener button1ClickListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
//location filter
if (locationFilterIsVisible) {
locationFilterSelection = Utils.DISTANCE_SMALL;
}
//date filters
else {
dateFilterSelection = Utils.DAY_MILI;
}
//change colors of buttons and update visible notes
setButtonsColor();
updateShowedNotes();
}
};
//all buttons listener
public View.OnClickListener button2ClickListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
//location filter
if (locationFilterIsVisible) {
locationFilterSelection = Utils.DISTANCE_MEDIUM;
}
//date filters
else {
dateFilterSelection = Utils.WEEK_MILI;
}
//change colors of buttons and update visible notes
setButtonsColor();
updateShowedNotes();
}
};
//all buttons listener
public View.OnClickListener button3ClickListener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
//location filter
if (locationFilterIsVisible) {
locationFilterSelection = Utils.DISTANCE_LONG;
}
//date filters
else {
dateFilterSelection = Utils.MONTH_MILI;
}
//change colors of buttons and update visible notes
setButtonsColor();
updateShowedNotes();
}
};
//set main filter colors
private void setButtonsColor() {
Log.d(TAG, "setButtonsColor: start");
//set date filter colors
if (dateFilterIsVisible) {
dateFilter.setBackgroundColor(Utils.filterColor);
if (dateFilterSelection == Utils.DAY_MILI) {
map_small_filter.setBackgroundColor(Utils.filterColor);
map_medium_filter.setBackgroundResource(android.R.drawable.btn_default);
map_large_filter.setBackgroundResource(android.R.drawable.btn_default);
} else if (dateFilterSelection == Utils.WEEK_MILI) {
map_small_filter.setBackgroundResource(android.R.drawable.btn_default);
map_medium_filter.setBackgroundColor(Utils.filterColor);
map_large_filter.setBackgroundResource(android.R.drawable.btn_default);
} else {
map_small_filter.setBackgroundResource(android.R.drawable.btn_default);
map_medium_filter.setBackgroundResource(android.R.drawable.btn_default);
map_large_filter.setBackgroundColor(Utils.filterColor);
}
} else {
dateFilter.setBackgroundResource(android.R.drawable.btn_default);
}
//set distance filter colors
if (locationFilterIsVisible) {
locationFilter.setBackgroundColor(Utils.filterColor);
if (locationFilterSelection == Utils.DISTANCE_SMALL) {
map_small_filter.setBackgroundColor(Utils.filterColor);
map_medium_filter.setBackgroundResource(android.R.drawable.btn_default);
map_large_filter.setBackgroundResource(android.R.drawable.btn_default);
} else if (locationFilterSelection == Utils.DISTANCE_MEDIUM) {
map_small_filter.setBackgroundResource(android.R.drawable.btn_default);
map_medium_filter.setBackgroundColor(Utils.filterColor);
map_large_filter.setBackgroundResource(android.R.drawable.btn_default);
} else {
map_small_filter.setBackgroundResource(android.R.drawable.btn_default);
map_medium_filter.setBackgroundResource(android.R.drawable.btn_default);
map_large_filter.setBackgroundColor(Utils.filterColor);
}
} else {
locationFilter.setBackgroundResource(android.R.drawable.btn_default);
}
}
public void updateShowedNotes() {
List<Note> presentedNotes = new ArrayList<>();
long timeDifference;
float distance;
//get current date and location
Location currLocation = new Location(gpsUtils.getLocation());
Date now = new Date();
Location targetLocation = new Location("");//provider name is unecessary
Date targetDate;
for (Note note : notes) {
// get note location and date
targetLocation.setLatitude(note.getLat());//your coords of course
targetLocation.setLongitude(note.getLon());
targetDate = new Date(note.getTimestamp());
//get time and date differences
timeDifference = now.getTime() - targetDate.getTime();
distance = currLocation.distanceTo(targetLocation);
//add to currently presented list according to filters.
if (timeDifference <= dateFilterSelection
&& distance <= locationFilterSelection){
presentedNotes.add(note);
}
}
noteListAdapter.updateList(presentedNotes);
list_notes.setAdapter(noteListAdapter);
}
}

View file

@ -40,6 +40,8 @@ import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Circle;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
@ -68,7 +70,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
private GPSUtils gpsUtils;
private MainActivity mainActivity;
private final int MAX_ZOOM = 16, MIN_ZOOM = 9, DEFAULT_ZOOM = 12;
private final int MAX_ZOOM = 16, MIN_ZOOM = 8, DEFAULT_ZOOM = 12;
private HashMap<Marker, Note> eventMarkerMap;
private ImageButton dateFilter;
private ImageButton locationFilter;
@ -84,6 +86,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
private Long dateFilterSelection;
private float locationFilterSelection;
List<Note> listOfNotes;
private Circle onMapCircle;
private final String day = "24 hours";
private final String week = "Week";
@ -238,9 +241,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
if (cameraPosition.zoom > MAX_ZOOM) {
getMap().animateCamera(CameraUpdateFactory.zoomTo(MAX_ZOOM));
}
// if (cameraPosition.zoom > MAX_ZOOM) {
// getMap().animateCamera(CameraUpdateFactory.zoomTo(MAX_ZOOM));
// }
if (cameraPosition.zoom < MIN_ZOOM) {
getMap().animateCamera(CameraUpdateFactory.zoomTo(MIN_ZOOM));
}
@ -255,6 +258,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
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;
}
updateLocationCircle();
mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM));
@ -273,6 +277,16 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
}
private void updateLocationCircle() {
if(onMapCircle!=null){
onMapCircle.remove();
}
onMapCircle = mMap.addCircle(new CircleOptions()
.center(new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude()))
.radius(locationFilterSelection)
.fillColor(Utils.circleColor));
}
GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter() { // Use default InfoWindow frame
@Override
public View getInfoWindow(Marker args) {
@ -550,6 +564,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
map_medium_filter.setBackgroundResource(android.R.drawable.btn_default);
map_large_filter.setBackgroundColor(Utils.filterColor);
}
updateLocationCircle();
} else {
locationFilter.setBackgroundResource(android.R.drawable.btn_default);
}
@ -583,6 +598,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
}
Log.d(TAG, "updateShowedNotes: ======= markers presented: "+ presentedNotes.size()+"=============");
mMap.clear();
updateLocationCircle();
new getMarkersFromNotes(mMap, eventMarkerMap).execute(presentedNotes);
}

View file

@ -48,7 +48,8 @@ public class Utils {
private static boolean mLocationPermission = false;
private static boolean mCameraPermission = false;
private static SharedPreferences prefs;
public static int filterColor = Color.parseColor("#33adff");
public static int filterColor = Color.parseColor("#33adff"), circleColor =0x6666a3ff;
public static final long DAY_MILI = 86400000L,WEEK_MILI = 604800000L,MONTH_MILI = 2592000000L;
public static final float DISTANCE_SMALL = 1000,DISTANCE_MEDIUM = 10000,DISTANCE_LONG = 100000;