Skip to content

Commit 75da88b

Browse files
committed
Implement deleting done checklist items
1 parent ab9407e commit 75da88b

File tree

33 files changed

+83
-26
lines changed

33 files changed

+83
-26
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class MainActivity : SimpleActivity() {
153153
findItem(R.id.delete_note).isVisible = multipleNotesExist
154154
findItem(R.id.export_all_notes).isVisible = multipleNotesExist && hasPermission(PERMISSION_WRITE_STORAGE)
155155
findItem(R.id.open_search).isVisible = !isCurrentItemChecklist()
156+
findItem(R.id.remove_done_items).isVisible = isCurrentItemChecklist()
156157
findItem(R.id.import_folder).isVisible = hasPermission(PERMISSION_READ_STORAGE)
157158

158159
saveNoteButton = findItem(R.id.save_note)
@@ -185,6 +186,7 @@ class MainActivity : SimpleActivity() {
185186
R.id.delete_note -> displayDeleteNotePrompt()
186187
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
187188
R.id.about -> launchAbout()
189+
R.id.remove_done_items -> removeDoneItems()
188190
else -> return super.onOptionsItemSelected(item)
189191
}
190192
return true
@@ -241,7 +243,8 @@ class MainActivity : SimpleActivity() {
241243
}
242244
}
243245

244-
private fun isCurrentItemChecklist() = mAdapter?.isChecklistFragment(view_pager.currentItem) ?: false
246+
private fun isCurrentItemChecklist() = mAdapter?.isChecklistFragment(view_pager.currentItem)
247+
?: false
245248

246249
private fun checkIntents(intent: Intent) {
247250
intent.apply {
@@ -503,11 +506,11 @@ class MainActivity : SimpleActivity() {
503506
val licenses = LICENSE_RTL
504507

505508
val faqItems = arrayListOf(
506-
FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons),
507-
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
508-
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons),
509-
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
510-
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons)
509+
FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons),
510+
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
511+
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons),
512+
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons),
513+
FAQItem(R.string.faq_7_title_commons, R.string.faq_7_text_commons)
511514
)
512515

