87 lines
2.6 KiB
Java
87 lines
2.6 KiB
Java
package app.fedilab.android.peertube.drawer;
|
|
/* Copyright 2020 Thomas Schneider
|
|
*
|
|
* This file is a part of TubeLab
|
|
*
|
|
* 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.
|
|
*
|
|
* TubeLab 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 TubeLab; if not,
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.ViewGroup;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import java.util.List;
|
|
|
|
import app.fedilab.android.peertube.client.MenuItemVideo;
|
|
import app.fedilab.android.peertube.databinding.DrawerMenuBinding;
|
|
|
|
|
|
public class MenuAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
|
|
|
private final List<MenuItemVideo> menuItemVideos;
|
|
public ItemClicked itemClicked;
|
|
|
|
|
|
public MenuAdapter(List<MenuItemVideo> menuItemVideos) {
|
|
this.menuItemVideos = menuItemVideos;
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return menuItemVideos.size();
|
|
}
|
|
|
|
|
|
@NonNull
|
|
@Override
|
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
DrawerMenuBinding itemBinding = DrawerMenuBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
|
return new ViewHolder(itemBinding);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
|
|
|
final ViewHolder holder = (ViewHolder) viewHolder;
|
|
|
|
final MenuItemVideo menuItemVideo = menuItemVideos.get(i);
|
|
|
|
holder.binding.menuIcon.setImageResource(menuItemVideo.getIcon());
|
|
holder.binding.title.setText(menuItemVideo.getTitle());
|
|
holder.binding.itemMenuContainer.setOnClickListener(v -> itemClicked.onItemClicked(menuItemVideo.getAction()));
|
|
|
|
}
|
|
|
|
public interface ItemClicked {
|
|
void onItemClicked(MenuItemVideo.actionType actionType);
|
|
}
|
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
DrawerMenuBinding binding;
|
|
|
|
ViewHolder(DrawerMenuBinding itemView) {
|
|
super(itemView.getRoot());
|
|
binding = itemView;
|
|
}
|
|
|
|
}
|
|
|
|
} |