mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-24 04:20:07 +01:00
Implement deleting done checklist items
This commit is contained in:
parent
ab9407ee7a
commit
75da88ba33
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user