This commit is contained in:
2023-10-06 20:04:35 +05:30
parent 5b56f826a4
commit 4470e5d2b1
16 changed files with 2308 additions and 26 deletions

View File

@@ -1,6 +1,7 @@
package com.app.simplitend.apputils;
import static com.app.simplitend.apputils.Constants.ACTIVITY_EXTRA_KEY;
import static com.app.simplitend.apputils.Constants.MEDICATION_REFILL;
import static com.app.simplitend.apputils.Constants.REMINDER_EXTRA_KEY;
import static com.app.simplitend.articles.ArticleShowerActivity.ARTICLE_TITLE;
import static com.app.simplitend.articles.ArticleShowerActivity.ARTICLE_URL_KEY;
@@ -272,6 +273,11 @@ public abstract class AppUtil {
switch (content_type) {
case Constants.PATIENT_OUT_OF_GEOFENCE:
if (!getCgNotificationPref(context, GEOFENCE_NOTIFICATIONS)){
// notifications are off by user
return;
}
title = patient_name + " is out of Geofence!";
setupBottomSheet(binding,
@@ -292,6 +298,12 @@ public abstract class AppUtil {
bsd.show();
break;
case Constants.ACTIVITY_TIME:
if (!getCgNotificationPref(context, ACTIVITY_NOTIFICATIONS)){
// notifications are off by user
return;
}
String routine_description = null;
try {
RoutineDetails routine = (RoutineDetails) intent.getSerializableExtra(ACTIVITY_EXTRA_KEY);
@@ -338,6 +350,12 @@ public abstract class AppUtil {
bsd.show();
break;
case Constants.MEDICINE_TIME:
if (!getCgNotificationPref(context, MEDICATIONS_NOTIFICATIONS)){
// notifications are off by user
return;
}
String description = null;
try {
@@ -379,6 +397,14 @@ public abstract class AppUtil {
bsd.show();
break;
case Constants.PATIENT_REQUESTED_DIRECTION:
if (!getCgNotificationPref(context, DIRECTIONS_NOTIFICATIONS)){
// notifications are off by user
return;
}
title = patient_name + " requested for directions to home";
setupBottomSheet(binding,
R.drawable.img_directioin_requested,
title, body,
@@ -397,6 +423,14 @@ public abstract class AppUtil {
bsd.show();
break;
case Constants.PATIENT_REQUESTED_SOS:
if (!getCgNotificationPref(context, SOS_NOTIFICATIONS)){
// notifications are off by user
return;
}
title = patient_name + " contacted help";
setupBottomSheet(binding,
R.drawable.img_sos_requested,
title, body,
@@ -412,10 +446,52 @@ public abstract class AppUtil {
}), true);
});
bsd.show();
break;
case MEDICATION_REFILL:
if (!getCgNotificationPref(context, MEDICATION_REFILL_NOTIFICATIONS)){
// notifications are off by user
return;
}
String refill_description = null;
title = "Medicines refill";
try {
ReminderResult reminder = (ReminderResult) intent.getSerializableExtra(REMINDER_EXTRA_KEY);
if (reminder != null) {
body = reminder.medicine_name + " (" + reminder.dosage + " " + reminder.dosage_unit + ")";
if (reminder.medication_instruction == null) reminder.medication_instruction = "None";
refill_description = "Quantity to be refilled: " + reminder.medication_quantity;
}
} catch (Exception e) {
// do nothing
}
setupBottomSheet(binding,
R.drawable.img_med_refill,
title, body,
refill_description, "Text patient",
v -> {
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
if (careGiverData == null || careGiverData.patientDetails == null) {
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
return;
}
AppUtil.messageNumber(context, careGiverData.patientDetails.phone_number);
}), true);
});
bsd.show();
break;
}
// already returning
}
private static void setupBottomSheet(BottomSheetAlertBinding binding,
@@ -486,9 +562,18 @@ public abstract class AppUtil {
mySharedPref.setArrayList("APP_LIST", appList);
}
// removing contact listing
setWhiteListedContacts(context, null);
// geofence details clear
updatePatientGeofence(context, null, null, null, null);
// removing geofence
// removing geofence of same tag
removeGeofence(context);
}
public static void removeGeofence(Context context) {
Log.d(GEOFENCE_TAG, "REMOVING GEOFENCE ID:" + GEOFENCE_ID);
GeofencingClient geofencingClient = LocationServices.getGeofencingClient(context);
geofencingClient.removeGeofences(Collections.singletonList(GEOFENCE_ID)).addOnSuccessListener(v -> {
Log.d(GEOFENCE_TAG, "patientSignOut: GEOFENCE REMOVED");
@@ -535,6 +620,39 @@ public abstract class AppUtil {
public static void cgSignOut(Context context) {
saveCgData(null, -1, context);
setWantSecurityFlag(context, NOT_ASKED_CG_SECURITY);
// setting up notification prefs default to yes
setCgNotificationPref(context, MEDICATIONS_NOTIFICATIONS, true);
setCgNotificationPref(context, MEDICATION_REFILL_NOTIFICATIONS, true);
setCgNotificationPref(context, ACTIVITY_NOTIFICATIONS, true);
setCgNotificationPref(context, SOS_NOTIFICATIONS, true);
setCgNotificationPref(context, DIRECTIONS_NOTIFICATIONS, true);
setCgNotificationPref(context, GEOFENCE_NOTIFICATIONS, true);
}
// caregiver notification preference
public static final String MEDICATIONS_NOTIFICATIONS = "medications_notifications";
public static final String MEDICATION_REFILL_NOTIFICATIONS = "MEDICATION_REFILL_notifications";
public static final String ACTIVITY_NOTIFICATIONS = "ACTIVITY_notifications";
public static final String GEOFENCE_NOTIFICATIONS = "GEOFENCE_notifications";
public static final String SOS_NOTIFICATIONS = "SOS_notifications";
public static final String DIRECTIONS_NOTIFICATIONS = "DIRECTIONS_notifications";
public static void setCgNotificationPref(Context context,
String notification,
boolean check){
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(notification, check);
editor.apply();
}
public static boolean getCgNotificationPref(Context context,
String notification){
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
return sp.getBoolean(notification, true);
}
// patient geofencing
@@ -572,15 +690,20 @@ public abstract class AppUtil {
}
public static void setWhiteListedContacts(Context context, List<ContactData> contactList){
Set<String> contactSet = new HashSet<>();
Set<String> contactSet;
for (ContactData contactData: contactList){
contactSet.add(contactData.phone_number);
if (contactList != null) {
contactSet = new HashSet<>();
for (ContactData contactData: contactList){
contactSet.add(contactData.phone_number);
if (contactData.extra_phone_numbers != null){
String[] extra_phone_numbers = contactData.extra_phone_numbers.split(",");
contactSet.addAll(Arrays.asList(extra_phone_numbers));
if (contactData.extra_phone_numbers != null){
String[] extra_phone_numbers = contactData.extra_phone_numbers.split(",");
contactSet.addAll(Arrays.asList(extra_phone_numbers));
}
}
} else {
contactSet = null;
}
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);

View File

@@ -12,4 +12,6 @@ public abstract class Constants {
public static final String PATIENT_REQUESTED_SOS = "patient_sos_clicked";
public static final String REMINDER_EXTRA_KEY = "reminder_extra_key";
public static final String ACTIVITY_EXTRA_KEY = "activity_extra_key";
public static final String MEDICATION_REFILL = "medication_refill";
}

View File

@@ -69,8 +69,21 @@ public class NotificationService implements INotificationServiceExtension {
return;
}
// addGeoFence(new LatLng(18.933154827942843, 72.82790520714602),
// 200, iNotificationReceivedEvent.getContext());
try {
double lat = extras.getDouble("lat");
double lng = extras.getDouble("lng");
double radius = extras.getDouble("radius");
Log.d(GEOFENCE_TAG, "DATA RECEIVED WITH NOTIFICATION : Lat/Lng: " + lat + "," + lng + " Radius: " + radius);
if (radius >= 0){
addGeoFence(new LatLng(lat, lng),
radius, iNotificationReceivedEvent.getContext());
}
}catch (Exception e){
Log.e(GEOFENCE_TAG, "COULDN'T CREATE GEOFENCE: " + e);
Log.e(GEOFENCE_TAG, "EXTRAS FROM NOTIFICATION: " + extras);
}
}else{
Log.d(GEOFENCE_TAG, "onNotificationReceived of PATIENT GEOFENCE CHANGED. BUT PATIENT IS LOGGED OUT.");
}
@@ -78,7 +91,9 @@ public class NotificationService implements INotificationServiceExtension {
}
@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
private void addGeoFence(@NonNull LatLng latLng, float GEOFENCING_RADIUS , Context context) {
private void addGeoFence(@NonNull LatLng latLng, double GEOFENCING_RADIUS , Context context) {
AppUtil.removeGeofence(context);
GeoFenceHelper geoFenceHelper = new GeoFenceHelper(context);
GeofencingClient geofencingClient = LocationServices.getGeofencingClient(context);
@@ -90,7 +105,7 @@ public class NotificationService implements INotificationServiceExtension {
}
}
Geofence geofence = geoFenceHelper.getGeoFence(GEOFENCE_ID, latLng, GEOFENCING_RADIUS,
Geofence geofence = geoFenceHelper.getGeoFence(GEOFENCE_ID, latLng, (float) GEOFENCING_RADIUS,
Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT);
GeofencingRequest geofencingRequest = geoFenceHelper.getGeoFencingRequest(geofence);
PendingIntent pendingIntent = geoFenceHelper.getPendingIntent();
@@ -101,7 +116,7 @@ public class NotificationService implements INotificationServiceExtension {
AppUtil.updatePatientGeofence(context, latLng.latitude+"", latLng.longitude+"",
GEOFENCING_RADIUS+"", "kms");
})
.addOnFailureListener(e -> Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage()));
.addOnFailureListener(e -> Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage() + " " + latLng + " Radius: " + GEOFENCING_RADIUS));
}
}

View File

@@ -84,6 +84,12 @@ public class CaregiverDashActivity extends AppCompatActivity implements
intent.putExtra(Constants.REMINDER_EXTRA_KEY, reminder);
}
}
}else if (Constants.MEDICATION_REFILL.equals(content_type) && viewModel.remindersList != null){
for (ReminderResult reminder: viewModel.remindersList){
if (id == reminder.id){
intent.putExtra(Constants.REMINDER_EXTRA_KEY, reminder);
}
}
}
}

