diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/repo/NotesRepoHelper.kt b/app/src/main/java/dev/arkbuilders/arkmemo/repo/NotesRepoHelper.kt index 7ebc600..63d4c42 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/repo/NotesRepoHelper.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/repo/NotesRepoHelper.kt @@ -91,7 +91,7 @@ class NotesRepoHelper return UserNoteProperties(title, description) } - suspend fun deleteNote(notes: List): Unit = + suspend fun deleteNotes(notes: List): Unit = withContext(Dispatchers.IO) { notes.forEach { note -> deleteNote(note) diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/repo/graphics/GraphicNotesRepo.kt b/app/src/main/java/dev/arkbuilders/arkmemo/repo/graphics/GraphicNotesRepo.kt index bc78b59..055773d 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/repo/graphics/GraphicNotesRepo.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/repo/graphics/GraphicNotesRepo.kt @@ -71,7 +71,7 @@ class GraphicNotesRepo } override suspend fun delete(notes: List) { - helper.deleteNote(notes) + helper.deleteNotes(notes) } override suspend fun read(): List = diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/repo/text/TextNotesRepo.kt b/app/src/main/java/dev/arkbuilders/arkmemo/repo/text/TextNotesRepo.kt index d6dfe7b..93521be 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/repo/text/TextNotesRepo.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/repo/text/TextNotesRepo.kt @@ -47,7 +47,7 @@ class TextNotesRepo } override suspend fun delete(notes: List) { - helper.deleteNote(notes) + helper.deleteNotes(notes) } override suspend fun delete(note: TextNote) { diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/repo/voices/VoiceNotesRepo.kt b/app/src/main/java/dev/arkbuilders/arkmemo/repo/voices/VoiceNotesRepo.kt index bd9dade..e83a4e3 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/repo/voices/VoiceNotesRepo.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/repo/voices/VoiceNotesRepo.kt @@ -43,7 +43,7 @@ class VoiceNotesRepo } override suspend fun delete(notes: List) { - helper.deleteNote(notes) + helper.deleteNotes(notes) } override suspend fun delete(note: VoiceNote) { diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt index 5006e4a..9774ea9 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/adapters/NotesListAdapter.kt @@ -55,7 +55,7 @@ class NotesListAdapter( private val selectedNoteCount by lazy { MutableLiveData() } val observableSelectedNoteCount by lazy { selectedNoteCount } - val selectedNotedForDelete = mutableListOf() + val selectedNotesForDelete = mutableListOf() fun setActivity(activity: AppCompatActivity) { this.activity = activity as MainActivity @@ -250,8 +250,9 @@ class NotesListAdapter( var selectedCount = 0 notes.forEachIndexed { index, note -> note.selected = mActionMode && index == pos - if (index == pos) { + if (note.selected) { selectedCount++ + selectedNotesForDelete.add(note) } } selectedNoteCount.postValue(selectedCount) @@ -260,10 +261,10 @@ class NotesListAdapter( fun toggleSelectAllItems(selected: Boolean) { notes.forEach { it.selected = selected } - selectedNotedForDelete.clear() + selectedNotesForDelete.clear() selectedNoteCount.postValue( if (selected) { - selectedNotedForDelete.addAll(notes) + selectedNotesForDelete.addAll(notes) notes.size } else { 0 @@ -322,12 +323,12 @@ class NotesListAdapter( selectedNoteCount.value?.let { count -> selectedNoteCount.postValue(count + 1) } - selectedNotedForDelete.add(selectedNote) + selectedNotesForDelete.add(selectedNote) } else { selectedNoteCount.value?.let { count -> selectedNoteCount.postValue(count - 1) } - selectedNotedForDelete.remove(selectedNote) + selectedNotesForDelete.remove(selectedNote) } buttonView.post { diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt index 3c9b264..fba1b95 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt @@ -70,7 +70,7 @@ class EditTextNotesFragment : BaseEditNoteFragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) notesViewModel.init {} - observeSaveResult(notesViewModel.getSaveNoteResultLiveData()) + if (arguments != null) { requireArguments().getParcelableCompat(NOTE_KEY, TextNote::class.java)?.let { note = it @@ -155,6 +155,7 @@ class EditTextNotesFragment : BaseEditNoteFragment() { ?: binding.toolbar.ivRightActionIcon.gone() view.viewTreeObserver.addOnWindowFocusChangeListener(windowFocusedListener) + observeSaveResult(notesViewModel.getSaveNoteResultLiveData()) } override fun isContentChanged(): Boolean { diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt index afb31a3..b0c24ba 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/NotesFragment.kt @@ -260,16 +260,20 @@ class NotesFragment : BaseFragment() { mItemTouchHelper = ItemTouchHelper(mItemTouchCallback) mItemTouchHelper?.attachToRecyclerView(binding.rvPinnedNotes) - if (notes.isNotEmpty()) { - binding.layoutBottomControl.visible() - binding.groupEmptyState.gone() - binding.rvPinnedNotes.visible() - binding.edtSearch.visible() - } else { + showEmptyState(isEmpty = notes.isEmpty()) + } + + private fun showEmptyState(isEmpty: Boolean) { + if (isEmpty) { binding.layoutBottomControl.gone() binding.groupEmptyState.visible() binding.rvPinnedNotes.gone() binding.edtSearch.gone() + } else { + binding.layoutBottomControl.visible() + binding.groupEmptyState.gone() + binding.rvPinnedNotes.visible() + binding.edtSearch.visible() } } @@ -431,6 +435,7 @@ class NotesFragment : BaseFragment() { binding.layoutBottomControl.visible() binding.edtSearch.visible() binding.ivSettings.visible() + notesAdapter?.toggleSelectAllItems(false) } else { binding.groupActionModeTexts.visible() updateSelectStateTexts(selectedCountForDelete) @@ -468,13 +473,16 @@ class NotesFragment : BaseFragment() { isAlert = true, onPositiveClick = { binding.pbLoading.visible() - val selectedNotes = notesAdapter?.selectedNotedForDelete ?: emptyList() + val selectedNotes = notesAdapter?.selectedNotesForDelete ?: emptyList() notesViewModel.onDeleteConfirmed(selectedNotes) { notesAdapter?.getNotes()?.removeAll(selectedNotes) binding.pbLoading.gone() toast(requireContext(), getString(R.string.note_deleted)) binding.rvPinnedNotes.adapter?.notifyDataSetChanged() toggleActionMode() + if (notesAdapter?.getNotes()?.isEmpty() == true) { + showEmptyState(true) + } } }, onNegativeClicked = {},