2016-08-03 00:54:03 +02:00
|
|
|
package org.schabi.newpipe.info_list;
|
2016-08-02 00:58:52 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2017-02-13 00:55:05 +01:00
|
|
|
import android.util.Log;
|
2016-08-02 00:58:52 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
2016-08-02 18:38:05 +02:00
|
|
|
import org.schabi.newpipe.R;
|
2017-02-12 13:33:03 +01:00
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
2016-08-02 00:58:52 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
/**
|
2016-09-12 00:33:11 +02:00
|
|
|
* Created by Christian Schabesberger on 01.08.16.
|
|
|
|
*
|
|
|
|
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
|
|
|
* InfoListAdapter.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe 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.
|
|
|
|
*
|
|
|
|
* NewPipe 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 NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-02 00:58:52 +02:00
|
|
|
*/
|
2016-09-12 00:33:11 +02:00
|
|
|
|
2016-08-03 00:54:03 +02:00
|
|
|
public class InfoListAdapter extends RecyclerView.Adapter<InfoItemHolder> {
|
2017-02-13 00:55:05 +01:00
|
|
|
private static final String TAG = InfoListAdapter.class.toString();
|
2016-08-02 00:58:52 +02:00
|
|
|
|
2017-01-11 11:06:24 +01:00
|
|
|
private final InfoItemBuilder infoItemBuilder;
|
2017-02-13 00:55:05 +01:00
|
|
|
private final List<InfoItem> infoItemList;
|
2016-08-02 00:58:52 +02:00
|
|
|
|
2016-08-03 00:54:03 +02:00
|
|
|
public InfoListAdapter(Activity a, View rootView) {
|
2016-09-26 17:02:55 +02:00
|
|
|
infoItemBuilder = new InfoItemBuilder(a, rootView);
|
2017-02-13 00:55:05 +01:00
|
|
|
infoItemList = new Vector<>();
|
2016-08-02 00:58:52 +02:00
|
|
|
}
|
|
|
|
|
2017-02-13 00:55:05 +01:00
|
|
|
public void setOnStreamItemSelectedListener
|
|
|
|
(InfoItemBuilder.OnInfoItemSelectedListener onItemSelectedListener) {
|
|
|
|
infoItemBuilder.setOnStreamInfoItemSelectedListener(onItemSelectedListener);
|
2016-08-02 20:59:53 +02:00
|
|
|
}
|
|
|
|
|
2017-02-13 00:55:05 +01:00
|
|
|
public void addInfoItemList(List<InfoItem> videos) {
|
2016-09-10 16:26:21 +02:00
|
|
|
if(videos!= null) {
|
2017-02-13 00:55:05 +01:00
|
|
|
infoItemList.addAll(videos);
|
2016-09-10 16:26:21 +02:00
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
2016-08-02 18:38:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 13:09:48 +02:00
|
|
|
public void clearSteamItemList() {
|
2017-02-13 00:55:05 +01:00
|
|
|
infoItemList.clear();
|
2016-08-02 18:38:05 +02:00
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2016-08-02 00:58:52 +02:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2017-02-13 00:55:05 +01:00
|
|
|
return infoItemList.size();
|
2016-08-02 00:58:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-03 00:54:03 +02:00
|
|
|
public InfoItemHolder onCreateViewHolder(ViewGroup parent, int i) {
|
2017-02-13 00:55:05 +01:00
|
|
|
switch(infoItemList.get(i).infoType()) {
|
|
|
|
case STREAM:
|
|
|
|
return new StreamInfoItemHolder(LayoutInflater.from(parent.getContext())
|
|
|
|
.inflate(R.layout.stream_item, parent, false));
|
|
|
|
case CHANNEL:
|
|
|
|
return new ChannelInfoItemHolder(LayoutInflater.from(parent.getContext())
|
|
|
|
.inflate(R.layout.channel_item, parent, false));
|
|
|
|
case PLAYLIST:
|
|
|
|
Log.e(TAG, "Playlist is not yet implemented");
|
|
|
|
return null;
|
|
|
|
default:
|
|
|
|
Log.e(TAG, "Trollolo");
|
|
|
|
return null;
|
|
|
|
}
|
2016-08-02 00:58:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-03 00:54:03 +02:00
|
|
|
public void onBindViewHolder(InfoItemHolder holder, int i) {
|
2017-02-13 00:55:05 +01:00
|
|
|
infoItemBuilder.buildByHolder(holder, infoItemList.get(i));
|
2016-08-02 00:58:52 +02:00
|
|
|
}
|
|
|
|
}
|