From 44c788d5de2e4f5b4f11d723f870810c5c805b04 Mon Sep 17 00:00:00 2001 From: 14Sandee Date: Mon, 30 Oct 2023 20:58:54 +0530 Subject: [PATCH] . --- .idea/deploymentTargetDropDown.xml | 12 +++ .../DirectionToHomeActivity.java | 95 ++++++++++++++++++- .../PatientMainViewModel.java | 11 +-- .../medreminder/AddReminderFragment.java | 33 ++++++- .../contacts/CreateContactFragment.java | 7 ++ .../fragments/register/CreatePinFragment.java | 6 +- .../res/layout/activity_direction_to_home.xml | 64 +++++++++---- .../res/layout/activity_pat_profile_info.xml | 2 +- .../main/res/layout/add_reminder_fragment.xml | 2 + .../layout/caregiver_dashboard_activity.xml | 5 +- .../layout/create_edit_contact_fragment.xml | 1 + app/src/main/res/values/strings.xml | 2 +- 12 files changed, 206 insertions(+), 34 deletions(-) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 03d9c98..80de00c 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,6 +1,18 @@ + + + + + + + + + + + + diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/DirectionToHomeActivity.java b/app/src/main/java/com/app/simplitend/patient_dashboard/DirectionToHomeActivity.java index b42dd13..bc6274c 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/DirectionToHomeActivity.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/DirectionToHomeActivity.java @@ -3,6 +3,8 @@ package com.app.simplitend.patient_dashboard; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; +import android.location.Address; +import android.location.Geocoder; import android.location.Location; import android.location.LocationManager; import android.net.Uri; @@ -32,6 +34,7 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.MarkerOptions; @@ -43,7 +46,9 @@ import com.google.maps.android.PolyUtil; import com.google.maps.model.DirectionsResult; import com.google.maps.model.DirectionsRoute; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; public class DirectionToHomeActivity extends AppCompatActivity implements OnMapReadyCallback, LocationListener { @@ -239,8 +244,8 @@ 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")); - 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("Senior's location")); + 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))); + 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))); } private void positionCamera(DirectionsRoute route, GoogleMap mMap) throws Exception{ @@ -310,6 +315,7 @@ public class DirectionToHomeActivity extends AppCompatActivity addMarkersToMap(directionsResult, mGoogleMap); positionCamera(directionsResult.routes[0], mGoogleMap); addPolyline(directionsResult, mGoogleMap); + loadAddresses(directionsResult); binding.progress.setVisibility(View.GONE); binding.progress.setEnabled(false); @@ -321,4 +327,89 @@ public class DirectionToHomeActivity extends AppCompatActivity } } + + private void loadAddresses(DirectionsResult directionsResult) { + String your_loc = ""; + try { + // fetching address from the lag lng + Geocoder geocoder = new Geocoder(this, Locale.getDefault()); + List
addresses = geocoder.getFromLocation(directionsResult.routes[0].legs[0].startLocation.lat, directionsResult.routes[0].legs[0].startLocation.lng, 1); + + if (addresses != null && addresses.size() > 0 && addresses.get(0) != null) { + Address address = addresses.get(0); + + if (address.getMaxAddressLineIndex() > 0 && address.getAddressLine(0) != null){ + your_loc = address.getAddressLine(0); + } + + if (your_loc != null && !your_loc.isEmpty()) your_loc += ", "; + + if (address.getLocality() != null){ + your_loc += address.getLocality(); + } + + if (your_loc != null && !your_loc.isEmpty()) your_loc += ", "; + + if (address.getAdminArea() != null){ + your_loc += address.getAdminArea(); + } + + if (your_loc != null && !your_loc.isEmpty()) your_loc += ", "; + + if (address.getCountryName() != null){ + your_loc += address.getCountryName(); + } + } + + } catch (Exception e) { + // do nothing as we couldn't load the location from the lat lng + if (your_loc != null && your_loc.isEmpty()) your_loc = null; + } + + if (your_loc != null){ + binding.yourLoc.setText(your_loc); + } + + String home_loc = ""; + try { + // fetching address from the lag lng + Geocoder geocoder = new Geocoder(this, Locale.getDefault()); + List
addresses = geocoder.getFromLocation(directionsResult.routes[0].legs[0].endLocation.lat, directionsResult.routes[0].legs[0].endLocation.lng, 1); + + if (addresses != null && addresses.size() > 0 && addresses.get(0) != null) { + Address address = addresses.get(0); + + if (address.getMaxAddressLineIndex() > 0 && address.getAddressLine(0) != null){ + home_loc = address.getAddressLine(0); + } + + if (home_loc != null && !home_loc.isEmpty()) home_loc += ", "; + + if (address.getLocality() != null){ + home_loc += address.getLocality(); + } + + if (home_loc != null && !home_loc.isEmpty()) home_loc += ", "; + + if (address.getAdminArea() != null){ + home_loc += address.getAdminArea(); + } + + if (home_loc != null && !home_loc.isEmpty()) home_loc += ", "; + + if (address.getCountryName() != null){ + home_loc += address.getCountryName(); + } + } + + } catch (Exception e) { + // do nothing as we couldn't load the location from the lat lng + if (home_loc != null && home_loc.isEmpty()) home_loc = null; + } + + if (home_loc != null){ + binding.homeLoc.setText(home_loc); + } + + } } \ No newline at end of file diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/PatientMainViewModel.java b/app/src/main/java/com/app/simplitend/patient_dashboard/PatientMainViewModel.java index 2218c60..75fcce8 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/PatientMainViewModel.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/PatientMainViewModel.java @@ -1,18 +1,16 @@ package com.app.simplitend.patient_dashboard; -import static android.content.Context.*; +import static android.content.Context.ACTIVITY_SERVICE; import static com.app.simplitend.locationupdates.LocationService.LOCATION_INTERVAL_BASE_TIME; import static com.app.simplitend.locationupdates.LocationService.LOCATION_UPDATE_MIN_INTERVAL; import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_ID; import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG; import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_REQUEST_TAG; -import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_UPDATES_REQUEST_CODE; import android.Manifest; import android.app.Activity; import android.app.ActivityManager; import android.app.PendingIntent; -import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; @@ -36,7 +34,6 @@ import com.app.simplitend.caregiverdashboard.mvvm.NotificationApiService; import com.app.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails; import com.app.simplitend.locationupdates.LocationService; import com.app.simplitend.patientgeofencing.GeoFenceHelper; -import com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver; import com.app.simplitend.patientprofile.PatientProfileAPIService; import com.app.simplitend.patientprofile.medreminder.mvvm.models.NearestActivity; import com.app.simplitend.patientprofile.medreminder.mvvm.models.NearestReminder; @@ -44,11 +41,9 @@ import com.app.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult; import com.app.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails; import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse; import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData; -import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.Geofence; import com.google.android.gms.location.GeofencingClient; import com.google.android.gms.location.GeofencingRequest; -import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.model.LatLng; @@ -159,7 +154,9 @@ public class PatientMainViewModel extends ViewModel { AppUtil.updatePatientGeofence(activity, latLng.latitude+"", latLng.longitude+"", GEOFENCING_RADIUS+"", unit); }) - .addOnFailureListener(e -> Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage() + " " + latLng + " Radius: " + GEOFENCING_RADIUS)); + .addOnFailureListener(e -> { + Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage() + " " + latLng + " Radius: " + GEOFENCING_RADIUS); + }); } diff --git a/app/src/main/java/com/app/simplitend/patientprofile/medreminder/AddReminderFragment.java b/app/src/main/java/com/app/simplitend/patientprofile/medreminder/AddReminderFragment.java index e54c955..f52d369 100644 --- a/app/src/main/java/com/app/simplitend/patientprofile/medreminder/AddReminderFragment.java +++ b/app/src/main/java/com/app/simplitend/patientprofile/medreminder/AddReminderFragment.java @@ -253,7 +253,7 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); - SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()); + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy", Locale.getDefault()); String selected_time = sdf.format(cal.getTime()); binding.getDate.setText(selected_time); @@ -389,6 +389,33 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh binding.getTime3.setError("Required"); } + boolean timeOk = true; + + // checking if times are equal + if (binding.getTime2.getVisibility() == View.VISIBLE && binding.getTime3.getVisibility() == View.VISIBLE){ + // all three times are visible + if (binding.getTime.getText().toString().equals(binding.getTime2.getText().toString())){ + // time 1 and 2 are same + timeOk = false; + }else if (binding.getTime.getText().toString().equals(binding.getTime3.getText().toString())){ + // time 1 and 3 are same + timeOk = false; + }else if (binding.getTime2.getText().toString().equals(binding.getTime3.getText().toString())){ + // time 2 and 3 are same + timeOk = false; + } + }else if (binding.getTime2.getVisibility() == View.VISIBLE){ + // time 1 and 2 are visible + if (binding.getTime.getText().toString().equals(binding.getTime2.getText().toString())){ + timeOk = false; + } + } + + if (!timeOk){ + allOkay = false; + Toast.makeText(requireContext(), "Medications times cannot be same.", Toast.LENGTH_SHORT).show(); + } + if (binding.quantity.getText().toString().trim().isEmpty()) { allOkay = false; binding.quantity.setError("Required"); @@ -522,8 +549,8 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh } private String formatDate(String medication_refill_date) { - String inputPattern = "yyyy-dd-MM"; - String outputPattern = "dd-MM-yyyy"; + String inputPattern = "yyyy-MM-dd"; + String outputPattern = "MM-dd-yyyy"; SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern, Locale.getDefault()); SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern, Locale.getDefault()); diff --git a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/contacts/CreateContactFragment.java b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/contacts/CreateContactFragment.java index bcae82d..670c472 100644 --- a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/contacts/CreateContactFragment.java +++ b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/contacts/CreateContactFragment.java @@ -30,6 +30,7 @@ import androidx.navigation.Navigation; import com.app.simplitend.R; import com.app.simplitend.apputils.AppUtil; +import com.app.simplitend.apputils.TextUtils; import com.app.simplitend.databinding.CreateContactViewHolderBinding; import com.app.simplitend.databinding.CreateEditContactFragmentBinding; import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact; @@ -171,6 +172,8 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts. } })); + binding.email.addTextChangedListener(TextUtils.LEADING_SPACE_WATCHER); + imageSelector = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { @@ -312,6 +315,10 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts. }else if (mustBeeCaregiver && !Patterns.EMAIL_ADDRESS.matcher(binding.email.getText().toString()).matches()){ allOkay = false; binding.email.setError("Invalid email"); + }else if (!mustBeeCaregiver && !binding.email.getText().toString().isEmpty() && !Patterns.EMAIL_ADDRESS.matcher(binding.email.getText().toString()).matches()){ + // optional email is not blank and invalid + allOkay = false; + binding.email.setError("Invalid email"); } // if (binding.countryCodes.getSelectedIndex() == -1 && allOkay) { diff --git a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/CreatePinFragment.java b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/CreatePinFragment.java index f0772cc..178e61b 100644 --- a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/CreatePinFragment.java +++ b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/fragments/register/CreatePinFragment.java @@ -151,7 +151,11 @@ public class CreatePinFragment extends Fragment implements WelcomeContracts.Regi } else if (binding.confirmPin.getText() == null || !binding.confirmPin.getText().toString().equals(binding.pin.getText().toString())) { allOkay = false; - Toast.makeText(requireContext(), "Confirm pin doesn't match.", Toast.LENGTH_SHORT).show(); + if (binding.confirmPin.getText().toString().trim().isEmpty()){ + Toast.makeText(requireContext(), "Please enter confirm pin", Toast.LENGTH_SHORT).show(); + }else{ + Toast.makeText(requireContext(), "Confirm pin doesn't match.", Toast.LENGTH_SHORT).show(); + } } return allOkay; diff --git a/app/src/main/res/layout/activity_direction_to_home.xml b/app/src/main/res/layout/activity_direction_to_home.xml index bd66aea..1348768 100644 --- a/app/src/main/res/layout/activity_direction_to_home.xml +++ b/app/src/main/res/layout/activity_direction_to_home.xml @@ -122,37 +122,67 @@ android:background="@drawable/edit_text_bg_2" > - - android:text="@string/your_location" - android:fontFamily="@font/nunito_medium" - android:textColor="@color/black" - android:textAppearance="@style/TextAppearance.Material3.TitleSmall" + - android:drawablePadding="15dp" - app:drawableStartCompat="@drawable/ic_plus" /> + + + - - android:text="@string/home_address_txt" - android:fontFamily="@font/nunito_medium" - android:textColor="@color/black" - android:textAppearance="@style/TextAppearance.Material3.TitleSmall" + - android:drawablePadding="15dp" - app:drawableStartCompat="@drawable/ic_plus" /> + + + diff --git a/app/src/main/res/layout/activity_pat_profile_info.xml b/app/src/main/res/layout/activity_pat_profile_info.xml index add7b03..5cb74f0 100644 --- a/app/src/main/res/layout/activity_pat_profile_info.xml +++ b/app/src/main/res/layout/activity_pat_profile_info.xml @@ -89,7 +89,7 @@ android:layout_width="@dimen/_100sdp" android:layout_height="@dimen/_100sdp" android:contentDescription="@string/onboard_image" - android:src="@drawable/ic_contact" /> + android:src="@drawable/senior_img" /> diff --git a/app/src/main/res/layout/add_reminder_fragment.xml b/app/src/main/res/layout/add_reminder_fragment.xml index 3234697..57c87ea 100644 --- a/app/src/main/res/layout/add_reminder_fragment.xml +++ b/app/src/main/res/layout/add_reminder_fragment.xml @@ -76,6 +76,8 @@ android:maxLength="50" + android:digits="@string/allowed_alphabets_n_numbers_with_space" + /> + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> Home Address go Call and message your loved ones - Select number to cal or message + Select number to call or message Call No frequently used apps added\nPlease select an app from below list to unlock. No frequently used apps added\nGoto Profile -> Frequently used apps to setup this feature.