,
This commit is contained in:
@@ -10,15 +10,14 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresPermission;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
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;
|
||||
@@ -26,7 +25,6 @@ import com.google.android.gms.location.LocationServices;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.onesignal.notifications.INotificationReceivedEvent;
|
||||
import com.onesignal.notifications.INotificationServiceExtension;
|
||||
import com.app.simplitend.patientgeofencing.GeoFenceHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -13,10 +13,10 @@ public abstract class RetrofitHelper {
|
||||
// urls
|
||||
|
||||
// Testing BASE URL
|
||||
private static final String BASE_URL = "https://simplitend.betadelivery.com/";
|
||||
// private static final String BASE_URL = "https://simplitend.betadelivery.com/";
|
||||
|
||||
// Staging BASE URL
|
||||
// private static final String BASE_URL = "https://simplitendapp.betadelivery.com/";
|
||||
private static final String BASE_URL = "https://simplitendapp.betadelivery.com/";
|
||||
|
||||
public static final String IMAGE_BASE_URL = BASE_URL + "storage/upload/";
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.app.simplitend.chats.mvvm.Receiver;
|
||||
import com.app.simplitend.chats.mvvm.RemoteMessage;
|
||||
import com.app.simplitend.databinding.ChatFragmentBinding;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.onesignal.OneSignal;
|
||||
import com.onesignal.notifications.INotificationLifecycleListener;
|
||||
import com.onesignal.notifications.INotificationWillDisplayEvent;
|
||||
import com.stfalcon.chatkit.messages.MessagesListAdapter;
|
||||
@@ -32,9 +31,14 @@ import com.stfalcon.chatkit.utils.DateFormatter;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
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 ChatFragment extends Fragment implements SocketHelper.Callback<Message>, ChatViewModel.ChatsCallBack {
|
||||
public class ChatFragment extends Fragment implements SocketHelper.Callback<Message>, ChatViewModel.ChatsCallBack, INotificationLifecycleListener {
|
||||
|
||||
private static final String TAG = "SOCKET_CHAT_TAG";
|
||||
|
||||
@@ -94,6 +98,8 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = ChatFragmentBinding.inflate(inflater, container, false);
|
||||
|
||||
// OneSignal.getNotifications().addForegroundLifecycleListener(this);
|
||||
|
||||
chatViewModel = new ViewModelProvider(requireActivity()).get(ChatViewModel.class);
|
||||
|
||||
initViews();
|
||||
@@ -165,6 +171,8 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
if (channel_id != null){
|
||||
SocketHelper.getInstance().stopMessages(channel_id);
|
||||
}
|
||||
|
||||
// OneSignal.getNotifications().removeForegroundLifecycleListener(this);
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
@@ -258,22 +266,6 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
getChats();
|
||||
}
|
||||
});
|
||||
|
||||
OneSignal.getNotifications().addForegroundLifecycleListener(new INotificationLifecycleListener() {
|
||||
@Override
|
||||
public void onWillDisplay(@NonNull INotificationWillDisplayEvent iNotificationWillDisplayEvent) {
|
||||
JSONObject extras = iNotificationWillDisplayEvent.getNotification().getAdditionalData();
|
||||
|
||||
try {
|
||||
if (extras == null) return;
|
||||
if (Constants.CHATS_NOTIFICATIONS.equals(extras.getString("content_type"))){
|
||||
iNotificationWillDisplayEvent.preventDefault();
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void enableDenButton(boolean enable){
|
||||
@@ -320,6 +312,7 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
@Override
|
||||
public void onChatsFetched(ArrayList<RemoteMessage> chatsList, int page_no) {
|
||||
// 2023-11-13 14:43:43 dateTime format
|
||||
// yyyy-MM-dd HH:mm:ss
|
||||
Log.d(TAG, "onChatsFetched: ");
|
||||
if (chatsList.size() < ChatViewModel.MESSAGES_PER_PAGE){
|
||||
this.isLastPageLoaded = true;
|
||||
@@ -338,13 +331,26 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
ArrayList<Message> messages = new ArrayList<>();
|
||||
|
||||
for (RemoteMessage remoteMessage: chatsList){
|
||||
|
||||
Date message_date;
|
||||
try {
|
||||
SimpleDateFormat sdf =
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
message_date = sdf.parse(remoteMessage.dateTime);
|
||||
if (message_date == null) throw new Exception();
|
||||
}catch (Exception e){
|
||||
message_date = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
Message message;
|
||||
if (sender_id.equals(remoteMessage.senderID)){
|
||||
// Author message
|
||||
message = new Message(new Author(sender_id, author_image), remoteMessage.message, remoteMessage.dateTime);
|
||||
message = new Message(new Author(sender_id, author_image), remoteMessage.message, message_date);
|
||||
}else{
|
||||
// receiver message
|
||||
message = new Message(new Receiver(sender_id, receiver_image), remoteMessage.message, remoteMessage.dateTime);
|
||||
message = new Message(new Receiver(sender_id, receiver_image), remoteMessage.message, message_date);
|
||||
}
|
||||
|
||||
messages.add(message);
|
||||
@@ -363,4 +369,18 @@ public class ChatFragment extends Fragment implements SocketHelper.Callback<Mess
|
||||
binding.noChatMsg.setText(R.string.couldn_t_load_chats);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWillDisplay(@NonNull INotificationWillDisplayEvent iNotificationWillDisplayEvent) {
|
||||
JSONObject extras = iNotificationWillDisplayEvent.getNotification().getAdditionalData();
|
||||
|
||||
try {
|
||||
if (extras == null) return;
|
||||
if (Constants.CHATS_NOTIFICATIONS.equals(extras.getString("content_type"))){
|
||||
iNotificationWillDisplayEvent.preventDefault();
|
||||
}
|
||||
}catch (Exception e){
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,12 @@ import com.app.simplitend.chats.mvvm.Author;
|
||||
import com.app.simplitend.chats.mvvm.Message;
|
||||
import com.app.simplitend.chats.mvvm.Receiver;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import io.socket.client.IO;
|
||||
import io.socket.client.Socket;
|
||||
import io.socket.emitter.Emitter;
|
||||
@@ -105,17 +111,30 @@ public class SocketHelper {
|
||||
if (args.length >= 4) {
|
||||
String received_sender_id = (String) args[1];
|
||||
String message_txt = (String) args[2];
|
||||
// 2023-11-24T12:30:41.652Z
|
||||
String date = (String) args[3]; // mm/dd/yyyy',' HH:mm:ss a
|
||||
|
||||
Date message_date;
|
||||
try {
|
||||
SimpleDateFormat sdf =
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
message_date = sdf.parse(date);
|
||||
if (message_date == null) throw new Exception();
|
||||
}catch (Exception e){
|
||||
message_date = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
Message message;
|
||||
|
||||
if (sender_id.equals(received_sender_id)){
|
||||
// Author message
|
||||
message = new Message(new Author(received_sender_id, author_image), message_txt, date);
|
||||
message = new Message(new Author(received_sender_id, author_image), message_txt, message_date);
|
||||
callback.onMessageSentSuccessfully();
|
||||
}else{
|
||||
// receiver message
|
||||
message = new Message(new Receiver(received_sender_id, receiver_image), message_txt, date);
|
||||
message = new Message(new Receiver(received_sender_id, receiver_image), message_txt, message_date);
|
||||
}
|
||||
|
||||
callback.onMessageReceived(message);
|
||||
|
||||
@@ -10,9 +10,9 @@ public class Message implements IMessage {
|
||||
private final IUser author;
|
||||
private final String text;
|
||||
|
||||
private final String date;
|
||||
private final Date date;
|
||||
|
||||
public Message(IUser user, String text, String date){
|
||||
public Message(IUser user, String text, Date date){
|
||||
this.author = user;
|
||||
this.text = text;
|
||||
this.date = date;
|
||||
@@ -35,6 +35,6 @@ public class Message implements IMessage {
|
||||
|
||||
@Override
|
||||
public Date getCreatedAt() {
|
||||
return new Date(System.currentTimeMillis());
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac
|
||||
|
||||
}), true);
|
||||
|
||||
PatientDataCache.setContactList(null); // to load new contact list
|
||||
PatientDataCache.getContactList(requireContext(), "Bearer " + AppUtil.getPatientToken(requireContext()),
|
||||
(contactList1 -> {
|
||||
this.contactList = contactList1;
|
||||
|
||||
Reference in New Issue
Block a user