コード例 #1
0
ファイル: NewsTabFragment.cs プロジェクト: zhanglinx/Cnblogs
        void initRecyclerKbArticles()
        {
            adapterKbArticles = new BaseRecyclerViewAdapter <KbArticles>(this.Activity, kbArticlesList, Resource.Layout.item_recyclerview_kbarticles, LoadMoreKbarticles);
            _recyclerView.SetAdapter(adapterKbArticles);
            adapterKbArticles.ItemClick += (position, tag) =>
            {
                System.Diagnostics.Debug.Write(position, tag);
                //AlertUtil.ToastShort(this.Activity, tag);
                DetailKbArticlesActivity.Enter(Activity, int.Parse(tag));
            };
            adapterKbArticles.ItemLongClick += (tag, position) =>
            {
                //AlertUtil.ToastShort(this.Activity, tag);
            };
            string read = Resources.GetString(Resource.String.read);
            string digg = Resources.GetString(Resource.String.digg);

            adapterKbArticles.OnConvertView += (holder, position) =>
            {
                holder.SetText(Resource.Id.tv_dateAdded, kbArticlesList[position].DateAdded.ToCommonString());
                holder.SetText(Resource.Id.tv_viewCount, kbArticlesList[position].ViewCount + " " + read);
                holder.SetText(Resource.Id.tv_summary, kbArticlesList[position].Summary);
                holder.SetText(Resource.Id.tv_diggCount, kbArticlesList[position].Diggcount + " " + digg);
                holder.SetText(Resource.Id.tv_title, kbArticlesList[position].Title);
                holder.SetText(Resource.Id.tv_author, kbArticlesList[position].Author);
                holder.GetView <CardView>(Resource.Id.ly_item).Tag = kbArticlesList[position].Id.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);
            };
        }