From ddaac51b1d563a4334432d18403d8383302e828a Mon Sep 17 00:00:00 2001 From: Aditya_WDI Date: Wed, 11 Oct 2023 21:08:52 +0530 Subject: [PATCH] . --- .idea/deploymentTargetDropDown.xml | 12 ++ .idea/misc.xml | 8 + .../activities/CaregiverDashActivity.java | 26 ++- .../patient_dashboard/chats/ChatFragment.java | 155 ++++++++++++------ .../chats/ReceiverViewHolder.java | 47 ++++++ .../chats/SenderViewHolder.java | 45 +++++ .../patient_dashboard/chats/SocketHelper.java | 61 ++++--- .../patient_dashboard/chats/mvvm/Author.java | 12 +- .../chats/mvvm/Receiver.java | 12 +- .../fragments/PatientDashboardFragment.java | 139 ++++++++++------ .../mvvm/models/PatientData.java | 2 + app/src/main/res/drawable/receiver_msg_bg.xml | 9 + app/src/main/res/layout/chat_fragment.xml | 60 +++++-- .../res/layout/receiver_msg_viewholder.xml | 43 +++++ .../main/res/layout/sender_msg_viewholder.xml | 26 +-- .../res/navigation/cp_dashboard_graph.xml | 3 + 16 files changed, 496 insertions(+), 164 deletions(-) create mode 100644 app/src/main/java/com/app/simplitend/patient_dashboard/chats/ReceiverViewHolder.java create mode 100644 app/src/main/java/com/app/simplitend/patient_dashboard/chats/SenderViewHolder.java create mode 100644 app/src/main/res/drawable/receiver_msg_bg.xml create mode 100644 app/src/main/res/layout/receiver_msg_viewholder.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 758cc80..8cf1166 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,6 +1,18 @@ + + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 773fe0f..3a88592 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -6,4 +7,11 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/CaregiverDashActivity.java b/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/CaregiverDashActivity.java index b67cd90..0b457b1 100644 --- a/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/CaregiverDashActivity.java +++ b/app/src/main/java/com/app/simplitend/caregiverdashboard/activities/CaregiverDashActivity.java @@ -316,7 +316,31 @@ public class CaregiverDashActivity extends AppCompatActivity implements binding.toolbar.setNavigationIcon(AppCompatResources.getDrawable(this, R.drawable.ic_menu)); binding.toolbar.setNavigationIconTint(getResources().getColor(R.color.white)); } else if (selectedItem == MenuItem.CHATS) { - replaceFragment(new ChatFragment(), "chat"); + CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> { + if (careGiverData1 != null && careGiverData1.patientDetails != null){ + this.careGiverData = careGiverData1; + + String sender_image; + if (careGiverData1.profile_photo == null){ + sender_image = String.valueOf(R.drawable.caregiver_img); + }else{ + sender_image = AppUtil.IMAGE_BASE_URL + careGiverData1.profile_photo; + } + + String receiver_image; + if (careGiverData1.patientDetails.profile_photo == null){ + receiver_image = String.valueOf(R.drawable.senior_img); + }else{ + receiver_image = AppUtil.IMAGE_BASE_URL + careGiverData1.patientDetails.profile_photo; + } + + replaceFragment(new ChatFragment(careGiverData1.patientId + "", + careGiverData1.first_name, + careGiverData1.patientDetails.first_name, + sender_image, + receiver_image), "chat"); + } + }), true); binding.toolbar.setVisibility(View.GONE); binding.bottomNav.setVisibility(View.GONE); diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ChatFragment.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ChatFragment.java index 870b81a..52ed7dc 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ChatFragment.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ChatFragment.java @@ -1,10 +1,12 @@ package com.app.simplitend.patient_dashboard.chats; import android.os.Bundle; -import android.util.Log; +import android.os.Handler; +import android.os.Looper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -12,14 +14,11 @@ import androidx.fragment.app.Fragment; import com.app.simplitend.R; import com.app.simplitend.databinding.ChatFragmentBinding; -import com.app.simplitend.patient_dashboard.chats.mvvm.Author; import com.app.simplitend.patient_dashboard.chats.mvvm.Message; -import com.app.simplitend.patient_dashboard.chats.mvvm.Receiver; +import com.bumptech.glide.Glide; import com.stfalcon.chatkit.messages.MessagesListAdapter; -import io.socket.emitter.Emitter; - -public class ChatFragment extends Fragment implements Emitter.Listener { +public class ChatFragment extends Fragment implements SocketHelper.Callback { private static final String TAG = "SOCKET_CHAT_TAG"; @@ -30,8 +29,32 @@ public class ChatFragment extends Fragment implements Emitter.Listener { protected MessagesListAdapter messageAdapter; - public ChatFragment() { + private final String nick_name, receiver_name; + + private final String author_image, receiver_image; + + private final String patient_id; + + public static final String SEND = "Send"; + + public ChatFragment(){ // required + this.patient_id = null; + this.nick_name = "NONE"; + this.receiver_name = "NONE"; + this.author_image = null; + this.receiver_image = null; + } + + public ChatFragment(String patient_id, + String nick_name, + String receiver_name, + String sender_image, String receiver_image) { + this.patient_id = patient_id; + this.nick_name = nick_name; + this.receiver_name = receiver_name; + this.author_image = sender_image; + this.receiver_image = receiver_image; } @Nullable @@ -39,32 +62,21 @@ public class ChatFragment extends Fragment implements Emitter.Listener { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = ChatFragmentBinding.inflate(inflater, container, false); - SocketHelper socketHelper = SocketHelper.getInstance(); - socketHelper.establishConnection(); - - socketHelper.joinChatRoom("BILAL", new Runnable() { - @Override - public void run() { - Log.d(TAG, "ROOM JOINED AS BILAL"); - } - }); - - socketHelper.getMessage(new SocketHelper.Callback() { - @Override - public void onSuccess(Object result) { - - } - - @Override - public void onError(Exception e) { - - } - }); - initViews(); clickEvents(); + if (patient_id != null){ + SocketHelper socketHelper = SocketHelper.getInstance(); + socketHelper.establishConnection(); + + socketHelper.getMessage(this, patient_id, nick_name, + receiver_image, + author_image); + + enableDenButton(true); + } + return binding.getRoot(); } @@ -72,12 +84,6 @@ public class ChatFragment extends Fragment implements Emitter.Listener { public void onDestroyView() { super.onDestroyView(); SocketHelper.getInstance().closeConnection(); - SocketHelper.getInstance().leaveChatRoom("BILAL", new Runnable() { - @Override - public void run() { - Log.d(TAG, "LEAVED ROOM AS ADITYA"); - } - }); } private void clickEvents() { @@ -88,36 +94,83 @@ public class ChatFragment extends Fragment implements Emitter.Listener { }); binding.sendBtn.setOnClickListener(v -> { - SocketHelper.getInstance().sendMessage("Hi there", "Bilal"); + if (binding.messageEt.getText().toString().trim().isEmpty()){ + return; + } + + SocketHelper.getInstance().sendMessage(binding.messageEt.getText().toString().trim(), nick_name, patient_id); + binding.messageEt.setText(""); + enableDenButton(false); }); } private void initViews() { - binding.chatTitle.setText("BILAL"); + binding.chatTitle.setText(receiver_name); MessagesListAdapter.HoldersConfig holdersConfig = new MessagesListAdapter.HoldersConfig(); - holdersConfig.setOutcomingLayout(R.layout.sender_msg_viewholder); + holdersConfig.setOutcoming(SenderViewHolder.class, R.layout.sender_msg_viewholder); + holdersConfig.setIncoming(ReceiverViewHolder.class, R.layout.receiver_msg_viewholder); messageAdapter = new MessagesListAdapter<>("sender", holdersConfig, (imageView, url, payload) -> { - if (url != null) imageView.setImageResource(Integer.parseInt(url)); + if (url != null){ + Glide.with(imageView.getContext()) + .load(url) + .fitCenter() + .placeholder(android.R.color.darker_gray) + .error(R.drawable.ic_user_outline) + .into(imageView); + }else{ + Glide.with(imageView.getContext()) + .load(R.drawable.ic_user_outline) + .fitCenter() + .placeholder(android.R.color.darker_gray) + .error(R.drawable.ic_user_outline) + .into(imageView); + } }); - binding.messageList.setAdapter(messageAdapter); - // static - messageAdapter.addToStart(new Message(new Author(), "Good morning"), true); - messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate! I am fine here how are you there"), true); - messageAdapter.addToStart(new Message(new Author(), "Good morning"), true); - messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate!"), true); - messageAdapter.addToStart(new Message(new Author(), "Good morning"), true); - messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate!"), true); - messageAdapter.addToStart(new Message(new Author(), "Good morning"), true); - messageAdapter.addToStart(new Message(new Receiver(), "Good morning mate!"), true); + binding.messageList.setAdapter(messageAdapter); + } + + private void enableDenButton(boolean enable){ + binding.sendBtn.setEnabled(enable); + + if (enable){ + binding.sendProgress.setVisibility(View.GONE); + binding.sendBtn.setText(SEND); + }else{ + binding.sendProgress.setVisibility(View.VISIBLE); + binding.sendBtn.setText(null); + } } @Override - public void call(Object... args) { - Log.d(TAG, "call: " + args); + public void onMessageReceived(Message message) { + new Handler(Looper.getMainLooper()).post(() -> { + if (messageAdapter == null) return; + + messageAdapter.addToStart(message, true); + }); + } + + @Override + public void onMessageSentSuccessfully() { + new Handler(Looper.getMainLooper()).post(() -> { + enableDenButton(true); + }); + } + + @Override + public void onError(Exception e) { + new Handler(Looper.getMainLooper()).post(() -> { + enableDenButton(true); + try { + Toast.makeText(requireContext(), "Couldn't send message", Toast.LENGTH_SHORT).show(); + } catch (Exception ex) { + // do nothing + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ReceiverViewHolder.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ReceiverViewHolder.java new file mode 100644 index 0000000..f29cc12 --- /dev/null +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/ReceiverViewHolder.java @@ -0,0 +1,47 @@ +package com.app.simplitend.patient_dashboard.chats; + +import android.graphics.Color; +import android.view.View; +import android.widget.TextView; + +import com.app.simplitend.R; +import com.app.simplitend.patient_dashboard.chats.mvvm.Message; +import com.bumptech.glide.Glide; +import com.stfalcon.chatkit.messages.MessagesListAdapter; + +import de.hdodenhof.circleimageview.CircleImageView; + +public class ReceiverViewHolder extends MessagesListAdapter.OutcomingMessageViewHolder { + + protected TextView message_txt; + protected CircleImageView avatar; + + public ReceiverViewHolder(View itemView) { + super(itemView); + message_txt = itemView.findViewById(R.id.messageText); + avatar = itemView.findViewById(R.id.messageUserAvatar_receiver); + } + + @Override + public void onBind(Message message) { + super.onBind(message); + message_txt.setText(message.getText()); + message_txt.setTextColor(Color.BLACK); + try { + try { + int res = Integer.parseInt(message.getUser().getAvatar()); + avatar.setImageResource(res); + }catch (Exception e){ + if (message.getUser().getAvatar() != null){ + Glide.with(avatar.getContext()) + .load(message.getUser().getAvatar()) + .placeholder(android.R.color.darker_gray) + .error(android.R.color.darker_gray) + .into(avatar); + } + } + }catch (Exception e){ + // do nothing + } + } +} diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SenderViewHolder.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SenderViewHolder.java new file mode 100644 index 0000000..4168f05 --- /dev/null +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SenderViewHolder.java @@ -0,0 +1,45 @@ +package com.app.simplitend.patient_dashboard.chats; + +import android.view.View; +import android.widget.TextView; + +import com.app.simplitend.R; +import com.app.simplitend.patient_dashboard.chats.mvvm.Message; +import com.bumptech.glide.Glide; +import com.stfalcon.chatkit.messages.MessagesListAdapter; + +import de.hdodenhof.circleimageview.CircleImageView; + +public class SenderViewHolder extends MessagesListAdapter.OutcomingMessageViewHolder { + + protected TextView message_txt; + protected CircleImageView avatar; + + public SenderViewHolder(View itemView) { + super(itemView); + message_txt = itemView.findViewById(R.id.messageText); + avatar = itemView.findViewById(R.id.messageUserAvatar_send); + } + + @Override + public void onBind(Message message) { + super.onBind(message); + message_txt.setText(message.getText()); + try { + try { + int res = Integer.parseInt(message.getUser().getAvatar()); + avatar.setImageResource(res); + }catch (Exception e){ + if (message.getUser().getAvatar() != null){ + Glide.with(avatar.getContext()) + .load(message.getUser().getAvatar()) + .placeholder(android.R.color.darker_gray) + .error(android.R.color.darker_gray) + .into(avatar); + } + } + }catch (Exception e){ + // do nothing + } + } +} diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SocketHelper.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SocketHelper.java index aac6ce7..4301f51 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SocketHelper.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/SocketHelper.java @@ -2,7 +2,11 @@ package com.app.simplitend.patient_dashboard.chats; import android.util.Log; -import org.json.JSONArray; +import androidx.annotation.NonNull; + +import com.app.simplitend.patient_dashboard.chats.mvvm.Author; +import com.app.simplitend.patient_dashboard.chats.mvvm.Message; +import com.app.simplitend.patient_dashboard.chats.mvvm.Receiver; import io.socket.client.IO; import io.socket.client.Socket; @@ -13,9 +17,6 @@ public class SocketHelper { private static final String TAG = "SOCKET_CHAT_TAG"; private static final String kHost = "http://77.68.102.23:3002/"; - private static final String kConnectUser = "connectUser"; - private static final String kUserList = "userList"; - private static final String kExitUser = "exitUser"; private static SocketHelper instance; private Socket mSocket; @@ -73,37 +74,49 @@ public class SocketHelper { } } - public void joinChatRoom(String nickname, final Runnable completion) { - mSocket.emit(kConnectUser, nickname); - completion.run(); - } - - public void leaveChatRoom(String nickname, final Runnable completion) { - mSocket.emit(kExitUser, nickname); - completion.run(); - } - - public void getMessage(final Callback callback) { - mSocket.on("newChatMessage", new Emitter.Listener() { + public void getMessage(final Callback callback, + @NonNull String patientId, + @NonNull String nickName, + String receiver_image, + String author_image) { + mSocket.on(patientId, new Emitter.Listener() { @Override public void call(Object... args) { - if (args.length >= 3) { - String nickName = (String) args[0]; - String message = (String) args[1]; - String date = (String) args[2]; + try { + if (args.length >= 3) { + String received_nickName = (String) args[0]; + String message_txt = (String) args[1]; + String date = (String) args[2]; - Log.d(TAG, " Message received " + message); + Message message; + + if (nickName.equals(received_nickName)){ + // Author message + message = new Message(new Author(received_nickName, author_image), message_txt); + callback.onMessageSentSuccessfully(); + }else{ + // receiver message + message = new Message(new Receiver(received_nickName, receiver_image), message_txt); + } + + callback.onMessageReceived(message); + } + } catch (Exception e) { + callback.onError(e); } } }); + + Log.d(TAG, "LISTENER FOR PATIENT ID : " + patientId); } - public void sendMessage(String message, String nickname) { - mSocket.emit("chatMessage", nickname, message); + public void sendMessage(@NonNull String message, @NonNull String nickname, @NonNull String patient_id) { + mSocket.emit("chatMessage", nickname, message, patient_id); } public interface Callback { - void onSuccess(T result); + void onMessageReceived(T result); + void onMessageSentSuccessfully(); void onError(Exception e); } } diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Author.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Author.java index 9239c72..d61f493 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Author.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Author.java @@ -4,6 +4,14 @@ import com.app.simplitend.R; import com.stfalcon.chatkit.commons.models.IUser; public class Author implements IUser { + + private final String name, avatar; + + public Author(String name, String avatar) { + this.name = name; + this.avatar = avatar; + } + @Override public String getId() { return "sender"; @@ -11,11 +19,11 @@ public class Author implements IUser { @Override public String getName() { - return null; + return name; } @Override public String getAvatar() { - return String.valueOf(R.drawable.static_3); + return avatar; } } diff --git a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Receiver.java b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Receiver.java index bd86224..41c82d0 100644 --- a/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Receiver.java +++ b/app/src/main/java/com/app/simplitend/patient_dashboard/chats/mvvm/Receiver.java @@ -1,10 +1,16 @@ package com.app.simplitend.patient_dashboard.chats.mvvm; -import com.app.simplitend.R; import com.stfalcon.chatkit.commons.models.IUser; public class Receiver implements IUser { + private final String name, avatar; + + public Receiver(String name, String avatar) { + this.name = name; + this.avatar = avatar; + } + @Override public String getId() { return "receiver"; @@ -12,11 +18,11 @@ public class Receiver implements IUser { @Override public String getName() { - return null; + return name; } @Override public String getAvatar() { - return String.valueOf(R.drawable.static_3); + return avatar; } } 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 e5dbf5e..5e8ae09 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 @@ -40,6 +40,7 @@ import com.app.simplitend.databinding.PatientDashboardFragmentBinding; import com.app.simplitend.patient_dashboard.DirectionToHomeActivity; import com.app.simplitend.patient_dashboard.NotificationsActivity; import com.app.simplitend.patient_dashboard.PatientMainViewModel; +import com.app.simplitend.patient_dashboard.chats.ChatFragment; import com.app.simplitend.patientprofile.ProfileContracts; import com.app.simplitend.patientprofile.medreminder.mvvm.ReminderViewModel; import com.app.simplitend.patientprofile.medreminder.mvvm.models.NearestActivity; @@ -78,13 +79,13 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac // date suffixes String[] suffixes = // 0 1 2 3 4 5 6 7 8 9 - { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", + {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", // 10 11 12 13 14 15 16 17 18 19 "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", // 20 21 22 23 24 25 26 27 28 29 - "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", + "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", // 30 31 - "th", "st" }; + "th", "st"}; // ticker broadcast receiver that is called every one minute passes the system clock private final BroadcastReceiver timeTickReceiver = new BroadcastReceiver() { @@ -122,7 +123,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac public void onReceive(Context context, Intent intent) { String content_type = intent.getStringExtra(CONTENT_TYPE_KEY); - if (Constants.ACTIVITY_TIME.equals(content_type) || Constants.MEDICINE_TIME.equals(content_type)){ + if (Constants.ACTIVITY_TIME.equals(content_type) || Constants.MEDICINE_TIME.equals(content_type)) { loadReminders(); } } @@ -136,11 +137,11 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac setDetails(); }), true); - PatientDataCache.getContactList(requireContext(),"Bearer " + AppUtil.getPatientToken(requireContext()), + PatientDataCache.getContactList(requireContext(), "Bearer " + AppUtil.getPatientToken(requireContext()), (contactList1 -> { this.contactList = contactList1; - if (contactList != null){ + if (contactList != null) { AppUtil.setWhiteListedContacts(requireContext(), contactList); } }), false); @@ -157,7 +158,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac private void setDetails() { if (patientData == null) return; - if (patientData.profile_photo != null){ + if (patientData.profile_photo != null) { Glide.with(requireContext()) .load(AppUtil.IMAGE_BASE_URL + patientData.profile_photo) .diskCacheStrategy(DiskCacheStrategy.DATA) @@ -169,9 +170,9 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac } private void initViews() { - if (viewModel.message_title == null){ + if (viewModel.message_title == null) { removeReminder(); - }else{ + } else { addReminder(); } } @@ -181,7 +182,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac super.onResume(); updateTime(); Activity activity = getActivity(); - if (activity != null){ + if (activity != null) { activity.registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); } } @@ -190,28 +191,61 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac public void onPause() { super.onPause(); Activity activity = getActivity(); - if (activity != null){ + if (activity != null) { activity.unregisterReceiver(timeTickReceiver); } } private void clickEvents() { - binding.chats.setOnClickListener(v -> - Navigation.findNavController(v).navigate(R.id.action_CPDashboardFragment_to_chatListFragment) - ); + binding.chats.setOnClickListener(v -> { + PatientDataCache.getPatientData(requireContext(), (patientData1 -> { + if (patientData1 != null){ + this.patientData = patientData1; + + try { + String sender_image; + if (patientData1.profile_photo == null){ + sender_image = String.valueOf(R.drawable.senior_img); + }else{ + sender_image = AppUtil.IMAGE_BASE_URL + patientData.profile_photo; + } + + String receiver_image; + if (patientData.caregiver_profile_photo == null){ + receiver_image = String.valueOf(R.drawable.caregiver_img); + }else{ + receiver_image = AppUtil.IMAGE_BASE_URL + patientData.caregiver_profile_photo; + } + + getParentFragmentManager().beginTransaction() + .replace(R.id.fragmentContainerView, new ChatFragment( + patientData1.patientId + "", + patientData1.first_name, + patientData.caregiver_name, + sender_image, + receiver_image + ), "patient_chat") + .addToBackStack("patient_chat") + .commitAllowingStateLoss(); + } catch (Exception e) { + // do nothing + } + } + }), true); + }); binding.sosBtn.setOnClickListener(v -> { PatientDataCache.getContactList(requireContext(), "Bearer " + AppUtil.getPatientToken(requireContext()), (contactList1 -> { this.contactList = contactList1; - viewModel.notifyRequestedSOS(AppUtil.getPatientUid(requireContext())+"", + viewModel.notifyRequestedSOS(AppUtil.getPatientUid(requireContext()) + "", AppUtil.getPatientToken(requireContext())); String phone_number = "911"; - for (ContactData contactData: contactList1){ - if (contactData.is_sos.equals("1")){ + for (ContactData contactData : contactList1) { + if (contactData.is_sos.equals("1")) { phone_number = contactData.phone_number; } } @@ -228,12 +262,12 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac "Bearer " + AppUtil.getPatientToken(requireContext()), (contactList1 -> { this.contactList = contactList1; - if (contactList != null){ + if (contactList != null) { Intent intent = new Intent(requireActivity(), CallsActivity.class); intent.putExtra(CALL_CONTACT_LIST_KEY, contactList); startActivity(intent); - }else{ + } else { Toast.makeText(requireContext(), "Couldn't load contact list", Toast.LENGTH_SHORT).show(); } }), true); @@ -259,7 +293,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac intent.putExtra(LAT_KEY, lat); intent.putExtra(LNG_KEY, lng); startActivity(intent); - }catch (Exception e){ + } catch (Exception e) { Toast.makeText(requireContext(), "Couldn't load your home location", Toast.LENGTH_SHORT).show(); } }); @@ -268,7 +302,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac PatientDataCache.getPatientData(requireActivity(), (patientData1 -> { this.patientData = patientData1; - if (patientData == null){ + if (patientData == null) { Toast.makeText(requireContext(), "Couldn't load notifications", Toast.LENGTH_SHORT).show(); return; } @@ -283,9 +317,9 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac } - private void loadReminders(){ + private void loadReminders() { reminderViewModel.getRemindersList(AppUtil.getPatientUid(requireContext()), - Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1, + Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1, "Bearer " + AppUtil.getPatientToken(requireContext()), this); } @@ -306,8 +340,8 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac } - public String getDayOfWeek(int position){ - switch (position){ + public String getDayOfWeek(int position) { + switch (position) { case 1: return "Sunday"; case 2: @@ -341,8 +375,8 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac viewModel.message_title = null; } - private void addReminder(){ - if (viewModel.message_title == null || viewModel.message_title.isEmpty()){ + private void addReminder() { + if (viewModel.message_title == null || viewModel.message_title.isEmpty()) { // removeReminder(); return; } @@ -351,7 +385,8 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac ViewGroup.LayoutParams layoutParams = binding.bgImg.getLayoutParams(); - layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._200sdp);; + layoutParams.height = (int) getResources().getDimension(com.intuit.sdp.R.dimen._200sdp); + ; binding.bgImg.setLayoutParams(layoutParams); @@ -379,7 +414,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac try { if (nearestReminder == null) throw new Exception(); - if (nearestReminder.upcoming_time == null){ + if (nearestReminder.upcoming_time == null) { viewModel.nearest_rem_time = Long.MAX_VALUE; throw new Exception(); } @@ -396,20 +431,20 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac viewModel.nearest_rem_time = time_diff; - if (time_diff < 0){ + if (time_diff < 0) { // the nearest time has already passed the current time // i.e. all the reminders has been done for current day throw new Exception(); - }else{ - time_diff = time_diff/1000; // milliseconds to seconds + } else { + time_diff = time_diff / 1000; // milliseconds to seconds long s = time_diff % 60; long m = (time_diff / 60) % 60; long h = (time_diff / (60 * 60)) % 24; StringBuilder reminder_txt = new StringBuilder("You should take yours medicines"); - if (time_diff > 3600){ + if (time_diff > 3600) { // time greater than 60 mins // thus, showing direct time SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault()); @@ -421,7 +456,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac reminder_txt.append(" at ").append(nearestReminder.upcoming_time); } - }else{ + } else { // show in minutes reminder_txt.append(" in ").append(m).append(" min"); @@ -433,7 +468,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac viewModel.message_sub_title_2 = nearestReminder.med_quantity + " " + nearestReminder.med_type; } - }catch (Exception e){ + } catch (Exception e) { // do nothing viewModel.message_sub_title_2 = viewModel.message_sub_title_1 = viewModel.message_title = null; } @@ -442,7 +477,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac try { routineViewModel.getRoutines(AppUtil.getPatientUid(requireContext()), "Bearer " + AppUtil.getPatientToken(requireContext()), - Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1, + Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1, this); } catch (Exception e) { // do nothing user has left the fragment @@ -456,9 +491,9 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac @Override public void onRoutinesFetchedFailed(Throwable t, String message) { - if (viewModel.message_title != null){ + if (viewModel.message_title != null) { addReminder(); - }else{ + } else { removeReminder(); } } @@ -469,10 +504,10 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac // next routine setting try { - if (nearestActivity.upcoming_time == null){ - if (viewModel.message_title != null){ + if (nearestActivity.upcoming_time == null) { + if (viewModel.message_title != null) { addReminder(); - }else{ + } else { removeReminder(); } return; @@ -488,24 +523,24 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac long time_diff = upcoming_date.getTime() - cur_date.getTime() + 1000; // +1000 for extra one min to reach that time - if (time_diff < 0){ + if (time_diff < 0) { // the nearest time has already passed the current time // i.e. all the reminders has been done for current day - if (viewModel.message_title != null){ + if (viewModel.message_title != null) { addReminder(); - }else{ + } else { removeReminder(); } - }else if (time_diff < viewModel.nearest_rem_time){ - time_diff = time_diff/1000; // milliseconds to seconds + } else if (time_diff < viewModel.nearest_rem_time) { + time_diff = time_diff / 1000; // milliseconds to seconds long s = time_diff % 60; long m = (time_diff / 60) % 60; long h = (time_diff / (60 * 60)) % 24; StringBuilder up_activity_txt = new StringBuilder("Get ready for your activity starting"); - if (time_diff > 3600){ + if (time_diff > 3600) { // time greater than 60 mins // thus, showing direct time SimpleDateFormat format_sdf = new SimpleDateFormat("hh:mm a", Locale.getDefault()); @@ -517,7 +552,7 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac up_activity_txt.append(" at ").append(nearestActivity.upcoming_time); } - }else{ + } else { // show in minutes up_activity_txt.append(" in ").append(m).append(" min"); @@ -529,15 +564,15 @@ public class PatientDashboardFragment extends Fragment implements ProfileContrac viewModel.message_sub_title_2 = null; } - }catch (Exception e){ - if (viewModel.message_title != null){ + } catch (Exception e) { + if (viewModel.message_title != null) { addReminder(); - }else{ + } else { removeReminder(); } } - if (viewModel.message_title != null){ + if (viewModel.message_title != null) { addReminder(); } } diff --git a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/PatientData.java b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/PatientData.java index ee14fbc..f15f2e7 100644 --- a/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/PatientData.java +++ b/app/src/main/java/com/app/simplitend/welcome/welcomepatient/mvvm/models/PatientData.java @@ -30,6 +30,8 @@ public class PatientData { public String one_signal_player_id; + public String caregiver_name, caregiver_profile_photo; + // progress flags public int isCareGiverLink , isPatientReminderData diff --git a/app/src/main/res/drawable/receiver_msg_bg.xml b/app/src/main/res/drawable/receiver_msg_bg.xml new file mode 100644 index 0000000..4e7b86d --- /dev/null +++ b/app/src/main/res/drawable/receiver_msg_bg.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/chat_fragment.xml b/app/src/main/res/layout/chat_fragment.xml index 991ca02..9b9e861 100644 --- a/app/src/main/res/layout/chat_fragment.xml +++ b/app/src/main/res/layout/chat_fragment.xml @@ -43,23 +43,24 @@ android:layout_height="match_parent" android:layout_above="@id/message_et" - app:incomingDefaultBubbleColor="#EEF5FC" - app:incomingTextColor="@color/black" - app:outcomingDefaultBubbleColor="#043E61" app:outcomingTextColor="@color/white_bg" app:outcomingTimeTextColor="@color/white" + app:outcomingBubblePaddingBottom="10dp" + app:outcomingBubblePaddingLeft="15dp" + app:outcomingBubblePaddingRight="15dp" + app:outcomingBubblePaddingTop="10dp" + /> - - android:layout_marginVertical="5dp" - android:layout_marginEnd="15dp" + + android:fontFamily="@font/nunito_regular" + android:textColor="@color/white_bg" + + app:backgroundTint="@color/color_primary" + + app:cornerRadius="5dp" + + /> + + + + diff --git a/app/src/main/res/layout/receiver_msg_viewholder.xml b/app/src/main/res/layout/receiver_msg_viewholder.xml new file mode 100644 index 0000000..24eec82 --- /dev/null +++ b/app/src/main/res/layout/receiver_msg_viewholder.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/sender_msg_viewholder.xml b/app/src/main/res/layout/sender_msg_viewholder.xml index d6121bc..474238b 100644 --- a/app/src/main/res/layout/sender_msg_viewholder.xml +++ b/app/src/main/res/layout/sender_msg_viewholder.xml @@ -1,10 +1,10 @@ + android:layout_marginRight="16dp"> + + - - \ No newline at end of file diff --git a/app/src/main/res/navigation/cp_dashboard_graph.xml b/app/src/main/res/navigation/cp_dashboard_graph.xml index b810e0f..289cc2e 100644 --- a/app/src/main/res/navigation/cp_dashboard_graph.xml +++ b/app/src/main/res/navigation/cp_dashboard_graph.xml @@ -14,6 +14,9 @@ +