Example #1
0
 void initRecycler()
 {
     adapter = new BaseRecyclerViewAdapter <NewsViewModel>(this.Activity, newsList, Resource.Layout.item_recyclerview_news, LoadMore);
     _recyclerView.SetAdapter(adapter);
     adapter.ItemClick += (position, tag) =>
     {
         System.Diagnostics.Debug.Write(position, tag);
         //AlertUtil.ToastShort(this.Activity, tag);
         DetailNewsActivity.Enter(Activity, int.Parse(tag));
     };
     adapter.ItemLongClick += (tag, position) =>
     {
         //AlertUtil.ToastShort(this.Activity, tag);
     };
     adapter.OnConvertView += (holder, position) =>
     {
         var model = newsList[position];
         holder.SetText(Resource.Id.tv_description, model.Summary);
         holder.SetText(Resource.Id.tv_title, model.Title);
         holder.SetText(Resource.Id.tv_commentCount, model.CommentCount.ToString());
         holder.SetText(Resource.Id.tv_dateAdded, model.DateAdded.ToCommonString());
         holder.SetText(Resource.Id.tv_diggCount, model.DiggCount.ToString());
         holder.SetText(Resource.Id.tv_viewCount, model.ViewCount.ToString());
         holder.GetView <CardView>(Resource.Id.ly_item).Tag = model.Id.ToString();
         holder.SetImageLoader(Resource.Id.iv_topicIcon, options, model.TopicIcon);
     };
 }
        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);
            };
        }