View File

@@ -1,20 +1,22 @@
package com.app.simplitend.caregiverdashboard.activities;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import com.app.simplitend.R;
import com.app.simplitend.apputils.AppUtil;
import com.app.simplitend.caregiverdashboard.activities.deactivateacc.DeActivateAccountActivity;
import com.app.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
import com.app.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
import com.app.simplitend.databinding.ActivityCgSettingsBinding;
import com.app.simplitend.databinding.NotificationSetupBottomSheetBinding;
import com.app.simplitend.welcome.activities.WelcomeActivity;
import com.google.android.material.bottomsheet.BottomSheetDialog;
public class CaregiverSettingsActivity extends AppCompatActivity implements CgHomeContracts.SignOutCallback {
@@ -23,19 +25,62 @@ public class CaregiverSettingsActivity extends AppCompatActivity implements CgHo
private CaregiverMainViewModel viewModel;
private ProgressDialog progressDialog;
private BottomSheetDialog nSetupDialog;
protected NotificationSetupBottomSheetBinding nSBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityCgSettingsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
viewModel = new ViewModelProvider(this).get(CaregiverMainViewModel.class);
progressDialog = new ProgressDialog(this);
nSBinding = NotificationSetupBottomSheetBinding.inflate(getLayoutInflater());
nSetupDialog = new BottomSheetDialog(this, R.style.BottomSheetDialog);
nSetupDialog.setContentView(nSBinding.getRoot());
setupNotifications();
initViews();
clickEvents();
}
private void setupNotifications() {
nSBinding.patientMedication.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.MEDICATIONS_NOTIFICATIONS));
nSBinding.patientMedRefill.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.MEDICATION_REFILL_NOTIFICATIONS));
nSBinding.patientActivity.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.ACTIVITY_NOTIFICATIONS));
nSBinding.patientGeofence.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.GEOFENCE_NOTIFICATIONS));
nSBinding.patientSos.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.SOS_NOTIFICATIONS));
nSBinding.patientDirection.setChecked(AppUtil.getCgNotificationPref(this, AppUtil.DIRECTIONS_NOTIFICATIONS));
nSBinding.patientMedication.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.MEDICATIONS_NOTIFICATIONS, b);
});
nSBinding.patientMedRefill.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.MEDICATION_REFILL_NOTIFICATIONS, b);
});
nSBinding.patientActivity.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.ACTIVITY_NOTIFICATIONS, b);
});
nSBinding.patientGeofence.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.GEOFENCE_NOTIFICATIONS, b);
});
nSBinding.patientSos.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.SOS_NOTIFICATIONS, b);
});
nSBinding.patientDirection.setOnCheckedChangeListener((compoundButton, b) -> {
AppUtil.setCgNotificationPref(this, AppUtil.DIRECTIONS_NOTIFICATIONS, b);
});
}
private void initViews() {
}
@@ -47,7 +92,8 @@ public class CaregiverSettingsActivity extends AppCompatActivity implements CgHo
AppUtil.showAlert(this,
"Are you sure?", "Do you want to sign out?",
getString(R.string.no),
((dialogInterface, i) -> {}),
((dialogInterface, i) -> {
}),
getString(R.string.yes),
((dialogInterface, i) -> {
progressDialog.setTitle("Please wait...");
@@ -75,6 +121,10 @@ public class CaregiverSettingsActivity extends AppCompatActivity implements CgHo
getString(R.string.privacy_policy));
});
binding.setupNoti.setOnClickListener(v -> {
nSetupDialog.show();
});
}
@Override

