Exemple #1
0
        // Create new views (invoked by the layout manager)
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            try
            {
                View itemView;

                if (viewType == (int)NativeFeedType.Video)
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_VideoFeed, parent, false);
                    Holders.VideoAdapterViewHolder vh = new Holders.VideoAdapterViewHolder(itemView, OnClick, OnLongClick);
                    return(vh);
                }
                else if (viewType == (int)NativeFeedType.Youtube)
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_YoutubeFeed, parent, false);
                    Holders.YoutubeAdapterViewHolder vh = new Holders.YoutubeAdapterViewHolder(itemView, OnClick, OnLongClick);
                    return(vh);
                }
                else if (viewType == (int)NativeFeedType.Gif || viewType == (int)NativeFeedType.Photo)
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_PhotoFeed, parent, false);
                    Holders.PhotoAdapterViewHolder vh = new Holders.PhotoAdapterViewHolder(itemView, OnClick, OnLongClick);
                    return(vh);
                }
                else if (viewType == (int)NativeFeedType.Funding)
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.ViewModel_HRecyclerView, parent, false);
                    Holders.FundingViewHolder vh = new Holders.FundingViewHolder(ActivityContext, itemView);
                    return(vh);
                }
                else if (viewType == (int)NativeFeedType.AdMob)
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostType_AdMob, parent, false);
                    Holders.AdMobAdapterViewHolder vh = new Holders.AdMobAdapterViewHolder(itemView);
                    return(vh);
                }
                else
                {
                    itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_MultiPhotoFeed, parent, false);
                    Holders.MultiPhotoAdapterViewHolder vh = new Holders.MultiPhotoAdapterViewHolder(itemView, OnClick, OnLongClick);
                    return(vh);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(null);
            }
        }
