.
This commit is contained in:
@@ -3,6 +3,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.apputils.NotificationService.NOTIFICATION_SENIOR_ADDRESS_KEY;
|
||||
import static com.app.simplitend.articles.ArticleShowerActivity.ARTICLE_TITLE;
|
||||
import static com.app.simplitend.articles.ArticleShowerActivity.ARTICLE_URL_KEY;
|
||||
import static com.app.simplitend.callwhitelisting.CallService.CONTACT_WHITE_LISTING_TAG;
|
||||
@@ -17,6 +18,8 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
@@ -317,11 +320,12 @@ public abstract class AppUtil {
|
||||
}
|
||||
|
||||
title = patient_name + " is out of Geofence!";
|
||||
String senior_address_gf = intent.getStringExtra(NOTIFICATION_SENIOR_ADDRESS_KEY);
|
||||
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_medication_time,
|
||||
title, "Current location",
|
||||
"Unknown", "Call senior",
|
||||
senior_address_gf, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
@@ -429,11 +433,13 @@ public abstract class AppUtil {
|
||||
}
|
||||
|
||||
title = patient_name + " requested for directions to home";
|
||||
body = "Current location:";
|
||||
String senior_address = intent.getStringExtra(NOTIFICATION_SENIOR_ADDRESS_KEY);
|
||||
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_directioin_requested,
|
||||
title, body,
|
||||
null, "Call senior",
|
||||
senior_address, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
@@ -514,6 +520,27 @@ public abstract class AppUtil {
|
||||
// already returning
|
||||
}
|
||||
|
||||
public static String getCompleteAddress(Context context, double LATITUDE, double LONGITUDE) {
|
||||
String strAdd = null;
|
||||
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
|
||||
try {
|
||||
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
|
||||
if (addresses != null) {
|
||||
Address returnedAddress = addresses.get(0);
|
||||
StringBuilder strReturnedAddress = new StringBuilder("");
|
||||
|
||||
for (int i = 0; i <= returnedAddress.getMaxAddressLineIndex(); i++) {
|
||||
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
|
||||
}
|
||||
strAdd = strReturnedAddress.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
return strAdd;
|
||||
}
|
||||
|
||||
private static void setupBottomSheet(BottomSheetAlertBinding binding,
|
||||
int img_res,
|
||||
String title, String description_title,
|
||||
|
||||
@@ -35,10 +35,12 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
public static final String NOTIFICATION_TITLE_KEY = "notification_title_key";
|
||||
public static final String NOTIFICATION_CONTENT_ID_KEY = "notification_title_key";
|
||||
|
||||
public static final String NOTIFICATION_SENIOR_ADDRESS_KEY = "notification_senior_address";
|
||||
|
||||
@Override
|
||||
public void onNotificationReceived(@NonNull INotificationReceivedEvent iNotificationReceivedEvent) {
|
||||
JSONObject extras = iNotificationReceivedEvent.getNotification().getAdditionalData();
|
||||
String content_type = null;
|
||||
String content_type = null, senior_current_address = null;
|
||||
int id = -1;
|
||||
if (extras != null) {
|
||||
try {
|
||||
@@ -47,6 +49,12 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
} catch (JSONException e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
senior_current_address = extras.getString("address");
|
||||
} catch (JSONException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
Intent intent = new Intent(AppUtil.NOTIFICATION_ACTION);
|
||||
@@ -54,6 +62,7 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
intent.putExtra(NOTIFICATION_BODY_KEY, iNotificationReceivedEvent.getNotification().getBody());
|
||||
intent.putExtra(NOTIFICATION_TITLE_KEY, iNotificationReceivedEvent.getNotification().getTitle());
|
||||
intent.putExtra(NOTIFICATION_CONTENT_ID_KEY, id);
|
||||
intent.putExtra(NOTIFICATION_SENIOR_ADDRESS_KEY, senior_current_address);
|
||||
|
||||
iNotificationReceivedEvent.getContext().sendBroadcast(intent);
|
||||
|
||||
|
||||
@@ -441,7 +441,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
@Override
|
||||
public void nearestReminder(NearestReminder nearestReminder) {
|
||||
Log.d("aditya", "nearestReminder: " + nearestReminder);
|
||||
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
@@ -552,7 +551,7 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
// the nearest time has already passed the current time
|
||||
// i.e. all the reminders has been done for current day
|
||||
|
||||
binding.upcomingActivity.setText(R.string.all_reminder_done);
|
||||
binding.upcomingActivity.setText(R.string.all_activity_done);
|
||||
}else{
|
||||
time_diff = time_diff/1000; // milliseconds to seconds
|
||||
long s = time_diff % 60;
|
||||
@@ -561,23 +560,13 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
|
||||
StringBuilder up_activity_txt = new StringBuilder(nearestActivity.upcoming_activity_name);
|
||||
|
||||
if (time_diff > 3600){
|
||||
// time greater than 60 mins
|
||||
// thus, showing direct time
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
binding.upcomingActivity.setText(up_activity_txt);
|
||||
|
||||
@@ -8,11 +8,13 @@ import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface NotificationApiService {
|
||||
|
||||
@POST("api/send-out-of-geofence-notification")
|
||||
Call<CallResponse<Object>> notifyOutOfGeoFence(@Body Map<String, String> body,
|
||||
|
||||
@Header("Authorization") String token);
|
||||
|
||||
@POST("api/send-notification-when-patient-clicks-on-sos")
|
||||
@@ -21,6 +23,7 @@ public interface NotificationApiService {
|
||||
|
||||
@POST("api/send-notification-when-patient-clicks-on-go")
|
||||
Call<CallResponse<Object>> notifyRequestedDirections(@Body Map<String, String> body,
|
||||
@Query("address") String address,
|
||||
@Header("Authorization") String token);
|
||||
|
||||
|
||||
|
||||
@@ -266,7 +266,9 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
binding.changeBtn.setOnClickListener(v -> {
|
||||
if (binding.search.getVisibility() == View.VISIBLE){
|
||||
binding.search.setVisibility(View.GONE);
|
||||
binding.changeBtn.setText(getString(R.string.change));
|
||||
}else{
|
||||
binding.changeBtn.setText(getString(R.string.close_));
|
||||
binding.search.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
@@ -356,15 +358,23 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
// do nothing
|
||||
|
||||
}
|
||||
StringBuilder senior_address = new StringBuilder("");
|
||||
|
||||
StringBuilder senior_address = new StringBuilder(patientData.address_line1);
|
||||
if (senior_address.length() != 0){
|
||||
senior_address.append(", ");
|
||||
if (patientData.address_line1 != null){
|
||||
senior_address.append(patientData.address_line1).append(", ");
|
||||
}
|
||||
|
||||
senior_address.append(patientData.city).append(", ")
|
||||
.append(patientData.state).append(", ")
|
||||
.append(patientData.country).append(".");
|
||||
if (patientData.city != null){
|
||||
senior_address.append(patientData.city).append(", ");
|
||||
}
|
||||
|
||||
if (patientData.state != null){
|
||||
senior_address.append(patientData.state).append(", ");
|
||||
}
|
||||
|
||||
if (patientData.country != null){
|
||||
senior_address.append(patientData.country).append(".");
|
||||
}
|
||||
|
||||
binding.homeAddress.setText(senior_address);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,8 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
private double pat_lat, pat_lng;
|
||||
private double pat_cur_lat, pat_cur_lng;
|
||||
|
||||
private String your_loc;
|
||||
|
||||
private ActivityResultLauncher<String[]> locationPermissionLauncher;
|
||||
private ActivityResultLauncher<Intent> enableLocationIntent;
|
||||
private FusedLocationProviderClient fusedLocationProviderClient;
|
||||
@@ -115,14 +117,19 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
});
|
||||
|
||||
binding.goBtn.setOnClickListener(v -> {
|
||||
String cur_location = pat_cur_lat + "," + pat_cur_lng;
|
||||
String pat_location = pat_lat + "," + pat_lng;
|
||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=" + pat_location + "&travelmode=walking"));
|
||||
|
||||
startActivity(intent);
|
||||
|
||||
String current_address = AppUtil.getCompleteAddress(this, pat_lat, pat_lng);
|
||||
if (current_address == null){
|
||||
current_address = "Unable to locate";
|
||||
}
|
||||
|
||||
viewModel.notifyRequestedDirections(AppUtil.getPatientUid(this)+"",
|
||||
current_address,
|
||||
AppUtil.getPatientToken(this));
|
||||
});
|
||||
|
||||
@@ -339,7 +346,6 @@ 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());
|
||||
@@ -348,6 +354,8 @@ public class DirectionToHomeActivity extends AppCompatActivity
|
||||
if (addresses != null && addresses.size() > 0 && addresses.get(0) != null) {
|
||||
Address address = addresses.get(0);
|
||||
|
||||
your_loc = "";
|
||||
|
||||
if (address.getMaxAddressLineIndex() > 0 && address.getAddressLine(0) != null){
|
||||
your_loc = address.getAddressLine(0);
|
||||
}
|
||||
|
||||
@@ -69,13 +69,18 @@ public class PatientMainViewModel extends ViewModel {
|
||||
|
||||
private final NotificationApiService notificationApiService;
|
||||
|
||||
public String message_title, message_sub_title_1, message_sub_title_2;
|
||||
public String ongoingActivityText, upcomingActivityText;
|
||||
public String upcomingReminderText, dailyReminderText;
|
||||
|
||||
public long nearest_rem_time;
|
||||
public List<ReminderResult> remindersList;
|
||||
public List<RoutineDetails> activityList;
|
||||
|
||||
public PatientMainViewModel() {
|
||||
cgHomeRepository = CgHomeRepository.getHomeRepository();
|
||||
notificationApiService = RetrofitHelper.getRetrofit().create(NotificationApiService.class);
|
||||
|
||||
this.ongoingActivityText = this.upcomingActivityText =
|
||||
this.upcomingReminderText = this.dailyReminderText = "Loading...";
|
||||
}
|
||||
|
||||
public void setGeofence(Activity activity, GeoFenceDetails geoFenceDetails, PatientData patientData) {
|
||||
@@ -178,11 +183,11 @@ public class PatientMainViewModel extends ViewModel {
|
||||
});
|
||||
}
|
||||
|
||||
public void notifyRequestedDirections(String patient_Id, String token){
|
||||
public void notifyRequestedDirections(String patient_Id, String address, String token){
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("patient_id", patient_Id);
|
||||
|
||||
notificationApiService.notifyRequestedDirections(body, "Bearer " + token)
|
||||
notificationApiService.notifyRequestedDirections(body, address, "Bearer " + token)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
@@ -252,134 +257,6 @@ public class PatientMainViewModel extends ViewModel {
|
||||
});
|
||||
}
|
||||
|
||||
// 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());
|
||||
@@ -448,4 +325,29 @@ public class PatientMainViewModel extends ViewModel {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
for (ReminderResult reminder: reminderResultList){
|
||||
if (!alreadyPassed(reminder.medicine_time)){
|
||||
nearestReminder.upcoming_time = reminder.medicine_time;
|
||||
nearestReminder.reminder_id = reminder.id;
|
||||
nearestReminder.medication_name = reminder.medicine_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// callback through main thread
|
||||
handler.post(() -> nearestResultCallback.nearestReminder(nearestReminder));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,18 +111,22 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
reminderViewModel = new ViewModelProvider(requireActivity()).get(ReminderViewModel.class);
|
||||
routineViewModel = new ViewModelProvider(requireActivity()).get(RoutineViewModel.class);
|
||||
|
||||
loadReminders();
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
|
||||
loadReminders();
|
||||
|
||||
loadActivities();
|
||||
|
||||
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)) {
|
||||
if (Constants.ACTIVITY_TIME.equals(content_type)){
|
||||
loadActivities();
|
||||
}else if (Constants.MEDICINE_TIME.equals(content_type)){
|
||||
loadReminders();
|
||||
}
|
||||
}
|
||||
@@ -173,11 +177,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
if (viewModel.message_title == null) {
|
||||
removeReminder();
|
||||
} else {
|
||||
addReminder();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,7 +202,17 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
private void clickEvents() {
|
||||
binding.refreshBtn.setOnClickListener(v -> {
|
||||
showLoadingProgress(true);
|
||||
|
||||
viewModel.ongoingActivityText = getString(R.string.loading);
|
||||
viewModel.upcomingActivityText = getString(R.string.loading);
|
||||
viewModel.upcomingReminderText = getString(R.string.loading);
|
||||
viewModel.dailyReminderText = getString(R.string.loading);
|
||||
|
||||
binding.activityMessage.setText(viewModel.upcomingActivityText);
|
||||
binding.reminderMessage.setText(viewModel.upcomingReminderText);
|
||||
|
||||
loadReminders();
|
||||
loadActivities();
|
||||
});
|
||||
|
||||
binding.chats.setOnClickListener(v -> {
|
||||
@@ -345,12 +355,23 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
}
|
||||
|
||||
private void loadReminders() {
|
||||
binding.reminderMessage.setText(viewModel.upcomingReminderText);
|
||||
|
||||
reminderViewModel.getRemindersList(AppUtil.getPatientUid(requireContext()),
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1,
|
||||
"Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
this);
|
||||
}
|
||||
|
||||
private void loadActivities(){
|
||||
binding.activityMessage.setText(viewModel.ongoingActivityText);
|
||||
|
||||
routineViewModel.getRoutines(AppUtil.getPatientUid(requireContext()),
|
||||
"Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1,
|
||||
this);
|
||||
}
|
||||
|
||||
private void showLoadingProgress(boolean isLoading){
|
||||
if (isLoading){
|
||||
binding.refreshBtn.setVisibility(View.GONE);
|
||||
@@ -401,76 +422,46 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
private void removeReminder() {
|
||||
|
||||
// removing card from screen code.
|
||||
// binding.homeReminder.setVisibility(View.GONE);
|
||||
//
|
||||
// try {
|
||||
// ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
// layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._140sdp);
|
||||
// binding.bgImg.setLayoutParams(layoutParams);
|
||||
// } catch (Exception e) {
|
||||
// // do nothing
|
||||
// }
|
||||
binding.homeReminder.setVisibility(View.GONE);
|
||||
|
||||
showLoadingProgress(false);
|
||||
|
||||
String no_med_message_title = "No upcoming activity or Medication reminder!";
|
||||
|
||||
binding.messageTitle.setText(no_med_message_title);
|
||||
|
||||
binding.messageSub1.setVisibility(View.GONE);
|
||||
binding.messageSub2.setVisibility(View.GONE);
|
||||
|
||||
viewModel.message_title = null;
|
||||
}
|
||||
|
||||
private void addReminder() {
|
||||
showLoadingProgress(false);
|
||||
|
||||
if (viewModel.message_title == null || viewModel.message_title.isEmpty()) {
|
||||
// removeReminder();
|
||||
return;
|
||||
try {
|
||||
ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._140sdp);
|
||||
binding.bgImg.setLayoutParams(layoutParams);
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
binding.homeReminder.setVisibility(View.VISIBLE);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams();
|
||||
|
||||
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);
|
||||
binding.messageSub1.setVisibility(View.VISIBLE);
|
||||
binding.messageSub2.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemindersListFetched(List<ReminderResult> reminderResult) {
|
||||
// viewModel.getNearestReminder(reminderResult, this);
|
||||
viewModel.remindersList = 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;
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
showLoadingProgress(false);
|
||||
binding.reminderMessage.setText(R.string.couldnt_load_data);
|
||||
|
||||
viewModel.upcomingReminderText = binding.reminderMessage.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nearestReminder(NearestReminder nearestReminder) {
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
// 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();
|
||||
if (nearestReminder.upcoming_time == null){
|
||||
binding.reminderMessage.setText(R.string.all_reminder_done);
|
||||
viewModel.upcomingReminderText = binding.reminderMessage.getText().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
@@ -483,87 +474,67 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
|
||||
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) {
|
||||
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
|
||||
binding.reminderMessage.setText(R.string.all_reminder_done);
|
||||
}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");
|
||||
StringBuilder reminder_txt = new StringBuilder(nearestReminder.medication_name);
|
||||
|
||||
if (time_diff > 3600) {
|
||||
// time greater than 60 mins
|
||||
// thus, showing direct time
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
binding.reminderMessage.setText(reminder_txt);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
viewModel.message_sub_title_2 = viewModel.message_sub_title_1 = viewModel.message_title = null;
|
||||
}catch (Exception e){
|
||||
binding.reminderMessage.setText(R.string.couldnt_load_data);
|
||||
}
|
||||
|
||||
// Now checking activities
|
||||
try {
|
||||
routineViewModel.getRoutines(AppUtil.getPatientUid(requireContext()),
|
||||
"Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1,
|
||||
this);
|
||||
} catch (Exception e) {
|
||||
// do nothing user has left the fragment
|
||||
}
|
||||
viewModel.upcomingReminderText = binding.reminderMessage.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutinesFetched(List<RoutineDetails> routineList) {
|
||||
viewModel.activityList = routineList;
|
||||
viewModel.getNearestActivity(routineList, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutinesFetchedFailed(Throwable t, String message) {
|
||||
if (viewModel.message_title != null) {
|
||||
addReminder();
|
||||
} else {
|
||||
removeReminder();
|
||||
}
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.activityMessage.setText(R.string.couldnt_load_data);
|
||||
|
||||
viewModel.ongoingActivityText = binding.activityMessage.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nearestActivity(NearestActivity nearestActivity) {
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
// next routine setting
|
||||
try {
|
||||
|
||||
if (nearestActivity.upcoming_time == null) {
|
||||
if (viewModel.message_title != null) {
|
||||
addReminder();
|
||||
} else {
|
||||
removeReminder();
|
||||
}
|
||||
if (nearestActivity.upcoming_time == null){
|
||||
binding.activityMessage.setText(R.string.no_upcoming_activities);
|
||||
|
||||
viewModel.upcomingActivityText = binding.activityMessage.getText().toString();
|
||||
viewModel.ongoingActivityText = binding.activityMessage.getText().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -577,57 +548,35 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
|
||||
long time_diff = upcoming_date.getTime() - cur_date.getTime() + 1000; // +1000 for extra one min to reach that time
|
||||
|
||||
if (time_diff < 0) {
|
||||
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
|
||||
binding.activityMessage.setText(R.string.all_activity_done);
|
||||
}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 up_activity_txt = new StringBuilder("Get ready for your activity starting");
|
||||
StringBuilder up_activity_txt = new StringBuilder(nearestActivity.upcoming_activity_name);
|
||||
|
||||
if (time_diff > 3600) {
|
||||
// time greater than 60 mins
|
||||
// thus, showing direct time
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
viewModel.message_title = up_activity_txt.toString();
|
||||
viewModel.message_sub_title_1 = nearestActivity.upcoming_activity_name;
|
||||
viewModel.message_sub_title_2 = null;
|
||||
binding.activityMessage.setText(up_activity_txt);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if (viewModel.message_title != null) {
|
||||
addReminder();
|
||||
} else {
|
||||
removeReminder();
|
||||
}
|
||||
}catch (Exception e){
|
||||
binding.activityMessage.setText(R.string.couldnt_load_data);
|
||||
}
|
||||
|
||||
if (viewModel.message_title != null) {
|
||||
addReminder();
|
||||
}
|
||||
viewModel.ongoingActivityText = binding.activityMessage.getText().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.app.simplitend.patientgeofencing;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
@@ -35,7 +36,19 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(GEOFENCE_TAG, "onReceive: " + intent.getExtras());
|
||||
|
||||
int transition_type = geofencingEvent.getGeofenceTransition();
|
||||
Location location = geofencingEvent.getTriggeringLocation();
|
||||
|
||||
String senior_address = null;
|
||||
if (location != null){
|
||||
senior_address = AppUtil.getCompleteAddress(context, location.getLatitude(), location.getLongitude());
|
||||
}
|
||||
|
||||
if (senior_address == null) {
|
||||
senior_address = "Unable to locate";
|
||||
}
|
||||
|
||||
switch (transition_type) {
|
||||
case Geofence.GEOFENCE_TRANSITION_DWELL:
|
||||
@@ -51,17 +64,19 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
|
||||
break;
|
||||
case Geofence.GEOFENCE_TRANSITION_EXIT:
|
||||
Log.d(GEOFENCE_TAG, "onReceive: EXIT");
|
||||
notifyOutOfGeofence(context);
|
||||
notifyOutOfGeofence(context, senior_address);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyOutOfGeofence(Context context) {
|
||||
private void notifyOutOfGeofence(Context context, String senior_address) {
|
||||
Log.d(GEOFENCE_TAG, "Sending notification to patient");
|
||||
Log.d(GEOFENCE_TAG, "Current location: " + senior_address);
|
||||
NotificationApiService apiService = RetrofitHelper.getRetrofit().create(NotificationApiService.class);
|
||||
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("patient_id", AppUtil.getPatientUid(context) + "");
|
||||
body.put("address", senior_address);
|
||||
|
||||
apiService.notifyOutOfGeoFence(body, "Bearer " + AppUtil.getPatientToken(context))
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
|
||||
@@ -249,7 +249,7 @@ public class SignInFragment extends Fragment implements WelcomeContracts.Registe
|
||||
.build();
|
||||
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_signInFragment_to_contactListFragment, null, navOptions);
|
||||
.navigate(R.id.action_signInFragment_to_createContactFragment, null, navOptions);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -375,6 +375,10 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.caregiverCheckView.setVisibility(View.VISIBLE);
|
||||
this.mustBeeCaregiver = true;
|
||||
binding.caregiverCheck.setChecked(true);
|
||||
|
||||
// setting up title
|
||||
setLayoutDetails(getString(R.string.create_caregiver_contact), getString(R.string.add_photo), getString(R.string.create_contact));
|
||||
addContactView("", true);
|
||||
}
|
||||
|
||||
// checking if there is any SOS contact already in list
|
||||
|
||||
@@ -450,7 +450,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
.zoom(15)
|
||||
.build();
|
||||
|
||||
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(default_map_pos));
|
||||
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(default_map_pos));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ public class SplashFragment extends Fragment
|
||||
.build();
|
||||
|
||||
Navigation.findNavController(binding.getRoot())
|
||||
.navigate(R.id.action_splashFragment_to_contactListFragment, null, navOptions);
|
||||
.navigate(R.id.action_splashFragment_to_createContactFragment, null, navOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ThankYouFragment extends Fragment {
|
||||
|
||||
private void clickEvents() {
|
||||
binding.proceed.setOnClickListener(v ->
|
||||
Navigation.findNavController(v).navigate(R.id.action_thankYouFragment_to_contactListFragment)
|
||||
Navigation.findNavController(v).navigate(R.id.action_thankYouFragment_to_createContactFragment)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user