diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index a4eb903c..7688a152 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -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) + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt index 051ebe1b..f2fdcbc4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt @@ -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() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt index ee7dff8d..f8b0a0dd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt @@ -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() } diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 6e04cb02..77c0903d 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -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" diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index c2eca26e..5b460095 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -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 diff --git a/app/src/main/res/values-az/strings.xml b/app/src/main/res/values-az/strings.xml index 81bc0d09..8bf0a2df 100644 --- a/app/src/main/res/values-az/strings.xml +++ b/app/src/main/res/values-az/strings.xml @@ -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 diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index c6b65ac7..4ac03129 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -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 diff --git a/app/src/main/res/values-cy/strings.xml b/app/src/main/res/values-cy/strings.xml index a62c7a73..fa57e780 100644 --- a/app/src/main/res/values-cy/strings.xml +++ b/app/src/main/res/values-cy/strings.xml @@ -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 diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 902ecdd4..d94430fc 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -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 diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 254f5d01..f455f1c7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -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 diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 3ce7e2dc..502f6114 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -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 diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 9632fff9..c4ee77e0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -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 diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c1aa311e..796b022c 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -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 diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index 01d43463..b92897ca 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -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 diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index ef36b540..a2769de7 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -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 diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 5739bc54..7b99f08e 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -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 diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 157ebac9..eb48936c 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -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 diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 157ebac9..eb48936c 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -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 diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 5c41a605..908f5dee 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -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 diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 7e1f3c0c..ed76369b 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -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 diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 017d71b6..81fcc6a8 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -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 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index cf32780c..63b44c9b 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -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 diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 6e8b9c01..d9e4d34f 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -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 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index ca7556fd..231c2a08 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -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 diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 08d90714..22a03f31 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -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: diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 60bbc695..63955a4c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -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 diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index f1f53a99..56d8135d 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -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 diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 746415d5..0b8b8e58 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -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 diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index e33bd65d..a0bfd88f 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -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 diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index bf88747c..ed0351bd 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -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 diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 777bf69b..749df9fd 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -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 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 54f53e4f..3c4fc985 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e20b2c4..dfbf5c2e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -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