public static RequestOptions GetRequestOptions(ImageStyle style, ImagePlaceholders imagePlaceholders)
        {
            try
            {
                var options = new RequestOptions();


                switch (style)
                {
                case ImageStyle.CenterCrop:
                    options.CenterCrop();
                    break;

                case ImageStyle.FitCenter:
                    options.FitCenter();
                    break;

                case ImageStyle.CircleCrop:
                    options.CircleCrop();
                    break;

                case ImageStyle.CircleCropWithBorder:
                    options.CircleCrop();
                    options.Transform(new GlideCircleWithBorder(2, Color.White));
                    break;

                case ImageStyle.RoundedCrop:
                    options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(20)));
                    break;

                default:
                    options.CenterCrop();
                    break;
                }


                switch (imagePlaceholders)
                {
                case ImagePlaceholders.Color:
                    var color = Methods.FunString.RandomColor();
                    options.Placeholder(new ColorDrawable(Color.ParseColor(color))).Fallback(new ColorDrawable(Color.ParseColor(color)));
                    break;

                case ImagePlaceholders.Drawable:
                    options.Placeholder(Resource.Drawable.ImagePlacholder).Fallback(Resource.Drawable.ImagePlacholder);
                    break;
                }

                return(options);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(new RequestOptions());
            }
        }
