Commit b9db25b6 authored by 9731301's avatar 9731301

add ArchivedAdaptor

parent 9fedf74e
package com.example.mynotepad.MenuFeatures.AllArchivedNotes.MyArchivedNotesRecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.mynotepad.MenuFeatures.AllNotes.MyNoteRecyclerView.MyNote;
import com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.R;
import java.util.ArrayList;
import java.util.List;
public class MyArchivedAdaptor extends RecyclerView.Adapter<MyArchivedAdaptor.ViewHolder> {
private List<MyNote> notes;
private List<MyDate> dates;
private ArrayList<DateOrNote> dateOrNoteList;
private OnArchivedItemClickListener onArchivedItemClickListener;
public MyArchivedAdaptor(List<MyNote> notes, List<MyDate> dates) {
this.notes = notes;
this.dates = dates;
dateOrNoteList = new ArrayList<>();
setarchivedNotesAndDates();
}
private void setarchivedNotesAndDates() {
setNotes();
setDates();
}
private void setDates() {
for (MyDate myDate : dates) {
if (myDate.isarchived()) {
DateOrNote date = new DateOrNote(myDate.getId(), "date", myDate.getDate(), myDate.getDescription());
dateOrNoteList.add(date);
}
}
}
private void setNotes() {
for (MyNote myNote : notes) {
if (myNote.isarchived()) {
DateOrNote note = new DateOrNote(myNote.getId(), "note", myNote.getTitle(), myNote.getDescription());
dateOrNoteList.add(note);
}
}
}
public void setOnArchivedItemClickListener(OnArchivedItemClickListener onArchivedItemClickListener) {
this.onArchivedItemClickListener = onArchivedItemClickListener;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_allnotes_item, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.titleTV.setText(dateOrNoteList.get(position).getTitle());
holder.descriptionTV.setText(dateOrNoteList.get(position).getDescription());
}
@Override
public int getItemCount() {
return dateOrNoteList.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
protected TextView titleTV, descriptionTV;
protected boolean isarchived;
public ViewHolder(View itemView) {
super(itemView);
titleTV = itemView.findViewById(R.id.titleTv);
descriptionTV = itemView.findViewById(R.id.descriptionTv);
isarchived = false;
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
}
@Override
public void onClick(View view) {
if (onArchivedItemClickListener != null) {
onArchivedItemClickListener.onItemClicked(dateOrNoteList.get(getAdapterPosition()));
}
}
@Override
public boolean onLongClick(View view) {
if (onArchivedItemClickListener != null)
onArchivedItemClickListener.onItemLongClicked(dateOrNoteList.get(getAdapterPosition()));
return true;
}
}
public ArrayList<DateOrNote> getDateOrNoteList() {
return dateOrNoteList;
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#4883B5DD">
</solid>
</shape>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment