private void DeleteClicked(int position) { var foundIdea = Global.Categories.FirstOrDefault(x => x.CategoryLbl == notes[position].Category).Items.FirstOrDefault(y => y.Title == notes[position].Title); if (foundIdea != null) { foundIdea.Note = null; } var foundBookmark = bookmarkedItems.FirstOrDefault(x => x.Title == notes[position].Title); if (foundBookmark != null) { foundBookmark.Note = null; } notes.RemoveAt(position); adapter.NotifyItemRemoved(position); if (notes.Count == 0) { ShowEmptyState(); } SaveChanges(); }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); notes = await DBAssist.DeserializeDBAsync <List <Note> >(notesdb); notes = notes ?? new List <Note>(); bookmarkedItems = await DBAssist.DeserializeDBAsync <List <Idea> >(bookmarksdb); bookmarkedItems = bookmarkedItems ?? new List <Idea>(); recycler = FindViewById <RecyclerView>(Resource.Id.notesRecyclerView); emptyState = FindViewById(Resource.Id.empty); if (notes.Count == 0) { ShowEmptyState(); } else { manager = new LinearLayoutManager(this); adapter = new NotesAdapter(notes); adapter.EditClicked += Adapter_EditClicked; adapter.ViewNoteClicked += (position) => { new AlertDialog.Builder(this) .SetTitle(notes[position].Name) .SetMessage(notes[position].Content) .SetPositiveButton("Great", (sender, e) => { return; }) .Create().Show(); }; adapter.DeleteClicked += (position) => { var foundIdea = Global.Categories.FirstOrDefault(x => x.CategoryLbl == notes[position].Category).Items.FirstOrDefault(y => y.Title == notes[position].Title); if (foundIdea != null) { foundIdea.Note = null; } var foundBookmark = bookmarkedItems.FirstOrDefault(x => x.Title == notes[position].Title); if (foundBookmark != null) { foundBookmark.Note = null; } notes.RemoveAt(position); adapter.NotifyItemRemoved(position); if (notes.Count == 0) { ShowEmptyState(); } }; recycler.SetAdapter(adapter); recycler.SetLayoutManager(manager); recycler.SetItemAnimator(new DefaultItemAnimator()); } }