Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
1
Indexable
Never
package com.example.carapp;

import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;

import com.example.carapp.classes.NewDriveClass;
import com.google.android.gms.common.util.concurrent.NumberedThreadFactory;
import com.google.firebase.database.DatabaseReference;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.stream.Collectors;

public class drivesAdapter extends RecyclerView.Adapter<drivesAdapter.MyViewHolder> {

    Context context;
    DatabaseReference reference;
    ArrayList<NewDriveClass> list;


    public drivesAdapter(Context context, ArrayList<NewDriveClass> list) {

        this.context = context;
        this.list = list;

    }



    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.drive_item,parent,false);
        return  new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        NewDriveClass new_drive = list.get(position);
        holder.From.setText(new_drive.getFrom());
        holder.To.setText( new_drive.getTo());
        holder.time.setText(new_drive.getTime());

        if(new_drive.getNumber().equals("ציוד"))
            holder.Number.setText(new_drive.getNumber());
        else
            holder.Number.setText( new_drive.getNumber());

        holder.Notes.setText(new_drive.getNote());

        if(new_drive.getPriority() == 1)
            holder.Priority.setBackgroundResource(R.color.Green);
        if (new_drive.getPriority() == 2)
            holder.Priority.setBackgroundResource(R.color.Yellow);
        if (new_drive.getPriority() == 3)
            holder.Priority.setBackgroundResource(R.color.Red);



    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder{

        TextView From, To, Number, Notes, time;
        ImageView Priority;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);

            From = itemView.findViewById(R.id.FromTV);
            To = itemView.findViewById(R.id.ToTV);
            Number = itemView.findViewById(R.id.NumberTV);
            Notes = itemView.findViewById(R.id.NotesTV);
            Priority = itemView.findViewById(R.id.PriorityColor);
            time = itemView.findViewById(R.id.timeTV);

/*
            name = itemView.findViewById(R.id.soldier_name);
            view_photos = itemView.findViewById(R.id.view_photos);
            dismiss = itemView.findViewById(R.id.dismiss_btn);
            not_dismiss = itemView.findViewById(R.id.notDismiss_btn);
            time = itemView.findViewById(R.id.time_send);

 */

        }
    }
}