location updates feature
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.app.simplitend.cg_geofencing;
|
||||
|
||||
import static com.app.simplitend.apputils.RetrofitHelper.IMAGE_BASE_URL;
|
||||
import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_REQUEST_TAG;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -38,6 +39,7 @@ import com.app.simplitend.databinding.GeofenceBottomSheetBinding;
|
||||
import com.app.simplitend.chats.SocketHelper;
|
||||
import com.app.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
@@ -55,6 +57,7 @@ import com.google.android.libraries.places.widget.model.AutocompleteActivityMode
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -142,7 +145,8 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
geofence_bs_binding = GeofenceBottomSheetBinding.inflate(getLayoutInflater());
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(1);
|
||||
isTrackingSenior = false;
|
||||
|
||||
isTrackingSenior = showLocationUpdates;
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
|
||||
if (careGiverData == null) return;
|
||||
@@ -168,6 +172,7 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
|
||||
private void changeToLocationUpdatesView() {
|
||||
|
||||
binding.seniorNameTitle.setVisibility(View.VISIBLE);
|
||||
binding.lastUpdated.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -181,6 +186,63 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
BottomSheetBehavior<LinearLayout> bs_behavior = BottomSheetBehavior.from(binding.locationBs);
|
||||
bs_behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, careGiverData1 -> {
|
||||
if (careGiverData1 != null && careGiverData1.patientDetails != null){
|
||||
this.careGiverData = careGiverData1;
|
||||
|
||||
binding.seniorNameTitle.setText(careGiverData.patientDetails.first_name);
|
||||
if (geoFenceDetails != null){
|
||||
binding.lastUpdated.setText(geoFenceDetails.updated_at);
|
||||
}
|
||||
|
||||
Glide.with(this)
|
||||
.load(IMAGE_BASE_URL + careGiverData1.patientDetails.profile_photo)
|
||||
.error(R.drawable.senior_img)
|
||||
.placeholder(android.R.color.darker_gray)
|
||||
.into(binding.bsSeniorImage);
|
||||
|
||||
binding.bsSeniorName.setText(patientData.first_name);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void updateCurrentLocationBs() {
|
||||
if (pat_cur_latLng != null && mHomeLatLng != null){
|
||||
Location homeLocation = new Location("Home");
|
||||
homeLocation.setLatitude(mHomeLatLng.latitude);
|
||||
homeLocation.setLongitude(mHomeLatLng.longitude);
|
||||
|
||||
Location cureLocation = new Location("current");
|
||||
cureLocation.setLatitude(pat_cur_latLng.latitude);
|
||||
cureLocation.setLongitude(pat_cur_latLng.longitude);
|
||||
|
||||
float distance = homeLocation.distanceTo(cureLocation);
|
||||
|
||||
if (distance > 160){
|
||||
distance = distance/1609; // meters to miles
|
||||
binding.bsDistanceFromHome.setVisibility(View.VISIBLE);
|
||||
binding.bsDistanceFromHome.setText(String.format(Locale.getDefault(), "%.2f miles away from home", distance));
|
||||
|
||||
binding.bsSeniorCurrentLocationTxt.setVisibility(View.VISIBLE);
|
||||
Geocoder geocoder = new Geocoder(this);
|
||||
try {
|
||||
List<Address> addresses = geocoder.getFromLocation(cureLocation.getLatitude(), cureLocation.getLongitude(), 1);
|
||||
if (addresses == null || addresses.isEmpty()) throw new Exception();
|
||||
|
||||
binding.bsSeniorCurrentLocationTxt.setText(addresses.get(0).getAdminArea());
|
||||
} catch (Exception e) {
|
||||
binding.bsSeniorCurrentLocationTxt.setText("No location data");
|
||||
}
|
||||
}else{
|
||||
binding.bsSeniorCurrentLocationTxt.setVisibility(View.GONE);
|
||||
binding.bsDistanceFromHome.setText("At home");
|
||||
}
|
||||
|
||||
}else {
|
||||
binding.bsSeniorCurrentLocationTxt.setText("No location data");
|
||||
binding.bsDistanceFromHome.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,6 +282,7 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
pat_cur_latLng = new LatLng(result.getLatitude(), result.getLongitude());
|
||||
updateCurrentLocationPatientMarker();
|
||||
updatePatientCurrentLocationDetails();
|
||||
updateCurrentLocationBs();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -571,6 +634,10 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
updateCurrentLocationPatientMarker();
|
||||
|
||||
if (showLocationUpdates){
|
||||
updateCurrentLocationBs();
|
||||
}
|
||||
|
||||
mMap.setOnMapClickListener(latLng1 -> {
|
||||
if (binding.search.getVisibility() != View.VISIBLE) {
|
||||
// search bar is not visible
|
||||
@@ -608,6 +675,10 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
updateHomeMarker(this.mHomeLatLng);
|
||||
addRadius();
|
||||
});
|
||||
|
||||
if (showLocationUpdates && pat_cur_latLng != null){
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pat_cur_latLng, 17));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentLocationPatientMarker() {
|
||||
|
||||
@@ -402,10 +402,11 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bs_senior_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:text="Aditya"
|
||||
android:text="@string/couldn_t_load"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textColor="@color/black"
|
||||
android:fontFamily="@font/nunito_bold"
|
||||
@@ -417,18 +418,21 @@
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bs_senior_current_location_txt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:text="On new link road"
|
||||
android:text="@string/couldn_t_load"
|
||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||
android:textColor="@color/black"
|
||||
android:fontFamily="@font/nunito_medium"
|
||||
|
||||
android:layout_gravity="center_vertical"
|
||||
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bs_distance_from_home"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
|
||||
@@ -486,5 +486,6 @@
|
||||
<string name="enter_new_address_here">Enter new address here</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="couldn_t_load_chats">Couldn\'t load chats</string>
|
||||
<string name="couldn_t_load">Couldn\'t load</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user