.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.app.simplitend.appblocking;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
@@ -17,6 +20,7 @@ import android.provider.Telephony;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@@ -28,6 +32,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.app.simplitend.R;
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.databinding.FuaEduDialogBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -68,6 +73,19 @@ public class FUAActivity extends AppCompatActivity {
|
||||
no_fua_txt = findViewById(R.id.no_fua_text);
|
||||
all_apps_title = findViewById(R.id.all_app_tile);
|
||||
fua_sub_title = findViewById(R.id.fua_sub_title);
|
||||
|
||||
if (AppUtil.shouldShowFUADialog(this)){
|
||||
FuaEduDialogBinding dialogBinding = FuaEduDialogBinding.inflate(getLayoutInflater());
|
||||
Dialog fuaDialog = new Dialog(this, R.style.BottomSheetDialog);
|
||||
fuaDialog.setContentView(dialogBinding.getRoot());
|
||||
|
||||
dialogBinding.checkBox.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
AppUtil.setShouldShowFuaDialog(this, !b);
|
||||
});
|
||||
|
||||
dialogBinding.close.setOnClickListener(v -> fuaDialog.dismiss());
|
||||
fuaDialog.show();
|
||||
}
|
||||
|
||||
if (!isAccessibilityAppBlockingEnabled()) {
|
||||
openAccessibilityDialog();
|
||||
|
||||
@@ -321,7 +321,7 @@ public abstract class AppUtil {
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_medication_time,
|
||||
title, "Current location",
|
||||
"Unknown", "Call patient",
|
||||
"Unknown", "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
@@ -433,7 +433,7 @@ public abstract class AppUtil {
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_directioin_requested,
|
||||
title, body,
|
||||
null, "Call patient",
|
||||
null, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
@@ -460,7 +460,7 @@ public abstract class AppUtil {
|
||||
setupBottomSheet(binding,
|
||||
R.drawable.img_sos_requested,
|
||||
title, body,
|
||||
null, "Call patient",
|
||||
null, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
@@ -579,6 +579,8 @@ public abstract class AppUtil {
|
||||
stop_accessibility_intent.setAction(TopAppDetectionService.STOP_ACCESSIBILITY_SERVICE);
|
||||
context.startService(stop_accessibility_intent);
|
||||
|
||||
setShouldShowFuaDialog(context, true);
|
||||
|
||||
// removing contact listing
|
||||
setWhiteListedContacts(context, null);
|
||||
|
||||
@@ -691,6 +693,19 @@ public abstract class AppUtil {
|
||||
return sp.getBoolean(notification, true);
|
||||
}
|
||||
|
||||
private static final String FUA_DIALOG = "FUA_dialog";
|
||||
|
||||
public static void setShouldShowFuaDialog(Context context, boolean b){
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putBoolean(FUA_DIALOG, b);
|
||||
editor.apply();
|
||||
}
|
||||
public static boolean shouldShowFUADialog(Context context){
|
||||
SharedPreferences sp = context.getSharedPreferences(CAREGIVER_DETAILS, Context.MODE_PRIVATE);
|
||||
return sp.getBoolean(FUA_DIALOG, true);
|
||||
}
|
||||
|
||||
// patient geofencing
|
||||
private static final String PATIENT_GEOFENCE_RADIUS = "patient_geofence_radius";
|
||||
private static final String PATIENT_GEOFENCE_RADIUS_UNIT = "patient_geofence_radius_unit";
|
||||
|
||||
@@ -160,7 +160,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
if (careGiverData == null) return;
|
||||
|
||||
binding.nearestReminder.setText(viewModel.upcomingReminderText);
|
||||
binding.dailyReminder.setText(viewModel.dailyReminderText);
|
||||
|
||||
reminderViewModel.getRemindersList(careGiverData.patientId,
|
||||
Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1,
|
||||
@@ -226,7 +225,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
binding.upcomingActivity.setText(viewModel.upcomingActivityText);
|
||||
binding.onGoingActivity.setText(viewModel.ongoingActivityText);
|
||||
binding.nearestReminder.setText(viewModel.upcomingReminderText);
|
||||
binding.dailyReminder.setText(viewModel.dailyReminderText);
|
||||
|
||||
loadReminders();
|
||||
loadActivities();
|
||||
@@ -437,10 +435,8 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
binding.nearestReminder.setText(R.string.couldnt_load_data);
|
||||
binding.dailyReminder.setText(R.string.couldnt_load_data);
|
||||
|
||||
viewModel.upcomingReminderText = binding.nearestReminder.getText().toString();
|
||||
viewModel.dailyReminderText = binding.dailyReminder.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -450,25 +446,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
binding.refreshProgress.setVisibility(View.GONE);
|
||||
binding.refreshBtn.setVisibility(View.VISIBLE);
|
||||
|
||||
try {
|
||||
// daily routine setting
|
||||
String daily_r_txt;
|
||||
|
||||
if (nearestReminder.daily_reminder_time == null){
|
||||
daily_r_txt = "No daily reminders for today";
|
||||
}else{
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
String daily_r_time = format_sdf.format(Objects.requireNonNull(input_sdf.parse(nearestReminder.daily_reminder_time)));
|
||||
daily_r_txt = "Daily reminder at " + daily_r_time;
|
||||
}
|
||||
|
||||
binding.dailyReminder.setText(daily_r_txt);
|
||||
}catch (Exception e){
|
||||
binding.dailyReminder.setText(R.string.couldnt_load_data);
|
||||
}
|
||||
|
||||
// next reminder setting
|
||||
try {
|
||||
if (nearestReminder == null) throw new Exception();
|
||||
@@ -476,7 +453,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
if (nearestReminder.upcoming_time == null){
|
||||
binding.nearestReminder.setText(R.string.all_reminder_done);
|
||||
viewModel.upcomingReminderText = binding.nearestReminder.getText().toString();
|
||||
viewModel.dailyReminderText = binding.dailyReminder.getText().toString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -501,25 +477,15 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
long m = (time_diff / 60) % 60;
|
||||
long h = (time_diff / (60 * 60)) % 24;
|
||||
|
||||
StringBuilder reminder_txt = new StringBuilder("Remind " + nearestReminder.medication_name);
|
||||
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);
|
||||
}
|
||||
|
||||
binding.nearestReminder.setText(reminder_txt);
|
||||
@@ -530,7 +496,6 @@ public class CgDashBoardFragment extends Fragment implements
|
||||
}
|
||||
|
||||
viewModel.upcomingReminderText = binding.nearestReminder.getText().toString();
|
||||
viewModel.dailyReminderText = binding.dailyReminder.getText().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.yarolegovich.slidingrootnav.SlidingRootNav;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -179,26 +178,13 @@ public class CaregiverMainViewModel extends ViewModel {
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// callback through main thread
|
||||
@@ -206,90 +192,6 @@ public class CaregiverMainViewModel extends ViewModel {
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.app.simplitend.cg_geofencing;
|
||||
import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_REQUEST_TAG;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
@@ -118,15 +120,18 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
Toast.makeText(this, "Couldn't load Geofence.", Toast.LENGTH_SHORT).show();
|
||||
geoFenceDetails = new GeoFenceDetails();
|
||||
onBackPressed();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(CaregiverMainViewModel.class);
|
||||
progressDialog = new ProgressDialog(this);
|
||||
|
||||
geofence_bs_binding = GeofenceBottomSheetBinding.inflate(getLayoutInflater());
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(1);
|
||||
isTrackingSenior = false;
|
||||
|
||||
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
|
||||
@@ -183,7 +188,6 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
// running on main thread
|
||||
new Handler(Looper.getMainLooper()).post(()-> {
|
||||
pat_cur_latLng = new LatLng(result.getLatitude(), result.getLongitude());
|
||||
Toast.makeText(CgGeoFencingActivity.this, "Update", Toast.LENGTH_SHORT).show();
|
||||
updateCurrentLocationPatientMarker();
|
||||
updatePatientCurrentLocationDetails();
|
||||
});
|
||||
@@ -221,7 +225,11 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
}
|
||||
|
||||
if (MILES.equals(geoFenceDetails.type)) {
|
||||
if (geoFenceDetails.type == null){
|
||||
// default
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(1);
|
||||
}
|
||||
else if (MILES.equals(geoFenceDetails.type)) {
|
||||
geofence_bs_binding.unitSpinner.selectItemByIndex(1);
|
||||
radius = radius / 1609.34f;
|
||||
} else {
|
||||
@@ -236,7 +244,6 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
geofence_bs_binding.radius.setText("" + radius);
|
||||
}
|
||||
geofence_bs_binding.message.setText(geoFenceDetails.message);
|
||||
geofence_bs_binding.location.setText(geoFenceDetails.location_name);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
@@ -256,6 +263,14 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
private void clickEvents() {
|
||||
binding.backBtn.setOnClickListener(v -> onBackPressed());
|
||||
|
||||
binding.changeBtn.setOnClickListener(v -> {
|
||||
if (binding.search.getVisibility() == View.VISIBLE){
|
||||
binding.search.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.search.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
binding.setGf.setOnClickListener(v -> {
|
||||
if (bottomSheetDialog != null) {
|
||||
bottomSheetDialog.show();
|
||||
@@ -263,9 +278,7 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
});
|
||||
|
||||
geofence_bs_binding.save.setOnClickListener(v -> {
|
||||
if (allOkay()) {
|
||||
saveGeoFence();
|
||||
}
|
||||
saveGeoFence();
|
||||
});
|
||||
|
||||
binding.search.setOnClickListener(v -> {
|
||||
@@ -287,7 +300,13 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
|
||||
binding.updateBtn.setOnClickListener(v -> {
|
||||
if (careGiverData != null) {
|
||||
updatePatientAddress();
|
||||
AppUtil.showAlert(this,
|
||||
"Update senior's geofence",
|
||||
"Are you sure you want to update the location?\nSenior Geofence will be updated.",
|
||||
getString(R.string.ok), ((dialogInterface, i) -> {
|
||||
updatePatientAddress();
|
||||
}),
|
||||
"Cancel", ((dialogInterface, i) -> {}));
|
||||
} else {
|
||||
Toast.makeText(this, "Cannot update address.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -326,19 +345,28 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
currL.setLongitude(pat_cur_latLng.longitude);
|
||||
|
||||
double distance = homeL.distanceTo(currL);
|
||||
distance /= 1000; // converting to KMs
|
||||
distance /= 1609.34; // converting to Miles
|
||||
if (distance <= 0.015){
|
||||
binding.distanceAwayTxt.setText(patientData.first_name + " is at Home");
|
||||
}else{
|
||||
binding.distanceAwayTxt.setText(String.format(patientData.first_name + " is %.2f Kms away", distance));
|
||||
binding.distanceAwayTxt.setText(String.format(patientData.first_name + " is %.2f miles away", distance));
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// do nothing
|
||||
|
||||
}
|
||||
|
||||
String address = patientData.address_line1;
|
||||
binding.homeAddress.setText(address);
|
||||
StringBuilder senior_address = new StringBuilder(patientData.address_line1);
|
||||
if (senior_address.length() != 0){
|
||||
senior_address.append(", ");
|
||||
}
|
||||
|
||||
senior_address.append(patientData.city).append(", ")
|
||||
.append(patientData.state).append(", ")
|
||||
.append(patientData.country).append(".");
|
||||
|
||||
binding.homeAddress.setText(senior_address);
|
||||
}
|
||||
|
||||
private void updatePatientAddress() {
|
||||
@@ -380,24 +408,6 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allOkay() {
|
||||
geofence_bs_binding.message.setError(null);
|
||||
geofence_bs_binding.location.setError(null);
|
||||
boolean allOkay = true;
|
||||
|
||||
if (geofence_bs_binding.message.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
geofence_bs_binding.message.setError("Required");
|
||||
}
|
||||
|
||||
if (geofence_bs_binding.location.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
geofence_bs_binding.location.setError("Required");
|
||||
}
|
||||
|
||||
return allOkay;
|
||||
}
|
||||
|
||||
private void saveGeoFence() {
|
||||
if (careGiverData == null) {
|
||||
Toast.makeText(this, "Couldn't add Fence.", Toast.LENGTH_SHORT).show();
|
||||
@@ -415,21 +425,28 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
if (geofence_bs_binding.unitSpinner.getSelectedIndex() == 1) {
|
||||
// it is miles
|
||||
radius = radius * 1609.34f; // to meters
|
||||
if (radius < 160.934 || radius > 8046.72) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage("Please select radius between\n0.1 mile - 5 mile")
|
||||
.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||
dialogInterface.dismiss();
|
||||
}).show();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// it is kms
|
||||
radius = radius * 1000; // to meters
|
||||
}
|
||||
|
||||
if (radius < 1000) {
|
||||
Toast.makeText(this, "Radius should be minimum 1 KM.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
} else if (radius > 10_000) {
|
||||
Toast.makeText(this, "Radius should be maximum 10 KM.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
if (radius < 100 || radius > 8000) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage("Please select radius between\n0.1 km - 8 km")
|
||||
.setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
|
||||
dialogInterface.dismiss();
|
||||
}).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
geoFenceDetails.message = geofence_bs_binding.message.getText().toString();
|
||||
geoFenceDetails.location_name = geofence_bs_binding.location.getText().toString();
|
||||
geoFenceDetails.radius = "" + radius;
|
||||
geoFenceDetails.type = geofence_bs_binding.unitSpinner.getSelectedIndex() == 0 ? KMS : MILES;
|
||||
geoFenceDetails.patient_xid = "" + careGiverData.patientId;
|
||||
@@ -483,6 +500,12 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
updateCurrentLocationPatientMarker();
|
||||
|
||||
mMap.setOnMapClickListener(latLng1 -> {
|
||||
if (binding.search.getVisibility() != View.VISIBLE){
|
||||
// search bar is not visible
|
||||
// user is not intending to change the home location
|
||||
return;
|
||||
}
|
||||
|
||||
this.mHomeLatLng = latLng1;
|
||||
isTrackingSenior = false;
|
||||
|
||||
@@ -530,7 +553,7 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
updateHomeMarker(home_lat_lng);
|
||||
addRadius();
|
||||
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home_lat_lng, 13));
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(home_lat_lng, 14));
|
||||
} catch (Exception e) {
|
||||
// near marine drive
|
||||
Toast.makeText(this, "Couldn't load home location", Toast.LENGTH_SHORT).show();
|
||||
@@ -563,7 +586,7 @@ public class CgGeoFencingActivity extends AppCompatActivity implements OnMapRead
|
||||
if (home_loc_marker != null) home_loc_marker.remove();
|
||||
|
||||
home_loc_marker = mMap.addMarker(markerOptions);
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(home_latLng, 13));
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(home_latLng, 14));
|
||||
}
|
||||
|
||||
private void registerMapSearchResultLauncher() {
|
||||
|
||||
@@ -136,7 +136,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
|
||||
if (current_subscription_plan_id != null){
|
||||
AppUtil.showAlert(this,
|
||||
"Cancel subscription",
|
||||
"Are you sure you want to cancel the current subscribed plan?\nThis will stop the recurring payments",
|
||||
"Are you sure you want to cancel the current subscribed plan?\nThis will stop the recurring payments.\nYou will be able to use the app until current plan expires.",
|
||||
getString(R.string.no),
|
||||
((dialogInterface, i) -> {}),
|
||||
getString(R.string.yes),
|
||||
|
||||
@@ -252,49 +252,49 @@ 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));
|
||||
});
|
||||
}
|
||||
// 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));
|
||||
|
||||
@@ -449,7 +449,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
|
||||
@Override
|
||||
public void onRemindersListFetched(List<ReminderResult> reminderResult) {
|
||||
viewModel.getNearestReminder(reminderResult, this);
|
||||
// viewModel.getNearestReminder(reminderResult, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@ import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.app.simplitend.R;
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.databinding.AddReminderFragmentBinding;
|
||||
@@ -32,13 +31,13 @@ import com.app.simplitend.patientprofile.medreminder.mvvm.models.FreqNMedTypeRes
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.Frequency;
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.MedicationType;
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class AddReminderFragment extends Fragment implements CompoundButton.OnCheckedChangeListener,
|
||||
ProfileContracts.FreqNMedTypesCallback,
|
||||
@@ -177,20 +176,18 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
|
||||
reminderResult.dosage_unit = String.valueOf(dosageTypeList.get(0).id);
|
||||
}
|
||||
|
||||
ArrayList<String> time_list = new ArrayList<>();
|
||||
|
||||
// saving the actual format of time i.e. HH:mm:ss as hint
|
||||
// and saving the formatted time as text i.e. hh:mm a
|
||||
reminderResult.time1 = binding.getTime.getHint().toString();
|
||||
time_list.add(binding.getTime.getHint().toString());
|
||||
|
||||
if (binding.getTime2.getVisibility() == View.VISIBLE){
|
||||
reminderResult.time2 = binding.getTime2.getHint().toString();
|
||||
}else{
|
||||
reminderResult.time2 = null;
|
||||
time_list.add(binding.getTime2.getHint().toString());
|
||||
}
|
||||
|
||||
if (binding.getTime3.getVisibility() == View.VISIBLE){
|
||||
reminderResult.time3 = binding.getTime3.getHint().toString();
|
||||
}else{
|
||||
reminderResult.time3 = null;
|
||||
time_list.add(binding.getTime3.getHint().toString());
|
||||
}
|
||||
|
||||
reminderResult.medication_quantity = binding.quantity.getText().toString();
|
||||
@@ -213,8 +210,13 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
|
||||
reminderResult.patientRemainderId = reminder.id;
|
||||
|
||||
reminderResult.reminder_marked = reminder.reminder_marked;
|
||||
|
||||
// to edit the reminder need to send medicine_time_list
|
||||
reminderResult.medicine_time_list = new ArrayList<>();
|
||||
reminderResult.medicine_time_list.add(binding.getTime.getHint().toString());
|
||||
} else {
|
||||
reminderResult.is_update = "0";
|
||||
reminderResult.medicine_time_list = time_list;
|
||||
}
|
||||
|
||||
String token = "Bearer " + AppUtil.getPatientToken(requireContext());
|
||||
@@ -446,6 +448,10 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
|
||||
|
||||
private void setLayoutDetails(ReminderResult reminder) {
|
||||
if (reminder != null) {
|
||||
// removing medication frequency spinner
|
||||
binding.frequencyView.setVisibility(View.GONE);
|
||||
binding.frequencyTitleView.setVisibility(View.GONE);
|
||||
|
||||
// intent is to edit the reminder
|
||||
binding.title.setText(getString(R.string.edit_reminder));
|
||||
|
||||
@@ -455,51 +461,10 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
|
||||
binding.getDate.setText(formatDate(reminder.medication_refill_date));
|
||||
binding.instructions.setText(reminder.medication_instruction);
|
||||
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
SimpleDateFormat output_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
|
||||
String refill_time_1, refill_time_2 = null, refill_time_3 = null;
|
||||
|
||||
try {
|
||||
Date date = input_sdf.parse(reminder.time1);
|
||||
if (date == null) throw new Exception();
|
||||
refill_time_1 = output_sdf.format(date);
|
||||
|
||||
if (reminder.time2 != null){
|
||||
binding.getTime2.setVisibility(View.VISIBLE);
|
||||
Date date2 = input_sdf.parse(reminder.time2);
|
||||
if (date2 == null) throw new Exception();
|
||||
refill_time_2 = output_sdf.format(date2);
|
||||
}else{
|
||||
binding.getTime2.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (reminder.time3 != null){
|
||||
binding.getTime3.setVisibility(View.VISIBLE);
|
||||
Date date3 = input_sdf.parse(reminder.time3);
|
||||
if (date3 == null) throw new Exception();
|
||||
refill_time_3 = output_sdf.format(date3);
|
||||
}else{
|
||||
binding.getTime3.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
refill_time_1 = reminder.time1;
|
||||
refill_time_2 = reminder.time2;
|
||||
refill_time_3 = reminder.time3;
|
||||
}
|
||||
|
||||
binding.getTime.setText(refill_time_1);
|
||||
binding.getTime.setHint(reminder.time1);
|
||||
|
||||
if (reminder.time2 != null){
|
||||
binding.getTime2.setText(refill_time_2);
|
||||
binding.getTime2.setHint(reminder.time2);
|
||||
}
|
||||
|
||||
if (reminder.time3 != null){
|
||||
binding.getTime3.setText(refill_time_3);
|
||||
binding.getTime3.setHint(reminder.time3);
|
||||
String medicine_time = AppUtil.formatDate("HH:mm:ss", "hh:mm a", reminder.medicine_time);
|
||||
if (medicine_time != null){
|
||||
binding.getTime.setText(medicine_time);
|
||||
binding.getTime.setHint(reminder.medicine_time);
|
||||
}
|
||||
|
||||
for (int i = 0; i < frequencyList.size(); i++) {
|
||||
@@ -700,6 +665,15 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
|
||||
timeText.setError(null);
|
||||
|
||||
Calendar calendar = Calendar.getInstance(Locale.getDefault());
|
||||
// setting calendar to set time
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
Date date = sdf.parse(timeText.getText().toString());
|
||||
if (date == null) throw new Exception();
|
||||
calendar.setTime(date);
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
TimePickerDialog tpd = new TimePickerDialog(requireContext(),
|
||||
(TimePickerDialog.OnTimeSetListener) (view, hourOfDay, minute) -> {
|
||||
|
||||
@@ -331,7 +331,6 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
binding.noData.setVisibility(View.GONE);
|
||||
|
||||
reminderAdapter.submitLIst(reminderResultList);
|
||||
|
||||
} else {
|
||||
binding.remindersRv.setVisibility(View.GONE);
|
||||
binding.noData.setVisibility(View.VISIBLE);
|
||||
@@ -542,6 +541,10 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
|
||||
reminderResult.medication_refill_date = refill_date;
|
||||
|
||||
// to edit the reminder need to send medicine_time_list
|
||||
reminderResult.medicine_time_list = new ArrayList<>();
|
||||
reminderResult.medicine_time_list.add(reminderResult.medicine_time);
|
||||
|
||||
reminderViewModel.addReminder(
|
||||
AppUtil.getPatientUid(requireContext()),
|
||||
reminderResult,
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.app.simplitend.R;
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.databinding.ReminderViewholderBinding;
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
|
||||
@@ -108,20 +109,12 @@ public class ReminderAdapter extends RecyclerView.Adapter<ReminderAdapter.Remind
|
||||
|
||||
binding.instruction.setText(instruction);
|
||||
|
||||
SimpleDateFormat input_sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
||||
SimpleDateFormat output_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault());
|
||||
String medicine_time = AppUtil.formatDate("HH:mm:ss", "hh:mm a", reminder.medicine_time);
|
||||
|
||||
String refill_time = selectNextReminder(reminder.time1, reminder.time2, reminder.time3);
|
||||
|
||||
try {
|
||||
Date date = input_sdf.parse(refill_time);
|
||||
refill_time = output_sdf.format(date);
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
if (medicine_time != null){
|
||||
binding.time.setText(medicine_time);
|
||||
}
|
||||
|
||||
binding.time.setText(refill_time);
|
||||
|
||||
String quantity = "";
|
||||
|
||||
if (reminder.medication_type != null && reminder.medication_type.size() > 0) {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ReminderRepository {
|
||||
.enqueue(new Callback<CallResponse<ReminderResult>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<ReminderResult>> call, Response<CallResponse<ReminderResult>> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().result != null){
|
||||
if (response.isSuccessful() && response.body() != null){
|
||||
if (response.body().status != 200){
|
||||
addReminderCallBack.onReminderAddFailed(new Exception(), response.body().message);
|
||||
return;
|
||||
|
||||
@@ -28,9 +28,8 @@ public class ReminderResult implements Serializable {
|
||||
public String fri;
|
||||
public String sat;
|
||||
public String sun;
|
||||
public String time1;
|
||||
public String time2;
|
||||
public String time3;
|
||||
public String medicine_time;
|
||||
public ArrayList<String> medicine_time_list;
|
||||
public String active;
|
||||
public String deleted_at;
|
||||
public String created_by;
|
||||
@@ -51,11 +50,11 @@ public class ReminderResult implements Serializable {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ReminderResult that = (ReminderResult) o;
|
||||
return id == that.id && Objects.equals(patient_xid, that.patient_xid) && Objects.equals(medicine_name, that.medicine_name) && Objects.equals(dosage, that.dosage) && Objects.equals(dosage_unit, that.dosage_unit) && Objects.equals(medication_type_xid, that.medication_type_xid) && Objects.equals(medication_frequency_xid, that.medication_frequency_xid) && Objects.equals(reminder_everyday_flag, that.reminder_everyday_flag) && Objects.equals(reminder_weekday_flag, that.reminder_weekday_flag) && Objects.equals(reminder_time, that.reminder_time) && Objects.equals(medication_quantity, that.medication_quantity) && Objects.equals(medication_refill_date, that.medication_refill_date) && Objects.equals(medication_instruction, that.medication_instruction) && Objects.equals(mon, that.mon) && Objects.equals(tue, that.tue) && Objects.equals(wed, that.wed) && Objects.equals(thu, that.thu) && Objects.equals(fri, that.fri) && Objects.equals(sat, that.sat) && Objects.equals(sun, that.sun) && Objects.equals(time1, that.time1) && Objects.equals(time2, that.time2) && Objects.equals(time3, that.time3) && Objects.equals(active, that.active);
|
||||
return id == that.id && Objects.equals(patient_xid, that.patient_xid) && Objects.equals(medicine_name, that.medicine_name) && Objects.equals(dosage, that.dosage) && Objects.equals(dosage_unit, that.dosage_unit) && Objects.equals(medication_type_xid, that.medication_type_xid) && Objects.equals(medication_frequency_xid, that.medication_frequency_xid) && Objects.equals(reminder_everyday_flag, that.reminder_everyday_flag) && Objects.equals(reminder_weekday_flag, that.reminder_weekday_flag) && Objects.equals(reminder_time, that.reminder_time) && Objects.equals(medication_quantity, that.medication_quantity) && Objects.equals(medication_refill_date, that.medication_refill_date) && Objects.equals(medication_instruction, that.medication_instruction) && Objects.equals(mon, that.mon) && Objects.equals(tue, that.tue) && Objects.equals(wed, that.wed) && Objects.equals(thu, that.thu) && Objects.equals(fri, that.fri) && Objects.equals(sat, that.sat) && Objects.equals(sun, that.sun) && Objects.equals(active, that.active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, patient_xid, medicine_name, dosage, dosage_unit, medication_type_xid, medication_frequency_xid, reminder_everyday_flag, reminder_weekday_flag, reminder_time, medication_quantity, medication_refill_date, medication_instruction, mon, tue, wed, thu, fri, sat, sun, time1, time2, time3, active);
|
||||
return Objects.hash(id, patient_xid, medicine_name, dosage, dosage_unit, medication_type_xid, medication_frequency_xid, reminder_everyday_flag, reminder_weekday_flag, reminder_time, medication_quantity, medication_refill_date, medication_instruction, mon, tue, wed, thu, fri, sat, sun, active);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user