Esempio n. 1
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            view = inflater.Inflate(Resource.Layout.NotasLayout, container, false);

            lvNotas      = view.FindViewById <ListView>(Resource.Id.lvNotas);
            btnNuevaNota = view.FindViewById <ImageButton>(Resource.Id.btnNuevaNota);

            persistencia       = new AppPersistence(activity);
            service            = new LogicaNotas();
            lvNotas.ItemClick += (s, a) =>
            {
                var notaFragment    = new NotaFragment(a.Position);
                var fragmentManager = FragmentManager.BeginTransaction();
                fragmentManager.Replace(Resource.Id.fragment_container, notaFragment);
                fragmentManager.Commit();
            };
            btnNuevaNota.Click += (s, a) =>
            {
                var notaFragment    = new NotaFragment();
                var fragmentManager = FragmentManager.BeginTransaction();
                fragmentManager.Replace(Resource.Id.fragment_container, notaFragment);
                fragmentManager.Commit();
            };

            service.GetNotasCompleted += (s, a) =>
            {
                persistencia.ListaNotas = a.Result.ToList();
                lvNotas.Adapter         = new NotaAdapter(activity, persistencia.ListaNotas.OrderByDescending(o => o.Fecha));
            };
            return(view);
        }
Esempio n. 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            view = inflater.Inflate(Resource.Layout.NotaLayout, container, false);

            etTitulo    = view.FindViewById <EditText>(Resource.Id.etTitulo);
            etContenido = view.FindViewById <EditText>(Resource.Id.etContenido);
            btnGuardar  = view.FindViewById <Button>(Resource.Id.btnGuardar);
            btnBorrar   = view.FindViewById <Button>(Resource.Id.btnBorrar);

            service = new LogicaNotas();
            service.AddNoteCompleted    += service_AddNoteCompleted;
            service.DeleteNotaCompleted += service_DeleteNotaCompleted;
            service.UpdateNotaCompleted += service_UpdateNotaCompleted;
            persistencia = new AppPersistence(activity);

            btnGuardar.Click += (s, _) =>
            {
                var titulo    = etTitulo.Text;
                var contenido = etContenido.Text;
                var fecha     = DateTime.Now;

                if (PosicionNota == -1)
                {
                    service.AddNoteAsync(new Nota()
                    {
                        Titulo = titulo, Contenido = contenido, Fecha = fecha
                    });
                }
                else
                {
                    service.UpdateNotaAsync(new Nota()
                    {
                        Id        = persistencia.ListaNotas[PosicionNota].Id,
                        Titulo    = titulo,
                        Contenido = contenido,
                        Fecha     = fecha
                    });
                }
            };
            btnBorrar.Click += (s, a) =>
            {
                var lista = persistencia.ListaNotas;
                //lista.RemoveAt(PosicionNota);
                //persistencia.ListaNotas = lista;
                service.DeleteNotaAsync(lista[PosicionNota].Id);

                var notaFragment    = new NotasFragment();
                var fragmentManager = FragmentManager.BeginTransaction();
                fragmentManager.Replace(Resource.Id.fragment_container, notaFragment);
                fragmentManager.Commit();
            };
            if (PosicionNota == -1)
            {
                btnBorrar.Visibility = ViewStates.Gone;
            }
            return(view);
        }