Exemple #2
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            try
            {
                if (position >= 0)
                {
                    int itemViewType = viewHolder.ItemViewType;

                    PostsObject item = PixelNewsFeedList[position];
                    if (item == null)
                    {
                        return;
                    }

                    item.Mp4 = Methods.FunString.StringNullRemover(item.Mp4);

                    switch (itemViewType)
                    {
                    case (int)NativeFeedType.Video:
                    {
                        if (viewHolder is Holders.VideoAdapterViewHolder holder)
                        {
                            if (item.MediaSet.Count > 0)
                            {
                                if (!string.IsNullOrEmpty(item.MediaSet[0]?.Extra))
                                {
                                    FullGlideRequestBuilder.Load(item.MediaSet[0]?.Extra).Into(holder.VideoImage);
                                }
                                else
                                {
                                    var fileName = item.MediaSet[0].File.Split('/').Last();
                                    var fileNameWithoutExtension = fileName.Split('.').First();

                                    item.MediaSet[0].Extra = Methods.Path.FolderDcimImage + "/" + fileNameWithoutExtension + ".png";

                                    var vidoePlaceHolderImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileNameWithoutExtension + ".png");
                                    if (vidoePlaceHolderImage == "File Dont Exists")
                                    {
                                        var bitmapImage = Methods.MultiMedia.Retrieve_VideoFrame_AsBitmap(ActivityContext, item.MediaSet[0]?.File);
                                        if (bitmapImage != null)
                                        {
                                            Methods.MultiMedia.Export_Bitmap_As_Image(bitmapImage, fileNameWithoutExtension, Methods.Path.FolderDcimImage);
                                            FullGlideRequestBuilder.Load(bitmapImage).Into(holder.VideoImage);
                                        }
                                        else
                                        {
                                            Glide.With(ActivityContext)
                                            .AsBitmap()
                                            .Placeholder(Resource.Drawable.blackdefault)
                                            .Error(Resource.Drawable.blackdefault)
                                            .Load(item.MediaSet[0]?.File)         // or URI/path
                                            .Into(holder.VideoImage);             //image view to set thumbnail to
                                        }
                                    }
                                    else
                                    {
                                        FullGlideRequestBuilder.Load(vidoePlaceHolderImage).Into(holder.VideoImage);
                                    }
                                }

                                //GlideImageLoader.LoadImage(ActivityContext, imageUri,holder.VideoImage, ImageStyle.FitCenter, ImagePlaceholders.Color);
                            }

                            holder.MainView.Tag = holder;

                            if (AppSettings.SetTabDarkTheme)
                            {
                                holder.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            SetDataDynamicForViewHolder(holder.ItemView, holder.Username, holder.UserAvatar, holder.Description, holder.Likeicon, holder.Favicon, holder.CommentCount,
                                                        holder.LikeCount, holder.ViewMoreComment, holder.TimeText, holder.Commenticon, holder.Moreicon, holder.ShareIcon, holder.IsPromoted, item);

                            if (!holder.PlayControl.HasOnClickListeners)
                            {
                                holder.PlayControl.Click += (sender, args) =>
                                {
                                    try
                                    {
                                        PRecyclerView.GetInstance()?.PlayVideo(!PRecyclerView.GetInstance().CanScrollVertically(1), holder, item);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                }
                            }
                            ;
                        }

                        break;
                    }

                    case (int)NativeFeedType.Youtube:
                    {
                        if (viewHolder is Holders.YoutubeAdapterViewHolder holder)
                        {
                            if (item.MediaSet.Count > 0)
                            {
                                if (string.IsNullOrEmpty(item.MediaSet[0]?.Extra))
                                {
                                    item.MediaSet[0].Extra = item.MediaSet[0]?.File;
                                }

                                FullGlideRequestBuilder.Load(item.MediaSet[0]?.Extra).Into(holder.VideoThumble);

                                //GlideImageLoader.LoadImage(ActivityContext, item.MediaSet[0]?.Extra, holder.VideoThumble, ImageStyle.FitCenter, ImagePlaceholders.Color);
                            }

                            if (AppSettings.SetTabDarkTheme)
                            {
                                holder.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            SetDataDynamicForViewHolder(holder.ItemView, holder.Username, holder.UserAvatar, holder.Description, holder.Likeicon, holder.Favicon, holder.CommentCount,
                                                        holder.LikeCount, holder.ViewMoreComment, holder.TimeText, holder.Commenticon, holder.Moreicon, holder.ShareIcon, holder.IsPromoted, item);


                            if (!holder.PlayButton.HasOnClickListeners)
                            {
                                holder.PlayButton.Click += (sender, args) =>
                                                           ClickListeners.OnPlayYoutubeButtonClicked(new YoutubeVideoClickEventArgs
                                    {
                                        Holder        = holder,
                                        NewsFeedClass = item,
                                        Position      = position,
                                        View          = holder.MainView
                                    });
                            }
                        }

                        break;
                    }

                    case (int)NativeFeedType.Photo:
                    {
                        if (viewHolder is Holders.PhotoAdapterViewHolder holder)
                        {
                            if (item.MediaSet.Count > 0)
                            {
                                if (string.IsNullOrEmpty(item.MediaSet[0]?.Extra))
                                {
                                    item.MediaSet[0].Extra = item.MediaSet[0]?.File;
                                }

                                FullGlideRequestBuilder.Load(item.MediaSet[0]?.File).Into(holder.Image);

                                //GlideImageLoader.LoadImage(ActivityContext, item.MediaSet[0]?.File, holder.Image, ImageStyle.FitCenter, ImagePlaceholders.Color);
                            }

                            if (AppSettings.SetTabDarkTheme)
                            {
                                holder.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            SetDataDynamicForViewHolder(holder.ItemView, holder.Username, holder.UserAvatar, holder.Description, holder.Likeicon, holder.Favicon, holder.CommentCount,
                                                        holder.LikeCount, holder.ViewMoreComment, holder.TimeText, holder.Commenticon, holder.Moreicon, holder.ShareIcon, holder.IsPromoted, item);
                        }

                        break;
                    }

                    case (int)NativeFeedType.Gif:
                    {
                        if (viewHolder is Holders.PhotoAdapterViewHolder holder)
                        {
                            if (AppSettings.SetTabDarkTheme)
                            {
                                holder.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            if (item.MediaSet.Count > 0)
                            {
                                if (string.IsNullOrEmpty(item.MediaSet[0]?.Extra))
                                {
                                    item.MediaSet[0].Extra = item.MediaSet[0]?.File;
                                }

                                FullGlideRequestBuilder.Load(item.MediaSet[0]?.File).Into(holder.Image);

                                //GlideImageLoader.LoadImage(ActivityContext, item.MediaSet[0]?.File,holder.Image, ImageStyle.FitCenter, ImagePlaceholders.Color);
                            }

                            SetDataDynamicForViewHolder(holder.ItemView, holder.Username, holder.UserAvatar, holder.Description, holder.Likeicon, holder.Favicon, holder.CommentCount,
                                                        holder.LikeCount, holder.ViewMoreComment, holder.TimeText, holder.Commenticon, holder.Moreicon, holder.ShareIcon, holder.IsPromoted, item);
                        }

                        break;
                    }

                    case (int)NativeFeedType.MultiPhoto:
                    {
                        if (viewHolder is Holders.MultiPhotoAdapterViewHolder holderMulti)
                        {
                            List <string> list = item.MediaSet.Select(image => image.File).ToList();

                            if (AppSettings.SetTabDarkTheme)
                            {
                                holderMulti.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            holderMulti.ViewPagerLayout.Adapter = new MultiImagePagerAdapter(ActivityContext, list);

                            holderMulti.ViewPagerLayout.CurrentItem = 0;
                            holderMulti.CircleIndicatorView.SetViewPager(holderMulti.ViewPagerLayout);

                            SetDataDynamicForViewHolder(holderMulti.ItemView, holderMulti.Username, holderMulti.UserAvatar, holderMulti.Description, holderMulti.Likeicon, holderMulti.Favicon, holderMulti.CommentCount, holderMulti.LikeCount,
                                                        holderMulti.ViewMoreComment, holderMulti.TimeText, holderMulti.Commenticon, holderMulti.Moreicon, holderMulti.ShareIcon, holderMulti.IsPromoted, item);
                        }

                        break;
                    }

                    case (int)NativeFeedType.Funding:
                    {
                        HolderFunding = viewHolder as Holders.FundingViewHolder;
                        BindFundingModel(HolderFunding, ListUtils.FundingList);
                        break;
                    }

                    case (int)NativeFeedType.AdMob:
                    {
                        Holders.AdMobAdapterViewHolder holder = viewHolder as Holders.AdMobAdapterViewHolder;
                        new Handler(Looper.MainLooper).Post(new Runnable(() =>
                            {
                                BindAdMob(holder);
                            })
                                                            );
                        break;
                    }

                    default:
                    {
                        if (viewHolder is Holders.PhotoAdapterViewHolder holder)
                        {
                            if (AppSettings.SetTabDarkTheme)
                            {
                                holder.MainPost.SetBackgroundResource(Resource.Drawable.Shape_Radius_Black_Btn);
                            }

                            if (item.MediaSet.Count > 0)
                            {
                                if (string.IsNullOrEmpty(item.MediaSet[0]?.Extra))
                                {
                                    item.MediaSet[0].Extra = item.MediaSet[0]?.File;
                                }

                                FullGlideRequestBuilder.Load(item.MediaSet[0]?.File).Into(holder.Image);
                                //GlideImageLoader.LoadImage(ActivityContext, item.MediaSet[0]?.File,holder.Image, ImageStyle.FitCenter, ImagePlaceholders.Color);
                            }

                            SetDataDynamicForViewHolder(holder.ItemView, holder.Username, holder.UserAvatar, holder.Description, holder.Likeicon, holder.Favicon, holder.CommentCount,
                                                        holder.LikeCount, holder.ViewMoreComment, holder.TimeText, holder.Commenticon, holder.Moreicon, holder.ShareIcon, holder.IsPromoted, item);
                        }

                        break;
                    }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }