diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 52d2edf..03d9c98 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,18 +1,6 @@ - - - - - - - - - - - - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9304821..4c2bddd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,13 +14,18 @@ android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" /> - + + + + + + + + = 7) // already number is incremented when notification is arrived { List 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); - OneSignal.getNotifications().removeNotification(notification.getId()); + int minPostTime = Integer.MAX_VALUE; + StatusBarNotification notification = null; + for (StatusBarNotification not: active_notifications){ + if (not.getPostTime() < minPostTime){ + notification = not; + } + } + + if (notification != null) { + OneSignal.getNotifications().removeNotification(notification.getId()); + } } } catch (Exception e) { // clearing all notifications diff --git a/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/EditProfileInfoActivity.java b/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/EditProfileInfoActivity.java index ec44387..468f9af 100644 --- a/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/EditProfileInfoActivity.java +++ b/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/EditProfileInfoActivity.java @@ -8,9 +8,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; -import android.text.Editable; import android.text.InputFilter; -import android.text.TextWatcher; import android.util.Log; import android.util.Patterns; import android.view.View; @@ -40,10 +38,6 @@ import com.github.dhaval2404.imagepicker.ImagePicker; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber; -import com.skydoves.powerspinner.OnSpinnerItemSelectedListener; - -import org.json.JSONArray; -import org.json.JSONObject; import java.io.BufferedReader; import java.io.File; @@ -199,22 +193,8 @@ public class EditProfileInfoActivity extends AppCompatActivity implements binding.street.setText(patientData.address_line1); binding.town.setText(patientData.city); binding.zipCode.setText(patientData.post_code); - - String country = patientData.country; - String state = patientData.state; - if (!countryList.contains(country)){ - countryList.add(country); - ArrayList states = new ArrayList<>(); - states.add(state); - country_N_states_map.put(country, states); - } - - try { - binding.countrySpinner.selectItemByIndex(countryList.indexOf(country)); - binding.stateSpinner.selectItemByIndex(country_N_states_map.get(country).indexOf(state)); - } catch (Exception e) { - // do nothing - } + binding.country.setText(patientData.country); + binding.state.setText(patientData.state); } @@ -222,8 +202,6 @@ public class EditProfileInfoActivity extends AppCompatActivity implements private void initViews() { - loadCountriesAndStates(); - // date picker dialog Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 18); @@ -257,8 +235,6 @@ public class EditProfileInfoActivity extends AppCompatActivity implements setFocusManager(); - inputFieldFocusManage(); - imageSelector = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { @@ -279,7 +255,7 @@ public class EditProfileInfoActivity extends AppCompatActivity implements binding.email.addTextChangedListener(TextUtils.LEADING_SPACE_WATCHER); binding.street.addTextChangedListener(TextUtils.LEADING_SPACE_WATCHER); - new EditTextErrorRemover(binding.name, binding.email, binding.contactNumber, binding.street); + new EditTextErrorRemover(binding.name, binding.email, binding.contactNumber); } @@ -328,8 +304,33 @@ public class EditProfileInfoActivity extends AppCompatActivity implements AppUtil.closeKeyboard(this); binding.countryCodes.showOrDismiss(); }); + + binding.country.setOnClickListener(this::showCannotChangeAddressDialog); + binding.street.setOnClickListener(this::showCannotChangeAddressDialog); + binding.town.setOnClickListener(this::showCannotChangeAddressDialog); + binding.state.setOnClickListener(this::showCannotChangeAddressDialog); + binding.zipCode.setOnClickListener(this::showCannotChangeAddressDialog); } + public void showCannotChangeAddressDialog(View view){ + if (!isCaregiver){ + // patient's profile is to be updated + if (isFromPatient){ + // patient app + AppUtil.showAlert(this, + "Couldn't update address", + "You can update the senior's address from the caregiver app's geofence screen.\n\nCaregiver app >> Senior profile >> geofence", + getString(R.string.ok), ((dialogInterface, i) -> dialogInterface.dismiss()), null, null); + }else{ + // senior app + AppUtil.showAlert(this, + "Couldn't update address", + "You can update the senior's address from the geofence screen.\n\nSenior profile >> geofence", + getString(R.string.ok), ((dialogInterface, i) -> dialogInterface.dismiss()), null, null); + } + } + } + private boolean allCgOkay() { binding.name.setError(null); @@ -588,121 +589,6 @@ public class EditProfileInfoActivity extends AppCompatActivity implements return input_date; } - private void inputFieldFocusManage() { - - binding.town.setOnEditorActionListener((textView, i, keyEvent) -> { - AppUtil.closeKeyboard(this); - binding.town.clearFocus(); - binding.stateSpinner.show(); - return true; - }); - - binding.zipCode.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void afterTextChanged(Editable editable) { - if (editable.toString().length() == 6){ - binding.zipCode.clearFocus(); - AppUtil.closeKeyboard(EditProfileInfoActivity.this); - } - } - }); - - } - - private void loadCountriesAndStates() { - - countryList = new ArrayList<>(); - - country_N_states_map = new HashMap<>(); - - try { - - String country_n_states_str = readCountryNStates(this); - - JSONArray country_n_states = new JSONObject(country_n_states_str).getJSONArray("countries"); - - Log.d(TAG, "loadCountriesAndStates: " + country_n_states); - - for (int i = 0; i < country_n_states.length(); i++) { - - String country = country_n_states.getJSONObject(i).getString("country"); - countryList.add(country); - - JSONArray states = country_n_states.getJSONObject(i).getJSONArray("states"); - - ArrayList stateList = new ArrayList<>(); - - for (int j = 0; j < states.length(); j++) { - stateList.add(states.getString(j)); - } - - country_N_states_map.put(country, stateList); - } - - } catch (Exception e) { - - Log.e(TAG, "load country and states: ", e); - } - - Log.d(TAG, "loadCountriesAndStates: " + countryList); - - binding.stateSpinner.setLifecycleOwner(this); - binding.countrySpinner.setLifecycleOwner(this); - - binding.countrySpinner.setItems(countryList); - - - // selecting United States country as by default -// if (countryList.contains(UNITED_STATES)){ -// binding.countrySpinner.selectItemByIndex(countryList.indexOf(UNITED_STATES)); -// -// if (country_N_states_map.containsKey(UNITED_STATES)) -// { -// binding.stateSpinner.setItems(country_N_states_map.get(UNITED_STATES)); -// } -// } - - binding.stateSpinner.setDismissWhenNotifiedItemSelected(true); - binding.countrySpinner.setDismissWhenNotifiedItemSelected(true); - - binding.stateSpinner.setIsFocusable(true); - binding.countrySpinner.setIsFocusable(true); - - binding.countrySpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener) (i, s, i1, t1) -> { - - binding.countrySpinner.setError(null); - - ArrayList stateList; - - if (country_N_states_map.containsKey(t1) && country_N_states_map.get(t1) != null) { - stateList = country_N_states_map.get(t1); - } else { - stateList = new ArrayList<>(); - } - - if (stateList != null) { - binding.stateSpinner.setItems(stateList); - binding.stateSpinner.clearSelectedItem(); - } - }); - - binding.stateSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener) (i, s, i1, t1) -> { - binding.stateSpinner.setError(null); - binding.zipCode.requestFocus(); - }); - - } - public String readCountryNStates(Context context) throws IOException { StringBuilder returnString = new StringBuilder(); diff --git a/app/src/main/java/com/app/simplitend/chats/SocketHelper.java b/app/src/main/java/com/app/simplitend/chats/SocketHelper.java index 75971aa..c791f96 100644 --- a/app/src/main/java/com/app/simplitend/chats/SocketHelper.java +++ b/app/src/main/java/com/app/simplitend/chats/SocketHelper.java @@ -11,6 +11,7 @@ import com.app.simplitend.chats.mvvm.Author; import com.app.simplitend.chats.mvvm.Message; import com.app.simplitend.chats.mvvm.Receiver; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -109,7 +110,7 @@ public class SocketHelper { try { if (args.length >= 4) { String received_sender_id = (String) args[1]; - String message_txt = (String) args[2]; + byte[] message_txt = (byte[]) args[2]; // 2023-11-24T12:30:41.652Z String date = (String) args[3]; // mm/dd/yyyy',' HH:mm:ss a @@ -129,11 +130,11 @@ public class SocketHelper { if (sender_id.equals(received_sender_id)){ // Author message - message = new Message(new Author(received_sender_id, author_image), message_txt, message_date); + message = new Message(new Author(received_sender_id, author_image), new String(message_txt, StandardCharsets.UTF_8), message_date); callback.onMessageSentSuccessfully(); }else{ // receiver message - message = new Message(new Receiver(received_sender_id, receiver_image), message_txt, message_date); + message = new Message(new Receiver(received_sender_id, receiver_image), new String(message_txt, StandardCharsets.UTF_8), message_date); } callback.onMessageReceived(message); @@ -152,7 +153,7 @@ public class SocketHelper { } public void sendMessage(@NonNull String message, @NonNull String sender_id, @NonNull String receiver_id, @NonNull String channel_id, String user_principal_id) { - mSocket.emit("chatMessage", sender_id, message, receiver_id, channel_id, user_principal_id); + mSocket.emit("chatMessage", sender_id, message.getBytes(StandardCharsets.UTF_8), receiver_id, channel_id, user_principal_id); } private static final String LOCATION_EVENT_PREFIX = "patientCurrentLocation"; diff --git a/app/src/main/java/com/app/simplitend/locationupdates/LocationService.java b/app/src/main/java/com/app/simplitend/locationupdates/LocationService.java index 831c4b3..a69dd09 100644 --- a/app/src/main/java/com/app/simplitend/locationupdates/LocationService.java +++ b/app/src/main/java/com/app/simplitend/locationupdates/LocationService.java @@ -1,5 +1,6 @@ package com.app.simplitend.locationupdates; +import static android.content.Intent.ACTION_BATTERY_CHANGED; import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG; import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_EXTRA_KEY; import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceiver.LOCATION_REQUEST_TAG; @@ -7,11 +8,15 @@ import static com.app.simplitend.patientgeofencing.PatientLocationUpdatesReceive import android.app.Notification; import android.app.NotificationManager; import android.app.Service; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.location.Location; +import android.os.BatteryManager; import android.os.IBinder; import android.util.Log; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -52,6 +57,8 @@ public class LocationService extends Service implements LocationClient.DefaultLo private DefaultLocationClient locationClient; + private BroadcastReceiver batteryChangeReceiver; + @Override public void onCreate() { super.onCreate(); @@ -59,6 +66,26 @@ public class LocationService extends Service implements LocationClient.DefaultLo LocationServices.getFusedLocationProviderClient(this)); SocketHelper.getInstance().establishConnection(null); + + batteryChangeReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (ACTION_BATTERY_CHANGED.equals(intent.getAction())){ + int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); + int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); + + float batteryPct = level * 100 / (float)scale; + + Toast.makeText(context, "" + batteryPct, Toast.LENGTH_SHORT).show(); + } + } + }; + +// try { +// registerReceiver(batteryChangeReceiver, new IntentFilter(ACTION_BATTERY_CHANGED)); +// } catch (Exception e) { +// // do nothing +// } } @Override @@ -117,6 +144,8 @@ public class LocationService extends Service implements LocationClient.DefaultLo stopSelf(); removeLocationUpdates(); SocketHelper.getInstance().closeConnection(); + +// unregisterReceiver(batteryChangeReceiver); } public void removeLocationUpdates() { diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/NotificationsActivity.java b/app/src/main/java/com/app/simplitend/patient_dashboard/NotificationsActivity.java index e8d9a56..2e6df3a 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/NotificationsActivity.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/NotificationsActivity.java @@ -22,6 +22,7 @@ import com.app.simplitend.apputils.RetrofitHelper; import com.app.simplitend.databinding.ActivityNotificationsBinding; import com.app.simplitend.databinding.NotificationViewholderBinding; import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse; +import com.onesignal.OneSignal; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -82,6 +83,13 @@ public class NotificationsActivity extends AppCompatActivity implements Callback } + @Override + protected void onResume() { + super.onResume(); + OneSignal.getNotifications().clearAllNotifications(); + AppUtil.clearAllNotifications(this); + } + @Override protected void attachBaseContext(Context newBase) { final Configuration configuration = new Configuration(newBase.getResources().getConfiguration()); diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/fragments/PatientDashboardFragment.java b/app/src/main/java/com/app/simplitend/patient_dashboard/fragments/PatientDashboardFragment.java index 6b8087d..f930a43 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/fragments/PatientDashboardFragment.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/fragments/PatientDashboardFragment.java @@ -52,6 +52,9 @@ import com.app.simplitend.welcome.welcomepatient.fragments.contacts.mvvm.models. import com.app.simplitend.welcome.welcomepatient.mvvm.models.PatientData; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.onesignal.OneSignal; +import com.onesignal.notifications.INotificationLifecycleListener; +import com.onesignal.notifications.INotificationWillDisplayEvent; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -60,7 +63,7 @@ import java.util.Date; import java.util.List; import java.util.Locale; -public class PatientDashboardFragment extends Fragment implements ProfileContracts.GetRemindersListCallback, CaregiverMainViewModel.GetNearestResultCallback, ProfileContracts.GetRoutinesCallback, CaregiverMainViewModel.GetNearestActivityCallback { +public class PatientDashboardFragment extends Fragment implements ProfileContracts.GetRemindersListCallback, CaregiverMainViewModel.GetNearestResultCallback, ProfileContracts.GetRoutinesCallback, CaregiverMainViewModel.GetNearestActivityCallback, INotificationLifecycleListener { // view binding protected PatientDashboardFragmentBinding binding; @@ -186,6 +189,8 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac } }), false); + OneSignal.getNotifications().addForegroundLifecycleListener(this); + return binding.getRoot(); } @@ -193,6 +198,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac public void onDestroyView() { super.onDestroyView(); requireContext().unregisterReceiver(notification_receiver); + OneSignal.getNotifications().removeForegroundLifecycleListener(this); } private void setDetails() { @@ -221,12 +227,23 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac public void onResume() { super.onResume(); updateTime(); + updateNotificationsCount(); Activity activity = getActivity(); if (activity != null) { activity.registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); } } + private void updateNotificationsCount() { + int notificationsCount = AppUtil.getNoOfNotificationsCount(requireContext()); + if (notificationsCount > 0){ + binding.notificationCount.setText(String.valueOf(notificationsCount)); + binding.notificationCount.setVisibility(View.VISIBLE); + }else { + binding.notificationCount.setVisibility(View.GONE); + } + } + @Override public void onPause() { super.onPause(); @@ -621,4 +638,13 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac viewModel.ongoingActivityText = binding.activityMessage.getText().toString(); } + + @Override + public void onWillDisplay(@NonNull INotificationWillDisplayEvent iNotificationWillDisplayEvent) { + try { + requireActivity().runOnUiThread(this::updateNotificationsCount); + } catch (Exception e) { + // do nothing + } + } } diff --git a/app/src/main/res/drawable/ic_notification_home.xml b/app/src/main/res/drawable/ic_notification_home.xml new file mode 100644 index 0000000..5218203 --- /dev/null +++ b/app/src/main/res/drawable/ic_notification_home.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_personal_info.xml b/app/src/main/res/layout/activity_personal_info.xml index 11e3d5b..9963c24 100644 --- a/app/src/main/res/layout/activity_personal_info.xml +++ b/app/src/main/res/layout/activity_personal_info.xml @@ -320,9 +320,8 @@ /> - - + app:drawableStartCompat="@drawable/ic_home" /> - + app:drawableStartCompat="@drawable/ic_home" /> - - + app:drawableStartCompat="@drawable/ic_home" /> diff --git a/app/src/main/res/layout/patient_dashboard_fragment.xml b/app/src/main/res/layout/patient_dashboard_fragment.xml index b8dd347..53edc4e 100644 --- a/app/src/main/res/layout/patient_dashboard_fragment.xml +++ b/app/src/main/res/layout/patient_dashboard_fragment.xml @@ -39,6 +39,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_centerVertical="true" + android:fontFamily="@font/nunito_bold" tools:text="12 : 00 PM" android:textColor="@color/white_bg" @@ -46,13 +48,12 @@ - + android:layout_marginHorizontal="15dp" + > + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f4a1d6..d1ccb26 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -314,7 +314,7 @@ Continue No contacts found. There are no contacts added in your contact directory. Please click on the "Create New Contact" button above. - Geofencing + Create a geofence Add geofence and receive notification when senior’s smartphone leaves the area of the geofence Unknown location Couldn\'t load address diff --git a/gradle.properties b/gradle.properties index 671a16c..e3c7ff4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,11 +22,13 @@ android.nonTransitiveRClass=true android.enableJetifier=true # production -SIMPLITEND_BASE_URL="https://app.simplitend.com/" -SIMPLITEND_SOKCET_HOST="https://app.simplitend.com:3002/" +#SIMPLITEND_BASE_URL="https://app.simplitend.com/" +#SIMPLITEND_SOKCET_HOST="https://app.simplitend.com:3002/" # staging -#SIMPLITEND_BASE_URL="https://staging.simplitend.com/" +SIMPLITEND_BASE_URL="https://staging.simplitend.com/" +SIMPLITEND_SOKCET_HOST="https://staging.simplitend.com:3002/" + # development #SIMPLITEND_BASE_URL="https://simplitend.betadelivery.com/" \ No newline at end of file