Implement deleting done checklist items

This commit is contained in:
tanvirahmod 2021-01-04 18:43:54 +06:00
parent ab9407ee7a
commit 75da88ba33
33 changed files with 83 additions and 26 deletions

View File

@ -153,6 +153,7 @@ class MainActivity : SimpleActivity() {
findItem(R.id.delete_note).isVisible = multipleNotesExist
findItem(R.id.export_all_notes).isVisible = multipleNotesExist && hasPermission(PERMISSION_WRITE_STORAGE)
findItem(R.id.open_search).isVisible = !isCurrentItemChecklist()
findItem(R.id.remove_done_items).isVisible = isCurrentItemChecklist()
findItem(R.id.import_folder).isVisible = hasPermission(PERMISSION_READ_STORAGE)
saveNoteButton = findItem(R.id.save_note)
@ -185,6 +186,7 @@ class MainActivity : SimpleActivity() {
R.id.delete_note -> displayDeleteNotePrompt()
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
R.id.about -> launchAbout()
R.id.remove_done_items -> removeDoneItems()
else -> return super.onOptionsItemSelected(item)
}
return true
@ -241,7 +243,8 @@ class MainActivity : SimpleActivity() {
}
}
private fun isCurrentItemChecklist() = mAdapter?.isChecklistFragment(view_pager.currentItem) ?: false
private fun isCurrentItemChecklist() = mAdapter?.isChecklistFragment(view_pager.currentItem)
?: false
private fun checkIntents(intent: Intent) {
intent.apply {
@ -904,7 +907,8 @@ class MainActivity : SimpleActivity() {
private fun saveCurrentNote(force: Boolean) {
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem)
?: ""
}
}
@ -1052,4 +1056,8 @@ class MainActivity : SimpleActivity() {
checkWhatsNew(this, BuildConfig.VERSION_CODE)
}
}
private fun removeDoneItems() {
getPagerAdapter().removeDoneCheckListItems(view_pager.currentItem)
}
}

View File

@ -89,4 +89,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
fragments[position] = fragment
return fragment
}
fun removeDoneCheckListItems(position: Int) {
(fragments[position] as? ChecklistFragment)?.removeDoneItems()
}
}

View File

@ -135,11 +135,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
private fun setupAdapter() {
with(view) {
fragment_placeholder.beVisibleIf(items.isEmpty())
fragment_placeholder_2.beVisibleIf(items.isEmpty())
checklist_list.beVisibleIf(items.isNotEmpty())
}
updateUIVisibility()
ChecklistAdapter(
activity = activity as SimpleActivity,
@ -176,6 +172,21 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
}
fun removeDoneItems() {
items.removeIf { it.isDone }
updateUIVisibility()
view.checklist_list.adapter?.notifyDataSetChanged()
saveNote()
}
private fun updateUIVisibility() {
with(view) {
fragment_placeholder.beVisibleIf(items.isEmpty())
fragment_placeholder_2.beVisibleIf(items.isEmpty())
checklist_list.beVisibleIf(items.isNotEmpty())
}
}
override fun saveChecklist() {
saveNote()
}

View File

@ -36,6 +36,11 @@
android:icon="@drawable/ic_rename_new"
android:title="@string/rename_note"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/remove_done_items"
android:title="@string/remove_done_items"
android:icon="@drawable/ic_delete_vector"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/share"
android:icon="@drawable/ic_share_vector"

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -99,6 +99,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -99,6 +99,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -100,6 +100,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -100,6 +100,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -99,6 +99,7 @@
<b> Reddit</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -97,6 +97,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Não encontrou todas as cadeias a traduzir? Existem mais algumas em:

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at

View File

@ -101,6 +101,7 @@
<b>Reddit:</b>
https://www.reddit.com/r/SimpleMobileTools
</string>
<string name="remove_done_items">Remove done items</string>
<!--
Haven't found some strings? There's more at