コード例 #1
0
ファイル: PostViewAdapter.cs プロジェクト: takigava/pikabu
 public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
 {
     if (viewType == Resource.Layout.PostTextCard)
     {
         View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostTextCard, parent, false);
         PostTextViewHolder vh = new PostTextViewHolder(row);
         return(vh);
     }
     if (viewType == Resource.Layout.PostImageCard)
     {
         View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostImageCard, parent, false);
         PostImageViewHolder vh = new PostImageViewHolder(row);
         return(vh);
     }
     if (viewType == Resource.Layout.PostMultiImageCard)
     {
         View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostMultiImageCard, parent, false);
         PostMultiImageViewHolder vh = new PostMultiImageViewHolder(row);
         return(vh);
     }
     else
     {
         View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostTextCard, parent, false);
         PostTextViewHolder vh = new PostTextViewHolder(row);
         return(vh);
     }
 }
コード例 #2
0
ファイル: PostViewAdapter.cs プロジェクト: takigava/pikabu
 public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
 {
     if (holder is PostTextViewHolder)
     {
         PostTextViewHolder vh = holder as PostTextViewHolder;
         FillTextPost(vh, position);
     }
     if (holder is PostImageViewHolder)
     {
         PostImageViewHolder vh = holder as PostImageViewHolder;
         FillImagePost(vh, position);
     }
     if (holder is PostMultiImageViewHolder)
     {
         PostMultiImageViewHolder vh = holder as PostMultiImageViewHolder;
         FillMultiImagePost(vh, position);
     }
 }
コード例 #3
0
ファイル: PostViewAdapter.cs プロジェクト: takigava/pikabu
		public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
		{	
			if (viewType == Resource.Layout.PostTextCard) {
				View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostTextCard, parent, false);
				PostTextViewHolder vh = new PostTextViewHolder(row);
				return vh;
			}
			if (viewType == Resource.Layout.PostImageCard) {
				View row = LayoutInflater.From (parent.Context).Inflate (Resource.Layout.PostImageCard, parent, false);
				PostImageViewHolder vh = new PostImageViewHolder (row);
				return vh;
			} 
			if (viewType == Resource.Layout.PostMultiImageCard)
			{
				View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostMultiImageCard, parent, false);
				PostMultiImageViewHolder vh = new PostMultiImageViewHolder(row);
				return vh;
			}
			else {
				View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostTextCard, parent, false);
				PostTextViewHolder vh = new PostTextViewHolder(row);
				return vh;
			}
		}
コード例 #4
0
ファイル: PostViewAdapter.cs プロジェクト: takigava/pikabu
        public void FillTextPost(PostTextViewHolder vh, int position)
        {
            try{
                vh.AuthorName.Text = _Posts[position].AuthorName;
                var context = Android.App.Application.Context;
                vh.HeaderRating.Text = _Posts [position].Rating.ToString();
                vh.BottomRating.Text = _Posts [position].Rating.ToString();
                if (_Posts [position].Rating > 0)
                {
                    vh.HeaderRating.SetTextColor(context.Resources.GetColor(Resource.Color.mainGreen));
                    vh.BottomRating.SetTextColor(context.Resources.GetColor(Resource.Color.mainGreen));
                    var text = " + " + _Posts[position].Rating;
                    vh.HeaderRating.Text = text;
                    vh.BottomRating.Text = text;
                }
                if (_Posts [position].Rating < 0)
                {
                    vh.HeaderRating.SetTextColor(context.Resources.GetColor(Resource.Color.red));
                    vh.BottomRating.SetTextColor(context.Resources.GetColor(Resource.Color.red));
                    var text = "" + _Posts[position].Rating;
                    vh.HeaderRating.Text = text;
                    vh.BottomRating.Text = text;
                }
                vh.PostTime.Text = _Posts[position].PostTime;
                vh.Title.Text    = _Posts[position].Title;
                if (_Posts[position].Description != null && !String.IsNullOrEmpty(_Posts[position].Description.ToString()))
                {
                    vh.Description.Text       = _Posts[position].Description.ToString();
                    vh.Description.Visibility = ViewStates.Visible;
                }
                else
                {
                    vh.Description.Text       = String.Empty;
                    vh.Description.Visibility = ViewStates.Gone;
                }

                SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
                Color textColor = context.Resources.GetColor(Resource.Color.mainGreen);

                foreach (var tag in _Posts[position].Tags)
                {
                    SpannableString tag1 = new SpannableString("#" + tag);

                    tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
                    stringBuilder.Append(tag1);
                    stringBuilder.Append("  ");
                    //SpannableString tag2 = new SpannableString(" ");
                    //stringBuilder.Append(tag2);
                    //stringBuilder.SetSpan(new TagSpan(backgroundColor, backgroundColor), stringBuilder.Length() - tag2.Length(), stringBuilder.Length(), SpanTypes.ExclusiveExclusive);
                }
                vh.Tags.SetText(stringBuilder, TextView.BufferType.Spannable);
                vh.Comments.Text = _Posts[position].Comments.ToString();
                vh.Text.Text     = _Posts [position].Text;
            }catch (Exception ex) {
                Insights.Initialize("0637c26a1b2e27693e05298f7c3c3a04c102a3c7", Application.Context);
                Insights.Report(ex, new Dictionary <string, string> {
                    { "Message", ex.Message }
                }, Insights.Severity.Error);
                var text = ex.Message;
            }
        }
