,
This commit is contained in:
12
.idea/deploymentTargetDropDown.xml
generated
12
.idea/deploymentTargetDropDown.xml
generated
@@ -1,18 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/6.7_Horizontal_Fold-in_API_34.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-12-01T10:15:23.925877Z" />
|
||||
<targetsSelectedWithDialog>
|
||||
<Target>
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- For app blocking -> open new window over other apps to deny access -->
|
||||
<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.PACKAGE_USAGE_STATS"
|
||||
@@ -229,6 +230,12 @@
|
||||
|
||||
<receiver android:name=".patientgeofencing.GeoFenceBroadcastReceiver" />
|
||||
<receiver android:name=".patientgeofencing.PatientLocationUpdatesReceiver" />
|
||||
<receiver android:name=".apputils.BootCompleteReceiver"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
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;
|
||||
@@ -24,28 +20,24 @@ import android.graphics.drawable.InsetDrawable;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
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.Nullable;
|
||||
import androidx.annotation.RawRes;
|
||||
|
||||
import com.app.simplitend.R;
|
||||
import com.app.simplitend.appblocking.TopAppDetectionService;
|
||||
import com.app.simplitend.articles.ArticleShowerActivity;
|
||||
import com.app.simplitend.databinding.AlertDialogBinding;
|
||||
import com.app.simplitend.databinding.BottomSheetAlertBinding;
|
||||
import com.app.simplitend.databinding.DecisionBottomsheetBinding;
|
||||
import com.app.simplitend.databinding.DoneBottomsheetBinding;
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
import com.app.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.app.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models.ContactData;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData;
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -69,7 +61,6 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -445,7 +436,11 @@ public abstract class AppUtil {
|
||||
// clearing location updates
|
||||
Intent intent = new Intent(context, LocationService.class);
|
||||
intent.setAction(LocationService.ACTION_STOP_LOCATION_UPDATES);
|
||||
context.startService(intent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent);
|
||||
}else {
|
||||
context.startService(intent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeGeofence(Context context) {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.app.simplitend.apputils;
|
||||
|
||||
import static com.app.simplitend.locationupdates.LocationService.LOCATION_INTERVAL_BASE_TIME;
|
||||
import static com.app.simplitend.locationupdates.LocationService.LOCATION_UPDATE_MIN_INTERVAL;
|
||||
import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_ID;
|
||||
import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresPermission;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
import com.app.simplitend.patientgeofencing.GeoFenceHelper;
|
||||
import com.google.android.gms.location.Geofence;
|
||||
import com.google.android.gms.location.GeofencingClient;
|
||||
import com.google.android.gms.location.GeofencingRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
|
||||
public class BootCompleteReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||
// starting over the Location updates service again
|
||||
Intent locationUpdateIntent = new Intent(context, LocationService.class);
|
||||
locationUpdateIntent.setAction(LocationService.ACTION_START_LOCATION_UPDATES);
|
||||
locationUpdateIntent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, LOCATION_INTERVAL_BASE_TIME);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(locationUpdateIntent);
|
||||
} else {
|
||||
context.startService(locationUpdateIntent);
|
||||
}
|
||||
|
||||
// setting up geofence if available
|
||||
String radius_str = AppUtil.getPatientGeofenceRadius(context);
|
||||
if (radius_str != null) {
|
||||
float radius_f;
|
||||
try {
|
||||
radius_f = Float.parseFloat(radius_str);
|
||||
} catch (NumberFormatException e) {
|
||||
radius_f = 0;
|
||||
}
|
||||
|
||||
if (radius_f != 0) {
|
||||
String[] latLngStr = AppUtil.getPatientLatLng(context);
|
||||
if (latLngStr[0] != null && latLngStr[1] != null) {
|
||||
LatLng latLng;
|
||||
try {
|
||||
latLng = new LatLng(Double.parseDouble(latLngStr[0]),
|
||||
Double.parseDouble(latLngStr[1]));
|
||||
} catch (Exception e) {
|
||||
latLng = null;
|
||||
}
|
||||
|
||||
if (latLng != null) {
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
addGeoFence(latLng, radius_f, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
private void addGeoFence(@NonNull LatLng latLng, float GEOFENCING_RADIUS , Context context) {
|
||||
|
||||
GeoFenceHelper geoFenceHelper = new GeoFenceHelper(context);
|
||||
GeofencingClient geofencingClient = LocationServices.getGeofencingClient(context);
|
||||
|
||||
// checking for background location updates for API level 29 and above
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.d(GEOFENCE_TAG, "setGeofence: NO BACKGROUND PERMISSION" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Geofence geofence = geoFenceHelper.getGeoFence(GEOFENCE_ID, latLng, GEOFENCING_RADIUS,
|
||||
Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT);
|
||||
GeofencingRequest geofencingRequest = geoFenceHelper.getGeoFencingRequest(geofence);
|
||||
PendingIntent pendingIntent = geoFenceHelper.getPendingIntent();
|
||||
|
||||
geofencingClient.addGeofences(geofencingRequest, pendingIntent)
|
||||
.addOnSuccessListener(aVoid -> {
|
||||
Log.d(GEOFENCE_TAG, "Geofence added successfully. " + latLng + " Radius: " + GEOFENCING_RADIUS + " meters");
|
||||
})
|
||||
.addOnFailureListener(e -> {
|
||||
Log.d(GEOFENCE_TAG, "onFailure: Geofence couldn't be added: " + e.getLocalizedMessage() + " " + latLng + " Radius: " + GEOFENCING_RADIUS);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,15 +26,14 @@ import com.google.android.gms.location.GeofencingClient;
|
||||
import com.google.android.gms.location.GeofencingRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.onesignal.OneSignal;
|
||||
import com.onesignal.notifications.INotificationReceivedEvent;
|
||||
import com.onesignal.notifications.INotificationServiceExtension;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -49,24 +48,26 @@ public class NotificationService implements INotificationServiceExtension {
|
||||
|
||||
@Override
|
||||
public void onNotificationReceived(@NonNull INotificationReceivedEvent iNotificationReceivedEvent) {
|
||||
// Log.d("aditya testing", "onNotificationReceived: " + iNotificationReceivedEvent.getNotification());
|
||||
|
||||
// showing maximum 7 notifications due to the limitations enforced by manufacturers
|
||||
// Thus, removing the oldest notification to show this new notification
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) iNotificationReceivedEvent.getContext().getSystemService(NOTIFICATION_SERVICE);
|
||||
try {
|
||||
int active_notifications_count = notificationManager.getActiveNotifications().length;
|
||||
if (active_notifications_count == 8) // already number is incremented when notification is arrived
|
||||
if (active_notifications_count >= 7) // already number is incremented when notification is arrived
|
||||
{
|
||||
List<StatusBarNotification> active_notifications = Arrays.asList(notificationManager.getActiveNotifications());
|
||||
active_notifications.sort(Comparator.comparingInt(n -> (int) n.getPostTime()));
|
||||
|
||||
// removing last item
|
||||
StatusBarNotification notification = active_notifications.get(active_notifications.size() - 1);
|
||||
notificationManager.cancel(notification.getId());
|
||||
OneSignal.getNotifications().removeNotification(notification.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// clearing all notifications
|
||||
notificationManager.cancelAll();
|
||||
OneSignal.getNotifications().clearAllNotifications();
|
||||
}
|
||||
|
||||
JSONObject extras = iNotificationReceivedEvent.getNotification().getAdditionalData();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class LocationService extends Service implements LocationClient.DefaultLo
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
return START_REDELIVER_INTENT;
|
||||
}
|
||||
|
||||
private void stopLocationUpdates() {
|
||||
|
||||
@@ -112,7 +112,11 @@ public class PatientMainViewModel extends ViewModel {
|
||||
Intent intent = new Intent(activity, LocationService.class);
|
||||
intent.setAction(LocationService.ACTION_START_LOCATION_UPDATES);
|
||||
intent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, LOCATION_INTERVAL_BASE_TIME);
|
||||
activity.startService(intent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
activity.startForegroundService(intent);
|
||||
}else {
|
||||
activity.startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -16,8 +16,8 @@ import androidx.annotation.NonNull;
|
||||
import com.app.simplitend.apputils.AppUtil;
|
||||
import com.app.simplitend.apputils.RetrofitHelper;
|
||||
import com.app.simplitend.caregiverdashboard.mvvm.NotificationApiService;
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
import com.app.simplitend.chats.SocketHelper;
|
||||
import com.app.simplitend.locationupdates.LocationService;
|
||||
import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
|
||||
import com.google.android.gms.location.Geofence;
|
||||
import com.google.android.gms.location.GeofencingEvent;
|
||||
@@ -78,7 +78,11 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
|
||||
Intent locationServiceIntent = new Intent(context, LocationService.class);
|
||||
locationServiceIntent.setAction(LocationService.ACTION_START_LOCATION_UPDATES);
|
||||
locationServiceIntent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, LOCATION_INTERVAL_BASE_TIME);
|
||||
context.startService(locationServiceIntent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent);
|
||||
}else {
|
||||
context.startService(intent);
|
||||
}
|
||||
break;
|
||||
case Geofence.GEOFENCE_TRANSITION_EXIT:
|
||||
Log.d(GEOFENCE_TAG, "onReceive: EXIT");
|
||||
@@ -105,49 +109,32 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
Log.d(GEOFENCE_TAG, "notifyPatient: " + chatsCred[2]);
|
||||
// sending message
|
||||
new SendMessageTask(message, chatsCred[0], chatsCred[1], chatsCred[2], chatsCred[3]).execute();
|
||||
sendMessage(message, chatsCred[0], chatsCred[1], chatsCred[2], chatsCred[3]);
|
||||
}
|
||||
|
||||
public static class SendMessageTask extends AsyncTask<Void, Void, Void> {
|
||||
@NonNull
|
||||
private final String message;
|
||||
private final int patientId, cg_id, channel_id, patient_principal_id;
|
||||
private void sendMessage(@NonNull String message, int patientId, int cg_id, int channel_id, int patient_principal_id) {
|
||||
SocketHelper socketHelper = SocketHelper.getInstance();
|
||||
|
||||
public SendMessageTask(@NonNull String message, int patientId, int cg_id, int channel_id, int patient_principal_id) {
|
||||
this.patientId = patientId;
|
||||
this.cg_id = cg_id;
|
||||
this.channel_id = channel_id;
|
||||
this.message = message;
|
||||
this.patient_principal_id = patient_principal_id;
|
||||
}
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: CONNECTING TO SOCKET");
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
SocketHelper socketHelper = SocketHelper.getInstance();
|
||||
socketHelper.establishConnection(new SocketHelper.SockCallBack() {
|
||||
@Override
|
||||
public void onSocketConnected() {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTED");
|
||||
socketHelper.sendMessage(message, cg_id + "", patientId + "", channel_id + "",
|
||||
patient_principal_id < 0?null:patient_principal_id+"");
|
||||
}
|
||||
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: CONNECTING TO SOCKET");
|
||||
@Override
|
||||
public void onConnectionError(Exception e) {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTION ERROR " + e);
|
||||
}
|
||||
|
||||
socketHelper.establishConnection(new SocketHelper.SockCallBack() {
|
||||
@Override
|
||||
public void onSocketConnected() {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTED");
|
||||
socketHelper.sendMessage(message, cg_id + "", patientId + "", channel_id + "",
|
||||
patient_principal_id < 0?null:patient_principal_id+"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionError(Exception e) {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTION ERROR " + e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET DISCONNECTED");
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET DISCONNECTED");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyOutOfGeofence(Context context, String senior_address) {
|
||||
@@ -179,7 +166,10 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
|
||||
Intent intent = new Intent(context, LocationService.class);
|
||||
intent.setAction(LocationService.ACTION_START_LOCATION_UPDATES);
|
||||
intent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, 5 * 1000); // every 5 seconds
|
||||
context.startService(intent);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent);
|
||||
}else {
|
||||
context.startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user