Пример #1
0
        void initRecycler()
        {
            adapter = new BaseRecyclerViewAdapter <QuestionModel>(this.Activity, listQuestion, Resource.Layout.item_recyclerview_question, LoadMore);
            _recyclerView.SetAdapter(adapter);
            adapter.ItemClick += (position, tag) =>
            {
                System.Diagnostics.Debug.Write(position, tag);
                //AlertUtil.ToastShort(this.Activity, tag);
                QuestionActivity.Enter(Activity, int.Parse(tag));
            };
            adapter.ItemLongClick += (tag, position) =>
            {
                //AlertUtil.ToastShort(this.Activity, tag);
            };
            string read   = Resources.GetString(Resource.String.read);
            string answer = Resources.GetString(Resource.String.answer);

            try
            {
                adapter.OnConvertView += (holder, position) =>
                {
                    var model = listQuestion[position];
                    holder.SetText(Resource.Id.tv_dateAdded, model.DateAdded.ToCommonString());
                    holder.SetText(Resource.Id.tv_title, model.Title);
                    //holder.SetText(Resource.Id.tv_summary, model.Summary);
                    //holder.SetText(Resource.Id.tv_viewCount, read + " " + model.ViewCount.ToString());
                    holder.SetText(Resource.Id.tv_answerCount, model.AnswerCount.ToString());
                    holder.SetText(Resource.Id.tv_awardCount, model.Award.ToString());
                    TextView tv_tags = (holder.GetView <TextView>(Resource.Id.tv_tags));
                    if (!string.IsNullOrEmpty(model.Tags))
                    {
                        tv_tags.Visibility = ViewStates.Visible;
                        tv_tags.Text       = model.Tags.Replace(',', ' ');
                    }
                    else
                    {
                        tv_tags.Visibility = ViewStates.Gone;
                    }
                    if (model.QuestionUserInfo != null && model.QuestionUserInfo.UserID > 0)
                    {
                        holder.SetText(Resource.Id.tv_userName, model.QuestionUserInfo.UserName);
                        holder.SetImageLoader(Resource.Id.iv_avatar, options, Constact.CnblogsPic + model.QuestionUserInfo.IconName);
                    }
                    holder.GetView <CardView>(Resource.Id.ly_item).Tag = model.Qid.ToString();
                    //holder.SetTag(Resource.Id.ly_item, model.Qid.ToString());
                };
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.ToString());
            }
        }
Пример #2
0
        async void initRecycler()
        {
            adapter = new BaseRecyclerViewAdapter <ZzkDocumentViewModel>(this, searchList, Resource.Layout.item_recyclerview_search, LoadMore);
            _recyclerView.SetAdapter(adapter);
            adapter.ItemClick += (position, tag) =>
            {
                var tempModel = searchList[position];
                tempModel.Title = tempModel.Title.Replace("<strong>", "").Replace("</strong>", "");
                switch (category)
                {
                case "Blog":
                    string  tempstr = tempModel.Uri.Replace("http://www.cnblogs.com/", "");
                    string  blogApp = tempstr.Substring(0, tempstr.IndexOf("/"));
                    Article article = new Article()
                    {
                        Id = int.Parse(tempModel.Id), Avatar = "", BlogApp = blogApp, Title = tempModel.Title, Author = tempModel.UserName, Url = tempModel.Uri, PostDate = tempModel.PublishTime, CommentCount = tempModel.CommentTimes, ViewCount = tempModel.ViewTimes, Diggcount = tempModel.VoteTimes
                    };
                    DetailBlogActivity.Enter(this, int.Parse(tag), article);
                    break;

                case "News":
                    NewsViewModel news = new NewsViewModel()
                    {
                        Id = int.Parse(tempModel.Id), Title = tempModel.Title, ViewCount = tempModel.ViewTimes, CommentCount = tempModel.CommentTimes, DiggCount = tempModel.VoteTimes, DateAdded = tempModel.PublishTime
                    };
                    DetailNewsActivity.Enter(this, int.Parse(tag), news);
                    break;

                case "Question":
                    QuestionActivity.Enter(this, int.Parse(tag), true);
                    break;

                case "Kb":
                    KbArticles kb = new KbArticles()
                    {
                        Id = int.Parse(tempModel.Id), Title = tempModel.Title, ViewCount = tempModel.ViewTimes, DateAdded = tempModel.PublishTime, Author = tempModel.UserName
                    };
                    DetailKbArticlesActivity.Enter(this, int.Parse(tag), kb);
                    break;

                default:
                    break;
                }
            };
            adapter.ItemLongClick += (tag, position) =>
            {
                AlertUtil.ToastShort(this, tag);
            };
            string read    = Resources.GetString(Resource.String.read);
            string comment = Resources.GetString(Resource.String.comment);
            string digg    = Resources.GetString(Resource.String.digg);

            adapter.OnConvertView += (holder, position) =>
            {
                var tempModel = searchList[position];
                if (tempModel.Id == null && !string.IsNullOrEmpty(tempModel.Uri))//问答id返回的是null,自己正则获取
                {
                    Regex regex = new Regex("\\d");
                    tempModel.Id = regex.Match(tempModel.Uri).Value;
                }
                //holder.SetText(Resource.Id.tv_dateAdded, tempModel.PublishTime.ToCommonString());
                holder.SetText(Resource.Id.tv_viewCount, tempModel.ViewTimes + " " + read);
                holder.SetText(Resource.Id.tv_commentCount, tempModel.CommentTimes + " " + comment);
                holder.SetText(Resource.Id.tv_diggCount, tempModel.VoteTimes + " " + digg);
                holder.SetText(Resource.Id.tv_url, tempModel.Uri);
                holder.SetText(Resource.Id.tv_author, tempModel.UserName);

                holder.GetView <LinearLayout>(Resource.Id.ly_item).Tag          = tempModel.Id.ToString();
                (holder.GetView <TextView>(Resource.Id.tv_title)).TextFormatted = Html.FromHtml(tempModel.Title.replaceStrongToFont());
                string tempstr = "<font color='#707070'>" + tempModel.PublishTime.ToString("yyyy年MM月dd日 HH:mm") + "</font>  " + tempModel.Content.replaceStrongToFont();
                (holder.GetView <TextView>(Resource.Id.tv_summary)).TextFormatted = Html.FromHtml(tempstr);
            };
        }