コード例 #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 FillImagePost(PostImageViewHolder 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;
                }
//				if(_Posts[position].FormattedDescription!=null && _Posts[position].FormattedDescription.Count>0){
//					SpannableStringBuilder descriptionBulder = new SpannableStringBuilder();
//					Color descTextColorDarkGray = context.Resources.GetColor(Resource.Color.darkGray);
//					Color descTextColorGray = context.Resources.GetColor(Resource.Color.gray);
//
//					foreach(var des in _Posts[position].FormattedDescription){
//						if(des.Item1 == "text"){
//							SpannableString tag1 = new SpannableString(des.Item2);
//
//							tag1.SetSpan(new ForegroundColorSpan(descTextColorGray), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag1);
//						}
//						if(des.Item1 == "textLink"){
//							SpannableString tag2 = new SpannableString(des.Item2);
//
//							tag2.SetSpan(new ForegroundColorSpan(descTextColorDarkGray), 0, tag2.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag2);
//						}
//					}
//					if(descriptionBulder.Count()>0){
//						//vh.Description.TextFormatted = descriptionBulder;
//						vh.Description.SetText(descriptionBulder,TextView.BufferType.Spannable);
//					}
//				}else{
//					vh.Description.Visibility = ViewStates.Invisible;
//					vh.Description.Text = null;
//				}
                //vh._Description.Text = _Posts[position].Description;
                //vh._Description.Text = _Posts[position].Description;
                SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
                Color textColor   = context.Resources.GetColor(Resource.Color.mainGreen);
                var   tagsBuilder = new StringBuilder();

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

                    tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveInclusive);
                    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);
                    //tagsBuilder.Append("#"+tag+" ");
                }

                vh.Tags.SetText(stringBuilder, TextView.BufferType.Spannable);
                //vh.Tags.Text = tagsBuilder.ToString();
                //vh.Tags.TextFormatted = stringBuilder;
                vh.Comments.Text = _Posts[position].Comments.ToString();
                vh.Image.Click  -= videoHandler;
                vh.Image.Click  -= _imageHandler;
                vh.Image.Click  -= gifHandler;
                if (_Posts[position].PostType == PostType.Video)
                {
                    if (vh.Image != null)
                    {
                        vh.Image.SetTag(Resource.String.currentPosition, vh.AdapterPosition.ToString());
                        vh.Image.SetTag(Resource.String.imageUrl, _Posts [vh.AdapterPosition].VideoUrl);

                        vh.Image.Click -= _imageHandler;
                        vh.Image.Click -= gifHandler;
                        vh.Image.Click -= videoHandler;
                        vh.Image.Click += videoHandler;
                        Picasso.With(Android.App.Application.Context)
                        .Load(_Posts[position].Url)
                        .Transform(new CropSquareTransformation())
                        .Into(vh.Image);
                    }
                }
                if (_Posts[position].PostType == PostType.Image)
                {
                    if (vh.Image != null)
                    {
                        vh.Image.SetTag(Resource.String.currentPosition, vh.AdapterPosition.ToString());
                        vh.Image.SetTag(Resource.String.imageUrl, _Posts [vh.AdapterPosition].Url);
                        vh.Image.SetTag(Resource.String.isbiggeravailable, _Posts [vh.AdapterPosition].IsBiggerAvailable);

                        vh.Image.Click -= videoHandler;
                        vh.Image.Click -= gifHandler;
                        vh.Image.Click -= _imageHandler;
                        vh.Image.Click += _imageHandler;
                        Picasso.With(Android.App.Application.Context)
                        .Load(_Posts[position].Url)
                        .Transform(new CropSquareTransformation())
                        .Into(vh.Image);
                    }
                }
                if (_Posts[position].PostType == PostType.Gif)
                {
                    if (vh.Image != null)
                    {
                        vh.Image.SetTag(Resource.String.currentPosition, vh.AdapterPosition.ToString());
                        vh.Image.SetTag(Resource.String.imageUrl, _Posts [vh.AdapterPosition].GifUrl);

                        vh.Image.Click -= videoHandler;
                        vh.Image.Click -= _imageHandler;
                        vh.Image.Click -= gifHandler;
                        vh.Image.Click += gifHandler;
                        Picasso.With(Android.App.Application.Context)
                        .Load(_Posts[position].Url)
                        .Transform(new CropSquareTransformation())
                        .Into(vh.Image);
                    }
                }
            }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 FillImagePost(PostImageViewHolder 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;
				}
