location updates from home screen without home location and geofence for reference
This commit is contained in:
@@ -10,6 +10,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.location.Location;
|
||||
@@ -17,6 +18,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
@@ -24,7 +26,9 @@ 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.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.app.simplitend.BuildConfig;
|
||||
@@ -38,9 +42,14 @@ import com.app.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.app.simplitend.chats.SocketHelper;
|
||||
import com.app.simplitend.databinding.ActivityCgGeofencingBinding;
|
||||
import com.app.simplitend.databinding.GeofenceBottomSheetBinding;
|
||||
import com.app.simplitend.databinding.MarkerBgBinding;
|
||||
import com.app.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
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.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
@@ -57,12 +66,17 @@ import com.google.android.libraries.places.widget.Autocomplete;
|
||||
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.maps.android.ui.IconGenerator;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class CgGeoFencingActivity extends AppCompatActivity implements OnMapReadyCallback,
|
||||
CgHomeContracts.SaveGeoFenceCallback, CgHomeContracts.UpdatePatientAddressCallback, CgHomeContracts.GetGeoFenceCallback {
|
||||
@@ -107,6 +121,8 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
protected boolean showLocationUpdates;
|
||||
|
||||
private IconGenerator iconGenerator;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -153,16 +169,28 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
this.careGiverData = careGiverData;
|
||||
this.patientData = careGiverData.patientDetails;
|
||||
|
||||
try {
|
||||
if (patientData == null) throw new Exception();
|
||||
|
||||
double lat = Double.parseDouble(patientData.lat);
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
|
||||
mHomeLatLng = new LatLng(lat, lng);
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
}), true);
|
||||
|
||||
initViews();
|
||||
|
||||
initBottomSheet();
|
||||
if (!showLocationUpdates) {
|
||||
initBottomSheet();
|
||||
updatePatientCurrentLocationDetails();
|
||||
}
|
||||
|
||||
clickEvents();
|
||||
|
||||
updatePatientCurrentLocationDetails();
|
||||
|
||||
establishSocketConnection();
|
||||
|
||||
if (showLocationUpdates){
|
||||
@@ -192,21 +220,29 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
progressDialog.setMessage("while we refresh the details");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
|
||||
CaregiverDataCache.setCareGiverData(null);
|
||||
CaregiverDataCache.getCaregiverData(this, careGiverData1 -> {
|
||||
if (careGiverData1 != null && careGiverData1.patientDetails != null){
|
||||
this.careGiverData = careGiverData1;
|
||||
this.patientData = careGiverData.patientDetails;
|
||||
|
||||
loadPatientsLocation();
|
||||
try {
|
||||
if (patientData == null) throw new Exception();
|
||||
|
||||
double lat = Double.parseDouble(patientData.lat);
|
||||
double lng = Double.parseDouble(patientData.lng);
|
||||
|
||||
mHomeLatLng = new LatLng(lat, lng);
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
CgHomeRepository.getHomeRepository().getGeoFenceDetails(AppUtil.getPatientUid(this) + "",
|
||||
"", "Bearer " + AppUtil.getPatientToken(this),
|
||||
this);
|
||||
}
|
||||
}, false);
|
||||
|
||||
});
|
||||
|
||||
BottomSheetBehavior<LinearLayout> bs_behavior = BottomSheetBehavior.from(binding.locationBs);
|
||||
@@ -217,8 +253,21 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
binding.seniorNameTitle.setText(careGiverData.patientDetails.first_name);
|
||||
if (geoFenceDetails != null){
|
||||
binding.lastUpdated.setText(geoFenceDetails.updated_at);
|
||||
if (geoFenceDetails != null && geoFenceDetails.patient_radius_location != null){
|
||||
String lastUpdatedTime;
|
||||
try {
|
||||
SimpleDateFormat inputSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.getDefault());
|
||||
inputSdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
SimpleDateFormat outPutSdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
lastUpdatedTime = outPutSdf.format(Objects.requireNonNull(inputSdf.parse(geoFenceDetails.patient_radius_location.updated_at)));
|
||||
} catch (Exception e) {
|
||||
lastUpdatedTime = geoFenceDetails.patient_radius_location.updated_at;
|
||||
}
|
||||
|
||||
binding.lastUpdated.setText(String.format("Last updated at %s", lastUpdatedTime));
|
||||
}else{
|
||||
binding.lastUpdated.setText("Last updated data nnt available");
|
||||
}
|
||||
|
||||
Glide.with(this)
|
||||
@@ -308,6 +357,9 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
updateCurrentLocationPatientMarker();
|
||||
updatePatientCurrentLocationDetails();
|
||||
updateCurrentLocationBs();
|
||||
|
||||
// last updated at
|
||||
binding.lastUpdated.setText(String.format("Last updated at %s", new SimpleDateFormat("hh:mm a", Locale.getDefault()).format(Calendar.getInstance().getTime())));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -655,7 +707,9 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.mMap = googleMap;
|
||||
|
||||
loadPatientsLocation();
|
||||
if (!showLocationUpdates) {
|
||||
loadPatientsLocation();// remove this if to also show patient home location along with geofence radius
|
||||
}
|
||||
|
||||
updateCurrentLocationPatientMarker();
|
||||
|
||||
@@ -712,11 +766,42 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
if (patientData != null) name = patientData.first_name;
|
||||
else name = "Senior's location";
|
||||
|
||||
MarkerOptions options = new MarkerOptions()
|
||||
final MarkerOptions options = new MarkerOptions()
|
||||
.position(pat_cur_latLng)
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location))
|
||||
.title(name)
|
||||
.draggable(false);
|
||||
if (showLocationUpdates && patientData != null) {
|
||||
|
||||
MarkerBgBinding markerBgBinding = MarkerBgBinding.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) {
|
||||
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
if (iconGenerator == null) {
|
||||
iconGenerator = new IconGenerator(CgGeoFencingActivity.this);
|
||||
markerBgBinding.markerBgImage.setImageDrawable(resource);
|
||||
iconGenerator.setContentView(markerBgBinding.getRoot());
|
||||
iconGenerator.setBackground(AppCompatResources.getDrawable(CgGeoFencingActivity.this, android.R.color.transparent));
|
||||
}
|
||||
|
||||
options.icon(BitmapDescriptorFactory.fromBitmap(iconGenerator.makeIcon()));
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.into(markerBgBinding.markerBgImage);
|
||||
} else {
|
||||
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.img_pat_curr_location));
|
||||
}
|
||||
|
||||
if (curr_loc_marker != null) curr_loc_marker.remove();
|
||||
curr_loc_marker = mMap.addMarker(options);
|
||||
@@ -879,9 +964,27 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
public void onGeofenceDetailsFetched(GeoFenceDetails geoFenceDetails) {
|
||||
progressDialog.dismiss();
|
||||
updateCurrentLocationPatientMarker();
|
||||
updatePatientCurrentLocationDetails();
|
||||
// updatePatientCurrentLocationDetails(); for also showing patient home location along with geofence radius
|
||||
if (showLocationUpdates){
|
||||
updateCurrentLocationBs();
|
||||
|
||||
// last updated at
|
||||
if (geoFenceDetails != null && geoFenceDetails.patient_radius_location != null){
|
||||
String lastUpdatedTime;
|
||||
try {
|
||||
SimpleDateFormat inputSdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", Locale.getDefault());
|
||||
inputSdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
SimpleDateFormat outPutSdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
lastUpdatedTime = outPutSdf.format(Objects.requireNonNull(inputSdf.parse(geoFenceDetails.patient_radius_location.updated_at)));
|
||||
} catch (Exception e) {
|
||||
lastUpdatedTime = geoFenceDetails.patient_radius_location.updated_at;
|
||||
}
|
||||
|
||||
binding.lastUpdated.setText(String.format("Last updated at %s", lastUpdatedTime));
|
||||
}else{
|
||||
binding.lastUpdated.setText("Last updated data nnt available");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
app/src/main/res/drawable/ic_marker_bg.png
Normal file
BIN
app/src/main/res/drawable/ic_marker_bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.7 KiB |
@@ -65,12 +65,11 @@
|
||||
android:visibility="gone"
|
||||
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/nunito_semibold"
|
||||
android:fontFamily="@font/nunito_regular"
|
||||
android:singleLine="true"
|
||||
tools:text="Last updated now "
|
||||
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleSmall"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textColor="@android:color/black"
|
||||
|
||||
/>
|
||||
|
||||
|
||||
27
app/src/main/res/layout/marker_bg.xml
Normal file
27
app/src/main/res/layout/marker_bg.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/marker_bg_image"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:translationZ="1dp"
|
||||
android:src="@drawable/senior_img"
|
||||
app:civ_circle_background_color="@color/color_primary"
|
||||
app:civ_border_color="@color/color_primary"
|
||||
app:civ_border_width="2dp"/>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:src="@drawable/ic_marker_bg"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user