View File

@@ -103,6 +103,8 @@ public class PatientMainViewModel extends ViewModel {
@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
private void addGeoFence(@NonNull LatLng latLng, float GEOFENCING_RADIUS , Activity activity, String unit) {
AppUtil.removeGeofence(activity);
GeoFenceHelper geoFenceHelper = new GeoFenceHelper(activity);
GeofencingClient geofencingClient = LocationServices.getGeofencingClient(activity);
@@ -135,7 +137,7 @@ 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()));
.addOnFailureListener(e -> Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage() + " " + latLng + " Radius: " + GEOFENCING_RADIUS));
}
@@ -161,7 +163,7 @@ public class PatientMainViewModel extends ViewModel {
Map<String, String> body = new HashMap<>();
body.put("patient_id", patient_Id);
notificationApiService.notifyRequestedSOS(body, "Bearer " + token)
notificationApiService.notifyRequestedDirections(body, "Bearer " + token)
.enqueue(new Callback<CallResponse<Object>>() {
@Override
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {

View File

@@ -299,7 +299,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
binding.dayOfWeek.setText(getDayOfWeek(calendar.get(Calendar.DAY_OF_WEEK)));
SimpleDateFormat date_sdf = new SimpleDateFormat("MMMM dd, yyyy", Locale.getDefault());
SimpleDateFormat date_sdf = new SimpleDateFormat("MMMM d, yyyy", Locale.getDefault());
String date_str = date_sdf.format(calendar.getTime());
binding.date.setText(date_str);

View File

@@ -236,7 +236,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("MM-dd-yyyy", Locale.getDefault());
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
String selected_time = sdf.format(cal.getTime());
binding.getDate.setText(selected_time);
@@ -474,8 +474,8 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
}
private String formatDate(String medication_refill_date) {
String inputPattern = "yyyy-MM-dd";
String outputPattern = "MM-dd-yyyy";
String inputPattern = "yyyy-dd-MM";
String outputPattern = "dd-MM-yyyy";
SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern, Locale.getDefault());
SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern, Locale.getDefault());

View File

@@ -18,7 +18,6 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.GridLayoutManager;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.app.simplitend.R;
import com.app.simplitend.apputils.AppUtil;
import com.app.simplitend.apputils.PatientDataCache;
@@ -29,6 +28,7 @@ import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.Contact
import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactListResponse;
import com.app.simplitend.welcome.welcomepatient.mvvm.WelcomeContracts;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import java.util.ArrayList;
import java.util.List;
@@ -129,7 +129,11 @@ public class AddContactFragment extends Fragment implements WelcomeContracts.Con
}
PatientDataCache.setContactList(new ArrayList<>(contactList));
AppUtil.setWhiteListedContacts(requireContext(), contactList);
try {
AppUtil.setWhiteListedContacts(requireContext(), contactList);
} catch (Exception e) {
// do nothing
}
for (int i = contactList.size(); i<10; i++){
contactList.add(new ContactData(-1));