This commit is contained in:
meet2711
2024-03-14 21:05:58 +05:30
parent 10519d88be
commit f3afd81571
8 changed files with 533 additions and 45 deletions

View File

@@ -3,20 +3,7 @@
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State>
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_7_Pro_API_33.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-03-13T14:30:44.563686Z" />
</State>
<State />
</entry>
</value>
</component>

View File

@@ -12,6 +12,8 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <!-- permissions for app blocking -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
@@ -262,6 +264,12 @@
<receiver android:name=".patient_dashboard.foodreminders.FoodReminderYesReceiver"/>
<service android:name=".patient_dashboard.foodreminders.FoodReminderNotifyingService"/>
<receiver android:name=".patient_dashboard.CallReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -446,7 +446,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
case MEAL_REMINDER:
setUpCgBottomSheet(binding,
R.drawable.img_out_of_geo,
R.drawable.img_meal_reminder,
patient_name + " has skipped their meal!", body,
null, "Call senior",
v -> {
@@ -615,7 +615,7 @@ public class BottomNotificationActivity extends AppCompatActivity {
break;
case MEAL_REMINDER:
setUpSeniorBottomSheet(binding,
R.drawable.img_medication_time,
R.drawable.img_meal_reminder,
"Meal reminder", title,
null, "No", view -> {
bsd.dismiss();

View File

@@ -0,0 +1,18 @@
package com.app.simplitend.patient_dashboard;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telecom.TelecomManager;
public class CallReceiver extends BroadcastReceiver {
private static final String TAG = "CallReceiver";
@Override
public void onReceive(Context context, Intent intent) {
TelecomManager telecomManager = (TelecomManager) context.getApplicationContext().getSystemService(TelecomManager.class);
}
}

View File

@@ -18,6 +18,7 @@ import android.util.Log;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.ViewModelProvider;
@@ -76,6 +77,8 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
finePermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION);
}), null, null);
}
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 1212);
});
registerForActivityResult(new ActivityResultContracts.RequestPermission(),
@@ -91,10 +94,6 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
RoleManager roleManager = getSystemService(RoleManager.class);
Intent i = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
startActivityForResult(i, 1214, null);
} else {
Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
startActivity(intent);
}
}
}).launch(Manifest.permission.READ_CONTACTS);
@@ -126,6 +125,12 @@ public class DashBoardActivity extends AppCompatActivity implements CgHomeContra
PatientMainViewModel.remindersList = null;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: " + resultCode);
}
private void initSocket(String uniqueKey) {
if (mSocket != null) return;

View File

@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast;
import com.onesignal.OneSignal;
@@ -59,7 +60,27 @@ public class PatSettingsActivity extends AppCompatActivity implements CgHomeCont
});
binding.callBlockCheck.setChecked(AppUtil.isCallBlockingEnabled(this));
binding.callBlockCheck.setOnCheckedChangeListener(((compoundButton, b) -> AppUtil.setIsCallBlockingEnabled(this, b)));
binding.callBlockCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b){
AppUtil.setIsCallBlockingEnabled(PatSettingsActivity.this, true);
}else{
AppUtil.showAlert(PatSettingsActivity.this,
"Turn off call blocking",
"Are you sure you want turn off call blocking?",
"No", ((dialogInterface, i) -> {
dialogInterface.dismiss();
binding.callBlockCheck.setOnCheckedChangeListener(null);
binding.callBlockCheck.setChecked(true);
binding.callBlockCheck.setOnCheckedChangeListener(this);
}),
"Turn off", ((dialogInterface, i) -> {
AppUtil.setIsCallBlockingEnabled(PatSettingsActivity.this, false);
}));
}
}
});
}
private void clickEvents() {

View File

@@ -16,8 +16,10 @@ import android.util.Log;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.ExistingWorkPolicy;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
@@ -39,34 +41,33 @@ public abstract class FoodScheduler {
BREAK_FAST, LUNCH, DINNER
}
private final static Meal breakFastMeal
, lunchMeal, dinnerMeal;
private final static Meal breakFastMeal, lunchMeal, dinnerMeal;
static {
breakFastMeal = new Meal(FOOD_TIME.BREAK_FAST, 9, 0);
lunchMeal = new Meal(FOOD_TIME.LUNCH, 13, 0);
dinnerMeal = new Meal(FOOD_TIME.DINNER, 20, 0);
breakFastMeal = new Meal(FOOD_TIME.BREAK_FAST, 16, 0);
lunchMeal = new Meal(FOOD_TIME.LUNCH, 18, 0);
dinnerMeal = new Meal(FOOD_TIME.DINNER, 21, 0);
}
public static void scheduleFoodReminders(Context context){
public static void scheduleFoodReminders(Context context) {
//breakfast
scheduleAt(context, breakFastMeal.hours, breakFastMeal.minutes,FOOD_TIME.BREAK_FAST);
scheduleAt(context, breakFastMeal.hours, breakFastMeal.minutes, FOOD_TIME.BREAK_FAST);
//lunch
scheduleAt(context, lunchMeal.hours, lunchMeal.minutes, FOOD_TIME.LUNCH);
//dinner
scheduleAt(context, dinnerMeal.hours, dinnerMeal.minutes, FOOD_TIME.DINNER);
}
public static void removeFoodReminders(Context context){
public static void removeFoodReminders(Context context) {
WorkManager.getInstance(context).cancelAllWorkByTag(FOOD_TIME.BREAK_FAST.name());
WorkManager.getInstance(context).cancelAllWorkByTag(FOOD_TIME.LUNCH.name());
WorkManager.getInstance(context).cancelAllWorkByTag(FOOD_TIME.DINNER.name());
}
private static void scheduleAt(Context context, @IntRange(from = 0, to = 23) int hours, @IntRange(from = 0, to = 59)int minutes, FOOD_TIME foodTime){
private static void scheduleAt(Context context, @IntRange(from = 0, to = 23) int hours, @IntRange(from = 0, to = 59) int minutes, FOOD_TIME foodTime) {
Class<? extends Worker> workClass = null;
switch (foodTime){
switch (foodTime) {
case BREAK_FAST:
workClass = BreakFastWorker.class;
break;
@@ -82,12 +83,13 @@ public abstract class FoodScheduler {
long nextReminderAt = nextReminderInMilliSeconds(hours, minutes);
// one shot work and then invoking another work for next day
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(workClass)
.setInitialDelay(nextReminderAt, TimeUnit.MILLISECONDS)
.addTag(foodTime.name())
.build();
WorkManager.getInstance(context).enqueueUniqueWork(
WorkManager.getInstance(context).enqueueUniqueWork(
foodTime.name(),
ExistingWorkPolicy.REPLACE,
workRequest
@@ -97,7 +99,7 @@ public abstract class FoodScheduler {
Log.d(TAG, "SCHEDULED " + foodTime.name() + " at " + hours + " hrs and " + minutes + " mins");
}
private static long nextReminderInMilliSeconds(int hour, int minutes){
private static long nextReminderInMilliSeconds(int hour, int minutes) {
Calendar currCal = Calendar.getInstance();
Calendar reminderCal = Calendar.getInstance();
@@ -106,7 +108,7 @@ public abstract class FoodScheduler {
reminderCal.set(Calendar.SECOND, 0);
reminderCal.set(Calendar.MILLISECOND, 0);
if (reminderCal.before(currCal)){
if (reminderCal.before(currCal)) {
// reminder time has already passed
// thus, reminder for next day
reminderCal.add(Calendar.DATE, 1);
@@ -115,7 +117,7 @@ public abstract class FoodScheduler {
return (reminderCal.getTimeInMillis() - currCal.getTimeInMillis());
}
private static void showNotification(Context context, String title, int which){
private static void showNotification(Context context, String title, int which) {
Intent yesIntent = new Intent(context, FoodReminderYesReceiver.class);
yesIntent.putExtra(WHICH_FOOD_REMINDER, which);
@@ -134,7 +136,7 @@ public abstract class FoodScheduler {
notificationManager.notify(FOOD_REMINDER_NOTIFICATION_ID + which, notification);
}
public static class BreakFastWorker extends Worker{
public static class BreakFastWorker extends Worker {
private final Context context;
@@ -147,10 +149,11 @@ public abstract class FoodScheduler {
@Override
public Result doWork() {
scheduleAt(context, breakFastMeal.hours, breakFastMeal.minutes, FOOD_TIME.BREAK_FAST);
if (PatientMainViewModel.remindersList == null){
Log.d(TAG, "doWork: BREAK_FAST");
if (PatientMainViewModel.remindersList == null) {
// app is not open
showNotification(context, "Have you done your breakfast?", 0);
}else {
} else {
Intent intent = new Intent(context, BottomNotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
@@ -162,7 +165,7 @@ public abstract class FoodScheduler {
}
}
public static class LunchWorker extends Worker{
public static class LunchWorker extends Worker {
private final Context context;
@@ -175,10 +178,10 @@ public abstract class FoodScheduler {
@Override
public Result doWork() {
scheduleAt(context, lunchMeal.hours, lunchMeal.minutes, FOOD_TIME.LUNCH);
if (PatientMainViewModel.remindersList == null){
if (PatientMainViewModel.remindersList == null) {
// app is not open
showNotification(context, "Have you done your lunch?", 1);
}else {
} else {
Intent intent = new Intent(context, BottomNotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
@@ -190,7 +193,7 @@ public abstract class FoodScheduler {
}
}
public static class DinnerWorker extends Worker{
public static class DinnerWorker extends Worker {
private final Context context;
@@ -203,10 +206,10 @@ public abstract class FoodScheduler {
@Override
public Result doWork() {
scheduleAt(context, dinnerMeal.hours, dinnerMeal.minutes, FOOD_TIME.DINNER);
if (PatientMainViewModel.remindersList == null){
if (PatientMainViewModel.remindersList == null) {
// app is not open
showNotification(context, "Have you done your dinner?", 2);
}else {
} else {
Intent intent = new Intent(context, BottomNotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(CONTENT_TYPE_KEY, MEAL_REMINDER);
@@ -218,7 +221,7 @@ public abstract class FoodScheduler {
}
}
static class Meal{
static class Meal {
public Meal(FOOD_TIME foodTime, int hours, int minutes) {
this.foodTime = foodTime;
this.hours = hours;

File diff suppressed because one or more lines are too long