2018-03-03 01:10:13 +01:00
|
|
|
package net.schueller.peertube.adapter;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-03-04 01:06:32 +01:00
|
|
|
import android.content.Intent;
|
2018-03-03 01:10:13 +01:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2018-03-04 01:06:32 +01:00
|
|
|
import android.util.Log;
|
2018-03-03 01:10:13 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.squareup.picasso.Picasso;
|
|
|
|
|
|
|
|
import net.schueller.peertube.R;
|
2018-03-04 01:06:32 +01:00
|
|
|
import net.schueller.peertube.activity.VideoPlayActivity;
|
2018-03-03 01:10:13 +01:00
|
|
|
import net.schueller.peertube.model.Video;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-03-04 01:06:32 +01:00
|
|
|
import static net.schueller.peertube.activity.VideoListActivity.EXTRA_VIDEOID;
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> {
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<Video> videoList;
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
public VideoAdapter(ArrayList<Video> videoList, Context context) {
|
|
|
|
this.videoList = videoList;
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
@NonNull
|
2018-03-03 01:10:13 +01:00
|
|
|
@Override
|
2018-03-03 02:02:00 +01:00
|
|
|
public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
2018-03-03 01:10:13 +01:00
|
|
|
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
|
|
|
View view = layoutInflater.inflate(R.layout.row_video, parent, false);
|
|
|
|
return new VideoViewHolder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-03 02:02:00 +01:00
|
|
|
public void onBindViewHolder(@NonNull VideoViewHolder holder, int position) {
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
Picasso.with(this.context)
|
|
|
|
.load("https://troll.tv" + videoList.get(position).getPreviewPath())
|
|
|
|
.into(holder.thumb);
|
|
|
|
|
|
|
|
holder.name.setText(videoList.get(position).getName());
|
2018-03-03 23:08:18 +01:00
|
|
|
holder.videoMeta.setText(videoList.get(position).getAccountName()
|
|
|
|
.concat("@")
|
|
|
|
.concat(videoList.get(position).getServerHost()).concat(" - ")
|
|
|
|
.concat(videoList.get(position).getViews()+" Views"));
|
2018-03-04 01:06:32 +01:00
|
|
|
|
|
|
|
holder.mView.setOnClickListener(v -> {
|
|
|
|
|
|
|
|
// Log.v("VideoAdapter", "click: " + videoList.get(position).getName());
|
|
|
|
|
|
|
|
Intent intent = new Intent(context, VideoPlayActivity.class);
|
|
|
|
intent.putExtra(EXTRA_VIDEOID, videoList.get(position).getUuid());
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 02:02:00 +01:00
|
|
|
public void setData(ArrayList<Video> data) {
|
|
|
|
videoList.addAll(data);
|
|
|
|
this.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-03 23:08:18 +01:00
|
|
|
public void clearData() {
|
|
|
|
videoList.clear();
|
|
|
|
this.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:10:13 +01:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return videoList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
class VideoViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
2018-03-03 23:08:18 +01:00
|
|
|
TextView name, videoMeta;
|
2018-03-03 01:10:13 +01:00
|
|
|
ImageView thumb;
|
2018-03-04 01:06:32 +01:00
|
|
|
View mView;
|
2018-03-03 01:10:13 +01:00
|
|
|
|
|
|
|
VideoViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
name = itemView.findViewById(R.id.name);
|
|
|
|
thumb = itemView.findViewById(R.id.thumb);
|
2018-03-03 23:08:18 +01:00
|
|
|
videoMeta = itemView.findViewById(R.id.videoMeta);
|
2018-03-04 01:06:32 +01:00
|
|
|
mView = itemView;
|
2018-03-03 01:10:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|