.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.ssb.simplitend.apputils;
|
||||
|
||||
import static com.ssb.simplitend.apputils.Constants.ACTIVITY_EXTRA_KEY;
|
||||
import static com.ssb.simplitend.apputils.Constants.REMINDER_EXTRA_KEY;
|
||||
import static com.ssb.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_ID;
|
||||
import static com.ssb.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG;
|
||||
|
||||
@@ -24,14 +26,13 @@ import com.bumptech.glide.Glide;
|
||||
import com.google.android.gms.location.GeofencingClient;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.onesignal.OneSignal;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.appblocking.MySharedPref;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.databinding.BottomSheetAlertBinding;
|
||||
import com.ssb.simplitend.databinding.DecisionBottomsheetBinding;
|
||||
import com.ssb.simplitend.databinding.DoneBottomsheetBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DashBoardActivity;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -41,9 +42,12 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AppUtil {
|
||||
@@ -72,11 +76,11 @@ public abstract class AppUtil {
|
||||
// util functions
|
||||
|
||||
// closes keyboard
|
||||
public static void closeKeyboard(Activity activity){
|
||||
if (activity != null){
|
||||
public static void closeKeyboard(Activity activity) {
|
||||
if (activity != null) {
|
||||
View view = activity.getCurrentFocus();
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
@@ -84,10 +88,10 @@ public abstract class AppUtil {
|
||||
|
||||
// show decision dialog
|
||||
public static void showSOSDecision(@NonNull Context context,
|
||||
@NonNull String decisionText,
|
||||
@NonNull String positiveText, @NonNull String negativeText,
|
||||
View.OnClickListener positiveClickListener,
|
||||
View.OnClickListener negativeClickListener) {
|
||||
@NonNull String decisionText,
|
||||
@NonNull String positiveText, @NonNull String negativeText,
|
||||
View.OnClickListener positiveClickListener,
|
||||
View.OnClickListener negativeClickListener) {
|
||||
|
||||
DecisionBottomsheetBinding binding = DecisionBottomsheetBinding.inflate(LayoutInflater.from(context));
|
||||
|
||||
@@ -117,7 +121,7 @@ public abstract class AppUtil {
|
||||
public static void showAnimateDBS(@NonNull Context context,
|
||||
@NonNull String title,
|
||||
@RawRes int rawRes, long doneInterval,
|
||||
@NonNull View.OnClickListener doneListener){
|
||||
@NonNull View.OnClickListener doneListener) {
|
||||
DoneBottomsheetBinding binding = DoneBottomsheetBinding.inflate(LayoutInflater.from(context));
|
||||
|
||||
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
@@ -143,9 +147,9 @@ public abstract class AppUtil {
|
||||
|
||||
// Show alert dialog
|
||||
public static synchronized void showAlert(@NonNull Context context,
|
||||
@NonNull String title, @NonNull String message,
|
||||
@NonNull String positiveText, @NonNull DialogInterface.OnClickListener positiveClickListener,
|
||||
String negativeText, DialogInterface.OnClickListener negativeClickListener) {
|
||||
@NonNull String title, @NonNull String message,
|
||||
@NonNull String positiveText, @NonNull DialogInterface.OnClickListener positiveClickListener,
|
||||
String negativeText, DialogInterface.OnClickListener negativeClickListener) {
|
||||
|
||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
|
||||
|
||||
@@ -226,14 +230,17 @@ public abstract class AppUtil {
|
||||
if (activity != null) activity.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void messageNumber(Context activity, String phone_number){
|
||||
public static void messageNumber(Context activity, String phone_number) {
|
||||
Uri uri = Uri.parse("smsto:" + phone_number);
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
|
||||
// intent.putExtra("sms_body", "The SMS text");
|
||||
if (activity != null) activity.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void showBottomAlert(Context context, String content_type, Intent intent) throws Exception {
|
||||
public static void showBottomAlert(Context context,
|
||||
String patient_name,
|
||||
String content_type, Intent intent) throws Exception {
|
||||
|
||||
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
BottomSheetAlertBinding binding = BottomSheetAlertBinding.inflate(LayoutInflater.from(context));
|
||||
bsd.setContentView(binding.getRoot());
|
||||
@@ -241,7 +248,7 @@ public abstract class AppUtil {
|
||||
String title = intent.getStringExtra(NotificationService.NOTIFICATION_TITLE_KEY);
|
||||
String body = intent.getStringExtra(NotificationService.NOTIFICATION_BODY_KEY);
|
||||
|
||||
switch (content_type){
|
||||
switch (content_type) {
|
||||
case Constants.PATIENT_OUT_OF_GEOFENCE:
|
||||
|
||||
setupBottomSheet(binding,
|
||||
@@ -249,8 +256,8 @@ public abstract class AppUtil {
|
||||
title, "Current location of patient",
|
||||
"Unknown", "Call patient",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context,(careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null){
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@@ -262,13 +269,41 @@ public abstract class AppUtil {
|
||||
bsd.show();
|
||||
break;
|
||||
case Constants.ACTIVITY_TIME:
|
||||
String routine_description = null;
|
||||
try {
|
||||
RoutineDetails routine = (RoutineDetails) intent.getSerializableExtra(ACTIVITY_EXTRA_KEY);
|
||||
if (routine != null) {
|
||||
title = patient_name + " has " + routine.routine_title + " activity";
|
||||
|
||||
String time;
|
||||
try {
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
SimpleDateFormat output_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
Date start_date = input_sdf.parse(routine.routine_start_time);
|
||||
time = output_sdf.format(Objects.requireNonNull(start_date));
|
||||
|
||||
} catch (Exception e) {
|
||||
time = routine.routine_start_time;
|
||||
}
|
||||
|
||||
body = "Today at " + time;
|
||||
|
||||
if (routine.routine_description == null) routine.routine_description = "None";
|
||||
|
||||
routine_description = "Description: " + routine.routine_description;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_activity_time,
|
||||
title, body,
|
||||
null, "Text patient",
|
||||
routine_description, "Text patient",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context,(careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null){
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@@ -280,13 +315,36 @@ public abstract class AppUtil {
|
||||
bsd.show();
|
||||
break;
|
||||
case Constants.MEDICINE_TIME:
|
||||
String description = null;
|
||||
|
||||
try {
|
||||
ReminderResult reminder = (ReminderResult) intent.getSerializableExtra(REMINDER_EXTRA_KEY);
|
||||
if (reminder != null) {
|
||||
title = "It's time for " + patient_name + "'s medicines";
|
||||
|
||||
body = reminder.medicine_name + " (" + reminder.medication_quantity;
|
||||
try {
|
||||
body += " " + reminder.medication_type.get(0).title;
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}finally {
|
||||
body += ")";
|
||||
}
|
||||
|
||||
if (reminder.medication_instruction == null) reminder.medication_instruction = "None";
|
||||
description = "Instructions: " + reminder.medication_instruction;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_medication_time,
|
||||
title, body,
|
||||
null, "Text patient",
|
||||
description, "Text patient",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context,(careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null){
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@@ -295,6 +353,42 @@ public abstract class AppUtil {
|
||||
}), true);
|
||||
});
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
case Constants.PATIENT_REQUESTED_DIRECTION:
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_directioin_requested,
|
||||
title, body,
|
||||
null, "Call 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.dialPhone(context, careGiverData.patientDetails.phone_number);
|
||||
}), true);
|
||||
});
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
case Constants.PATIENT_REQUESTED_SOS:
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_sos_requested,
|
||||
title, body,
|
||||
null, "Call 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.dialPhone(context, careGiverData.patientDetails.phone_number);
|
||||
}), true);
|
||||
});
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
}
|
||||
@@ -317,7 +411,7 @@ public abstract class AppUtil {
|
||||
|
||||
// ********************* USER DATA UTILS ******************************************
|
||||
|
||||
public static void savePatientData(String token, int patient_uid, Context context, boolean isLoggedIn){
|
||||
public static void savePatientData(String token, int patient_uid, Context context, boolean isLoggedIn) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
@@ -331,12 +425,12 @@ public abstract class AppUtil {
|
||||
|
||||
}
|
||||
|
||||
public static String getPatientToken(Context context){
|
||||
public static String getPatientToken(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getString(PATIENT_TOKEN, "");
|
||||
}
|
||||
|
||||
public static int getPatientUid(Context context){
|
||||
public static int getPatientUid(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getInt(PATIENT_UID, -1);
|
||||
}
|
||||
@@ -346,7 +440,7 @@ public abstract class AppUtil {
|
||||
return sp.getBoolean(IS_PATIENT_LOGGED_IN, false);
|
||||
}
|
||||
|
||||
public static void patientSignOut(Context context){
|
||||
public static void patientSignOut(Context context) {
|
||||
AppUtil.savePatientData(null, -1, context, false);
|
||||
|
||||
// app block list clear
|
||||
@@ -366,12 +460,9 @@ public abstract class AppUtil {
|
||||
}).addOnFailureListener(v -> {
|
||||
Log.d(GEOFENCE_TAG, "patientSignOut: GEOFENCE COULDN'T BE REMOVE " + v);
|
||||
});
|
||||
|
||||
// closing notifications
|
||||
OneSignal.getUser().getPushSubscription().optOut();
|
||||
}
|
||||
|
||||
public static void saveCgData(String token, int patient_id, Context context){
|
||||
public static void saveCgData(String token, int patient_id, Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
@@ -387,12 +478,12 @@ public abstract class AppUtil {
|
||||
|
||||
}
|
||||
|
||||
public static String getCgToken(Context context){
|
||||
public static String getCgToken(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getString(CAREGIVER_TOKEN, null);
|
||||
}
|
||||
|
||||
public static void setWantSecurityFlag(Context context, int watSecurity){
|
||||
public static void setWantSecurityFlag(Context context, int watSecurity) {
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
@@ -401,17 +492,14 @@ public abstract class AppUtil {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static int getWantSecurityFlag(Context context){
|
||||
public static int getWantSecurityFlag(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getInt(CG_APP_SECURITY, NOT_ASKED_CG_SECURITY);
|
||||
}
|
||||
|
||||
public static void cgSignOut(Context context){
|
||||
public static void cgSignOut(Context context) {
|
||||
saveCgData(null, -1, context);
|
||||
setWantSecurityFlag(context, NOT_ASKED_CG_SECURITY);
|
||||
|
||||
// closing notification
|
||||
OneSignal.getUser().getPushSubscription().optOut();
|
||||
}
|
||||
|
||||
// patient geofencing
|
||||
@@ -420,7 +508,7 @@ public abstract class AppUtil {
|
||||
private static final String PATIENT_GEOFENCE_LATITUDE = "patient_geofence_latitude";
|
||||
private static final String PATIENT_GEOFENCE_LONGITUDE = "patient_geofence_longitude";
|
||||
|
||||
public static void updatePatientGeofence(Context context, String lat, String lng, String radius, String radius_unit){
|
||||
public static void updatePatientGeofence(Context context, String lat, String lng, String radius, String radius_unit) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
@@ -433,17 +521,17 @@ public abstract class AppUtil {
|
||||
Log.d(GEOFENCE_TAG, "updatePatientGeofence: UPDATED");
|
||||
}
|
||||
|
||||
public static String[] getPatientLatLng(Context context){
|
||||
public static String[] getPatientLatLng(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
return new String[]{sp.getString(PATIENT_GEOFENCE_LATITUDE, null), sp.getString(PATIENT_GEOFENCE_LONGITUDE, null)};
|
||||
}
|
||||
|
||||
public static String getPatientGeofenceRadius(Context context){
|
||||
public static String getPatientGeofenceRadius(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getString(PATIENT_GEOFENCE_RADIUS, null);
|
||||
}
|
||||
|
||||
public static String getPatientGeofenceRadiusUnit(Context context){
|
||||
public static String getPatientGeofenceRadiusUnit(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(PATIENT_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getString(PATIENT_GEOFENCE_RADIUS_UNIT, null);
|
||||
}
|
||||
@@ -455,24 +543,24 @@ public abstract class AppUtil {
|
||||
|
||||
String local_radius = getPatientGeofenceRadius(context);
|
||||
|
||||
if (local_radius != null){
|
||||
if (local_radius != null) {
|
||||
try {
|
||||
float local_radius_f = Float.parseFloat(local_radius);
|
||||
float remote_radius_f = Float.parseFloat(remote_radius);
|
||||
|
||||
if (local_radius_f != remote_radius_f){
|
||||
if (local_radius_f != remote_radius_f) {
|
||||
// radius' are different
|
||||
// thus, should add geofence
|
||||
return true;
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// radius is equal thus, checking for unit of the radius
|
||||
String local_radius_unit = getPatientGeofenceRadiusUnit(context);
|
||||
if (!remote_radius_unit.equals(local_radius_unit)){
|
||||
if (!remote_radius_unit.equals(local_radius_unit)) {
|
||||
// remote radius units are different
|
||||
// thus, should add geofence
|
||||
return true;
|
||||
@@ -481,7 +569,7 @@ public abstract class AppUtil {
|
||||
// checking for lat lng
|
||||
String[] local_lat_lng = getPatientLatLng(context);
|
||||
if (data.lat != null && data.lng != null) {
|
||||
if (!data.lat.equals(local_lat_lng[0]) || !data.lng.equals(local_lat_lng[1])){
|
||||
if (!data.lat.equals(local_lat_lng[0]) || !data.lng.equals(local_lat_lng[1])) {
|
||||
// remote lat lng has changed
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,4 +7,8 @@ public abstract class Constants {
|
||||
public static final String GEOFENCING_RADIUS_UPDATED = "geofencing_radius_updated";
|
||||
public static final String HOME_LOCATION_UPDATED = "home_location_updated";
|
||||
public static final String PATIENT_OUT_OF_GEOFENCE = "patient_outof_geofence";
|
||||
public static final String PATIENT_REQUESTED_DIRECTION = "patient_requested_help";
|
||||
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";
|
||||
}
|
||||
@@ -33,14 +33,17 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
public static final String CONTENT_TYPE_KEY = "content_type_key";
|
||||
public static final String NOTIFICATION_BODY_KEY = "notification_body_key";
|
||||
public static final String NOTIFICATION_TITLE_KEY = "notification_title_key";
|
||||
public static final String NOTIFICATION_CONTENT_ID_KEY = "notification_title_key";
|
||||
|
||||
@Override
|
||||
public void onNotificationReceived(@NonNull INotificationReceivedEvent iNotificationReceivedEvent) {
|
||||
JSONObject extras = iNotificationReceivedEvent.getNotification().getAdditionalData();
|
||||
String content_type = null;
|
||||
int id = -1;
|
||||
if (extras != null) {
|
||||
try {
|
||||
content_type = extras.getString("content_type");
|
||||
id = extras.getInt("id");
|
||||
} catch (JSONException e) {
|
||||
// do nothing
|
||||
}
|
||||
@@ -50,6 +53,7 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
intent.putExtra(CONTENT_TYPE_KEY, content_type);
|
||||
intent.putExtra(NOTIFICATION_BODY_KEY, iNotificationReceivedEvent.getNotification().getBody());
|
||||
intent.putExtra(NOTIFICATION_TITLE_KEY, iNotificationReceivedEvent.getNotification().getTitle());
|
||||
intent.putExtra(NOTIFICATION_CONTENT_ID_KEY, id);
|
||||
|
||||
iNotificationReceivedEvent.getContext().sendBroadcast(intent);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ssb.simplitend.apputils;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.onesignal.Continue;
|
||||
import com.onesignal.OneSignal;
|
||||
import com.onesignal.debug.LogLevel;
|
||||
import com.ssb.simplitend.R;
|
||||
@@ -17,5 +18,17 @@ public class SimpliTendApp extends Application {
|
||||
|
||||
// OneSignal Initialization
|
||||
OneSignal.initWithContext(this, getString(R.string.ONE_SIGNAL_APP_ID));
|
||||
|
||||
// requestPermission will show the native Android notification permission prompt.
|
||||
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
|
||||
if (r.isSuccess()) {
|
||||
if (r.getData() != null) {
|
||||
// `requestPermission` completed successfully and the user has accepted permission
|
||||
} else {
|
||||
// `requestPermission` completed successfully but the user has rejected permission
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ssb.simplitend.caregiverdashboard.activities;
|
||||
|
||||
import static com.ssb.simplitend.apputils.NotificationService.CONTENT_TYPE_KEY;
|
||||
import static com.ssb.simplitend.apputils.NotificationService.NOTIFICATION_CONTENT_ID_KEY;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -9,9 +10,7 @@ import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -20,8 +19,6 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.onesignal.Continue;
|
||||
import com.onesignal.OneSignal;
|
||||
import com.onesignal.notifications.INotificationLifecycleListener;
|
||||
import com.onesignal.notifications.INotificationWillDisplayEvent;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.CaregiverDataCache;
|
||||
@@ -37,13 +34,12 @@ import com.ssb.simplitend.databinding.CaregiverDashboardActivityBinding;
|
||||
import com.ssb.simplitend.databinding.CaregiverDashboardMenuBinding;
|
||||
import com.ssb.simplitend.faqs.FAQ_Activity;
|
||||
import com.ssb.simplitend.patient_dashboard.chats.ChatFragment;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.ssb.simplitend.welcome.welcomecg.mvvm.CareGiverData;
|
||||
import com.yarolegovich.slidingrootnav.SlidingRootNavBuilder;
|
||||
import com.yarolegovich.slidingrootnav.callback.DragStateListener;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
DragStateListener,
|
||||
HomeBottomNav.OnBottomNavItemSelectListener {
|
||||
@@ -53,7 +49,6 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
private CaregiverDashboardMenuBinding menuBinding;
|
||||
protected CaregiverMainViewModel viewModel;
|
||||
private CareGiverData careGiverData;
|
||||
|
||||
private BroadcastReceiver notification_receiver;
|
||||
|
||||
@Override
|
||||
@@ -77,8 +72,37 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String content_type = intent.getStringExtra(CONTENT_TYPE_KEY);
|
||||
int id = intent.getIntExtra(NOTIFICATION_CONTENT_ID_KEY, -1);
|
||||
|
||||
if (id != -1){
|
||||
if (Constants.ACTIVITY_TIME.equals(content_type) && viewModel.activityList != null){
|
||||
for (RoutineDetails routine: viewModel.activityList){
|
||||
if (id == routine.id){
|
||||
intent.putExtra(Constants.ACTIVITY_EXTRA_KEY, routine);
|
||||
}
|
||||
}
|
||||
}else if (Constants.MEDICINE_TIME.equals(content_type) && viewModel.remindersList != null){
|
||||
for (ReminderResult reminder: viewModel.remindersList){
|
||||
if (id == reminder.id){
|
||||
intent.putExtra(Constants.REMINDER_EXTRA_KEY, reminder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AppUtil.showBottomAlert(CaregiverDashActivity.this, content_type, intent);
|
||||
String patient_name;
|
||||
if (careGiverData != null && careGiverData.patientDetails != null){
|
||||
patient_name = careGiverData.patientDetails.first_name;
|
||||
}else{
|
||||
patient_name = "Your loved one";
|
||||
}
|
||||
|
||||
AppUtil.showBottomAlert(CaregiverDashActivity.this,
|
||||
patient_name,
|
||||
content_type,
|
||||
intent);
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
@@ -198,21 +222,6 @@ public class CaregiverDashActivity extends AppCompatActivity implements
|
||||
|
||||
// initializing dashboard fragment
|
||||
replaceFragment(new CgDashBoardFragment(), "dashboard");
|
||||
|
||||
OneSignal.getUser().getPushSubscription().optIn();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
// requestPermission will show the native Android notification permission prompt.
|
||||
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
|
||||
if (r.isSuccess()) {
|
||||
if (r.getData() != null) {
|
||||
// `requestPermission` completed successfully and the user has accepted permission
|
||||
} else {
|
||||
// `requestPermission` completed successfully but the user has rejected permission
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayoutDetails() {
|
||||
|
||||
@@ -383,6 +383,7 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
@Override
|
||||
public void onRemindersListFetched(List<ReminderResult> reminderResult) {
|
||||
viewModel.remindersList = reminderResult;
|
||||
viewModel.getNearestReminder(reminderResult, this);
|
||||
}
|
||||
|
||||
@@ -490,6 +491,7 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
@Override
|
||||
public void onRoutinesFetched(List<RoutineDetails> routineList) {
|
||||
viewModel.activityList = routineList;
|
||||
viewModel.getNearestActivity(routineList, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ public class CaregiverMainViewModel extends ViewModel {
|
||||
public String ongoingActivityText, upcomingActivityText;
|
||||
public String upcomingReminderText, dailyReminderText;
|
||||
|
||||
public List<ReminderResult> remindersList;
|
||||
public List<RoutineDetails> activityList;
|
||||
|
||||
public CaregiverMainViewModel(){
|
||||
this.cgHomeRepository = CgHomeRepository.getHomeRepository();
|
||||
this.ongoingActivityText = this.upcomingActivityText =
|
||||
|
||||
@@ -15,4 +15,13 @@ public interface NotificationApiService {
|
||||
Call<CallResponse<Object>> notifyOutOfGeoFence(@Body Map<String, String> body,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@POST("api/send-notification-when-patient-clicks-on-sos")
|
||||
Call<CallResponse<Object>> notifyRequestedSOS(@Body Map<String, String> body,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@POST("api/send-notification-when-patient-clicks-on-go")
|
||||
Call<CallResponse<Object>> notifyRequestedDirections(@Body Map<String, String> body,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,40 +26,18 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
|
||||
|
||||
private GeoFenceDetails geoFenceDetails;
|
||||
|
||||
private boolean geofencing_verified = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dash_board_cp);
|
||||
|
||||
// committtttttt
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(PatientMainViewModel.class);
|
||||
|
||||
// requestPermission will show the native Android notification permission prompt.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
|
||||
// requestPermission will show the native Android notification permission prompt.
|
||||
geofencing_verified = false;
|
||||
OneSignal.getNotifications().requestPermission(true, Continue.with(r -> {
|
||||
geofencing_verified = true;
|
||||
if (r.isSuccess()) {
|
||||
viewModel.getGeoFenceDetails("" + AppUtil.getPatientUid(this),
|
||||
"", "Bearer " + AppUtil.getPatientToken(this),
|
||||
this);
|
||||
}
|
||||
}));
|
||||
|
||||
if (!geofencing_verified){
|
||||
viewModel.getGeoFenceDetails("" + AppUtil.getPatientUid(this),
|
||||
"", "Bearer " + AppUtil.getPatientToken(this),
|
||||
this);
|
||||
}
|
||||
|
||||
}else{
|
||||
viewModel.getGeoFenceDetails("" + AppUtil.getPatientUid(this),
|
||||
"", "Bearer " + AppUtil.getPatientToken(this),
|
||||
this);
|
||||
}
|
||||
|
||||
viewModel.getGeoFenceDetails(AppUtil.getPatientUid(this) + "",
|
||||
"", "Bearer " + AppUtil.getPatientToken(this),
|
||||
this);
|
||||
}
|
||||
|
||||
private void validateAndAddGeofence(GeoFenceDetails geoFenceDetails) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresPermission;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationListener;
|
||||
@@ -49,6 +50,8 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
|
||||
protected ActivityDirectionToHomeBinding binding;
|
||||
|
||||
private PatientMainViewModel viewModel;
|
||||
|
||||
public static final String LAT_KEY = "lat_key";
|
||||
public static final String LNG_KEY = "lng_key";
|
||||
|
||||
@@ -70,6 +73,8 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
binding = ActivityDirectionToHomeBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(PatientMainViewModel.class);
|
||||
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.hasExtra(LAT_KEY) && intent.hasExtra(LNG_KEY)){
|
||||
pat_lat = intent.getDoubleExtra(LAT_KEY, 0);
|
||||
@@ -100,6 +105,9 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||
Uri.parse("http://maps.google.com/maps?saddr=" + cur_location + "&daddr=" + pat_location));
|
||||
startActivity(intent);
|
||||
|
||||
viewModel.notifyRequestedDirections(AppUtil.getPatientUid(this)+"",
|
||||
AppUtil.getPatientToken(this));
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v -> {
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -24,18 +26,49 @@ import com.google.android.gms.location.GeofencingRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.RetrofitHelper;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CgHomeRepository;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.NotificationApiService;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.ssb.simplitend.patientgeofencing.GeoFenceHelper;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.NearestActivity;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.NearestReminder;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class PatientMainViewModel extends ViewModel {
|
||||
|
||||
private static final String TAG = "PatientMainViewModel";
|
||||
|
||||
private final CgHomeRepository cgHomeRepository;
|
||||
|
||||
private final NotificationApiService notificationApiService;
|
||||
|
||||
public String message_title, message_sub_title_1, message_sub_title_2;
|
||||
|
||||
public long nearest_rem_time;
|
||||
|
||||
public PatientMainViewModel() {
|
||||
cgHomeRepository = CgHomeRepository.getHomeRepository();
|
||||
notificationApiService = RetrofitHelper.getRetrofit().create(NotificationApiService.class);
|
||||
}
|
||||
|
||||
public void setGeofence(Activity activity, GeoFenceDetails geoFenceDetails, PatientData patientData) {
|
||||
@@ -77,7 +110,7 @@ public class PatientMainViewModel extends ViewModel {
|
||||
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(GEOFENCE_TAG, "setGeofence: REQUESTING BACKGROUND LOCATION PERMISSION" );
|
||||
AppUtil.showSOSDecision(activity,
|
||||
"We understand your privacy.\nTo enable Geofencing we need to access your location while the app is closed.\nKindly click on the Settings button below and select \"Allow all the time\"",
|
||||
"Testing content\nWe understand your privacy.\nTo enable Geofencing we need to access your location while the app is closed.\nKindly click on the Settings button below and select \"Allow all the time\"",
|
||||
"Settings", "No thanks", view -> {
|
||||
// No thanks click
|
||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION}, LOCATION_REQUEST_CODE);
|
||||
@@ -104,4 +137,268 @@ public class PatientMainViewModel extends ViewModel {
|
||||
.addOnFailureListener(e -> Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage()));
|
||||
|
||||
}
|
||||
|
||||
public void notifyRequestedSOS(String patient_Id, String token){
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("patient_id", patient_Id);
|
||||
|
||||
notificationApiService.notifyRequestedSOS(body, "Bearer " + token)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
Log.d(TAG, "onResponse: NOTIFIED CG ABOUT SOS REQUESTED");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {
|
||||
Log.d(TAG, "onFailure: Notifying cg about SoS failed" + t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void notifyRequestedDirections(String patient_Id, String token){
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("patient_id", patient_Id);
|
||||
|
||||
notificationApiService.notifyRequestedSOS(body, "Bearer " + token)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
Log.d(TAG, "onResponse: NOTIFIED CG ABOUT DIRECTIONS REQUESTED");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {
|
||||
Log.d(TAG, "onFailure: Notifying cg about DIRECTIONS failed" + t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void getNearestActivity(List<RoutineDetails> activityList,
|
||||
@NonNull CaregiverMainViewModel.GetNearestActivityCallback activityCallback){
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
executor.execute(() -> {
|
||||
// Background work
|
||||
|
||||
NearestActivity nearestActivity = new NearestActivity();
|
||||
|
||||
try {
|
||||
|
||||
for (RoutineDetails activity: activityList){
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
Date start_date = input_sdf.parse(activity.routine_start_time);
|
||||
Date end_date = input_sdf.parse(activity.routine_end_time);
|
||||
|
||||
if (start_date == null || end_date == null) throw new Exception();
|
||||
|
||||
Calendar cur_cal = Calendar.getInstance();
|
||||
|
||||
// matching date and seconds of the current date and routine dates
|
||||
Date cur_date = new Date(start_date.getYear(), start_date.getMonth(), start_date.getDate(), cur_cal.get(Calendar.HOUR_OF_DAY), cur_cal.get(Calendar.MINUTE), 0);
|
||||
start_date.setSeconds(0);
|
||||
end_date.setSeconds(0);
|
||||
|
||||
// checking on going activity
|
||||
if (cur_date.getTime() >= start_date.getTime() &&
|
||||
cur_date.getTime() <= end_date.getTime()){
|
||||
// on going activity
|
||||
nearestActivity.ongoing_activity_name = activity.routine_title;
|
||||
nearestActivity.ongoing_start_time = activity.routine_start_time;
|
||||
nearestActivity.ongoing_end_time = activity.routine_end_time;
|
||||
}
|
||||
|
||||
// checking upcoming activity
|
||||
if (start_date.getTime() > cur_date.getTime() && smallestTime(activity.routine_start_time, nearestActivity.upcoming_time)){
|
||||
// upcoming_time for this reminder is less than nearestReminder.upcoming_time
|
||||
// thus, updating nearest reminder
|
||||
|
||||
nearestActivity.upcoming_time = activity.routine_start_time;
|
||||
nearestActivity.activity_id = activity.id;
|
||||
nearestActivity.upcoming_activity_name = activity.routine_title;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
handler.post(() -> activityCallback.nearestActivity(nearestActivity));
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void getNearestReminder(List<ReminderResult> reminderResultList,
|
||||
@NonNull CaregiverMainViewModel.GetNearestResultCallback nearestResultCallback){
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
executor.execute(() -> {
|
||||
// background thread work
|
||||
|
||||
NearestReminder nearestReminder = new NearestReminder();
|
||||
|
||||
try {
|
||||
for (ReminderResult reminder: reminderResultList){
|
||||
|
||||
if (reminder.all_days == 1){
|
||||
nearestReminder.daily_reminder_time = reminder.time1;
|
||||
}
|
||||
|
||||
String upcoming_time = selectNextReminder(reminder.time1, reminder.time2, reminder.time3);
|
||||
|
||||
if (upcoming_time != null && smallestTime(upcoming_time, nearestReminder.upcoming_time)){
|
||||
// upcoming_time for this reminder is less than nearestReminder.upcoming_time
|
||||
// thus, updating nearest reminder
|
||||
|
||||
nearestReminder.upcoming_time = upcoming_time;
|
||||
nearestReminder.reminder_id = reminder.id;
|
||||
nearestReminder.medication_name = reminder.medicine_name;
|
||||
nearestReminder.med_quantity = reminder.medication_quantity;
|
||||
try {
|
||||
nearestReminder.med_type = reminder.medication_type.get(0).title;
|
||||
}catch (Exception e){
|
||||
nearestReminder.med_type = "units";
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// callback through main thread
|
||||
handler.post(() -> nearestResultCallback.nearestReminder(nearestReminder));
|
||||
});
|
||||
}
|
||||
|
||||
private String selectNextReminder(@NonNull String time1, String time2, String time3) {
|
||||
return selectNextReminder(time1, selectNextReminder(time2, time3));
|
||||
}
|
||||
|
||||
private String selectNextReminder(String time1, String time2) {
|
||||
if (time1 == null && time2 == null) return null;
|
||||
if (time2 == null) {
|
||||
// time 2 is null
|
||||
// thus, checking if time1 has already passed current_time or not.
|
||||
|
||||
if (alreadyPassed(time1)){
|
||||
// the time1 has already passed the current time
|
||||
// thus, returning null
|
||||
|
||||
return null;
|
||||
}else{
|
||||
// the time1 is yet to come
|
||||
|
||||
return time1;
|
||||
}
|
||||
}
|
||||
if (time1 == null){
|
||||
// time1 is null
|
||||
// thus, checking if time2 has already passed current_time or not.
|
||||
|
||||
if (alreadyPassed(time2)){
|
||||
// the time1 has already passed the current time
|
||||
// thus, returning null
|
||||
|
||||
return null;
|
||||
}else{
|
||||
// the time1 is yet to come
|
||||
|
||||
return time2;
|
||||
}
|
||||
}
|
||||
|
||||
// comparing this 2 times with current time
|
||||
// first converting time string to calendar
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date date1 = input_sdf.parse(time1);
|
||||
Date date2 = input_sdf.parse(time2);
|
||||
|
||||
if (date2 == null || date1 == null) throw new Exception();
|
||||
|
||||
Calendar cur_cal = Calendar.getInstance();
|
||||
Date cur_date = new Date(date1.getYear(), date1.getMonth(), date1.getDate(), cur_cal.get(Calendar.HOUR_OF_DAY), cur_cal.get(Calendar.MINUTE), date1.getSeconds());
|
||||
|
||||
// All three above dates are of same date 01 Jan 1970
|
||||
// but, of different times i.e. hh:mm:ss
|
||||
|
||||
long t1 = date1.getTime();
|
||||
long t2 = date2.getTime();
|
||||
long c_t = cur_date.getTime();
|
||||
|
||||
if (t1 < c_t && t2 > c_t){
|
||||
// t1 time is passed and t2 time is yet to come for the same day
|
||||
// thus, returning t2
|
||||
return time2;
|
||||
}else if (t1 > c_t && t2 < c_t){
|
||||
// t1 is yet to come for this day, and t2 has already been passed
|
||||
// thus, returning t1
|
||||
return time1;
|
||||
}else if (t1 > c_t && t2 > c_t){
|
||||
// Both the times are greater than current time, yet to come
|
||||
// In this case, we show the smallest time
|
||||
|
||||
if (t1 < t2) return time1;
|
||||
else return time2;
|
||||
}else{
|
||||
// Last case would be both the times has passed the current time
|
||||
// thus, returning null
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
// if something goes wrong, returning the time1
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the time has passed current time or not
|
||||
private boolean alreadyPassed(String time1) {
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date date = input_sdf.parse(time1);
|
||||
if (date == null) throw new Exception();
|
||||
|
||||
Calendar cur_cal = Calendar.getInstance();
|
||||
Date cur_date = new Date(date.getYear(), date.getMonth(), date.getDate(), cur_cal.get(Calendar.HOUR_OF_DAY), cur_cal.get(Calendar.MINUTE), date.getSeconds());
|
||||
|
||||
return date.getTime() <= cur_date.getTime();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if time1 is less than time2;
|
||||
private boolean smallestTime(@NonNull String time1, String time2) {
|
||||
if (time2 == null) return true;
|
||||
|
||||
// comparing this 2 times with current time
|
||||
// first converting time string to calendar
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date date1 = input_sdf.parse(time1);
|
||||
Date date2 = input_sdf.parse(time2);
|
||||
|
||||
if (date2 == null || date1 == null) throw new Exception();
|
||||
|
||||
// All times above dates are of same date 01 Jan 1970
|
||||
// but, of different times i.e. hh:mm:ss
|
||||
|
||||
long t1 = date1.getTime();
|
||||
long t2 = date2.getTime();
|
||||
|
||||
return t1 < t2;
|
||||
}catch (Exception e){
|
||||
// if something goes wrong, returning the time1
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ssb.simplitend.patient_dashboard.fragments;
|
||||
|
||||
import static com.ssb.simplitend.apputils.NotificationService.CONTENT_TYPE_KEY;
|
||||
import static com.ssb.simplitend.patient_dashboard.DirectionToHomeActivity.LAT_KEY;
|
||||
import static com.ssb.simplitend.patient_dashboard.DirectionToHomeActivity.LNG_KEY;
|
||||
import static com.ssb.simplitend.patient_dashboard.fragments.CallsActivity.CALL_CONTACT_LIST_KEY;
|
||||
@@ -18,6 +19,7 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -25,9 +27,19 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.appblocking.FUAActivity;
|
||||
import com.ssb.simplitend.apputils.AppUtil;
|
||||
import com.ssb.simplitend.apputils.Constants;
|
||||
import com.ssb.simplitend.apputils.PatientDataCache;
|
||||
import com.ssb.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.ssb.simplitend.databinding.PatientDashboardFragmentBinding;
|
||||
import com.ssb.simplitend.patient_dashboard.DirectionToHomeActivity;
|
||||
import com.ssb.simplitend.patient_dashboard.PatientMainViewModel;
|
||||
import com.ssb.simplitend.patientprofile.ProfileContracts;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.ReminderViewModel;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.NearestActivity;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.NearestReminder;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineViewModel;
|
||||
import com.ssb.simplitend.welcome.activities.WelcomeActivity;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
@@ -35,17 +47,26 @@ import com.ssb.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class PatientDashboardFragment extends Fragment {
|
||||
public class PatientDashboardFragment extends Fragment implements ProfileContracts.GetRemindersListCallback, CaregiverMainViewModel.GetNearestResultCallback, ProfileContracts.GetRoutinesCallback, CaregiverMainViewModel.GetNearestActivityCallback {
|
||||
|
||||
// view binding
|
||||
protected PatientDashboardFragmentBinding binding;
|
||||
|
||||
private ReminderViewModel reminderViewModel;
|
||||
private RoutineViewModel routineViewModel;
|
||||
|
||||
private PatientData patientData;
|
||||
|
||||
private ArrayList<ContactData> contactList;
|
||||
|
||||
private PatientMainViewModel viewModel;
|
||||
|
||||
private BroadcastReceiver notification_receiver;
|
||||
|
||||
// date suffixes
|
||||
String[] suffixes =
|
||||
// 0 1 2 3 4 5 6 7 8 9
|
||||
@@ -78,10 +99,29 @@ public class PatientDashboardFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = PatientDashboardFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(PatientMainViewModel.class);
|
||||
reminderViewModel = new ViewModelProvider(requireActivity()).get(ReminderViewModel.class);
|
||||
routineViewModel = new ViewModelProvider(requireActivity()).get(RoutineViewModel.class);
|
||||
|
||||
loadReminders();
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
notification_receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String content_type = intent.getStringExtra(CONTENT_TYPE_KEY);
|
||||
|
||||
if (Constants.ACTIVITY_TIME.equals(content_type) || Constants.MEDICINE_TIME.equals(content_type)){
|
||||
loadReminders();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
requireContext().registerReceiver(notification_receiver, new IntentFilter(AppUtil.NOTIFICATION_ACTION));
|
||||
|
||||
PatientDataCache.getPatientData(requireContext(), (patientData -> {
|
||||
this.patientData = patientData;
|
||||
|
||||
@@ -96,6 +136,12 @@ public class PatientDashboardFragment extends Fragment {
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
requireContext().unregisterReceiver(notification_receiver);
|
||||
}
|
||||
|
||||
private void setDetails() {
|
||||
if (patientData == null) return;
|
||||
|
||||
@@ -109,6 +155,11 @@ public class PatientDashboardFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
if (viewModel.message_title == null){
|
||||
removeReminder();
|
||||
}else{
|
||||
addReminder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,7 +188,10 @@ public class PatientDashboardFragment extends Fragment {
|
||||
|
||||
binding.sosBtn.setOnClickListener(v -> {
|
||||
// fake sign out
|
||||
|
||||
// TODO: 08-08-2023 remove this
|
||||
viewModel.notifyRequestedSOS(AppUtil.getPatientUid(requireContext())+"",
|
||||
AppUtil.getPatientToken(requireContext()));
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Test mode", "Do you want to log out?",
|
||||
@@ -169,11 +223,6 @@ public class PatientDashboardFragment extends Fragment {
|
||||
}), true);
|
||||
});
|
||||
|
||||
binding.calls.setOnLongClickListener(v -> {
|
||||
addReminder();
|
||||
return true;
|
||||
});
|
||||
|
||||
binding.profile.setOnClickListener(v -> {
|
||||
Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_patientProfileInfoFragment);
|
||||
});
|
||||
@@ -201,6 +250,13 @@ public class PatientDashboardFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
private void loadReminders(){
|
||||
reminderViewModel.getRemindersList(AppUtil.getPatientUid(requireContext()),
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1,
|
||||
"Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
this);
|
||||
}
|
||||
|
||||
private void updateTime() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
@@ -246,9 +302,16 @@ public class PatientDashboardFragment extends Fragment {
|
||||
layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._140sdp);
|
||||
|
||||
binding.bgImg.setLayoutParams(layoutParams);
|
||||
|
||||
viewModel.message_title = null;
|
||||
}
|
||||
|
||||
private void addReminder(){
|
||||
if (viewModel.message_title == null || viewModel.message_title.isEmpty()){
|
||||
// removeReminder();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.homeReminder.setVisibility(View.VISIBLE);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
@@ -256,5 +319,187 @@ public class PatientDashboardFragment extends Fragment {
|
||||
layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._200sdp);;
|
||||
|
||||
binding.bgImg.setLayoutParams(layoutParams);
|
||||
|
||||
binding.messageTitle.setText(viewModel.message_title);
|
||||
binding.messageSub1.setText(viewModel.message_sub_title_1);
|
||||
binding.messageSub2.setText(viewModel.message_sub_title_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemindersListFetched(List<ReminderResult> reminderResult) {
|
||||
viewModel.getNearestReminder(reminderResult, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchRemindersListFailed(Throwable t, String message) {
|
||||
removeReminder();
|
||||
viewModel.message_title = null;
|
||||
viewModel.message_sub_title_1 = null;
|
||||
viewModel.message_sub_title_2 = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nearestReminder(NearestReminder nearestReminder) {
|
||||
// next reminder setting
|
||||
try {
|
||||
if (nearestReminder == null) throw new Exception();
|
||||
|
||||
if (nearestReminder.upcoming_time == null){
|
||||
viewModel.nearest_rem_time = Long.MAX_VALUE;
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
Date upcoming_date = input_sdf.parse(nearestReminder.upcoming_time);
|
||||
if (upcoming_date == null) throw new Exception();
|
||||
|
||||
Calendar cur_cal = Calendar.getInstance();
|
||||
Date cur_date = new Date(upcoming_date.getYear(), upcoming_date.getMonth(), upcoming_date.getDate(), cur_cal.get(Calendar.HOUR_OF_DAY), cur_cal.get(Calendar.MINUTE), upcoming_date.getSeconds());
|
||||
|
||||
long time_diff = upcoming_date.getTime() - cur_date.getTime() + 1000; // +1000 for extra one min to reach that time
|
||||
|
||||
viewModel.nearest_rem_time = time_diff;
|
||||
|
||||
if (time_diff < 0){
|
||||
// the nearest time has already passed the current time
|
||||
// i.e. all the reminders has been done for current day
|
||||
|
||||
throw new Exception();
|
||||
}else{
|
||||
time_diff = time_diff/1000; // milliseconds to seconds
|
||||
long s = time_diff % 60;
|
||||
long m = (time_diff / 60) % 60;
|
||||
long h = (time_diff / (60 * 60)) % 24;
|
||||
|
||||
StringBuilder reminder_txt = new StringBuilder("You should take yours medicines");
|
||||
|
||||
if (time_diff > 3600){
|
||||
// time greater than 60 mins
|
||||
// thus, showing direct time
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
try {
|
||||
String time = format_sdf.format(upcoming_date);
|
||||
reminder_txt.append(" at ").append(time);
|
||||
} catch (Exception e) {
|
||||
reminder_txt.append(" at ").append(nearestReminder.upcoming_time);
|
||||
}
|
||||
|
||||
}else{
|
||||
// show in minutes
|
||||
reminder_txt.append(" in ").append(m).append(" min");
|
||||
|
||||
if (m > 1) reminder_txt.append("s"); // plural
|
||||
}
|
||||
|
||||
viewModel.message_title = reminder_txt.toString();
|
||||
viewModel.message_sub_title_1 = nearestReminder.medication_name;
|
||||
viewModel.message_sub_title_2 = nearestReminder.med_quantity + " " + nearestReminder.med_type;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
viewModel.message_sub_title_2 = viewModel.message_sub_title_1 = viewModel.message_title = null;
|
||||
}
|
||||
|
||||
// Now checking activities
|
||||
routineViewModel.getRoutines(AppUtil.getPatientUid(requireContext()),
|
||||
"Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1,
|
||||
this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutinesFetched(List<RoutineDetails> routineList) {
|
||||
viewModel.getNearestActivity(routineList, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutinesFetchedFailed(Throwable t, String message) {
|
||||
if (viewModel.message_title != null){
|
||||
addReminder();
|
||||
}else{
|
||||
removeReminder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nearestActivity(NearestActivity nearestActivity) {
|
||||
|
||||
// next routine setting
|
||||
try {
|
||||
|
||||
if (nearestActivity.upcoming_time == null){
|
||||
if (viewModel.message_title != null){
|
||||
addReminder();
|
||||
}else{
|
||||
removeReminder();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
|
||||
Date upcoming_date = input_sdf.parse(nearestActivity.upcoming_time);
|
||||
if (upcoming_date == null) throw new Exception();
|
||||
|
||||
Calendar cur_cal = Calendar.getInstance();
|
||||
Date cur_date = new Date(upcoming_date.getYear(), upcoming_date.getMonth(), upcoming_date.getDate(), cur_cal.get(Calendar.HOUR_OF_DAY), cur_cal.get(Calendar.MINUTE), upcoming_date.getSeconds());
|
||||
|
||||
long time_diff = upcoming_date.getTime() - cur_date.getTime() + 1000; // +1000 for extra one min to reach that time
|
||||
|
||||
if (time_diff < 0){
|
||||
// the nearest time has already passed the current time
|
||||
// i.e. all the reminders has been done for current day
|
||||
|
||||
if (viewModel.message_title != null){
|
||||
addReminder();
|
||||
}else{
|
||||
removeReminder();
|
||||
}
|
||||
}else if (time_diff < viewModel.nearest_rem_time){
|
||||
time_diff = time_diff/1000; // milliseconds to seconds
|
||||
long s = time_diff % 60;
|
||||
long m = (time_diff / 60) % 60;
|
||||
long h = (time_diff / (60 * 60)) % 24;
|
||||
|
||||
StringBuilder up_activity_txt = new StringBuilder("Get ready for your activity starting");
|
||||
|
||||
if (time_diff > 3600){
|
||||
// time greater than 60 mins
|
||||
// thus, showing direct time
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
try {
|
||||
String time = format_sdf.format(upcoming_date);
|
||||
up_activity_txt.append(" at ").append(time);
|
||||
} catch (Exception e) {
|
||||
up_activity_txt.append(" at ").append(nearestActivity.upcoming_time);
|
||||
}
|
||||
|
||||
}else{
|
||||
// show in minutes
|
||||
up_activity_txt.append(" in ").append(m).append(" min");
|
||||
|
||||
if (m > 1) up_activity_txt.append("s"); // plural
|
||||
}
|
||||
|
||||
viewModel.message_title = up_activity_txt.toString();
|
||||
viewModel.message_sub_title_1 = nearestActivity.upcoming_activity_name;
|
||||
viewModel.message_sub_title_2 = null;
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
if (viewModel.message_title != null){
|
||||
addReminder();
|
||||
}else{
|
||||
removeReminder();
|
||||
}
|
||||
}
|
||||
|
||||
if (viewModel.message_title != null){
|
||||
addReminder();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ public class NearestReminder {
|
||||
public String medication_name;
|
||||
public String daily_reminder_time;
|
||||
|
||||
public String med_quantity;
|
||||
|
||||
public String med_type;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NearestReminder{" +
|
||||
|
||||
Reference in New Issue
Block a user