From 1a2840b33fb2e28a97a29e1372da6b1514fa9497 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 29 Feb 2016 16:10:46 +0100 Subject: [PATCH] made ui handle missing information on search --- .../newpipe/VideoInfoItemViewCreator.java | 33 ++++++++++++++++--- .../newpipe/VideoItemDetailFragment.java | 4 +-- .../org/schabi/newpipe/VideoListAdapter.java | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java index 0c909e325..b9dbebea8 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItemViewCreator.java @@ -41,8 +41,10 @@ class VideoInfoItemViewCreator { this.inflater = inflater; } - public View getViewFromVideoInfoItem(View convertView, ViewGroup parent, StreamPreviewInfo info, Context context) { + public View getViewFromVideoInfoItem(View convertView, ViewGroup parent, StreamPreviewInfo info) { ViewHolder holder; + + // generate holder if(convertView == null) { convertView = inflater.inflate(R.layout.video_item, parent, false); holder = new ViewHolder(); @@ -57,20 +59,41 @@ class VideoInfoItemViewCreator { holder = (ViewHolder) convertView.getTag(); } + // fill with information + + /* if(info.thumbnail == null) { holder.itemThumbnailView.setImageResource(R.drawable.dummy_thumbnail); } else { holder.itemThumbnailView.setImageBitmap(info.thumbnail); } + */ holder.itemVideoTitleView.setText(info.title); - holder.itemUploaderView.setText(info.uploader); - holder.itemDurationView.setText(info.duration); - holder.itemViewCountView.setText(shortViewCount(info.view_count)); + if(info.uploader != null && !info.uploader.isEmpty()) { + holder.itemUploaderView.setText(info.uploader); + } else { + holder.itemDurationView.setVisibility(View.INVISIBLE); + } + if(info.duration != null && !info.duration.isEmpty()) { + holder.itemDurationView.setText(info.duration); + } else { + holder.itemDurationView.setVisibility(View.GONE); + } + if(info.view_count >= 0) { + holder.itemViewCountView.setText(shortViewCount(info.view_count)); + } else { + holder.itemViewCountView.setVisibility(View.GONE); + } if(!info.upload_date.isEmpty()) { holder.itemUploadDateView.setText(info.upload_date+" • "); } - imageLoader.displayImage(info.thumbnail_url, holder.itemThumbnailView, displayImageOptions); + if(info.thumbnail_url != null && !info.thumbnail_url.isEmpty()) { + imageLoader.displayImage(info.thumbnail_url, holder.itemThumbnailView, displayImageOptions); + } else { + holder.itemThumbnailView.setImageResource(R.drawable.dummy_thumbnail); + } + return convertView; } diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 50e0aeaba..d86b195de 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -290,7 +290,7 @@ public class VideoItemDetailFragment extends Fragment { View nextVideoView = null; if(info.next_video != null) { nextVideoView = videoItemViewCreator - .getViewFromVideoInfoItem(null, nextVideoFrame, info.next_video, getContext()); + .getViewFromVideoInfoItem(null, nextVideoFrame, info.next_video); } else { activity.findViewById(R.id.detailNextVidButtonAndContentLayout).setVisibility(View.GONE); activity.findViewById(R.id.detailNextVideoTitle).setVisibility(View.GONE); @@ -672,7 +672,7 @@ public class VideoItemDetailFragment extends Fragment { ArrayList similar = new ArrayList<>(info.related_videos); for (final StreamPreviewInfo item : similar) { View similarView = videoItemViewCreator - .getViewFromVideoInfoItem(null, similarLayout, item, getContext()); + .getViewFromVideoInfoItem(null, similarLayout, item); similarView.setClickable(true); similarView.setFocusable(true); diff --git a/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java b/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java index 06dab38b4..d69b842cf 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/VideoListAdapter.java @@ -78,7 +78,7 @@ class VideoListAdapter extends BaseAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { - convertView = viewCreator.getViewFromVideoInfoItem(convertView, parent, videoList.get(position), context); + convertView = viewCreator.getViewFromVideoInfoItem(convertView, parent, videoList.get(position)); if(listView.isItemChecked(position)) { convertView.setBackgroundColor(ContextCompat.getColor(context,R.color.light_youtube_primary_color));