Skip to content

Commit e9b5efa

Browse files
authored
Merge pull request #388 from tanvir-ahmod/fix_382
Fix #382 , Implement deleting done checklist items
2 parents 0fc3523 + 0132c9b commit e9b5efa

File tree

33 files changed

+60
-5
lines changed

33 files changed

+60
-5
lines changed

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

Lines changed: 6 additions & 0 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
@@ -1058,4 +1060,8 @@ class MainActivity : SimpleActivity() {
10581060
checkWhatsNew(this, BuildConfig.VERSION_CODE)
10591061
}
10601062
}
1063+
1064+
private fun removeDoneItems() {
1065+
getPagerAdapter().removeDoneCheckListItems(view_pager.currentItem)
1066+
}
10611067
}

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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ 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(
145141
activity = activity as SimpleActivity,
@@ -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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">إضافة عنصر قائمة تدقيق جديد</string>
5656
<string name="add_new_checklist_items">إضافة عناصر قائمة تدقيق جديدة</string>
5757
<string name="checklist_is_empty">قائمة التدقيق فارغة</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">تصدير جميع الملاحظات كملفات</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">Add a new checklist item</string>
5656
<string name="add_new_checklist_items">Add new checklist items</string>
5757
<string name="checklist_is_empty">The checklist is empty</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">Bütün qeydləri fayl şəklində çıxar</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">Přidat do seznamu novou položku</string>
5656
<string name="add_new_checklist_items">Přidat do seznamu nové položky</string>
5757
<string name="checklist_is_empty">Seznam položek je prázdný</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">Exportovat všechny poznámky jako soubory</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">Ychwanegu eitem newydd at restr wirio</string>
5656
<string name="add_new_checklist_items">Ychwanegu eitemau newydd at restr wirio</string>
5757
<string name="checklist_is_empty">Mae\'r rhestr wirio yn wag</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">Allforio pob nodyn fel ffeil</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">Føj et nyt punkt til tjeklisten</string>
5656
<string name="add_new_checklist_items">Føj nye punkter til tjeklisten</string>
5757
<string name="checklist_is_empty">Tjeklisten er tom</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">Eksporter alle noter som filer</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<string name="add_new_checklist_item">Einen neuen Checklisteneintrag hinzufügen</string>
5656
<string name="add_new_checklist_items">Neue Checklisteneinträge hinzufügen</string>
5757
<string name="checklist_is_empty">Die Checkliste ist leer</string>
58+
<string name="remove_done_items">Remove done items</string>
5859

5960
<!-- Import / Export -->
6061
<string name="export_all_notes">Alle Notizen als Dateien exportieren</string>

0 commit comments

Comments
 (0)