Beispiel #1
0
        private void Initialize(SearchGroupAdapterViewHolder holder, GroupClass item)
        {
            try
            {
                GlideImageLoader.LoadImage(ActivityContext, item.Avatar, holder.Image, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);

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

                CategoriesController cat = new CategoriesController();
                holder.About.Text = cat.Get_Translate_Categories_Communities(item.CategoryId, item.Category, "Group");

                //var drawable = TextDrawable.InvokeBuilder().BeginConfig().FontSize(30).EndConfig().BuildRound("", Color.ParseColor("#1A237E"));

                if (item.IsOwner != null && item.IsOwner.Value || item.UserId == UserDetails.UserId)
                {
                    holder.Button.Visibility = ViewStates.Gone;
                }
                else
                {
                    //Set style Btn Joined Group
                    if (WoWonderTools.IsJoinedGroup(item))
                    {
                        holder.Button.SetBackgroundResource(Resource.Drawable.follow_button_profile_friends_pressed);
                        holder.Button.SetTextColor(Color.ParseColor("#ffffff"));
                        holder.Button.Text = ActivityContext.GetText(Resource.String.Btn_Joined);
                        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_Join_Group);
                        holder.Button.Tag  = "false";
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            try
            {
                switch (viewHolder)
                {
                case SuggestedGroupAdapterViewHolder holder:
                {
                    var item = GroupList[position];
                    if (item != null)
                    {
                        GlideImageLoader.LoadImage(ActivityContext, item.Cover, holder.Image, ImageStyle.CenterCrop, ImagePlaceholders.Drawable);

                        holder.Name.Text         = Methods.FunString.DecodeString(item.GroupName);
                        holder.CountMembers.Text = Methods.FunString.FormatPriceValue(item.Members) + " " + ActivityContext.GetString(Resource.String.Lbl_Members);

                        if (item.IsOwner != null && item.IsOwner.Value || item.UserId == UserDetails.UserId)
                        {
                            holder.JoinButton.Visibility = ViewStates.Gone;
                        }
                        else
                        {
                            if (WoWonderTools.IsJoinedGroup(item))
                            {
                                holder.JoinButton.SetBackgroundResource(Resource.Drawable.buttonFlatGray);
                                holder.JoinButton.SetTextColor(Color.White);
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Joined);
                                holder.JoinButton.Tag  = "true";
                            }
                            else
                            {
                                holder.JoinButton.SetBackgroundResource(Resource.Drawable.buttonFlat);
                                holder.JoinButton.SetTextColor(Color.White);
                                holder.JoinButton.Text = ActivityContext.GetString(Resource.String.Btn_Join_Group);
                                holder.JoinButton.Tag  = "false";
                            }
                        }
                    }

                    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:
                    {
                        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);
            }
        }