I'm making an app where user-input tasks are shown in cardview. Each tasks have their own due dates and when the due date is up, it will show up at the bottom of the list.
In the code below, The due dates are passed via my task object class. After comparing due dates (.getTaskDate) with current date, I should put the overdue task at the bottom here.
Inside my adapter:
//Overdue tasks
String Currdate = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());
if(Currdate.compareTo(tasks.getTaskDate())>0 )
{
taskViewHolder.cardView.setBackgroundColor(mContext.getResources().getColor(R.color.colorRed));
}
How should I implement this feature and is it done inside the MainActivity or my Adapter? I have similar date sorting feature which sorts the date in ascending order inside my MainActivity :
private static void sortDates(final List<TaskObject> listViewItems) {
Collections.sort(listViewItems, new Comparator<TaskObject>() {
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
@Override
public int compare(TaskObject t1, TaskObject t2) {
try {
return dateFormat.parse(t1.getTaskDate()).compareTo(dateFormat.parse(t2.getTaskDate()));
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
}
});
}
