diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 128d662..b5a061b 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -45,7 +45,8 @@
android:label="@string/title_activity_sharing" />
+ android:label="@string/title_activity_sharing"
+ android:launchMode="singleTop" />
coordsMap = new HashMap<>();
+
+ private CoordinateService coordinateService;
+ private CompositeDisposable disposable = new CompositeDisposable();
+
// 4 search
private ListView listView;
@@ -65,16 +98,60 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
+ final String authToken = sharedPref.getString("authToken",null);
+ coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
+
+ mHandler = new Handler();
Bundle extras = getIntent().getExtras();
Mapbox.getInstance(this, getString(R.string.access_token));
+
+
+ mapView = (MapView) findViewById(R.id.mapView);
+ mapView.onCreate(savedInstanceState);
+ mapView.getMapAsync(this);
+
configureconfigureNavigationDrawer();
configureBottomNavigationView();
configureLogoutButton();
}
+ @Override
+ public void onMapReady(MapboxMap map) {
+ mapboxMap = map;
+ final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
+ .position(new LatLng(52.466782,16.927549)));
+ mStatusChecker.run();
+
+ mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
+ @Override
+ public void onMapClick(@NonNull LatLng point) {
+
+ // When the user clicks on the map, we want to animate the marker to that
+ // location.
+ ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
+ new LatLngEvaluator(), marker.getPosition(), point);
+ markerAnimator.setDuration(2000);
+ markerAnimator.start();
+ }
+ });
+ }
+
+
+ Runnable mStatusChecker = new Runnable() {
+ @Override
+ public void run() {
+ try{
+ fetchTopCoords();
+ } finally {
+ mHandler.postDelayed(mStatusChecker, mInterval);
+ }
+ }
+ };
+
private void configureconfigureNavigationDrawer() {
listView = findViewById(R.id.list_item);
Toolbar toolbar = findViewById(R.id.toolbar_main);
@@ -282,18 +359,116 @@ public class MainActivity extends AppCompatActivity {
}
}
- @Override
- protected void onResume() {
- super.onResume();
+ private static class LatLngEvaluator implements TypeEvaluator {
+ // Method is used to interpolate the marker animation.
+
+ private LatLng latLng = new LatLng();
+
+ @Override
+ public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
+ latLng.setLatitude(startValue.getLatitude()
+ + ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
+ latLng.setLongitude(startValue.getLongitude()
+ + ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
+ return latLng;
+ }
+ }
+
+ private void fetchTopCoords() {
+ disposable.add(
+// coordinateService.getTopCoordinates()
+ coordinateService.getOnlineCoordinates()
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribeWith(new DisposableSingleObserver>() {
+ @Override
+ public void onSuccess(List coordsList) {
+
+
+ for (Coordinate element : coordsList) {
+ String id = element.getUserId();
+ Coordinate cord = coordsMap.get(id);
+
+
+ Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
+ Log.d("mapper", "b " + coordsMap.size());
+ if (cord != null) {
+ if (!cord.getLongitude().equals(element.getLongitude())
+ ) {
+ Log.d("mapper", " cos sie zienilo ");
+ Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
+ .title(cord.getUserId())
+ .position(new LatLng(cord.getLatitude(),cord.getLongitude())));
+
+ ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
+ new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
+ markerAnimator.setDuration(2000);
+ markerAnimator.start();
+
+ coordsMap.replace(id,element);
+ } else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
+ Log.d("mapper", "update");
+ Log.d("mapper", " "+cord.getTimeStamp());
+ Log.d("mapper", " "+element.getTimeStamp());
+ coordsMap.replace(id,element);
+ }
+ } else {
+ coordsMap.put(id,element);
+ mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
+ }
+ }
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ Log.e("Error",e.toString());
+ }
+ })
+ );
+
}
@Override
- protected void onPause() {
+ protected void onStart() {
+ super.onStart();
+ mapView.onStart();
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mapView.onResume();
+ }
+
+ @Override
+ public void onPause() {
super.onPause();
+ mapView.onPause();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapView.onStop();
+ }
+
+ @Override
+ public void onLowMemory() {
+ super.onLowMemory();
+ mapView.onLowMemory();
}
protected void onDestroy() {
super.onDestroy();
+ mapView.onDestroy();
+ mHandler.removeCallbacks(mStatusChecker);
+ disposable.dispose();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ mapView.onSaveInstanceState(outState);
}
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 807eab3..1b3c6cc 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,6 +1,7 @@
+
+
+
+