I have items to show in android app via recycler view. I have successfully implemented and fetch the data from server. Items are showing in the recycler view list. I have also sorted the newest items in the top of the list. I have done in the backend to sort the newest items in the top of the list by using php code and SQL and successfully done it. But now I want to implement a text that is this:- NEW in the list. Which means it will only show for the newest items and automatically deleted after 5 days.
I have successfully implement the NEW tag in the frontend and it is showing, But The new tag is only showing for the current date. I want to show that "NEW" tag for 5 more days. I put logic but it is not helping me, and it is showing for only for the current date. Here is my code for showing NEW:-
MyAdapter class --> onBindViewHolder()
Json data:-
"creation_date": "2021-09-06"
final String creation_date = ModelClass.getCreation_date(); //JSON data "creation date". getCreation_date() invoking Getter method from model class"
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
String Current_date = sdf.format(c.getTime());
c.add(Calendar.DAY_OF_MONTH, 5); //here I have increase the date to 5
String EndDate = sdf.format(c.getTime());
if (Current_date.equals(creation_date)) {
myViewHolder.creation_date.setVisibility(View.VISIBLE);
}
else if (creation_date.equals(EndDate)) {
myViewHolder.creation_date.setVisibility(View.VISIBLE);
} else {
myViewHolder.creation_date.setVisibility(View.GONE);
}
The main problem is How can I show the NEW tag after the creation date for 5 more days and after 5 days Textview(creation_date) Visibility will be GONE?
right now if my creation date is same with the current date then it is showing the new tag, but I want to show for 5 more days and after 5 days it should deleted.
Right now the Output is showing like this:-
