2017-09-03 08:04:18 +02:00
|
|
|
package org.schabi.newpipe.info_list.holder;
|
|
|
|
|
|
|
|
import android.support.v4.content.ContextCompat;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.R;
|
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
|
|
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
2018-03-16 04:07:20 +01:00
|
|
|
import org.schabi.newpipe.util.ImageDisplayConstants;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.Localization;
|
|
|
|
|
|
|
|
public class StreamMiniInfoItemHolder extends InfoItemHolder {
|
|
|
|
|
|
|
|
public final ImageView itemThumbnailView;
|
|
|
|
public final TextView itemVideoTitleView;
|
|
|
|
public final TextView itemUploaderView;
|
|
|
|
public final TextView itemDurationView;
|
|
|
|
|
|
|
|
StreamMiniInfoItemHolder(InfoItemBuilder infoItemBuilder, int layoutId, ViewGroup parent) {
|
|
|
|
super(infoItemBuilder, layoutId, parent);
|
|
|
|
|
|
|
|
itemThumbnailView = itemView.findViewById(R.id.itemThumbnailView);
|
|
|
|
itemVideoTitleView = itemView.findViewById(R.id.itemVideoTitleView);
|
|
|
|
itemUploaderView = itemView.findViewById(R.id.itemUploaderView);
|
|
|
|
itemDurationView = itemView.findViewById(R.id.itemDurationView);
|
|
|
|
}
|
|
|
|
|
|
|
|
public StreamMiniInfoItemHolder(InfoItemBuilder infoItemBuilder, ViewGroup parent) {
|
|
|
|
this(infoItemBuilder, R.layout.list_stream_mini_item, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFromItem(final InfoItem infoItem) {
|
|
|
|
if (!(infoItem instanceof StreamInfoItem)) return;
|
|
|
|
final StreamInfoItem item = (StreamInfoItem) infoItem;
|
|
|
|
|
2017-12-08 15:05:08 +01:00
|
|
|
itemVideoTitleView.setText(item.getName());
|
2018-03-18 16:37:49 +01:00
|
|
|
itemUploaderView.setText(item.getUploaderName());
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2018-03-18 16:37:49 +01:00
|
|
|
if (item.getDuration() > 0) {
|
|
|
|
itemDurationView.setText(Localization.getDurationString(item.getDuration()));
|
|
|
|
itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(),
|
|
|
|
R.color.duration_background_color));
|
2017-09-03 08:04:18 +02:00
|
|
|
itemDurationView.setVisibility(View.VISIBLE);
|
2018-03-18 16:37:49 +01:00
|
|
|
} else if (item.getStreamType() == StreamType.LIVE_STREAM) {
|
2017-09-03 08:04:18 +02:00
|
|
|
itemDurationView.setText(R.string.duration_live);
|
2018-03-18 16:37:49 +01:00
|
|
|
itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(),
|
|
|
|
R.color.live_duration_background_color));
|
2017-09-03 08:04:18 +02:00
|
|
|
itemDurationView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
itemDurationView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default thumbnail is shown on error, while loading and if the url is empty
|
|
|
|
itemBuilder.getImageLoader()
|
2018-03-18 16:37:49 +01:00
|
|
|
.displayImage(item.getThumbnailUrl(),
|
|
|
|
itemThumbnailView,
|
2018-03-16 04:07:20 +01:00
|
|
|
ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS);
|
2017-09-03 08:04:18 +02:00
|
|
|
|
2018-02-26 05:12:20 +01:00
|
|
|
itemView.setOnClickListener(view -> {
|
|
|
|
if (itemBuilder.getOnStreamSelectedListener() != null) {
|
|
|
|
itemBuilder.getOnStreamSelectedListener().selected(item);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
});
|
2017-11-11 23:47:34 +01:00
|
|
|
|
2018-03-18 16:37:49 +01:00
|
|
|
switch (item.getStreamType()) {
|
2017-11-11 23:47:34 +01:00
|
|
|
case AUDIO_STREAM:
|
|
|
|
case VIDEO_STREAM:
|
|
|
|
case LIVE_STREAM:
|
|
|
|
case AUDIO_LIVE_STREAM:
|
2018-02-26 05:12:20 +01:00
|
|
|
enableLongClick(item);
|
|
|
|
break;
|
|
|
|
case FILE:
|
2017-11-11 23:47:34 +01:00
|
|
|
case NONE:
|
|
|
|
default:
|
|
|
|
disableLongClick();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enableLongClick(final StreamInfoItem item) {
|
|
|
|
itemView.setLongClickable(true);
|
2018-02-26 05:12:20 +01:00
|
|
|
itemView.setOnLongClickListener(view -> {
|
|
|
|
if (itemBuilder.getOnStreamSelectedListener() != null) {
|
|
|
|
itemBuilder.getOnStreamSelectedListener().held(item);
|
2017-11-11 23:47:34 +01:00
|
|
|
}
|
2018-02-26 05:12:20 +01:00
|
|
|
return true;
|
2017-11-11 23:47:34 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void disableLongClick() {
|
|
|
|
itemView.setLongClickable(false);
|
|
|
|
itemView.setOnLongClickListener(null);
|
2017-09-03 08:04:18 +02:00
|
|
|
}
|
|
|
|
}
|