.
This commit is contained in:
@@ -23,12 +23,17 @@ import com.ssb.simplitend.patientprofile.medreminder.mvvm.ReminderAdapter;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.ReminderViewModel;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ReminderFragment extends Fragment implements RecyclerTouchListener.OnSwipeOptionsClickListener,
|
||||
ProfileContracts.GetRemindersListCallback, ProfileContracts.ReminderDeleteCallback {
|
||||
ProfileContracts.GetRemindersListCallback, ProfileContracts.ReminderDeleteCallback,
|
||||
ProfileContracts.AddReminderCallBack,
|
||||
ReminderAdapter.ReminderCheckClickListener{
|
||||
|
||||
// view binding
|
||||
protected RemindersFragmentBinding binding;
|
||||
@@ -128,6 +133,7 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
|
||||
binding.remindersRv.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
reminderAdapter = new ReminderAdapter();
|
||||
reminderAdapter.setCheckClickListener(this);
|
||||
binding.remindersRv.setAdapter(reminderAdapter);
|
||||
|
||||
recyclerTouchListener = new RecyclerTouchListener(requireActivity(), binding.remindersRv);
|
||||
@@ -185,6 +191,7 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
dayViewHolder.day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
dayViewHolder.day.setText(reminderViewModel.getDayOfWeek(dayViewHolder.day_of_week - 1));
|
||||
dayViewHolder.date.setText(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
|
||||
dayViewHolder.mDate = calendar.getTime();
|
||||
|
||||
calendar.add(Calendar.DAY_OF_WEEK, 1);
|
||||
}
|
||||
@@ -238,6 +245,9 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
|
||||
private void setDayOfWeek(int selection){
|
||||
|
||||
// setting selected date in adapter
|
||||
reminderAdapter.setSelected_date(weekDayViewsList.get(selection).mDate);
|
||||
|
||||
clearSelection();
|
||||
|
||||
switch (reminderViewModel.selected_dow = selection){
|
||||
@@ -378,4 +388,97 @@ public class ReminderFragment extends Fragment implements RecyclerTouchListener.
|
||||
.navigate(R.id.action_reminderFragment_to_addReminderFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReminderAdded(ReminderResult reminderDetails) {
|
||||
progressDialog.dismiss();
|
||||
loadReminderList(weekDayViewsList.get(reminderViewModel.selected_dow).day_of_week);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReminderAddFailed(Throwable t, String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
getString(R.string.something_went_wrong),
|
||||
message,
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
}, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheck(ReminderResult reminderResult, int position) {
|
||||
// is user checking only today's check
|
||||
|
||||
if (reminderResult.reminder_marked == null){
|
||||
/*
|
||||
now, we don't want to allow checking of routine of other day
|
||||
*/
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(reminderViewModel.selected_dow).date.getText().toString());
|
||||
|
||||
if (today_date == selected_date){
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this routine?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(reminderResult, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
}else{
|
||||
Toast.makeText(requireContext(), "Cannot done future routine.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRoutine(ReminderResult reminderResult, int position) {
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("saving your reminder");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Calendar current = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
reminderResult.patientRemainderId = reminderResult.id;
|
||||
reminderResult.reminder_marked = sdf.format(current.getTime());
|
||||
reminderResult.is_update = "1";
|
||||
|
||||
// need to change date format as backend accepts dd-MM-yyyy
|
||||
// and responds as yyyy-dd-MM
|
||||
SimpleDateFormat date_f1 = new SimpleDateFormat("yyyy-dd-MM", Locale.getDefault());
|
||||
SimpleDateFormat date_f2 = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
|
||||
|
||||
String refill_date;
|
||||
|
||||
try {
|
||||
Date date = date_f1.parse(reminderResult.medication_refill_date);
|
||||
refill_date = date_f2.format(date);
|
||||
}catch (Exception e){
|
||||
refill_date = date_f2.format(Calendar.getInstance().getTime());
|
||||
}
|
||||
|
||||
reminderResult.medication_refill_date = refill_date;
|
||||
|
||||
reminderViewModel.addReminder(
|
||||
AppUtil.getPatientUid(requireContext()),
|
||||
reminderResult,
|
||||
"Bearer " + AppUtil.getUserToken(requireContext()),
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@ package com.ssb.simplitend.patientprofile.medreminder;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class WeekDayViewHolder {
|
||||
public LinearLayout card;
|
||||
public TextView day, date;
|
||||
|
||||
public int day_of_week;
|
||||
|
||||
public Date mDate;
|
||||
|
||||
public WeekDayViewHolder() {
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ssb.simplitend.patientprofile.medreminder.mvvm;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
@@ -11,10 +12,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.databinding.ReminderViewholderBinding;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.Reminder;
|
||||
import com.ssb.simplitend.patientprofile.medreminder.mvvm.models.ReminderResult;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineAdapter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -32,14 +34,30 @@ public class ReminderAdapter extends ListAdapter<ReminderResult, ReminderAdapter
|
||||
}
|
||||
};
|
||||
|
||||
private ReminderCheckClickListener checkClickListener;
|
||||
|
||||
// static thing for selection status
|
||||
public final boolean[] selection_state;
|
||||
|
||||
private volatile Date selected_date;
|
||||
|
||||
public ReminderAdapter(){
|
||||
super(DIFF_CALLBACK);
|
||||
this.selection_state = new boolean[2];
|
||||
}
|
||||
|
||||
public void setCheckClickListener(ReminderCheckClickListener checkClickListener) {
|
||||
this.checkClickListener = checkClickListener;
|
||||
}
|
||||
|
||||
public void setSelected_date(Date selected_date) {
|
||||
this.selected_date = selected_date;
|
||||
}
|
||||
|
||||
public Date getSelected_date() {
|
||||
return selected_date;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReminderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -50,6 +68,11 @@ public class ReminderAdapter extends ListAdapter<ReminderResult, ReminderAdapter
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReminderViewHolder holder, int position) {
|
||||
holder.setReminder(getItem(position), position);
|
||||
|
||||
holder.binding.done.setOnClickListener(v -> {
|
||||
if (checkClickListener != null) checkClickListener.onCheck(getItem(position), position);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static class ReminderViewHolder extends RecyclerView.ViewHolder{
|
||||
@@ -91,22 +114,69 @@ public class ReminderAdapter extends ListAdapter<ReminderResult, ReminderAdapter
|
||||
binding.medImg.setImageResource(R.drawable.img_med_type_2);
|
||||
}
|
||||
|
||||
binding.done.setOnClickListener(v -> {
|
||||
if (selection_state[position]){
|
||||
// item selected. un-selecting now
|
||||
binding.sideBar.setBackgroundTintList(null);
|
||||
binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.white_bg));
|
||||
binding.done.setImageResource(R.drawable.ic_done_accent);
|
||||
}else{
|
||||
// item un-selected. selecting now
|
||||
binding.sideBar.setBackgroundTintList(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_primary));
|
||||
binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_accent));
|
||||
binding.done.setImageResource(R.drawable.ic_done_accent_2);
|
||||
}
|
||||
// binding.done.setOnClickListener(v -> {
|
||||
// if (selection_state[position]){
|
||||
// // item selected. un-selecting now
|
||||
// binding.sideBar.setBackgroundTintList(null);
|
||||
// binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.white_bg));
|
||||
// binding.done.setImageResource(R.drawable.ic_done_accent);
|
||||
// }else{
|
||||
// // item un-selected. selecting now
|
||||
// binding.sideBar.setBackgroundTintList(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_primary));
|
||||
// binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_accent));
|
||||
// binding.done.setImageResource(R.drawable.ic_done_accent_2);
|
||||
// }
|
||||
//
|
||||
// selection_state[position] = !selection_state[position];
|
||||
// });
|
||||
|
||||
selection_state[position] = !selection_state[position];
|
||||
});
|
||||
if (reminder.reminder_marked != null){
|
||||
/*
|
||||
This routine is done for some day.
|
||||
New, checking if this routine done is done today or day before it
|
||||
*/
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date routine_date = sdf.parse(reminder.reminder_marked);
|
||||
if (routine_date == null)
|
||||
throw new Exception("Cannot parse routine marked date from Backend");
|
||||
|
||||
ReminderAdapter routineAdapter = (ReminderAdapter) getBindingAdapter();
|
||||
|
||||
if (routineAdapter == null) throw new Exception();
|
||||
|
||||
Date selected_date = routineAdapter.getSelected_date();
|
||||
Calendar selected_calendar = Calendar.getInstance();
|
||||
selected_calendar.setTime(selected_date);
|
||||
|
||||
Calendar routine_calendar = Calendar.getInstance();
|
||||
routine_calendar.setTime(routine_date);
|
||||
|
||||
if (routine_calendar.get(Calendar.DAY_OF_MONTH) == selected_calendar.get(Calendar.DAY_OF_MONTH)){
|
||||
// it is the same day on which routine is checked
|
||||
// as routine done date is equal to selected_tab date
|
||||
binding.sideBar.setBackgroundTintList(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_primary));
|
||||
binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.color_accent));
|
||||
binding.done.setImageResource(R.drawable.ic_done_accent_2);
|
||||
}else{
|
||||
// item selected. un-selecting now
|
||||
binding.sideBar.setBackgroundTintList(null);
|
||||
binding.card.setCardBackgroundColor(AppCompatResources.getColorStateList(itemView.getContext(), R.color.white_bg));
|
||||
binding.done.setImageResource(R.drawable.ic_done_accent);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(itemView.getContext(), "Couldn't mark it done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface ReminderCheckClickListener{
|
||||
void onCheck(ReminderResult reminderResult, int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public class ReminderResult implements Serializable {
|
||||
public ArrayList<MedicationType> medication_type;
|
||||
public ArrayList<MedicationFrequency> medication_frequency;
|
||||
|
||||
public String reminder_marked;
|
||||
|
||||
public String is_update;
|
||||
|
||||
public ReminderResult(){}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.Navigation;
|
||||
@@ -25,15 +26,26 @@ import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineAdapter;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineDetails;
|
||||
import com.ssb.simplitend.patientprofile.setuproutine.mvvm.RoutineViewModel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class RoutineFragment extends Fragment implements RoutineAdapter.ClickListener,
|
||||
RoutineAdapter.DeleteClickListener,
|
||||
RoutineAdapter.CheckClickListener,
|
||||
ProfileContracts.GetRoutinesCallback,
|
||||
ProfileContracts.RoutineDeleteCallback {
|
||||
ProfileContracts.RoutineDeleteCallback,
|
||||
ProfileContracts.AddNUpdateRoutineCallback {
|
||||
|
||||
private static final String TAG = "RoutineFragment";
|
||||
|
||||
// view binding
|
||||
protected RoutineFragmentBinding binding;
|
||||
|
||||
@@ -124,6 +136,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
routineAdapter = new RoutineAdapter();
|
||||
routineAdapter.setDeleteClickListener(this);
|
||||
routineAdapter.setClickListener(this);
|
||||
routineAdapter.setCheckClickListener(this);
|
||||
binding.routineRv.setAdapter(routineAdapter);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@@ -174,6 +187,7 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
dayViewHolder.day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
dayViewHolder.day.setText(routineViewModel.getDayOfWeek(dayViewHolder.day_of_week - 1));
|
||||
dayViewHolder.date.setText(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
|
||||
dayViewHolder.mDate = calendar.getTime();
|
||||
|
||||
calendar.add(Calendar.DAY_OF_WEEK, 1);
|
||||
}
|
||||
@@ -181,6 +195,9 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
private void setDayOfWeek(int selection){
|
||||
|
||||
// setting selected date in adapter
|
||||
routineAdapter.setSelected_date(weekDayViewsList.get(selection).mDate);
|
||||
|
||||
clearSelection();
|
||||
|
||||
switch (routineViewModel.selected_dow = selection){
|
||||
@@ -362,4 +379,84 @@ public class RoutineFragment extends Fragment implements RoutineAdapter.ClickLis
|
||||
|
||||
Navigation.findNavController(binding.getRoot()).navigate(R.id.action_routineFragment_to_addRoutineFragment, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckClick(RoutineDetails routineDetails, int position) {
|
||||
// is user checking only today's check
|
||||
|
||||
if (routineDetails.routine_marked == null){
|
||||
/*
|
||||
now, we don't want to allow checking of routine of other day
|
||||
*/
|
||||
try {
|
||||
int today_date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
|
||||
int selected_date = Integer.parseInt(weekDayViewsList.get(routineViewModel.selected_dow).date.getText().toString());
|
||||
|
||||
if (today_date == selected_date){
|
||||
AppUtil.showAlert(requireContext(),
|
||||
"Are you sure?",
|
||||
"Do yuo want to check this routine?\nThis cannot be undone.",
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
|
||||
updateRoutine(routineDetails, position);
|
||||
|
||||
}, getString(R.string.no),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
}else{
|
||||
Toast.makeText(requireContext(), "Cannot done future routine.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
Toast.makeText(requireContext(), "Couldn't be done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRoutine(RoutineDetails routine, int position) {
|
||||
|
||||
progressDialog.setTitle("Please wait...");
|
||||
progressDialog.setMessage("saving your routine");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
|
||||
Calendar current = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
routine.patientRoutineId = routine.id;
|
||||
routine.routine_marked = sdf.format(current.getTime());
|
||||
routine.is_update = 1;
|
||||
|
||||
routineViewModel.addNUpdateRoutine(
|
||||
AppUtil.getPatientUid(requireContext()),
|
||||
routine,
|
||||
"Bearer " + AppUtil.getUserToken(requireContext()),
|
||||
this
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutineAdded(RoutineDetails medicationInfo) {
|
||||
progressDialog.dismiss();
|
||||
loadRoutineList(weekDayViewsList.get(routineViewModel.selected_dow).day_of_week);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRoutineAddFailed(Throwable t, String message) {
|
||||
progressDialog.dismiss();
|
||||
|
||||
AppUtil.showAlert(requireContext(),
|
||||
getString(R.string.something_went_wrong),
|
||||
message,
|
||||
getString(R.string.yes),
|
||||
(dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
}, null, null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
package com.ssb.simplitend.patientprofile.setuproutine.mvvm;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.ssb.simplitend.R;
|
||||
import com.ssb.simplitend.databinding.RoutineViewholderBinding;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.RoutineViewHolder> {
|
||||
|
||||
private static final String TAG = "RoutineAdapter";
|
||||
|
||||
private static final DiffUtil.ItemCallback<RoutineDetails> DIFF_UTIL = new DiffUtil.ItemCallback<RoutineDetails>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull RoutineDetails oldItem, @NonNull RoutineDetails newItem) {
|
||||
@@ -34,6 +40,10 @@ public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.R
|
||||
private DeleteClickListener deleteClickListener;
|
||||
private ClickListener clickListener;
|
||||
|
||||
private CheckClickListener checkClickListener;
|
||||
|
||||
private volatile Date selected_date;
|
||||
|
||||
public RoutineAdapter() {
|
||||
super(DIFF_UTIL);
|
||||
}
|
||||
@@ -46,6 +56,18 @@ public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.R
|
||||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
public void setCheckClickListener(CheckClickListener checkClickListener) {
|
||||
this.checkClickListener = checkClickListener;
|
||||
}
|
||||
|
||||
public void setSelected_date(Date selected_date) {
|
||||
this.selected_date = selected_date;
|
||||
}
|
||||
|
||||
public Date getSelected_date() {
|
||||
return selected_date;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RoutineViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -66,6 +88,11 @@ public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.R
|
||||
if (clickListener != null) clickListener.onClick(getItem(position), position);
|
||||
});
|
||||
|
||||
holder.binding.check.setOnClickListener(v -> {
|
||||
if (checkClickListener != null)
|
||||
checkClickListener.onCheckClick(getItem(position), position);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static class RoutineViewHolder extends RecyclerView.ViewHolder {
|
||||
@@ -110,6 +137,46 @@ public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.R
|
||||
String end_slot = end_time.substring(0, 2) + " " + end_time.substring(end_time.length() - 2);
|
||||
binding.endTimeStatic.setText(end_slot);
|
||||
|
||||
if (routine.routine_marked != null){
|
||||
/*
|
||||
This routine is done for some day.
|
||||
New, checking if this routine done is done today or day before it
|
||||
*/
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
|
||||
try {
|
||||
Date routine_date = sdf.parse(routine.routine_marked);
|
||||
if (routine_date == null)
|
||||
throw new Exception("Cannot parse routine marked date from Backend");
|
||||
|
||||
RoutineAdapter routineAdapter = (RoutineAdapter) getBindingAdapter();
|
||||
|
||||
if (routineAdapter == null) throw new Exception();
|
||||
|
||||
Date selected_date = routineAdapter.getSelected_date();
|
||||
Calendar selected_calendar = Calendar.getInstance();
|
||||
selected_calendar.setTime(selected_date);
|
||||
|
||||
Calendar routine_calendar = Calendar.getInstance();
|
||||
routine_calendar.setTime(routine_date);
|
||||
|
||||
Log.d(TAG, "setData: " + routine_calendar.get(Calendar.DAY_OF_MONTH) + " " + selected_calendar.get(Calendar.DAY_OF_MONTH));
|
||||
|
||||
if (routine_calendar.get(Calendar.DAY_OF_MONTH) == selected_calendar.get(Calendar.DAY_OF_MONTH)){
|
||||
// it is the same day on which routine is checked
|
||||
// as routine done date is equal to selected_tab date
|
||||
binding.check.setImageResource(R.drawable.ic_check_green);
|
||||
}else{
|
||||
binding.check.setImageResource(R.drawable.ic_un_check);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "setData: ", e);
|
||||
Toast.makeText(itemView.getContext(), "Couldn't mark it done.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -126,4 +193,9 @@ public class RoutineAdapter extends ListAdapter<RoutineDetails, RoutineAdapter.R
|
||||
void onClick(RoutineDetails routineDetails, int position);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CheckClickListener {
|
||||
void onCheckClick(RoutineDetails routineDetails, int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class RoutineDetails implements Serializable {
|
||||
public String created_at;
|
||||
public String updated_at;
|
||||
|
||||
public String routine_marked;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -6,6 +6,9 @@ import androidx.lifecycle.ViewModel;
|
||||
import com.ssb.simplitend.patientprofile.ProfileContracts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
public class RoutineViewModel extends ViewModel {
|
||||
|
||||
@@ -43,6 +46,7 @@ public class RoutineViewModel extends ViewModel {
|
||||
routinesRepository.deleteRoutine(patient_id, patient_routine_id, adapterPosition, token, deleteCallback);
|
||||
}
|
||||
|
||||
|
||||
public String getDayOfWeek(int position){
|
||||
switch (position){
|
||||
case 0:
|
||||
|
||||
@@ -8,7 +8,9 @@ import com.ssb.simplitend.patientprofile.ProfileContracts;
|
||||
import com.ssb.simplitend.welcome.mvvm.models.CallResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.ssb.simplitend.welcome.fragments;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -67,6 +69,25 @@ public class SignInFragment extends Fragment implements WelcomeContracts.Registe
|
||||
binding.pin
|
||||
);
|
||||
|
||||
binding.pin.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() == 4){
|
||||
AppUtil.closeKeyboard(requireActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
@@ -114,32 +116,38 @@ public class ContactListFragment extends Fragment{
|
||||
// filters contact list w.r.t searchInput
|
||||
private void filterContactList(String searchInput) {
|
||||
|
||||
if(searchInput.isEmpty()) {
|
||||
contactListAdapter.submitList(contactList);
|
||||
return;
|
||||
}
|
||||
new Thread(() -> {
|
||||
|
||||
ArrayList<Contact> filteredList = new ArrayList<>();
|
||||
|
||||
for (Contact contact: contactList){
|
||||
if (contact.first_name != null && contact.first_name.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.phone_number != null && contact.phone_number.trim().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.email_address != null && contact.email_address.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.relationship != null && contact.relationship.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
if(searchInput.isEmpty()) {
|
||||
contactListAdapter.submitList(contactList);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (filteredList.isEmpty()) {
|
||||
Toast.makeText(requireContext(), "No match found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
ArrayList<Contact> filteredList = new ArrayList<>();
|
||||
|
||||
contactListAdapter.submitList(filteredList);
|
||||
for (Contact contact: contactList){
|
||||
if (contact.first_name != null && contact.first_name.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.phone_number != null && contact.phone_number.trim().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.email_address != null && contact.email_address.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}else if (contact.relationship != null && contact.relationship.trim().toLowerCase().contains(searchInput)){
|
||||
filteredList.add(contact);
|
||||
}
|
||||
}
|
||||
|
||||
binding.contactRv.smoothScrollToPosition(0);
|
||||
if (filteredList.isEmpty()) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
Toast.makeText(requireContext(), "No match found", Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
}
|
||||
|
||||
contactListAdapter.submitList(filteredList);
|
||||
|
||||
binding.contactRv.smoothScrollToPosition(0);
|
||||
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -179,11 +179,9 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
InputFilter phoneFilter = (charSequence, i, i1, spanned, i2, i3) -> {
|
||||
String phone_number_str = charSequence.toString();
|
||||
|
||||
String country_code;
|
||||
String country_code = null;
|
||||
|
||||
if (binding.countryCodes.getSelectedIndex() == -2){
|
||||
country_code = "+1";
|
||||
}else{
|
||||
if (binding.countryCodes.getSelectedIndex() != -1){
|
||||
country_code = countryCodeList.get(binding.countryCodes.getSelectedIndex());
|
||||
}
|
||||
|
||||
@@ -197,11 +195,13 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
// nothing
|
||||
}
|
||||
|
||||
if (!countryCodeList.contains(country_code)){
|
||||
if (country_code != null && !countryCodeList.contains(country_code)){
|
||||
countryCodeList.add(country_code);
|
||||
}
|
||||
|
||||
binding.countryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
if (country_code != null){
|
||||
binding.countryCodes.selectItemByIndex(countryCodeList.indexOf(country_code));
|
||||
}
|
||||
|
||||
if (phone_number_str.length() > 10){
|
||||
// pasted number length is greater than 10
|
||||
@@ -324,11 +324,6 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
binding.name.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.relationship.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.relationship.setError("Required");
|
||||
}
|
||||
|
||||
if (binding.phoneNumber.getText().toString().trim().isEmpty()) {
|
||||
allOkay = false;
|
||||
binding.phoneNumber.setError("Required");
|
||||
@@ -443,6 +438,7 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
}
|
||||
|
||||
private void setDetails() {
|
||||
|
||||
if (contactData.contact_photo != null)
|
||||
{
|
||||
Glide.with(requireContext())
|
||||
@@ -461,11 +457,20 @@ public class CreateContactFragment extends Fragment implements WelcomeContracts.
|
||||
// there is a country code
|
||||
int index = countryCodeList.indexOf(code_phone[0]);
|
||||
|
||||
if (index >= 0) binding.countryCodes.selectItemByIndex(index);
|
||||
else binding.countryCodes.clearSelectedItem();
|
||||
int i;
|
||||
|
||||
if (index >= 0) {
|
||||
// country code exits
|
||||
binding.countryCodes.selectItemByIndex(index);
|
||||
i = 1;
|
||||
} else {
|
||||
// country code doesn't exits
|
||||
i = 0;
|
||||
binding.countryCodes.clearSelectedItem();
|
||||
}
|
||||
|
||||
contactData.phone_number = "";
|
||||
for (int i = 1; i < code_phone.length; i++) {
|
||||
for (; i < code_phone.length; i++) {
|
||||
contactData.phone_number = contactData.phone_number.concat(code_phone[i]);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,8 @@ import static com.ssb.simplitend.welcome.fragments.forgotpin.ForgotPinFragment.E
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -85,6 +87,44 @@ public class ChangePinFragment extends Fragment implements WelcomeContracts.Upda
|
||||
binding.pin,
|
||||
binding.confirmPin
|
||||
);
|
||||
|
||||
binding.pin.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() == 4){
|
||||
binding.confirmPin.requestFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
binding.confirmPin.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() == 4){
|
||||
AppUtil.closeKeyboard(requireActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void clickEvents() {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.ssb.simplitend.welcome.fragments.register;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -57,6 +59,44 @@ public class CreatePinFragment extends Fragment implements WelcomeContracts.Regi
|
||||
loadPinsSavedState();
|
||||
|
||||
progressDialog = new ProgressDialog(requireContext());
|
||||
|
||||
binding.pin.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() == 4){
|
||||
binding.confirmPin.requestFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
binding.confirmPin.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() == 4){
|
||||
AppUtil.closeKeyboard(requireActivity());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadPinsSavedState() {
|
||||
|
||||
@@ -105,8 +105,6 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(WelcomeViewModel.class);
|
||||
|
||||
Log.d(TAG, "onCreateView: " + viewModel.getPatientData());
|
||||
|
||||
initViews();
|
||||
|
||||
clickEvents();
|
||||
@@ -181,7 +179,7 @@ public class LocationFragment extends Fragment implements OnMapReadyCallback,
|
||||
currentLocation = new LatLng(lat, lng);
|
||||
}else{
|
||||
// default current location // washington DC
|
||||
currentLocation = new LatLng(0, 0);
|
||||
currentLocation = new LatLng(40.75796541422796, -73.98557368665934);
|
||||
}
|
||||
|
||||
if (patientData.address_line1 != null){
|
||||
|
||||
Reference in New Issue
Block a user