fedilab-Android-App/app/src/main/java/app/fedilab/android/drawers/ReactionAdapter.java

82 lines
2.7 KiB
Java
Raw Normal View History

2020-03-10 07:28:55 +01:00
package app.fedilab.android.drawers;
2020-03-10 07:34:24 +01:00
/* Copyright 2020 Thomas Schneider
2020-03-10 07:28:55 +01:00
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2020-03-10 07:34:24 +01:00
import android.widget.LinearLayout;
2020-03-10 07:28:55 +01:00
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import app.fedilab.android.R;
2020-03-10 07:34:24 +01:00
import app.fedilab.android.client.Entities.Reaction;
2020-03-10 07:28:55 +01:00
/**
2020-03-10 07:34:24 +01:00
* Created by Thomas on 10/03/2020.
* Adapter for reactions on messages
2020-03-10 07:28:55 +01:00
*/
2020-03-10 07:34:24 +01:00
public class ReactionAdapter extends RecyclerView.Adapter {
2020-03-10 07:28:55 +01:00
2020-03-10 07:34:24 +01:00
private List<Reaction> reactions;
2020-03-10 07:28:55 +01:00
2020-03-10 07:34:24 +01:00
public ReactionAdapter(List<Reaction> reactions) {
this.reactions = reactions;
2020-03-10 07:28:55 +01:00
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int position) {
2020-03-10 07:34:24 +01:00
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_reaction, parent, false));
2020-03-10 07:28:55 +01:00
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
2020-03-10 07:34:24 +01:00
final Reaction reaction = reactions.get(viewHolder.getAdapterPosition());
2020-03-10 07:28:55 +01:00
ViewHolder holder = (ViewHolder) viewHolder;
2020-03-10 07:34:24 +01:00
holder.reaction_name.setText(reaction.getName());
holder.reaction_count.setText(String.valueOf(reaction.getCount()));
2020-03-10 07:28:55 +01:00
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
2020-03-10 07:34:24 +01:00
return reactions.size();
2020-03-10 07:28:55 +01:00
}
static class ViewHolder extends RecyclerView.ViewHolder {
2020-03-10 07:34:24 +01:00
TextView reaction_name, reaction_count;
LinearLayout reaction_container;
2020-03-10 07:28:55 +01:00
public ViewHolder(@NonNull View itemView) {
super(itemView);
2020-03-10 07:34:24 +01:00
reaction_name = itemView.findViewById(R.id.reaction_name);
reaction_count = itemView.findViewById(R.id.reaction_count);
reaction_container = itemView.findViewById(R.id.reaction_container);
2020-03-10 07:28:55 +01:00
}
}
}