protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.CommentLayout); post_id = Intent.GetStringExtra("post_id"); Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetActionBar(toolbar); ActionBar.Title = Intent.GetStringExtra("Titulo"); ActionBar.SetDisplayHomeAsUpEnabled(true); DashboardController = new EscritorioController(); post = DashboardController.GetSinglePost(post_id); FillPost(); svComentarios = FindViewById <ScrollView>(Resource.Id.svComentarios); tlComentarios = FindViewById <TableLayout>(Resource.Id.comment_table); comentarios = DashboardController.GetComentariosPost(post_id, localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo"), page, sizePage); if (Convert.ToInt32(Intent.GetStringExtra("comments_total")) > 0) { tlComentarios.RemoveAllViews(); FillComments(); } SwipeRefreshLayout refresher = FindViewById <SwipeRefreshLayout>(Resource.Id.swipe_container); refresher.SetColorSchemeColors(Color.Gray, Color.LightGray, Color.Gray, Color.DarkGray, Color.Black, Color.DarkGray); refresher.Refresh += (sender, e) => { comentarios = DashboardController.GetComentariosPost(post_id, localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo"), page, sizePage); if (comentarios.Count != 0) { tlComentarios.RemoveAllViews(); FillComments(); } ((SwipeRefreshLayout)sender).Refreshing = false; }; svComentarios.ScrollChange += (sender, e) => { if ((comentarios.Count / (page + 1)) < sizePage - 1) { if ((((ScrollView)sender).ScrollY / (page + 1)) > ((svComentarios.Height) * .4)) { ++page; FillComments(); } } }; }
async void FillComments() { AndHUD.Shared.Show(this, null, -1, MaskType.Black); await Task.Delay(500); comentarios.Skip(page * sizePage).Take(sizePage).AsParallel().ToList().ForEach(comentario => { LayoutInflater liView = LayoutInflater; View CommentView = liView.Inflate(Resource.Layout.PostLayout, null, true); CommentView.SetMinimumWidth(Resources.DisplayMetrics.WidthPixels); //string Usuario_Id = !string.IsNullOrEmpty(comentario.Miembro_Id) ? comentario.Miembro_Id : comentario.Colaborador_Empresa_Id; KeyValuePair <string, string> current = new KeyValuePair <string, string>(comentario.Usuario.Usuario_Id, comentario.Usuario.Usuario_Tipo); ImageButton imgPerfil = CommentView.FindViewById <ImageButton>(Resource.Id.imgPerfil); if (Usuario_Fotos_Perfil.ContainsKey(current)) { if (Usuario_Fotos_Perfil[current] != null) { imgPerfil.SetImageBitmap(BitmapFactory.DecodeByteArray(Usuario_Fotos_Perfil[current], 0, Usuario_Fotos_Perfil[current].Length)); } else { imgPerfil.SetImageResource(Resource.Mipmap.ic_profile_empty); } } else { comentario.Usuario.Usuario_Fotografia_Perfil = new UploadImages().DownloadFileFTP(comentario.Usuario.Usuario_Fotografia, usuario_imagen_path); Usuario_Fotos_Perfil.Add(current, comentario.Usuario.Usuario_Fotografia_Perfil); if (comentario.Usuario.Usuario_Fotografia_Perfil != null) { imgPerfil.SetImageBitmap(BitmapFactory.DecodeByteArray(comentario.Usuario.Usuario_Fotografia_Perfil, 0, comentario.Usuario.Usuario_Fotografia_Perfil.Length)); } else { imgPerfil.SetImageResource(Resource.Mipmap.ic_profile_empty); } } /*if (comentario.Usuario.Usuario_Fotografia_Perfil != null) * imgPerfil.SetImageBitmap(BitmapFactory.DecodeByteArray(comentario.Usuario.Usuario_Fotografia_Perfil, 0, comentario.Usuario.Usuario_Fotografia_Perfil.Length)); * else * imgPerfil.SetImageResource(Resource.Mipmap.ic_profile_empty); * imgPerfil.Click += (sender, e) => ShowPerfilCard(new UsuariosController().GetMemberData(post.Usuario.Usuario_Id, post.Usuario.Usuario_Tipo));*/ TextView lblNombre = CommentView.FindViewById <TextView>(Resource.Id.lblNombre); lblNombre.Text = comentario.Usuario.Usuario_Nombre; lblNombre.Click += (sender, e) => ShowPerfilCard(new UsuariosController().GetMemberData(post.Usuario.Usuario_Id, post.Usuario.Usuario_Tipo)); TextView lblPuesto = CommentView.FindViewById <TextView>(Resource.Id.lblPuesto); lblPuesto.Text = comentario.Usuario.Usuario_Puesto; TextView lblFecha = CommentView.FindViewById <TextView>(Resource.Id.lblFecha); lblFecha.Text = comentario.Comentario_Fecha; TextView lblPost = CommentView.FindViewById <TextView>(Resource.Id.lblPost); lblPost.SetMaxWidth(Convert.ToInt32(Resources.DisplayMetrics.WidthPixels * .911)); lblPost.Text = comentario.Comentario_Contenido; TextView lblLike = CommentView.FindViewById <TextView>(Resource.Id.lblLikeText); lblLike.Text = comentario.Comentario_Me_Gustan_Cantidad + " " + Resources.GetString(Resource.String.str_dashboard_likes); ImageView imgLike = CommentView.FindViewById <ImageView>(Resource.Id.imgLikes); lblLike.Click += delegate { string transaccion = "ALTA"; if (post.Publicacion_Me_Gusta_Usuario == ((int)TiposMeGusta.Activo).ToString()) { transaccion = "BAJA"; } else if (post.Publicacion_Me_Gusta_Usuario == ((int)TiposMeGusta.Baja).ToString()) { transaccion = "MODIFICAR"; } if (new EscritorioController().CommentLike(comentario.Comentario_Id, localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo"), transaccion)) { lblLike.Text = new EscritorioController().GetLikesComments(comentario.Comentario_Id) + " " + Resources.GetString(Resource.String.str_dashboard_likes); if (transaccion == "BAJA") { post.Publicacion_Me_Gusta_Usuario = "0"; lblLike.SetTextColor(Color.Black); imgLike.SetColorFilter(Resources.GetColor(Resource.Color.button_unpressed)); } else { post.Publicacion_Me_Gusta_Usuario = "1"; lblLike.SetTextColor(Color.Rgb(57, 87, 217)); imgLike.SetColorFilter(Resources.GetColor(Resource.Color.like_heart_pressed)); } } }; if (comentario.Comentario_Me_Gusta_Usuario == ((int)TiposMeGusta.Activo).ToString()) { lblLike.SetTextColor(Color.Rgb(57, 87, 217)); imgLike.SetColorFilter(Resources.GetColor(Resource.Color.like_heart_pressed)); } CommentView.FindViewById <TextView>(Resource.Id.lblComentariosText).Visibility = ViewStates.Invisible; CommentView.FindViewById <ImageView>(Resource.Id.imgMore).Click += delegate { using (PopupMenu menuPost = new PopupMenu(this, CommentView.FindViewById <ImageView>(Resource.Id.imgMore))) { menuPost.Inflate(Resource.Menu.post_reporte_menu); menuPost.MenuItemClick += delegate { if (DashboardController.OcultarComment(post.Usuario.Usuario_Id, post.Usuario.Usuario_Tipo, comentario.Publicacion_Id, comentario.Comentario_Id)) { Toast.MakeText(this, "Comentario eliminado", ToastLength.Short).Show(); page = 0; comentarios = DashboardController.GetComentariosPost(post_id, localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo"), page, sizePage); if (comentarios.Count != 0) { tlComentarios.RemoveAllViews(); FillComments(); } } else { Toast.MakeText(this, "Existió un error al eliminar el comentario", ToastLength.Short).Show(); } }; menuPost.Show(); } }; TableRow row = new TableRow(this); row.AddView(CommentView); tlComentarios.AddView(row); }); AndHUD.Shared.Dismiss(this); }