public override bool OnContextItemSelected(IMenuItem item) { AdapterView.AdapterContextMenuInfo info = item.MenuInfo as AdapterView.AdapterContextMenuInfo; int actionId = item.ItemId; NoteItem note = Notes[info.Position]; // Opción: Reproducir if (actionId == 0) { DibbiAudio.PreparePlay(note.Filename); DibbiPlayer.State = PlayerState.NoteAudio; DibbiPlayer.Title = note.Description; DibbiPlayer.Show(FragmentManager, "player_dialog"); } // Opción: Eliminar if (actionId == 1) { // Eliminar nota de la base de datos. DibbiData.removeNote(note); // Eliminar de la lista Notes.Remove(note); NotesAdapter.NotifyDataSetChanged(); Toast.MakeText(this, "Nota eliminada", ToastLength.Short).Show(); } return(base.OnContextItemSelected(item)); }
private void ListViewItemClick(object sender, AdapterView.ItemClickEventArgs e) { NoteItem note = Notes[e.Position]; DibbiAudio.PreparePlay(note.Filename); DibbiPlayer.State = PlayerState.NoteAudio; DibbiPlayer.Show(FragmentManager, "player_dialog"); }
private void ConfirmDialogClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(playerDescription.Text) || string.IsNullOrWhiteSpace(playerDescription.Text)) { Toast.MakeText(Activity, "Falta una descripción.", ToastLength.Short).Show(); return; } NoteItem note = new NoteItem() { CreatedAt = DateTime.Now, Description = playerDescription.Text, Duration = Methods.DurationToString(Duration), Filename = string.Format("{0}/{1}.3gp", Activity.FilesDir.AbsolutePath, playerDescription.Text) }; PropertyEventArgs <NoteItem> eventArgs = new PropertyEventArgs <NoteItem>(note); EventHandler <PropertyEventArgs <NoteItem> > onDialogConfirm = DialogConfirm; onDialogConfirm(this, eventArgs); Dismiss(); }
private async void OnDialogConfirm(object sender, PropertyEventArgs <NoteItem> e) { // Guardar audio en directorio local de la aplicacion. Stream fos = null; using (fos = OpenFileOutput(e.Property.Description + ".3gp", FileCreationMode.Private)) { byte[] noteAudio = File.ReadAllBytes(DibbiAudio.FileName); fos.Write(noteAudio, 0, noteAudio.Length); } // Guardar datos de la nota en la base de datos. NoteItem note = await DibbiData.addNote(e.Property); // Añadir nota a la lista. Notes.Insert(0, note); NotesAdapter.NotifyDataSetChanged(); Toast.MakeText(this, "Nota guardada", ToastLength.Short).Show(); // Mostrar el inicio de la lista (notas se añaden al comienzo). NotesList.SetSelection(0); }
public async void removeNote(NoteItem note) { File.Delete(note.Filename); await Db.DeleteAsync(note); }
public async Task <NoteItem> addNote(NoteItem note) { note.Id = await Db.InsertAsync(note); return(note); }