Пример #2
0
        public static RequestOptions GetRequestOptions(ImageStyle style, ImagePlaceholders imagePlaceholders)
        {
            try
            {
                var options = new RequestOptions();


                switch (style)
                {
                case ImageStyle.CenterCrop:
                    options.CenterCrop();
                    break;

                case ImageStyle.FitCenter:
                    options.FitCenter();
                    break;

                case ImageStyle.CircleCrop:
                    options.CircleCrop();
                    break;

                case ImageStyle.RoundedCrop:
                    options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(25)))
                    .SetPriority(Priority.High).Override(450)
                    .SetUseAnimationPool(false).SetDiskCacheStrategy(DiskCacheStrategy.All)
                    .Error(Resource.Drawable.ImagePlacholder_circle)
                    .Placeholder(Resource.Drawable.ImagePlacholder_circle);
                    break;

                default:
                    options.CenterCrop();
                    break;
                }


                switch (imagePlaceholders)
                {
                case ImagePlaceholders.Color:
                    var color = Methods.FunString.RandomColor();
                    options.Placeholder(new ColorDrawable(Color.ParseColor(color))).Fallback(new ColorDrawable(Color.ParseColor(color)));
                    break;

                case ImagePlaceholders.Drawable:
                    options.Placeholder(Resource.Drawable.ImagePlacholder).Fallback(Resource.Drawable.ImagePlacholder);
                    break;
                }

                return(options);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new RequestOptions());
            }
        }
        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            try
            {
                var item = SocialList[viewHolder.AdapterPosition];
                if (item != null)
                {
                    switch (item.TypeView)
                    {
                    case SocialModelType.MangedGroups:
                    {
                        switch (viewHolder)
                        {
                        case AdapterHolders.GroupsSocialViewHolder holder:
                        {
                            switch (GroupsAdapter)
                            {
                            case null:
                                holder.GroupsRecyclerView?.SetLayoutManager(new LinearLayoutManager(ActivityContext, LinearLayoutManager.Horizontal, false));
                                GroupsAdapter = new UserGroupsAdapter(ActivityContext)
                                {
                                    GroupList = new ObservableCollection <GroupClass>()
                                };
                                holder.GroupsRecyclerView?.SetAdapter(GroupsAdapter);
                                GroupsAdapter.ItemClick += GroupsAdapterOnItemClick;
                                break;
                            }

                            var countList = item.MangedGroupsModel.GroupsList.Count;
                            switch (item.MangedGroupsModel.GroupsList.Count)
                            {
                            case > 0 when countList > 0:
                            {
                                foreach (var user in from user in item.MangedGroupsModel.GroupsList let check = GroupsAdapter.GroupList.FirstOrDefault(a => a.GroupId == user.GroupId) where check == null select user)
                                {
                                    GroupsAdapter.GroupList.Add(user);
                                }

                                GroupsAdapter.NotifyItemRangeInserted(countList - 1, GroupsAdapter.GroupList.Count - countList);
                                break;
                            }

                            case > 0:
                                GroupsAdapter.GroupList = new ObservableCollection <GroupClass>(item.MangedGroupsModel.GroupsList);
                                GroupsAdapter.NotifyDataSetChanged();
                                break;
                            }

                            holder.AboutHead.Text       = item.MangedGroupsModel?.TitleHead;
                            holder.AboutMore.Text       = item.MangedGroupsModel?.More;
                            holder.AboutMore.Visibility = GroupsAdapter?.GroupList?.Count >= 5 ? ViewStates.Visible : ViewStates.Invisible;
                            break;
                        }
                        }

                        break;
                    }

                    case SocialModelType.JoinedGroups:
                    {
                        switch (viewHolder)
                        {
                        case GroupsAdapterViewHolder holder:
                        {
                            var options = new RequestOptions();
                            options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(110)));
                            options.Error(Resource.Drawable.ImagePlacholder).Placeholder(Resource.Drawable.ImagePlacholder);

                            GlideImageLoader.LoadImage(ActivityContext, item.GroupData.Avatar, holder.Image, ImageStyle.CenterCrop, ImagePlaceholders.Drawable, false, options);

                            holder.Name.Text = Methods.FunString.DecodeString(item.GroupData.Name);

                            if (WoWonderTools.IsJoinedGroup(item.GroupData))
                            {
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Joined);
                                holder.JoinButton.Tag  = "true";
                            }
                            else
                            {
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Join_Group);
                                holder.JoinButton.Tag  = "false";
                            }

                            break;
                        }
                        }

                        break;
                    }

                    case SocialModelType.Section:
                    {
                        if (viewHolder is not AdapterHolders.SectionViewHolder holder)
                        {
                            return;
                        }

                        holder.AboutHead.Text = item.TitleHead;
                        break;
                    }

                    case SocialModelType.MangedPages:
                    {
                        switch (viewHolder)
                        {
                        case AdapterHolders.PagesSocialViewHolder holder:
                        {
                            switch (PagesAdapter)
                            {
                            case null:
                                holder.PagesRecyclerView?.SetLayoutManager(new LinearLayoutManager(ActivityContext, LinearLayoutManager.Horizontal, false));
                                PagesAdapter = new UserPagesAdapter(ActivityContext)
                                {
                                    PageList = new ObservableCollection <PageClass>()
                                };
                                holder.PagesRecyclerView?.SetAdapter(PagesAdapter);
                                PagesAdapter.ItemClick += PagesAdapterOnItemClick;
                                break;
                            }

                            var countList = item.PagesModelClass.PagesList.Count;
                            switch (item.PagesModelClass.PagesList.Count)
                            {
                            case > 0 when countList > 0:
                            {
                                foreach (var user in from user in item.PagesModelClass.PagesList let check = PagesAdapter.PageList.FirstOrDefault(a => a.PageId == user.PageId) where check == null select user)
                                {
                                    PagesAdapter.PageList.Add(user);
                                }

                                PagesAdapter.NotifyItemRangeInserted(countList - 1, PagesAdapter.PageList.Count - countList);
                                break;
                            }

                            case > 0:
                                PagesAdapter.PageList = new ObservableCollection <PageClass>(item.PagesModelClass.PagesList);
                                PagesAdapter.NotifyDataSetChanged();
                                break;
                            }

                            holder.AboutHead.Text       = item.PagesModelClass?.TitleHead;
                            holder.AboutMore.Text       = item.PagesModelClass?.More;
                            holder.AboutMore.Visibility = PagesAdapter?.PageList?.Count >= 5 ? ViewStates.Visible : ViewStates.Invisible;
                            break;
                        }
                        }

                        break;
                    }

                    case SocialModelType.LikedPages:
                    {
                        switch (viewHolder)
                        {
                        case PageAdapterViewHolder holder:
                        {
                            GlideImageLoader.LoadImage(ActivityContext, item.PageData.Avatar, holder.Image, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);

                            holder.About.Text = item.PageData.Category;

                            if (!string.IsNullOrEmpty(item.PageData.PageTitle) || !string.IsNullOrWhiteSpace(item.PageData.PageTitle))
                            {
                                holder.Name.Text = Methods.FunString.SubStringCutOf(Methods.FunString.DecodeString(item.PageData.PageTitle), 20);
                            }
                            else
                            {
                                holder.Name.Text = Methods.FunString.SubStringCutOf(Methods.FunString.DecodeString(item.PageData.PageName), 20);
                            }

                            //Set style Btn Like page
                            if (WoWonderTools.IsLikedPage(item.PageData))
                            {
                                holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends_pressed);
                                holder.Button.SetTextColor(Color.ParseColor("#ffffff"));
                                holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Unlike);
                                holder.Button.Tag  = "true";
                            }
                            else
                            {
                                holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends);
                                holder.Button.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                                holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                                holder.Button.Tag  = "false";
                            }

                            break;
                        }
                        }

                        break;
                    }

                    case SocialModelType.Pages:
                        break;

                    case SocialModelType.Groups:
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            try
            {
                var item = SocialList[viewHolder.AdapterPosition];
                if (item != null)
                {
                    switch (item.TypeView)
                    {
                    case SocialModelType.MangedGroups:
                    {
                        if (viewHolder is AdapterHolders.GroupsSocialViewHolder holder)
                        {
                            if (holder.GroupsAdapter.GroupList.Count == 0)
                            {
                                holder.GroupsAdapter.GroupList = new ObservableCollection <GroupClass>(item.MangedGroupsModel.GroupsList);
                                holder.GroupsAdapter.NotifyDataSetChanged();
                            }
                            else if (item.MangedGroupsModel?.GroupsList != null && holder.GroupsAdapter.GroupList.Count != item.MangedGroupsModel.GroupsList.Count)
                            {
                                holder.GroupsAdapter.GroupList = new ObservableCollection <GroupClass>(item.MangedGroupsModel.GroupsList);
                                holder.GroupsAdapter.NotifyDataSetChanged();
                            }

                            if (!string.IsNullOrEmpty(item.MangedGroupsModel?.TitleHead))
                            {
                                holder.AboutHead.Text = item.MangedGroupsModel?.TitleHead;
                            }

                            holder.AboutMore.Text = item.MangedGroupsModel?.More;

                            if (holder.GroupsAdapter?.GroupList?.Count >= 5)
                            {
                                holder.AboutMore.Visibility     = ViewStates.Visible;
                                holder.AboutMoreIcon.Visibility = ViewStates.Visible;
                            }
                            else
                            {
                                holder.AboutMore.Visibility     = ViewStates.Invisible;
                                holder.AboutMoreIcon.Visibility = ViewStates.Invisible;
                            }

                            if (!holder.AboutMore.HasOnClickListeners)
                            {
                                holder.AboutMore.Click     += (sender, args) => { OpenAllViewer("MangedGroupsModel", item); };
                                holder.AboutMoreIcon.Click += (sender, args) => { OpenAllViewer("MangedGroupsModel", item); };
                            }
                        }

                        break;
                    }

                    case SocialModelType.JoinedGroups:
                    {
                        if (viewHolder is GroupsAdapterViewHolder holder)
                        {
                            var options = new RequestOptions();
                            options.Transform(new MultiTransformation(new CenterCrop(), new RoundedCorners(110)));
                            options.Error(Resource.Drawable.ImagePlacholder).Placeholder(Resource.Drawable.ImagePlacholder);

                            GlideImageLoader.LoadImage(ActivityContext, item.GroupData.Avatar, holder.Image, ImageStyle.CenterCrop, ImagePlaceholders.Drawable, false, options);

                            if (!string.IsNullOrEmpty(item.GroupData.GroupTitle) || !string.IsNullOrWhiteSpace(item.GroupData.GroupTitle))
                            {
                                holder.Name.Text = Methods.FunString.DecodeString(item.GroupData.GroupName);
                            }
                            else
                            {
                                holder.Name.Text = Methods.FunString.DecodeString(item.GroupData.GroupName);
                            }

                            if (item.GroupData.IsJoined == "true" || item.GroupData.IsJoined == "yes")
                            {
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Joined);
                                holder.JoinButton.Tag  = "true";
                            }
                            else
                            {
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Join_Group);
                                holder.JoinButton.Tag  = "false";
                            }

                            if (!holder.JoinButton.HasOnClickListeners)
                            {
                                holder.JoinButton.Click += (sender, args) =>
                                {
                                    try
                                    {
                                        if (!Methods.CheckConnectivity())
                                        {
                                            Toast.MakeText(ActivityContext, ActivityContext.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                                            return;
                                        }

                                        if (holder.JoinButton.Tag.ToString() == "false")
                                        {
                                            holder.JoinButton.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                                            holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Joined);
                                            holder.JoinButton.Tag  = "true";
                                        }
                                        else
                                        {
                                            holder.JoinButton.SetTextColor(Color.Black);
                                            holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Join_Group);
                                            holder.JoinButton.Tag  = "false";
                                        }

                                        PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                                () => RequestsAsync.Group.Join_Group(item.GroupData.GroupId)
                                            });
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                };
                            }
                        }

                        break;
                    }

                    case SocialModelType.Section:
                    {
                        if (!(viewHolder is AdapterHolders.SectionViewHolder holder))
                        {
                            return;
                        }

                        holder.AboutHead.Text = item.TitleHead;
                        if (string.IsNullOrEmpty(item.MoreIcon))
                        {
                            holder.AboutMoreIcon.Text = item.MoreIcon;
                        }
                        break;
                    }

                    case SocialModelType.MangedPages:
                    {
                        if (viewHolder is AdapterHolders.PagesSocialViewHolder holder)
                        {
                            if (holder.PagesAdapter.UserPagesList.Count == 0)
                            {
                                holder.PagesAdapter.UserPagesList = new ObservableCollection <PageClass>(item.PagesModelClass.PagesList);
                                holder.PagesAdapter.NotifyDataSetChanged();
                            }
                            else if (item.PagesModelClass?.PagesList != null && holder.PagesAdapter.UserPagesList.Count != item.PagesModelClass.PagesList.Count)
                            {
                                holder.PagesAdapter.UserPagesList = new ObservableCollection <PageClass>(item.PagesModelClass.PagesList);
                                holder.PagesAdapter.NotifyDataSetChanged();
                            }

                            if (!string.IsNullOrEmpty(item.PagesModelClass?.TitleHead))
                            {
                                holder.AboutHead.Text = item.PagesModelClass?.TitleHead;
                            }

                            holder.AboutMore.Text = item.PagesModelClass?.More;

                            if (holder.PagesAdapter?.UserPagesList?.Count >= 5)
                            {
                                holder.AboutMore.Visibility     = ViewStates.Visible;
                                holder.AboutMoreIcon.Visibility = ViewStates.Visible;
                            }
                            else
                            {
                                holder.AboutMore.Visibility     = ViewStates.Invisible;
                                holder.AboutMoreIcon.Visibility = ViewStates.Invisible;
                            }

                            if (!holder.AboutMore.HasOnClickListeners)
                            {
                                holder.AboutMore.Click     += (sender, args) => { OpenAllViewer("MangedPagesModel", item); };
                                holder.AboutMoreIcon.Click += (sender, args) => { OpenAllViewer("MangedPagesModel", item); };
                            }
                        }

                        break;
                    }

                    case SocialModelType.LikedPages:
                    {
                        if (viewHolder is PageAdapterViewHolder holder)
                        {
                            GlideImageLoader.LoadImage(ActivityContext, item.PageData.Avatar, holder.Image, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);

                            holder.About.Text = item.PageData.Category;

                            if (!string.IsNullOrEmpty(item.PageData.PageTitle) || !string.IsNullOrWhiteSpace(item.PageData.PageTitle))
                            {
                                holder.Name.Text = Methods.FunString.SubStringCutOf(Methods.FunString.DecodeString(item.PageData.PageTitle), 14);
                            }
                            else
                            {
                                holder.Name.Text = Methods.FunString.SubStringCutOf(Methods.FunString.DecodeString(item.PageData.PageName), 14);
                            }

                            //Set style Btn Like page
                            if (item.PageData.IsLiked == "true" || item.PageData.IsLiked == "yes")
                            {
                                holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends_pressed);
                                holder.Button.SetTextColor(Color.ParseColor("#ffffff"));
                                holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Unlike);
                                holder.Button.Tag  = "true";
                            }
                            else
                            {
                                holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends);
                                holder.Button.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                                holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                                holder.Button.Tag  = "false";
                            }

                            if (!holder.Button.HasOnClickListeners)
                            {
                                holder.Button.Click += (sender, args) =>
                                {
                                    try
                                    {
                                        if (!Methods.CheckConnectivity())
                                        {
                                            Toast.MakeText(ActivityContext, ActivityContext.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                                            return;
                                        }

                                        if (holder.Button.Tag.ToString() == "false")
                                        {
                                            holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends_pressed);
                                            holder.Button.SetTextColor(Color.ParseColor("#ffffff"));
                                            holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Unlike);
                                            holder.Button.Tag  = "true";
                                        }
                                        else
                                        {
                                            holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends);
                                            holder.Button.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                                            holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                                            holder.Button.Tag  = "false";
                                        }
                                        PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                                () => RequestsAsync.Page.Like_Page(item.PageData.PageId)
                                            });
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                };
                            }
                        }

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