513516
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
@@ -691,8 +694,8 @@ class MainActivity : SimpleActivity() {
691694

692695
private fun showExportFilePickUpdateDialog(exportPath: String, textToExport: String) {
693696
val items = arrayListOf(
694-
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
695-
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
697+
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
698+
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
696699

697700
RadioGroupDialog(this, items) {
698701
val syncFile = it as Int == EXPORT_FILE_SYNC
@@ -722,8 +725,8 @@ class MainActivity : SimpleActivity() {
722725
private fun exportAllNotes() {
723726
ExportFilesDialog(this, mNotes) { parent, extension ->
724727
val items = arrayListOf(
725-
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
726-
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
728+
RadioItem(EXPORT_FILE_SYNC, getString(R.string.update_file_at_note)),
729+
RadioItem(EXPORT_FILE_NO_SYNC, getString(R.string.only_export_file_content)))
727730

728731
RadioGroupDialog(this, items) {
729732
val syncFile = it as Int == EXPORT_FILE_SYNC
@@ -904,7 +907,8 @@ class MainActivity : SimpleActivity() {
904907
private fun saveCurrentNote(force: Boolean) {
905908
getPagerAdapter().saveCurrentNote(view_pager.currentItem, force)
906909
if (mCurrentNote.type == NoteType.TYPE_CHECKLIST.value) {
907-
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem) ?: ""
910+
mCurrentNote.value = getPagerAdapter().getNoteChecklistItems(view_pager.currentItem)
911+
?: ""
908912
}
909913
}
910914

@@ -1052,4 +1056,8 @@ class MainActivity : SimpleActivity() {
10521056
checkWhatsNew(this, BuildConfig.VERSION_CODE)
10531057
}
10541058
}
1059+
1060+
private fun removeDoneItems() {
1061+
getPagerAdapter().removeDoneCheckListItems(view_pager.currentItem)
1062+
}
10551063
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/NotesPagerAdapter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
8989
fragments[position] = fragment
9090
return fragment
9191
}
92+
93+
fun removeDoneCheckListItems(position: Int) {
94+
(fragments[position] as? ChecklistFragment)?.removeDoneItems()
95+
}
9296
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
6161
try {
6262
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
6363
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
64-
?: ArrayList(1)
64+
?: ArrayList(1)
6565
} catch (e: Exception) {
6666
migrateCheckListOnFailure(storedNote)
6767
}
@@ -81,9 +81,9 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
8181

8282
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
8383
items.add(ChecklistItem(
84-
id = index,
85-
title = value,
86-
isDone = false
84+
id = index,
85+
title = value,
86+
isDone = false
8787
))
8888
}
8989

@@ -135,18 +135,14 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
135135
}
136136

137137
private fun setupAdapter() {
138-
with(view) {
139-
fragment_placeholder.beVisibleIf(items.isEmpty())
140-
fragment_placeholder_2.beVisibleIf(items.isEmpty())
141-
checklist_list.beVisibleIf(items.isNotEmpty())
142-
}
138+
updateUIVisibility()
143139

144140
ChecklistAdapter(
145-
activity = activity as SimpleActivity,
146-
items = items,
147-
listener = this,
148-
recyclerView = view.checklist_list,
149-
showIcons = true
141+
activity = activity as SimpleActivity,
142+
items = items,
143+
listener = this,
144+
recyclerView = view.checklist_list,
145+
showIcons = true
150146
) { item ->
151147
val clickedNote = item as ChecklistItem
152148
clickedNote.isDone = !clickedNote.isDone
@@ -176,6 +172,21 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
176172
}
177173
}
178174

175+
fun removeDoneItems() {
176+
items.removeIf { it.isDone }
177+
updateUIVisibility()
178+
view.checklist_list.adapter?.notifyDataSetChanged()
179+
saveNote()
180+
}
181+
182+
private fun updateUIVisibility() {
183+
with(view) {
184+
fragment_placeholder.beVisibleIf(items.isEmpty())
185+
fragment_placeholder_2.beVisibleIf(items.isEmpty())
186+
checklist_list.beVisibleIf(items.isNotEmpty())
187+
}
188+
}
189+
179190
override fun saveChecklist() {
180191
saveNote()
181192
}

app/src/main/res/menu/menu.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto">
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
44
<item
55
android:id="@+id/save_note"
66
android:icon="@drawable/ic_save_vector"
@@ -36,6 +36,11 @@
3636
android:icon="@drawable/ic_rename_new"
3737
android:title="@string/rename_note"
3838
app:showAsAction="ifRoom"/>
39+
<item
40+
android:id="@+id/remove_done_items"
41+
android:title="@string/remove_done_items"
42+
android:icon="@drawable/ic_delete_vector"
43+
app:showAsAction="ifRoom"/>
3944
<item
4045
android:id="@+id/share"
4146
android:icon="@drawable/ic_share_vector"

app/src/main/res/values-ar/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<b>Reddit:</b>
102102
https://www.reddit.com/r/SimpleMobileTools
103103
</string>
104+
<string name="remove_done_items">Remove done items</string>
104105

105106
<!--
106107
Haven't found some strings? There's more at

app/src/main/res/values-az/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<b>Reddit:</b>
102102
https://www.reddit.com/r/SimpleMobileTools
103103
</string>
104+
<string name="remove_done_items">Remove done items</string>
104105

105106
<!--
106107
Haven't found some strings? There's more at

app/src/main/res/values-cs/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<b>Reddit:</b>
102102
https://www.reddit.com/r/SimpleMobileTools
103103
</string>
104+
<string name="remove_done_items">Remove done items</string>
104105

105106
<!--
106107
Haven't found some strings? There's more at

app/src/main/res/values-cy/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<b>Reddit:</b>
102102
https://www.reddit.com/r/SimpleMobileTools
103103
</string>
104+
<string name="remove_done_items">Remove done items</string>
104105

105106
<!--
106107
Haven't found some strings? There's more at

app/src/main/res/values-da/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<b>Reddit:</b>
102102
https://www.reddit.com/r/SimpleMobileTools
103103
</string>
104+
<string name="remove_done_items">Remove done items</string>
104105

105106
<!--
106107
Haven't found some strings? There's more at

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<b>Reddit:</b>
100100
https://www.reddit.com/r/SimpleMobileTools
101101
</string>
102+
<string name="remove_done_items">Remove done items</string>
102103

103104
<!--
104105
Haven't found some strings? There's more at

0 commit comments

Comments
 (0)