コード例 #5
0
ファイル: PostViewAdapter.cs プロジェクト: takigava/pikabu
		public void FillTextPost(PostTextViewHolder vh,int position){
			try{
				vh.AuthorName.Text = _Posts[position].AuthorName;
				var context = Android.App.Application.Context;
				vh.HeaderRating.Text = _Posts [position].Rating.ToString ();
				vh.BottomRating.Text = _Posts [position].Rating.ToString ();
				if (_Posts [position].Rating > 0) {
					vh.HeaderRating.SetTextColor (context.Resources.GetColor(Resource.Color.mainGreen));
					vh.BottomRating.SetTextColor (context.Resources.GetColor(Resource.Color.mainGreen));
					var text = " + "+_Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				if (_Posts [position].Rating < 0) {
					vh.HeaderRating.SetTextColor (context.Resources.GetColor(Resource.Color.red));
					vh.BottomRating.SetTextColor (context.Resources.GetColor(Resource.Color.red));
					var text = ""+_Posts[position].Rating;
					vh.HeaderRating.Text = text;
					vh.BottomRating.Text = text;
				}
				vh.PostTime.Text = _Posts[position].PostTime;
				vh.Title.Text = _Posts[position].Title;
				if(_Posts[position].Description!=null && !String.IsNullOrEmpty(_Posts[position].Description.ToString())){
					vh.Description.Text = _Posts[position].Description.ToString();
					vh.Description.Visibility = ViewStates.Visible;
				}else{
					vh.Description.Text = String.Empty;
					vh.Description.Visibility = ViewStates.Gone;
				}

				SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
				Color textColor = context.Resources.GetColor(Resource.Color.mainGreen);

				foreach (var tag in _Posts[position].Tags) {
					SpannableString tag1 = new SpannableString("#"+tag);

					tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
					stringBuilder.Append(tag1);
					stringBuilder.Append("  ");
					//SpannableString tag2 = new SpannableString(" ");
					//stringBuilder.Append(tag2);
					//stringBuilder.SetSpan(new TagSpan(backgroundColor, backgroundColor), stringBuilder.Length() - tag2.Length(), stringBuilder.Length(), SpanTypes.ExclusiveExclusive);
				}
				vh.Tags.SetText(stringBuilder,TextView.BufferType.Spannable);
				vh.Comments.Text = _Posts[position].Comments.ToString();
				vh.Text.Text = _Posts [position].Text;
			}catch(Exception ex){
				Insights.Initialize("0637c26a1b2e27693e05298f7c3c3a04c102a3c7", Application.Context);
				Insights.Report(ex,new Dictionary<string,string>{{"Message",ex.Message}},Insights.Severity.Error);
				var text = ex.Message;
			}
		}