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 {
@ -503,11 +506,11 @@ class MainActivity : SimpleActivity() {
val licenses = LICENSE_RTL
val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons),
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons),
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons)
FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons),
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons),
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons)
)
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
@ -691,8 +694,8 @@ class MainActivity : SimpleActivity() {
private fun showExportFilePickUpdateDialog(exportPath: String, textToExport: String) {
val items = arrayListOf(
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
RadioGroupDialog(this, items) {
val syncFile = it as Int == EXPORT_FILE_SYNC
@ -722,8 +725,8 @@ class MainActivity : SimpleActivity() {
private fun exportAllNotes() {
ExportFilesDialog(this, mNotes) { parent, extension ->
val items = arrayListOf(
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
RadioGroupDialog(this, items) {
val syncFile = it as Int == EXPORT_FILE_SYNC
@ -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

@ -61,7 +61,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
try {
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
?: ArrayList(1)
?: ArrayList(1)
} catch (e: Exception) {
migrateCheckListOnFailure(storedNote)
}
@ -81,9 +81,9 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
items.add(ChecklistItem(
id = index,
title = value,
isDone = false
id = index,
title = value,
isDone = false
))
}
@ -135,18 +135,14 @@ 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,
items = items,
listener = this,
recyclerView = view.checklist_list,
showIcons = true
activity = activity as SimpleActivity,
items = items,
listener = this,
recyclerView = view.checklist_list,
showIcons = true
) { item ->
val clickedNote = item as ChecklistItem
clickedNote.isDone = !clickedNote.isDone
@ -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

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/save_note"
android:icon="@drawable/ic_save_vector"
@ -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