Add modal on marker click
This commit is contained in:
parent
03235ce18b
commit
583305ff31
@ -176,7 +176,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void getUserProfile(String userId) {
|
private void getUserProfile(String userId) {
|
||||||
|
|
||||||
disposable.add(userService.getUserByID(userId)
|
disposable.add(userService.getUserById(userId)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::saveUserProfileToSharedPreferences, this::handleError));
|
.subscribe(this::saveUserProfileToSharedPreferences, this::handleError));
|
||||||
|
@ -5,60 +5,68 @@ import android.animation.ObjectAnimator;
|
|||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.animation.LinearInterpolator;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
|
import com.auth0.android.jwt.Claim;
|
||||||
|
import com.auth0.android.jwt.JWT;
|
||||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||||
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||||
|
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||||
|
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||||
|
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
|
||||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
|
||||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
|
||||||
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
|
||||||
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.animation.LinearInterpolator;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
|
||||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
|
||||||
|
|
||||||
import com.mapbox.mapboxsdk.Mapbox;
|
|
||||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
|
||||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
|
||||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
|
||||||
import com.mapbox.mapboxsdk.maps.MapView;
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||||
|
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||||
|
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||||
|
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||||
import com.uam.wmi.findmytutor.R;
|
import com.uam.wmi.findmytutor.R;
|
||||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||||
|
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||||
|
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||||
|
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||||
|
import com.uam.wmi.findmytutor.model.User;
|
||||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||||
|
import com.uam.wmi.findmytutor.service.UserService;
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||||
import com.uam.wmi.findmytutor.utils.mapUtils;
|
import com.uam.wmi.findmytutor.utils.mapUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
@ -66,49 +74,52 @@ import io.reactivex.observers.DisposableSingleObserver;
|
|||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
import java.util.Locale;
|
|
||||||
|
import static com.mapbox.mapboxsdk.style.layers.Property.NONE;
|
||||||
|
import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE;
|
||||||
|
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||||
|
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||||
|
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||||
|
import static com.uam.wmi.findmytutor.R.id.activity_content;
|
||||||
|
|
||||||
|
|
||||||
public class MapActivity extends BaseActivity
|
public class MapActivity extends BaseActivity
|
||||||
implements PermissionsListener, OnMapReadyCallback {
|
implements PermissionsListener, OnMapReadyCallback {
|
||||||
private String tag = getClass().getName();
|
|
||||||
|
|
||||||
|
String currentLanguage = "pl", currentLang;
|
||||||
|
private String tag = getClass().getName();
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
private LocationComponent locationComponent;
|
private LocationComponent locationComponent;
|
||||||
LocationManager mLocationManager;
|
|
||||||
|
|
||||||
|
|
||||||
private CoordinateService coordinateService;
|
private CoordinateService coordinateService;
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private UserService userService;
|
||||||
|
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
private int mInterval = 10000;
|
private int mInterval = 10000;
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
private Runnable mStatusChecker;
|
private Runnable mStatusChecker;
|
||||||
|
|
||||||
private MapView mapView;
|
private MapView mapView;
|
||||||
private MapboxMap mapboxMap;
|
private MapboxMap mapboxMap;
|
||||||
private Marker droppedMarker;
|
private Marker droppedMarker;
|
||||||
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
private HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
||||||
private HashMap<String, Marker> markerHash = new HashMap<>();
|
private HashMap<String, Marker> markerHash = new HashMap<>();
|
||||||
|
|
||||||
private int zoomParam = 17;
|
private int zoomParam = 17;
|
||||||
private int bearingParam = 180;
|
private int bearingParam = 180;
|
||||||
private int tiltParam = 30;
|
private int tiltParam = 30;
|
||||||
|
|
||||||
Locale myLocale;
|
|
||||||
String currentLanguage = "pl", currentLang;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||||
final String authToken = sharedPref.getString("authToken", null);
|
|
||||||
|
|
||||||
// fetching coords service
|
// fetching coords service
|
||||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||||
.create(CoordinateService.class);
|
.create(CoordinateService.class);
|
||||||
|
|
||||||
|
userService = ApiClient.getClient(getApplicationContext())
|
||||||
|
.create(UserService.class);
|
||||||
|
|
||||||
mStatusChecker = () -> {
|
mStatusChecker = () -> {
|
||||||
try {
|
try {
|
||||||
fetchTopCoords();
|
fetchTopCoords();
|
||||||
@ -137,19 +148,67 @@ public class MapActivity extends BaseActivity
|
|||||||
mStatusChecker.run();
|
mStatusChecker.run();
|
||||||
enableLocationPlugin();
|
enableLocationPlugin();
|
||||||
|
|
||||||
// // TODO what should happend on click?
|
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||||
// mapboxMap.setOnMarkerClickListener(marker1 -> {
|
createMarkerModal(marker.getTitle());
|
||||||
//
|
return true;
|
||||||
// // Show a toast with the title of the selected marker
|
});
|
||||||
//// Toast.makeText(MapActivity.this, marker.getTitle(), Toast.LENGTH_SHORT).show();
|
|
||||||
// return true;
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
setOnMapLongClickListener();
|
setOnMapLongClickListener();
|
||||||
// addStaticLayer();
|
// addStaticLayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createMarkerModal(String userId) {
|
||||||
|
disposable.add(userService.getUserById(userId)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(this::createMarkerModal, this::handleError));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMarkerModal(User user) {
|
||||||
|
String cordStatus = coordsMap.get(user.getId()).getLabel();
|
||||||
|
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||||
|
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null);
|
||||||
|
|
||||||
|
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
|
||||||
|
alertDialogBuilderUserInput.setView(view);
|
||||||
|
|
||||||
|
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||||
|
// User cancelled the dialog
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView userName = view.findViewById(R.id.userName);
|
||||||
|
TextView status = view.findViewById(R.id.label);
|
||||||
|
|
||||||
|
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
|
||||||
|
status.setText(String.format("%s ", cordStatus));
|
||||||
|
|
||||||
|
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||||
|
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void handleError(Throwable error) {
|
||||||
|
showError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showError(Throwable e) {
|
||||||
|
String message;
|
||||||
|
|
||||||
|
if (e instanceof HttpException) {
|
||||||
|
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||||
|
message = RestApiHelper.getErrorMessage(responseBody);
|
||||||
|
}else {
|
||||||
|
message = "Network Error!";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setOnMapLongClickListener() {
|
private void setOnMapLongClickListener() {
|
||||||
|
|
||||||
final boolean[] cancel = {false};
|
final boolean[] cancel = {false};
|
||||||
@ -298,7 +357,6 @@ public class MapActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<Coordinate> coordsList) {
|
public void onSuccess(List<Coordinate> coordsList) {
|
||||||
|
|
||||||
|
|
||||||
Log.e(tag, "");
|
Log.e(tag, "");
|
||||||
|
|
||||||
for (Coordinate element : coordsList) {
|
for (Coordinate element : coordsList) {
|
||||||
@ -329,7 +387,6 @@ public class MapActivity extends BaseActivity
|
|||||||
markerAnimator.setInterpolator(new LinearInterpolator());
|
markerAnimator.setInterpolator(new LinearInterpolator());
|
||||||
markerAnimator.start();
|
markerAnimator.start();
|
||||||
|
|
||||||
|
|
||||||
// chba niepotrzbene
|
// chba niepotrzbene
|
||||||
mapboxMap.getMarkerViewManager().update();
|
mapboxMap.getMarkerViewManager().update();
|
||||||
|
|
||||||
@ -339,10 +396,12 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Log.e(tag, "Marker Added: " + id);
|
Log.e(tag, "Marker Added: " + id);
|
||||||
|
|
||||||
coordsMap.put(id, element);
|
coordsMap.put(id, element);
|
||||||
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
Marker marker = mapboxMap.addMarker(new MarkerOptions()
|
||||||
.title(element.getLabel())
|
.title(id)
|
||||||
.position(new LatLng(element.getLatitude(), element.getLongitude())));
|
.position(new LatLng(element.getLatitude(), element.getLongitude())));
|
||||||
markerHash.put(id, marker);
|
markerHash.put(id, marker);
|
||||||
}
|
}
|
||||||
@ -493,7 +552,7 @@ public class MapActivity extends BaseActivity
|
|||||||
|
|
||||||
permissionsManager = new PermissionsManager(this);
|
permissionsManager = new PermissionsManager(this);
|
||||||
permissionsManager.requestLocationPermissions(this);
|
permissionsManager.requestLocationPermissions(this);
|
||||||
permissionsManager.onRequestPermissionsResult(0, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, new int[] {0});
|
permissionsManager.onRequestPermissionsResult(0, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new int[]{0});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ public class BackgroundLocalizationService extends Service {
|
|||||||
latitude,
|
latitude,
|
||||||
longitude,
|
longitude,
|
||||||
altitude,
|
altitude,
|
||||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
"Jestem zajęty",
|
||||||
PrefUtils.getUserId(getApplicationContext())
|
PrefUtils.getUserId(getApplicationContext())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public interface UserService {
|
|||||||
Single<PagedResultReturnedTutors> getPagedStudents(@Path("pageNum") String pageNum);
|
Single<PagedResultReturnedTutors> getPagedStudents(@Path("pageNum") String pageNum);
|
||||||
|
|
||||||
@GET("api/users/{id}")
|
@GET("api/users/{id}")
|
||||||
Single<User> getUserByID(@Path("id") String userID);
|
Single <User> getUserById(@Path("id") String userID);
|
||||||
|
|
||||||
@PUT("api/users/{id}")
|
@PUT("api/users/{id}")
|
||||||
Completable updateUserByID(@Path("id") String userID, @Body User user);
|
Completable updateUserByID(@Path("id") String userID, @Body User user);
|
||||||
|
@ -56,7 +56,6 @@ public class PrefUtils {
|
|||||||
return getSharedPreferences(context).getString("USER_ID", null);
|
return getSharedPreferences(context).getString("USER_ID", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getUserStatus(Context context) {
|
public static String getUserStatus(Context context) {
|
||||||
return getSharedPreferences(context).getString("USER_STATUS", "Android");
|
return getSharedPreferences(context).getString("USER_STATUS", "Android");
|
||||||
}
|
}
|
||||||
|
BIN
app/src/main/res/drawable-v21/custom_marker.png
Normal file
BIN
app/src/main/res/drawable-v21/custom_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 923 B |
BIN
app/src/main/res/drawable-v24/custom_marker.png
Normal file
BIN
app/src/main/res/drawable-v24/custom_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 923 B |
BIN
app/src/main/res/drawable/custom_marker.png
Normal file
BIN
app/src/main/res/drawable/custom_marker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 923 B |
30
app/src/main/res/layout/marker_modal.xml
Normal file
30
app/src/main/res/layout/marker_modal.xml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/userName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/dimen_10"
|
||||||
|
android:fontFamily="sans-serif-medium"
|
||||||
|
android:lineSpacingExtra="8sp"
|
||||||
|
android:textColor="@color/colorAccent"
|
||||||
|
android:textSize="@dimen/lbl_new_note_title"
|
||||||
|
android:textStyle="normal" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/label"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:lineSpacingExtra="8sp"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:textColor="@color/note_list_text"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user