work pc 2
This commit is contained in:
15
.idea/deploymentTargetDropDown.xml
generated
15
.idea/deploymentTargetDropDown.xml
generated
@@ -3,7 +3,20 @@
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State />
|
||||
<State>
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="C:\Users\wdila\.android\avd\Pixel_6_Pro_API_30_1.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2024-03-13T12:06:52.676192600Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
</component>
|
||||
|
||||
@@ -260,7 +260,8 @@
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
<receiver android:name=".patient_dashboard.FoodReminderReceiver"/>
|
||||
<receiver android:name=".patient_dashboard.foodreminders.FoodReminderYesReceiver"/>
|
||||
<service android:name=".patient_dashboard.foodreminders.FoodReminderNotifyingService"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -29,6 +29,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RawRes;
|
||||
@@ -41,7 +42,7 @@ import com.app.simplitend.databinding.AlertDialogBinding;
|
||||
import com.app.simplitend.databinding.DecisionBottomsheetBinding;
|
||||
import com.app.simplitend.databinding.DoneBottomsheetBinding;
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
import com.app.simplitend.patient_dashboard.FoodScheduler;
|
||||
import com.app.simplitend.patient_dashboard.foodreminders.FoodScheduler;
|
||||
import com.app.simplitend.patient_dashboard.PatientMainViewModel;
|
||||
import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
@@ -315,7 +316,7 @@ public abstract class AppUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void dialPhone(Context activity, String phone_number) {
|
||||
public static void dialPhone(Activity activity, String phone_number) {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",
|
||||
phone_number, null));
|
||||
if (activity != null) activity.startActivity(intent);
|
||||
|
||||
@@ -8,13 +8,16 @@ import static com.app.simplitend.apputils.AppUtil.MEDICATION_REFILL_NOTIFICATION
|
||||
import static com.app.simplitend.apputils.AppUtil.SOS_NOTIFICATIONS;
|
||||
import static com.app.simplitend.apputils.AppUtil.getCgNotificationPref;
|
||||
import static com.app.simplitend.apputils.Constants.ACTIVITY_EXTRA_KEY;
|
||||
import static com.app.simplitend.apputils.Constants.MEAL_REMINDER;
|
||||
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.CONTENT_TYPE_KEY;
|
||||
import static com.app.simplitend.apputils.NotificationService.NOTIFICATION_CONTENT_ID_KEY;
|
||||
import static com.app.simplitend.apputils.NotificationService.NOTIFICATION_SENIOR_ADDRESS_KEY;
|
||||
import static com.app.simplitend.locationupdates.LocationService.EXTRA_BATTERY_PERCENTAGE;
|
||||
import static com.app.simplitend.patient_dashboard.foodreminders.FoodReminderYesReceiver.WHICH_FOOD_REMINDER;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -22,6 +25,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
@@ -30,18 +35,31 @@ import com.app.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
|
||||
import com.app.simplitend.chats.ChatsActivity;
|
||||
import com.app.simplitend.databinding.BottomSheetAlertBinding;
|
||||
import com.app.simplitend.patient_dashboard.PatientMainViewModel;
|
||||
import com.app.simplitend.patient_dashboard.foodreminders.FoodReminderNotifyingService;
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.app.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class BottomNotificationActivity extends AppCompatActivity {
|
||||
|
||||
private ActivityResultLauncher<String> callPermission;
|
||||
private String selected_phone_number = null;
|
||||
|
||||
private BottomSheetDialog bsd = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -52,6 +70,14 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
// }
|
||||
|
||||
callPermission = registerForActivityResult(new ActivityResultContracts.RequestPermission(),
|
||||
isGranted -> {
|
||||
if (selected_phone_number == null) return;
|
||||
|
||||
if (bsd != null) bsd.dismiss();
|
||||
AppUtil.callPhone(this, selected_phone_number);
|
||||
});
|
||||
|
||||
if (AppUtil.getCgToken(this) != null){
|
||||
// handle caregiver bottom sheets
|
||||
handleCaregiverBottomSheets();
|
||||
@@ -154,7 +180,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
|
||||
if (content_type == null) return;
|
||||
|
||||
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
BottomSheetAlertBinding binding = BottomSheetAlertBinding.inflate(LayoutInflater.from(context));
|
||||
bsd.setContentView(binding.getRoot());
|
||||
|
||||
@@ -209,13 +235,13 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
senior_distance, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
AppUtil.dialPhone(context, careGiverData.patientDetails.phone_number);
|
||||
selected_phone_number = careGiverData.patientDetails.phone_number;
|
||||
callPermission.launch(Manifest.permission.CALL_PHONE);
|
||||
}), true);
|
||||
});
|
||||
|
||||
@@ -336,13 +362,13 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
doh_distance, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
AppUtil.dialPhone(context, careGiverData.patientDetails.phone_number);
|
||||
selected_phone_number = careGiverData.patientDetails.phone_number;
|
||||
callPermission.launch(Manifest.permission.CALL_PHONE);
|
||||
}), true);
|
||||
});
|
||||
|
||||
@@ -364,13 +390,13 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
null, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
bsd.dismiss();
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
AppUtil.dialPhone(context, careGiverData.patientDetails.phone_number);
|
||||
selected_phone_number = careGiverData.patientDetails.phone_number;
|
||||
callPermission.launch(Manifest.permission.CALL_PHONE);
|
||||
}), true);
|
||||
});
|
||||
|
||||
@@ -417,6 +443,26 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
|
||||
case MEAL_REMINDER:
|
||||
setUpCgBottomSheet(binding,
|
||||
R.drawable.img_out_of_geo,
|
||||
title, body,
|
||||
null, "Call senior",
|
||||
v -> {
|
||||
CaregiverDataCache.getCaregiverData(context, (careGiverData -> {
|
||||
if (careGiverData == null || careGiverData.patientDetails == null) {
|
||||
Toast.makeText(context, "Couldn't load data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
selected_phone_number = careGiverData.patientDetails.phone_number;
|
||||
callPermission.launch(Manifest.permission.CALL_PHONE);
|
||||
}), true);
|
||||
});
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
}
|
||||
|
||||
// already returning
|
||||
@@ -442,7 +488,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
|
||||
if (content_type == null) return;
|
||||
|
||||
BottomSheetDialog bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
bsd = new BottomSheetDialog(context, R.style.BottomSheetDialog);
|
||||
BottomSheetAlertBinding binding = BottomSheetAlertBinding.inflate(LayoutInflater.from(context));
|
||||
bsd.setContentView(binding.getRoot());
|
||||
|
||||
@@ -466,7 +512,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
null, "Close", view -> {
|
||||
bsd.dismiss();
|
||||
finish();
|
||||
});
|
||||
}, null, null);
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
@@ -515,7 +561,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
routine_description, "Close", view -> {
|
||||
bsd.dismiss();
|
||||
finish();
|
||||
});
|
||||
}, null, null);
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
@@ -563,10 +609,36 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
description, "Close", view -> {
|
||||
bsd.dismiss();
|
||||
finish();
|
||||
});
|
||||
},null, null);
|
||||
|
||||
bsd.show();
|
||||
break;
|
||||
case MEAL_REMINDER:
|
||||
setUpSeniorBottomSheet(binding,
|
||||
R.drawable.img_medication_time,
|
||||
"Meal reminder", title,
|
||||
null, "No", view -> {
|
||||
bsd.dismiss();
|
||||
int which_meal = intent.getIntExtra(WHICH_FOOD_REMINDER, -1);
|
||||
if (which_meal == -1) return;
|
||||
|
||||
FoodReminderNotifyingService.NotificationsApiService apiService = RetrofitHelper.getRetrofit().create(FoodReminderNotifyingService.NotificationsApiService.class);
|
||||
Map<String, Integer> requestBody = new HashMap<>();
|
||||
requestBody.put("patient_id", AppUtil.getPatientUid(this));
|
||||
requestBody.put("meal_type", which_meal);
|
||||
|
||||
apiService.sendMealNotification("Bearer " + AppUtil.getPatientToken(this), requestBody)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {}
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {}
|
||||
});
|
||||
}, "Yes",view -> {
|
||||
bsd.dismiss();
|
||||
});
|
||||
bsd.show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +646,9 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
int img_res,
|
||||
String title, String description_title,
|
||||
String description, String btn_text,
|
||||
View.OnClickListener btn_clickListener) {
|
||||
View.OnClickListener btn_clickListener,
|
||||
String close_txt,
|
||||
View.OnClickListener close_clickListener) {
|
||||
// binding.image.setImageResource(img_res);
|
||||
Glide.with(binding.image)
|
||||
.load(img_res)
|
||||
@@ -583,7 +657,13 @@ public class BottomNotificationActivity extends AppCompatActivity {
|
||||
binding.descriptionTitle.setText(description_title);
|
||||
binding.description.setText(description);
|
||||
|
||||
binding.close.setVisibility(View.GONE);
|
||||
if (close_clickListener == null){
|
||||
binding.close.setVisibility(View.GONE);
|
||||
}else{
|
||||
binding.close.setVisibility(View.VISIBLE);
|
||||
binding.close.setText(close_txt);
|
||||
binding.close.setOnClickListener(close_clickListener);
|
||||
}
|
||||
|
||||
binding.btn.setText(btn_text);
|
||||
binding.btn.setOnClickListener(btn_clickListener);
|
||||
|
||||
@@ -17,4 +17,6 @@ public abstract class Constants {
|
||||
public static final String ACTIVITY_EXTRA_KEY = "activity_extra_key";
|
||||
|
||||
public static final String MEDICATION_REFILL = "medication_refill";
|
||||
|
||||
public static final String MEAL_REMINDER = "meals_time_reminder";
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class MyPatientFragment extends Fragment implements CgHomeContracts.GetGe
|
||||
|
||||
binding.phoneNumber.setOnClickListener(v -> {
|
||||
if (careGiverData != null && careGiverData.patientDetails != null) {
|
||||
AppUtil.dialPhone(requireActivity(), careGiverData.patientDetails.phone_number);
|
||||
AppUtil.callPhone(requireActivity(), careGiverData.patientDetails.phone_number);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.app.simplitend.apputils.Constants;
|
||||
import com.app.simplitend.apputils.PatientDataCache;
|
||||
import com.app.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
|
||||
import com.app.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
|
||||
import com.app.simplitend.patient_dashboard.foodreminders.FoodScheduler;
|
||||
|
||||
import io.socket.client.IO;
|
||||
import io.socket.client.Socket;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.app.simplitend.patient_dashboard;
|
||||
|
||||
import static com.app.simplitend.patient_dashboard.FoodScheduler.FOOD_REMINDER_NOTIFICATION_ID;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class FoodReminderReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "FoodScheduler";
|
||||
|
||||
public static final String REMINDER_ACTION = "reminder_action";
|
||||
public static final String WHICH_FOOD_REMINDER = "which_food_reminder";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int which_meal = intent.getIntExtra(WHICH_FOOD_REMINDER, -1);
|
||||
int action = intent.getIntExtra(REMINDER_ACTION, -1);
|
||||
|
||||
Log.d(TAG, "onReceive: " + which_meal + " " + action);
|
||||
|
||||
if (which_meal != -1 && action != -1){
|
||||
if (action == 1){
|
||||
// user clicked on yes
|
||||
Toast.makeText(context, "Yes", Toast.LENGTH_SHORT).show();
|
||||
}else{
|
||||
// user clicked on no
|
||||
Toast.makeText(context, "No", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.app.simplitend.patient_dashboard.foodreminders;
|
||||
|
||||
import static com.app.simplitend.patient_dashboard.foodreminders.FoodReminderYesReceiver.WHICH_FOOD_REMINDER;
|
||||
import static com.app.simplitend.patient_dashboard.foodreminders.FoodScheduler.FOOD_REMINDER_NOTIFICATION_ID;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.apputils.RetrofitHelper;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public class FoodReminderNotifyingService extends Service {
|
||||
|
||||
private static final String TAG = "FoodScheduler";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
int which_meal = intent.getIntExtra(WHICH_FOOD_REMINDER, -1);
|
||||
|
||||
if (which_meal != -1){
|
||||
Log.d(TAG, "NO clicked for " + which_meal);
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(FOOD_REMINDER_NOTIFICATION_ID + which_meal);
|
||||
|
||||
NotificationsApiService apiService = RetrofitHelper.getRetrofit().create(NotificationsApiService.class);
|
||||
|
||||
Map<String, Integer> body = new HashMap<>();
|
||||
body.put("patient_id", AppUtil.getPatientUid(this));
|
||||
body.put("meal_type", which_meal);
|
||||
|
||||
apiService.sendMealNotification("Bearer " + AppUtil.getPatientToken(this), body)
|
||||
.enqueue(new Callback<CallResponse<Object>>() {
|
||||
@Override
|
||||
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
|
||||
Log.d(TAG, "onResponse: " + response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CallResponse<Object>> call, Throwable t) {
|
||||
Log.d(TAG, "onFailure: " + t);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
public interface NotificationsApiService{
|
||||
|
||||
@POST("api/send-notification-to-caregiver-meals-time")
|
||||
Call<CallResponse<Object>> sendMealNotification(@Header("Authorization") String token, @Body Map<String, Integer> body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.app.simplitend.patient_dashboard.foodreminders;
|
||||
|
||||
import static com.app.simplitend.patient_dashboard.foodreminders.FoodScheduler.FOOD_REMINDER_NOTIFICATION_ID;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class FoodReminderYesReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "FoodScheduler";
|
||||
public static final String WHICH_FOOD_REMINDER = "which_food_reminder";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int which = intent.getIntExtra(WHICH_FOOD_REMINDER, -1);
|
||||
if (which != -1){
|
||||
Log.d(TAG, "YES clicked for : " + which);
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(FOOD_REMINDER_NOTIFICATION_ID + which);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.app.simplitend.patient_dashboard;
|
||||
package com.app.simplitend.patient_dashboard.foodreminders;
|
||||
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
import static com.app.simplitend.apputils.Constants.MEAL_REMINDER;
|
||||
import static com.app.simplitend.apputils.NotificationService.CONTENT_TYPE_KEY;
|
||||
import static com.app.simplitend.apputils.NotificationService.NOTIFICATION_TITLE_KEY;
|
||||
import static com.app.simplitend.locationupdates.LocationService.FOOD_REMINDER_NOTIFICATION_CHANNEL_ID;
|
||||
import static com.app.simplitend.patient_dashboard.FoodReminderReceiver.REMINDER_ACTION;
|
||||
import static com.app.simplitend.patient_dashboard.FoodReminderReceiver.WHICH_FOOD_REMINDER;
|
||||
import static com.app.simplitend.patient_dashboard.foodreminders.FoodReminderYesReceiver.WHICH_FOOD_REMINDER;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
@@ -21,6 +23,8 @@ import androidx.work.Worker;
|
||||
import androidx.work.WorkerParameters;
|
||||
|
||||
import com.app.simplitend.R;
|
||||
import com.app.simplitend.apputils.BottomNotificationActivity;
|
||||
import com.app.simplitend.patient_dashboard.PatientMainViewModel;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -39,9 +43,9 @@ public abstract class FoodScheduler {
|
||||
, lunchMeal, dinnerMeal;
|
||||
|
||||
static {
|
||||
breakFastMeal = new Meal(FOOD_TIME.BREAK_FAST, 21, 8);
|
||||
lunchMeal = new Meal(FOOD_TIME.LUNCH, 20, 23);
|
||||
dinnerMeal = new Meal(FOOD_TIME.DINNER, 20, 24);
|
||||
breakFastMeal = new Meal(FOOD_TIME.BREAK_FAST, 18, 56);
|
||||
lunchMeal = new Meal(FOOD_TIME.LUNCH, 18, 57);
|
||||
dinnerMeal = new Meal(FOOD_TIME.DINNER, 19, 17);
|
||||
}
|
||||
|
||||
public static void scheduleFoodReminders(Context context){
|
||||
@@ -112,18 +116,17 @@ public abstract class FoodScheduler {
|
||||
}
|
||||
|
||||
private static void showNotification(Context context, String title, int which){
|
||||
Intent yesIntent = new Intent(context, FoodReminderReceiver.class);
|
||||
yesIntent.putExtra(REMINDER_ACTION, 1);
|
||||
Intent yesIntent = new Intent(context, FoodReminderYesReceiver.class);
|
||||
yesIntent.putExtra(WHICH_FOOD_REMINDER, which);
|
||||
Intent noIntent = new Intent(context, FoodReminderReceiver.class);
|
||||
noIntent.putExtra(REMINDER_ACTION, 0);
|
||||
|
||||
Intent noIntent = new Intent(context, FoodReminderNotifyingService.class);
|
||||
noIntent.putExtra(WHICH_FOOD_REMINDER, which);
|
||||
|
||||
Notification notification = new Notification.Builder(context, FOOD_REMINDER_NOTIFICATION_CHANNEL_ID)
|
||||
.setContentTitle(title)
|
||||
.setSmallIcon(R.mipmap.ic_launcher_round)
|
||||
.addAction(new Notification.Action.Builder(null, "Yes", PendingIntent.getBroadcast(context, FOOD_REMINDER_NOTIFICATION_ID, yesIntent, PendingIntent.FLAG_IMMUTABLE)).build())
|
||||
.addAction(new Notification.Action.Builder(null, "No", PendingIntent.getBroadcast(context, FOOD_REMINDER_NOTIFICATION_ID, noIntent, PendingIntent.FLAG_IMMUTABLE)).build())
|
||||
.addAction(new Notification.Action.Builder(null, "Yes", PendingIntent.getBroadcast(context, which, yesIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)).build())
|
||||
.addAction(new Notification.Action.Builder(null, "No", PendingIntent.getService(context, which, noIntent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)).build())
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.build();
|
||||
|
||||
@@ -143,8 +146,18 @@ public abstract class FoodScheduler {
|
||||
@NonNull
|
||||
@Override
|
||||
public Result doWork() {
|
||||
showNotification(context, "Have you done your breakfast?", 0);
|
||||
scheduleAt(context, breakFastMeal.hours, breakFastMeal.minutes, FOOD_TIME.BREAK_FAST);
|
||||
if (PatientMainViewModel.remindersList == null){
|
||||
// app is not open
|
||||
showNotification(context, "Have you done your breakfast?", 0);
|
||||
}else {
|
||||
Intent intent = new Intent(context, BottomNotificationActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
|
||||
intent.putExtra(WHICH_FOOD_REMINDER, 0);
|
||||
intent.putExtra(NOTIFICATION_TITLE_KEY, "Did you have your breakfast?");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -161,8 +174,18 @@ public abstract class FoodScheduler {
|
||||
@NonNull
|
||||
@Override
|
||||
public Result doWork() {
|
||||
showNotification(context, "Have you done your lunch?", 1);
|
||||
scheduleAt(context, lunchMeal.hours, lunchMeal.minutes, FOOD_TIME.LUNCH);
|
||||
if (PatientMainViewModel.remindersList == null){
|
||||
// app is not open
|
||||
showNotification(context, "Have you done your lunch?", 1);
|
||||
}else {
|
||||
Intent intent = new Intent(context, BottomNotificationActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
|
||||
intent.putExtra(WHICH_FOOD_REMINDER, 1);
|
||||
intent.putExtra(NOTIFICATION_TITLE_KEY, "Did you have your lunch?");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -179,8 +202,18 @@ public abstract class FoodScheduler {
|
||||
@NonNull
|
||||
@Override
|
||||
public Result doWork() {
|
||||
showNotification(context, "Have you done your dinner?", 2);
|
||||
scheduleAt(context, dinnerMeal.hours, dinnerMeal.minutes, FOOD_TIME.DINNER);
|
||||
if (PatientMainViewModel.remindersList == null){
|
||||
// app is not open
|
||||
showNotification(context, "Have you done your dinner?", 2);
|
||||
}else {
|
||||
Intent intent = new Intent(context, BottomNotificationActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
|
||||
intent.putExtra(WHICH_FOOD_REMINDER, 2);
|
||||
intent.putExtra(NOTIFICATION_TITLE_KEY, "Did you have your dinner?");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import static com.app.simplitend.patient_dashboard.NotificationsActivity.USER_TO
|
||||
import static com.app.simplitend.patient_dashboard.fragments.CallsActivity.CALL_CONTACT_LIST_KEY;
|
||||
import static com.app.simplitend.patient_dashboard.fragments.CallsActivity.IS_50_CONTACTS_VIEW;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -26,6 +27,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -88,6 +91,8 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
|
||||
private BroadcastReceiver notification_receiver;
|
||||
|
||||
private ActivityResultLauncher<String> callPermissionLauncher;
|
||||
|
||||
// date suffixes
|
||||
String[] suffixes =
|
||||
// 0 1 2 3 4 5 6 7 8 9
|
||||
@@ -124,6 +129,13 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
reminderViewModel = new ViewModelProvider(requireActivity()).get(ReminderViewModel.class);
|
||||
routineViewModel = new ViewModelProvider(requireActivity()).get(RoutineViewModel.class);
|
||||
|
||||
callPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(),
|
||||
isGranted -> {
|
||||
if (patientData == null) return;
|
||||
|
||||
AppUtil.callPhone(requireActivity(), patientData.phone_number);
|
||||
});
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
@@ -369,8 +381,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
Log.d(CALL_BLOCKING_WORk, "CALL BLOCKING DISABLED");
|
||||
}
|
||||
|
||||
AppUtil.callPhone(requireActivity(), phone_number);
|
||||
|
||||
callPermissionLauncher.launch(Manifest.permission.CALL_PHONE);
|
||||
}), true);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user