This commit is contained in:
neslihanturan 2018-03-03 01:03:00 +03:00
parent 0cbbcad525
commit faeebc9caf
6 changed files with 22 additions and 112 deletions

View file

@ -15,9 +15,6 @@ import android.util.Log;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.inject.Inject;
import javax.inject.Singleton;
import timber.log.Timber;
public class LocationServiceManager implements LocationListener {
@ -131,18 +128,14 @@ public class LocationServiceManager implements LocationListener {
|| isMoreAccurate
|| (isNewer && !isLessAccurate)
|| (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)) {
Log.d("deneme","distance:"+results[0]);
if (results[0] < 1000) { // Means change is smaller than 1000 meter
return LocationChangeType.LOCATION_SLIGHTLY_CHANGED;
} else {
return LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
}
// If the new location is more than two minutes older, it must be worse
} else{
Log.d("deneme","distance:"+results[0]);
return LocationChangeType.LOCATION_NOT_CHANGED;
}
}
/**
@ -178,17 +171,14 @@ public class LocationServiceManager implements LocationListener {
@Override
public void onLocationChanged(Location location) {
Log.d("deneme","location changed");
if (isBetterLocation(location, lastLocation)
.equals(LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED)) {
Log.d("deneme","location SIGNIFICANTLY changed better location");
lastLocation = location;
for (LocationUpdateListener listener : locationListeners) {
listener.onLocationChangedSignificantly(LatLng.from(lastLocation));
}
} else if (isBetterLocation(location, lastLocation)
.equals(LocationChangeType.LOCATION_SLIGHTLY_CHANGED)) {
Log.d("deneme","location SLIGHTLY changed better location");
lastLocation = location;
for (LocationUpdateListener listener : locationListeners) {
listener.onLocationChangedSlightly(LatLng.from(lastLocation));
@ -212,8 +202,8 @@ public class LocationServiceManager implements LocationListener {
}
public enum LocationChangeType{
LOCATION_SIGNIFICANTLY_CHANGED,
LOCATION_SLIGHTLY_CHANGED,
LOCATION_SIGNIFICANTLY_CHANGED, //Went out of borders of nearby markers
LOCATION_SLIGHTLY_CHANGED, //User might be walking or driving
LOCATION_NOT_CHANGED
}
}

View file

@ -78,38 +78,18 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
ButterKnife.bind(this);
resumeFragment();
bundle = new Bundle();
//initBottomSheetBehaviour();
initDrawer();
}
private void resumeFragment() {
Log.d("deneme","resumeFragment");
// find the retained fragment on activity restarts
//android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
// nearbyMapFragment = (NearbyMapFragment) fm.findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
// Find the retained fragment on activity restarts
nearbyMapFragment = getMapFragment();
// create the fragment and data the first time
/*if (nearbyMapFragment == null) {
// add the fragment
//nearbyMapFragment = new NearbyMapFragment();
//fm.beginTransaction().add(nearbyMapFragment, TAG_RETAINED_MAP_FRAGMENT).commit();
setMapFragment();
// load data from a data source or perform any calculation
}*/
nearbyListFragment = getListFragment();
/*if (nearbyListFragment == null) {
setListFragment();
}*/
}
private void initBottomSheetBehaviour() {
Log.d("deneme","initBottomSheetBehaviour");
transparentView.setAlpha(0);
bottomSheet.getLayoutParams().height = getWindowManager()
.getDefaultDisplay().getHeight() / 16 * 9;
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
@ -259,8 +239,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("deneme","onActivityResult");
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
Timber.d("User is back from Settings page");
@ -321,13 +299,13 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
*/
private void refreshView(boolean isHardRefresh,
LocationServiceManager.LocationChangeType locationChangeType) {
Log.d("deneme","refreshView");
if (lockNearbyView) {
return;
}
locationManager.registerLocationManager();
LatLng lastLocation = locationManager.getLastLocation();
if (curLatLang != null && curLatLang.equals(lastLocation)) { //refresh view only if location has changed
if (isHardRefresh) {
ViewUtil.showLongToast(this, R.string.nearby_location_has_not_changed);
@ -358,12 +336,9 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
bundle.putString("CurLatLng", gsonCurLatLng);
updateMapFragment(true);
}
}
//private void populatePlaces(List<Place> placeList) {
private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
Log.d("deneme","populatePlaces");
List<Place> placeList = nearbyPlacesInfo.placeList;
LatLng[] boundaryCoordinates = nearbyPlacesInfo.boundaryCoordinates;
Gson gson = new GsonBuilder()
@ -389,27 +364,16 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
lockNearbyView(true);
setMapFragment();
setListFragment();
hideProgressBar();
lockNearbyView(false);
} else { // There are fragments, just update the map and list
} else {
// There are fragments, just update the map and list
updateMapFragment(false);
updateListFragment();
}
/*if (nearbyListFragment == null) {
lockNearbyView(true);
setListFragment();
lockNearbyView(false);
} else {
updateListFragment();
}*/
}
private void lockNearbyView(boolean lock) {
Log.d("deneme","lockNearbyView");
if (lock) {
lockNearbyView = true;
locationManager.unregisterLocationManager();
@ -422,7 +386,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
private void hideProgressBar() {
Log.d("deneme","hideProgressBar");
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
@ -433,7 +396,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
private void removeMapFragment() {
Log.d("deneme","removeMapFragment");
if (nearbyMapFragment != null) {
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().remove(nearbyMapFragment).commit();
@ -445,7 +407,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
private void removeListFragment() {
Log.d("deneme","removeListFragment");
if (nearbyListFragment != null) {
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().remove(nearbyListFragment).commit();
@ -453,7 +414,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
private void updateMapFragment(boolean isSlightUpdate) {
Log.d("deneme","updateMapFragment");
/*
* Significant update means updating nearby place markers. Slightly update means only
* updating current location marker and camera target.
@ -463,20 +423,18 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
* */
NearbyMapFragment nearbyMapFragment = getMapFragment();
if (nearbyMapFragment != null && curLatLang != null) {
// TODO: buradasın eger sınırlara yakınsan significant update yap ve methodların adlarını değiştir.
hideProgressBar(); // In case it is visible (this happens, not an impossible case)
/*
* If we are close to nearby places boundaries, we need a significant update to
* get new nearby places. Check order is south, north, west, east
* */
hideProgressBar(); // In case it is visible (this happens, not an impossible case)
if (nearbyMapFragment.boundaryCoordinates != null
&& (curLatLang.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude()
|| curLatLang.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude()
|| curLatLang.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude()
|| curLatLang.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
Log.d("deneme","updateMapFragment1");
// populate places
placesDisposable = Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLang))
@ -490,21 +448,17 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
if (isSlightUpdate) {
Log.d("deneme","updateMapFragment2");
nearbyMapFragment.setArguments(bundle);
nearbyMapFragment.updateMapSlightly();
} else {
Log.d("deneme","updateMapFragment3");
nearbyMapFragment.setArguments(bundle);
nearbyMapFragment.updateMapSignificantly();
updateListFragment();
}
} else {
Log.d("deneme","updateMapFragment4");
lockNearbyView(true);
setMapFragment();
setListFragment();
hideProgressBar();
lockNearbyView(false);
}
@ -519,20 +473,17 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
* Calls fragment for map view.
*/
private void setMapFragment() {
Log.d("deneme","setMapFragment");
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
nearbyMapFragment = new NearbyMapFragment();
nearbyMapFragment.setArguments(bundle);
fragmentTransaction.replace(R.id.container, nearbyMapFragment, TAG_RETAINED_MAP_FRAGMENT);
fragmentTransaction.commitAllowingStateLoss();
//hideProgressBar();
}
/**
* Calls fragment for list view.
*/
private void setListFragment() {
Log.d("deneme","setListFragment");
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
nearbyListFragment = new NearbyListFragment();
nearbyListFragment.setArguments(bundle);
@ -544,18 +495,12 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
@Override
public void onLocationChangedSignificantly(LatLng latLng) {
Log.d("deneme","onLocationChangedSignificantly");
Toast.makeText(this, "onLocationChangedSignificantly",
Toast.LENGTH_LONG).show();
refreshView(false,
LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED);
}
@Override
public void onLocationChangedSlightly(LatLng latLng) {
Log.d("deneme","onLocationChangedSlightly");
Toast.makeText(this, "onLocationChangedSlightly",
Toast.LENGTH_LONG).show();
refreshView(false,
LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED);
}
@ -563,5 +508,4 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
public void prepareViewsForSheetPosition(int bottomSheetState) {
// TODO
}
}

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
import com.pedrogomez.renderers.ListAdapteeCollection;
import com.pedrogomez.renderers.RVRendererAdapter;
import com.pedrogomez.renderers.RendererAdapter;
import com.pedrogomez.renderers.RendererBuilder;
import java.util.Collections;

View file

@ -46,10 +46,8 @@ public class NearbyController {
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) {
Timber.d("Loading attractions near %s", curLatLng);
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();
//LatLng[] cornerCoordinates = new LatLng[4];
//LatLng west, east, north, south = new LatLng(0,0,0);
if (curLatLng == null) {
//return Collections.emptyList();
return null;
}
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());

View file

@ -12,7 +12,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.pedrogomez.renderers.RVRendererAdapter;
import com.pedrogomez.renderers.RendererAdapter;
import java.lang.reflect.Type;
import java.util.Collections;

View file

@ -103,6 +103,7 @@ public class NearbyMapFragment extends DaggerFragment {
private PolygonOptions currentLocationPolygonOptions;
private boolean isBottomListSheetExpanded;
private final double CAMERA_TARGET_SHIFT_FACTOR = 0.06;
@Inject @Named("prefs") SharedPreferences prefs;
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
@ -114,8 +115,7 @@ public class NearbyMapFragment extends DaggerFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getArguments();
//initViews();
//setListeners();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer())
.create();
@ -133,10 +133,6 @@ public class NearbyMapFragment extends DaggerFragment {
placeList,
getActivity());
boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType);
Log.d("deneme", boundaryCoordinates[0].getLatitude()+","+ boundaryCoordinates[0].getLongitude());
Log.d("deneme", boundaryCoordinates[1].getLatitude()+","+ boundaryCoordinates[1].getLongitude());
Log.d("deneme", boundaryCoordinates[2].getLatitude()+","+ boundaryCoordinates[2].getLongitude());
Log.d("deneme", boundaryCoordinates[3].getLatitude()+","+ boundaryCoordinates[3].getLongitude());
}
Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token));
@ -182,8 +178,7 @@ public class NearbyMapFragment extends DaggerFragment {
}
public void updateMapSlightly() {
// Get arguments from bundle for new location
// Get arguments from bundle for new location
Bundle bundle = this.getArguments();
if (mapboxMap != null) {
Gson gson = new GsonBuilder()
@ -194,22 +189,20 @@ public class NearbyMapFragment extends DaggerFragment {
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
}
updateMapToTrackPosition();
}
}
public void updateMapSignificantly() {
Log.d("deneme", "oldu updateMapSignificantly");
Bundle bundle = this.getArguments();
if (mapboxMap != null) {
Log.d("deneme", "oldu1 updateMapSignificantly");
if (bundle != null) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer())
.create();
Log.d("deneme", "oldu2 updateMapSignificantly");
String gsonPlaceList = bundle.getString("PlaceList");
String gsonLatLng = bundle.getString("CurLatLng");
String gsonBoundaryCoordinates = bundle.getString("BoundaryCoord");
@ -228,16 +221,12 @@ public class NearbyMapFragment extends DaggerFragment {
addCurrentLocationMarker(mapboxMap);
updateMapToTrackPosition();
addNearbyMarkerstoMapBoxMap();
}/*else {
setupMapView(bundle);
}*/
//mapView.setStyleUrl("asset://mapstyle.json");
}
}
// Only update current position marker and camera view
private void updateMapToTrackPosition() {
// Change
Log.d("deneme","updateMapToTrackPosition");
if (currentLocationMarker != null) {
LatLng curMapBoxLatLng = new LatLng(curLatLng.getLatitude(),curLatLng.getLongitude());
ValueAnimator markerAnimator = ObjectAnimator.ofObject(currentLocationMarker, "position",
@ -260,7 +249,7 @@ public class NearbyMapFragment extends DaggerFragment {
// Make camera to follow user on location change
CameraPosition position = new CameraPosition.Builder()
.target(isBottomListSheetExpanded ?
new LatLng(curMapBoxLatLng.getLatitude()- 0.09,
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR,
curMapBoxLatLng.getLongitude())
: curMapBoxLatLng ) // Sets the new camera position
.zoom(11) // Same zoom level
@ -279,23 +268,22 @@ public class NearbyMapFragment extends DaggerFragment {
if (isBottomListSheetExpanded) {
// Make camera to follow user on location change
position = new CameraPosition.Builder()
.target(new LatLng(curLatLng.getLatitude() - 0.09,
curLatLng.getLongitude())) // Sets the new camera target above current to make it visible when sheet is expanded
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR,
curLatLng.getLongitude())) // Sets the new camera target above
// current to make it visible when sheet is expanded
.zoom(11) // Same zoom level
.build();
} else {
// Make camera to follow user on location change
position = new CameraPosition.Builder()
.target(new LatLng(curLatLng.getLatitude(),
curLatLng.getLongitude())) // Sets the new camera target above current to make it visible when sheet is expanded
curLatLng.getLongitude())) // Sets the new camera target to curLatLng
.zoom(11) // Same zoom level
.build();
}
mapboxMap.animateCamera(CameraUpdateFactory
.newCameraPosition(position), 1000);
}
}
@ -412,7 +400,6 @@ public class NearbyMapFragment extends DaggerFragment {
@Override
public void onMapReady(MapboxMap mapboxMap) {
NearbyMapFragment.this.mapboxMap = mapboxMap;
//addNearbyMarkerstoMapBoxMap();
updateMapSignificantly();
}
});
@ -446,13 +433,11 @@ public class NearbyMapFragment extends DaggerFragment {
.strokeColor(Color.parseColor("#55000000"))
.fillColor(Color.parseColor("#11000000"));
mapboxMap.addPolygon(currentLocationPolygonOptions);
//latestSignificantUpdate = curLatLng; // To remember the last point we update nearby markers
}
private void addNearbyMarkerstoMapBoxMap() {
Log.d("deneme", "oldu3");
mapboxMap.addMarkers(baseMarkerOptions);
mapboxMap.addMarkers(baseMarkerOptions);
mapboxMap.setOnInfoWindowCloseListener(marker -> {
if (marker == selected){
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
@ -471,7 +456,6 @@ public class NearbyMapFragment extends DaggerFragment {
return false;
});
// addCurrentLocationMarker(mapboxMap);
}
@ -687,9 +671,6 @@ public class NearbyMapFragment extends DaggerFragment {
setListeners();
transparentView.setClickable(false);
transparentView.setAlpha(0);
/*closeFabs(isFabOpen);
hideFAB();
this.getView().requestFocus();*/
}
@Override
@ -710,7 +691,6 @@ public class NearbyMapFragment extends DaggerFragment {
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
private LatLng latLng = new LatLng();
@Override