//				if(_Posts[position].FormattedDescription!=null && _Posts[position].FormattedDescription.Count>0){
//					SpannableStringBuilder descriptionBulder = new SpannableStringBuilder();
//					Color descTextColorDarkGray = context.Resources.GetColor(Resource.Color.darkGray);
//					Color descTextColorGray = context.Resources.GetColor(Resource.Color.gray);
//
//					foreach(var des in _Posts[position].FormattedDescription){
//						if(des.Item1 == "text"){
//							SpannableString tag1 = new SpannableString(des.Item2);
//
//							tag1.SetSpan(new ForegroundColorSpan(descTextColorGray), 0, tag1.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag1);
//						}
//						if(des.Item1 == "textLink"){
//							SpannableString tag2 = new SpannableString(des.Item2);
//
//							tag2.SetSpan(new ForegroundColorSpan(descTextColorDarkGray), 0, tag2.Length(), SpanTypes.ExclusiveExclusive);
//							descriptionBulder.Append(tag2);
//						}
//					}
//					if(descriptionBulder.Count()>0){
//						//vh.Description.TextFormatted = descriptionBulder;
//						vh.Description.SetText(descriptionBulder,TextView.BufferType.Spannable);
//					}
//				}else{
//					vh.Description.Visibility = ViewStates.Invisible;
//					vh.Description.Text = null;
//				}
				//vh._Description.Text = _Posts[position].Description;
				//vh._Description.Text = _Posts[position].Description;
				SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
				Color textColor = context.Resources.GetColor(Resource.Color.mainGreen);
				var tagsBuilder = new StringBuilder();

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

					tag1.SetSpan(new ForegroundColorSpan(textColor), 0, tag1.Length(), SpanTypes.ExclusiveInclusive);
					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);
					//tagsBuilder.Append("#"+tag+" ");
				}

				vh.Tags.SetText(stringBuilder,TextView.BufferType.Spannable);
				//vh.Tags.Text = tagsBuilder.ToString();
				//vh.Tags.TextFormatted = stringBuilder;
				vh.Comments.Text = _Posts[position].Comments.ToString();
				vh.Image.Click -= videoHandler;
				vh.Image.Click -= imageHandler;
				vh.Image.Click -= gifHandler;
				if(_Posts[position].PostType==PostType.Video){
					if (vh.Image != null) {
						vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
						vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].VideoUrl);

						vh.Image.Click -= imageHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click -= videoHandler;
						vh.Image.Click += videoHandler;
						Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
							.Transform(new CropSquareTransformation())
							.Into(vh.Image);
					}
				}
				if(_Posts[position].PostType==PostType.Image){
				if (vh.Image != null) {
					vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
					vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].Url);
					vh.Image.SetTag (Resource.String.isbiggeravailable,_Posts [vh.AdapterPosition].IsBiggerAvailable);

						vh.Image.Click -= videoHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click -= imageHandler;
						vh.Image.Click += imageHandler;
					Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
						.Transform(new CropSquareTransformation())
						.Into(vh.Image);
				}
				}
				if(_Posts[position].PostType==PostType.Gif){
					if (vh.Image != null) {
						vh.Image.SetTag (Resource.String.currentPosition, vh.AdapterPosition.ToString ());
						vh.Image.SetTag (Resource.String.imageUrl, _Posts [vh.AdapterPosition].GifUrl);

						vh.Image.Click -= videoHandler;
						vh.Image.Click -= imageHandler;
						vh.Image.Click -= gifHandler;
						vh.Image.Click += gifHandler;
						Picasso.With(Android.App.Application.Context)
							.Load(_Posts[position].Url)
							.Transform(new CropSquareTransformation())
							.Into(vh.Image);
					}
				}



			}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;
			}
		}