This commit is contained in:
14Sandee
2023-11-07 21:09:52 +05:30
parent f713bb7555
commit ccf5ad636d
19 changed files with 313 additions and 401 deletions

View File

@@ -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,

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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));
});
}
}

View File

@@ -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();
}
}

View File

@@ -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>>() {

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -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)
);
}
}

View File

@@ -31,7 +31,7 @@
android:layout_marginBottom="5dp"
android:fontFamily="@font/nunito_medium"
tools:text="@string/create_contact"
android:textAppearance="@style/TextAppearance.Material3.HeadlineMedium"
android:textSize="@dimen/_16ssp"
android:textColor="@color/black" />
<de.hdodenhof.circleimageview.CircleImageView
@@ -54,7 +54,7 @@
android:layout_gravity="center_horizontal"
android:fontFamily="@font/nunito_medium"
android:textColor="@color/black"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
android:textSize="@dimen/_12ssp"
/>
<TextView

View File

@@ -125,13 +125,11 @@
>
<TextView
android:id="@+id/message_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="You should take yours medicines in 2 : 24"
android:text="@null"
android:fontFamily="@font/nunito_semibold"
android:text="@string/upcoming_activity_"
android:fontFamily="@font/nunito_bold"
android:textColor="@color/black"
android:textSize="@dimen/_16ssp"
@@ -139,88 +137,83 @@
android:ellipsize="end"
/>
<RelativeLayout
<TextView
android:id="@+id/activity_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Run at 3:30 pm"
android:fontFamily="@font/nunito_medium"
android:textColor="@color/black"
android:textSize="@dimen/_14ssp"
android:maxLines="1"
android:ellipsize="end"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
>
<TextView
android:id="@+id/message_sub_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next_medication_schedule"
android:fontFamily="@font/nunito_bold"
android:textColor="@color/black"
android:textSize="@dimen/_16ssp"
tools:text="Vitamin D3"
android:fontFamily="@font/nunito_medium"
android:textColor="@color/black"
android:textSize="@dimen/_14ssp"
android:maxLines="2"
android:ellipsize="end"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
/>
android:maxLines="1"
android:maxEms="5"
android:ellipsize="end"
<TextView
android:id="@+id/reminder_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
tools:text="Paracetamol at 3:30 pm"
android:fontFamily="@font/nunito_medium"
android:textColor="@color/black"
android:textSize="@dimen/_14ssp"
<TextView
android:id="@+id/message_sub_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
tools:text="2 capsules"
android:fontFamily="@font/nunito_medium"
android:textColor="@color/black"
android:textSize="@dimen/_14ssp"
/>
android:layout_toEndOf="@id/message_sub_1"
android:layout_marginStart="15dp"
<ImageView
android:id="@+id/close_reminder_"
android:layout_width="20dp"
android:layout_height="20dp"
android:contentDescription="@string/close"
android:visibility="gone"
android:layout_centerVertical="true"
app:srcCompat="@drawable/ic_close_primary"
android:maxLines="1"
android:maxEms="5"
android:ellipsize="end"
android:layout_gravity="end"
/>
/>
<ImageView
android:id="@+id/close_reminder"
android:layout_width="20dp"
android:layout_height="20dp"
android:contentDescription="@string/close"
android:visibility="gone"
<ImageView
android:id="@+id/refresh_btn_"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_refresh"
android:contentDescription="@string/refresh"
android:layout_gravity="end"
android:visibility="visible"
/>
app:srcCompat="@drawable/ic_close_primary"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
/>
<ImageView
android:id="@+id/refresh_btn"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_refresh"
android:contentDescription="@string/refresh"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:visibility="visible"
/>
<ProgressBar
android:id="@+id/refresh_progress"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:indeterminateTint="@color/color_primary_dark"
android:indeterminate="true"
/>
</RelativeLayout>
<ProgressBar
android:id="@+id/refresh_progress_"
android:visibility="gone"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:indeterminateTint="@color/color_primary_dark"
android:indeterminate="true"
/>
</LinearLayout>

View File

@@ -44,12 +44,12 @@
<action
android:id="@+id/action_signInFragment_to_profileProgressFragment"
app:destination="@id/profileProgressFragment" />
<action
android:id="@+id/action_signInFragment_to_contactListFragment"
app:destination="@id/contactListFragment" />
<action
android:id="@+id/action_signInFragment_to_reActivateFragment"
app:destination="@id/reActivateFragment" />
<action
android:id="@+id/action_signInFragment_to_createContactFragment"
app:destination="@id/createContactFragment" />
</fragment>
<fragment
android:id="@+id/forgotPinFragment"
@@ -103,8 +103,8 @@
android:name="com.app.simplitend.welcome.welcomepatient.fragments.register.ThankYouFragment"
android:label="ThankYouFragment" >
<action
android:id="@+id/action_thankYouFragment_to_contactListFragment"
app:destination="@id/contactListFragment" />
android:id="@+id/action_thankYouFragment_to_createContactFragment"
app:destination="@id/createContactFragment" />
</fragment>
<fragment
android:id="@+id/contactListFragment"
@@ -121,7 +121,7 @@
<action
android:id="@+id/action_createContactFragment_to_addContactFragment"
app:destination="@id/addContactFragment"
app:popUpTo="@id/contactListFragment"
app:popUpTo="@id/thankYouFragment"
app:popUpToInclusive="true"
/>
</fragment>
@@ -204,9 +204,6 @@
<action
android:id="@+id/action_splashFragment_to_welcomeFragment"
app:destination="@id/welcomeFragment" />
<action
android:id="@+id/action_splashFragment_to_contactListFragment"
app:destination="@id/contactListFragment" />
<action
android:id="@+id/action_splashFragment_to_profileProgressFragment"
app:destination="@id/profileProgressFragment" />
@@ -216,6 +213,9 @@
<action
android:id="@+id/action_splashFragment_to_reActivateFragment"
app:destination="@id/reActivateFragment" />
<action
android:id="@+id/action_splashFragment_to_createContactFragment"
app:destination="@id/createContactFragment" />
</fragment>
<fragment
android:id="@+id/medicalInfoFragment"

View File

@@ -74,10 +74,11 @@
<string name="thank_you">Thank you !</string>
<string name="let_s_add_your_caregiver_contact_information">Let\'s add your caregiver contact information</string>
<string name="proceed">Proceed</string>
<string name="please_add_your_caregiver_contact_information">Please add your caregiver contact information</string>
<string name="please_add_your_caregiver_contact_information">Please select a contact</string>
<string name="search_contact">Search contact</string>
<string name="create_new_contact">Create new contact</string>
<string name="create_contact">Create contact</string>
<string name="create_caregiver_contact">Please add your caregiver contact information</string>
<string name="edit_contact">Edit contact</string>
<string name="save">Save</string>
<string name="change_photo">Change photo</string>
@@ -371,6 +372,7 @@
<string name="year_">/year</string>
<string name="on_going_activity">On going activity</string>
<string name="upcoming_activity">Upcoming activity</string>
<string name="upcoming_activity_">Upcoming activity:</string>
<string name="none">None</string>
<string name="view_more"><u>view more</u></string>
<string name="no_articles_found">No articles found!</string>
@@ -408,6 +410,7 @@
<string name="couldnt_load_data">Couldn\'t load data</string>
<string name="no_data">No data</string>
<string name="all_reminder_done">No reminders for today.</string>
<string name="all_activity_done">No activities for today.</string>
<string name="no_ongoing_activity">No ongoing activity</string>
<string name="no_upcoming_activities">No upcoming activities</string>
<string name="direction_to_home">Direction to home</string>