.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.app.simplitend.patient_dashboard;
|
||||
|
||||
import static com.app.simplitend.apputils.RetrofitHelper.IMAGE_BASE_URL;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.location.Location;
|
||||
@@ -19,8 +22,10 @@ import android.widget.Toast;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresPermission;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
@@ -29,6 +34,12 @@ import com.app.simplitend.R;
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.apputils.PatientDataCache;
|
||||
import com.app.simplitend.databinding.ActivityDirectionToHomeBinding;
|
||||
import com.app.simplitend.databinding.MarkerBgSmallBinding;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationListener;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
@@ -47,6 +58,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.maps.DirectionsApi;
|
||||
import com.google.maps.GeoApiContext;
|
||||
import com.google.maps.android.PolyUtil;
|
||||
import com.google.maps.android.ui.IconGenerator;
|
||||
import com.google.maps.model.DirectionsResult;
|
||||
import com.google.maps.model.DirectionsRoute;
|
||||
|
||||
@@ -279,7 +291,52 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
private void addMarkersToMap(DirectionsResult results, GoogleMap mMap) throws Exception {
|
||||
pat_cur_lat = results.routes[0].legs[0].startLocation.lat;
|
||||
pat_cur_lng = results.routes[0].legs[0].startLocation.lng;
|
||||
mMap.addMarker(new MarkerOptions().position(new com.google.android.gms.maps.model.LatLng(results.routes[0].legs[0].startLocation.lat ,results.routes[0].legs[0].startLocation.lng)).title("Your location").icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location)));
|
||||
|
||||
PatientDataCache.getPatientData(this, patientData -> {
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(new com.google.android.gms.maps.model.LatLng(results.routes[0].legs[0].startLocation.lat ,results.routes[0].legs[0].startLocation.lng))
|
||||
.title("Your location");
|
||||
|
||||
if (patientData != null && patientData.profile_photo != null) {
|
||||
|
||||
MarkerBgSmallBinding markerBgBinding = MarkerBgSmallBinding.inflate(getLayoutInflater());
|
||||
|
||||
Glide.with(this)
|
||||
.load(IMAGE_BASE_URL + patientData.profile_photo)
|
||||
.error(R.drawable.img_pat_curr_location)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.addListener(new RequestListener<Drawable>() {
|
||||
@Override
|
||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location));
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
try {
|
||||
IconGenerator iconGenerator = new IconGenerator(DirectionToHomeActivity.this);
|
||||
markerBgBinding.markerBgImage.setImageDrawable(resource);
|
||||
iconGenerator.setContentView(markerBgBinding.getRoot());
|
||||
iconGenerator.setBackground(AppCompatResources.getDrawable(DirectionToHomeActivity.this, android.R.color.transparent));
|
||||
|
||||
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon()));
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
} catch (Exception e) {
|
||||
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location));
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(markerBgBinding.markerBgImage);
|
||||
} else {
|
||||
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location));
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
}
|
||||
}, false);
|
||||
|
||||
mMap.addMarker(new MarkerOptions().position(new com.google.android.gms.maps.model.LatLng(results.routes[0].legs[0].endLocation.lat ,results.routes[0].legs[0].endLocation.lng)).title("Home location").icon(BitmapDescriptorFactory.fromResource(R.drawable.img_home_marker)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user