public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { StopViewHolder viewHolder = holder as StopViewHolder; KeyValuePair <string, Stop[]> stop = filteredStops.ElementAt(position); viewHolder.Icon.SetImageDrawable(stop.Value[0].Line.GetIconDrawable(viewHolder.ItemView.Context)); viewHolder.Name.Text = stop.Key; if (this.position != null) { float distance = stop.Value[0].Position - this.position.Value; distance = (float)Math.Ceiling(distance / 100) * 100; viewHolder.Description.Text = distance > 1000 ? ((distance / 1000) + " km") : (distance + " m"); } else { viewHolder.Description.Text = ""; } viewHolder.Favorite.SetImageResource(stop.Value.Any(s => s.GetIsFavorite()) ? Resource.Drawable.ic_star : Resource.Drawable.ic_star_border); viewHolder.Favorite.Visibility = StopClick != null ? ViewStates.Gone : ViewStates.Visible; if (!viewHolders.Contains(viewHolder)) { viewHolders.Add(viewHolder); } }
public void OnClick(View view) { StopViewHolder viewHolder = viewHolders.First(vh => vh.ItemView == view); KeyValuePair <string, Stop[]> stop = filteredStops.ElementAt(viewHolder.AdapterPosition); if (StopClick != null) { StopClick.Invoke(this, stop.Value.First()); } else { Intent intent = new Intent(view.Context, typeof(StopActivity)); intent.PutExtra("Stop", stop.Value.First().Id); view.Context.StartActivity(intent); } }
private void Favorite_Click(object sender, EventArgs e) { View view = sender as View; StopViewHolder viewHolder = viewHolders.First(vh => vh.ItemView == view.Parent); KeyValuePair <string, Stop[]> stop = filteredStops.ElementAt(viewHolder.AdapterPosition); if (stop.Value.Any(s => s.GetIsFavorite())) { foreach (Stop s in stop.Value) { s.SetIsFavorite(false); } } else { foreach (Stop s in stop.Value) { s.SetIsFavorite(true); } } NotifyItemChanged(viewHolder.AdapterPosition); }