mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-05-20 17:04:14 +02:00
Fix formatting for checklist notes
This commit is contained in:
parent
92f4863b8a
commit
68991ce1cd
@ -1,15 +1,24 @@
|
|||||||
package com.simplemobiletools.notes.pro.adapters
|
package com.simplemobiletools.notes.pro.adapters
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.SpannableString
|
||||||
|
import android.text.style.StrikethroughSpan
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
|
||||||
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA_INT
|
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA_INT
|
||||||
|
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.notes.pro.R
|
import com.simplemobiletools.notes.pro.R
|
||||||
|
import com.simplemobiletools.notes.pro.extensions.config
|
||||||
|
import com.simplemobiletools.notes.pro.models.ChecklistItem
|
||||||
import com.simplemobiletools.notes.pro.models.Note
|
import com.simplemobiletools.notes.pro.models.Note
|
||||||
|
import com.simplemobiletools.notes.pro.models.NoteType
|
||||||
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
|
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_holder
|
||||||
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
|
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_text
|
||||||
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
|
import kotlinx.android.synthetic.main.open_note_item.view.open_note_item_title
|
||||||
@ -58,9 +67,50 @@ class OpenNoteAdapter(
|
|||||||
setTextColor(properPrimaryColor)
|
setTextColor(properPrimaryColor)
|
||||||
}
|
}
|
||||||
open_note_item_text.apply {
|
open_note_item_text.apply {
|
||||||
text = note.getNoteStoredValue(context)
|
text = note.getFormattedValue(context)
|
||||||
setTextColor(textColor)
|
setTextColor(textColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Note.getFormattedValue(context: Context): CharSequence? {
|
||||||
|
return when (type) {
|
||||||
|
NoteType.TYPE_TEXT -> getNoteStoredValue(context)
|
||||||
|
NoteType.TYPE_CHECKLIST -> {
|
||||||
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
|
var items = Gson().fromJson<List<ChecklistItem>>(getNoteStoredValue(context), checklistItemType) ?: listOf()
|
||||||
|
items = items.filter { it.title != null }.let {
|
||||||
|
val sorting = context.config.sorting
|
||||||
|
ChecklistItem.sorting = sorting
|
||||||
|
if (ChecklistItem.sorting and SORT_BY_CUSTOM == 0) {
|
||||||
|
it.sorted().let {
|
||||||
|
if (context.config?.moveDoneChecklistItems == true) {
|
||||||
|
it.sortedBy { it.isDone }
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val linePrefix = "• "
|
||||||
|
val stringifiedItems = items.joinToString(separator = System.lineSeparator()) {
|
||||||
|
"${linePrefix}${it.title}"
|
||||||
|
}
|
||||||
|
|
||||||
|
val formattedText = SpannableString(stringifiedItems)
|
||||||
|
var currentPos = 0
|
||||||
|
items.forEach { item ->
|
||||||
|
currentPos += linePrefix.length
|
||||||
|
if (item.isDone) {
|
||||||
|
formattedText.setSpan(StrikethroughSpan(), currentPos, currentPos + item.title.length, 0)
|
||||||
|
}
|
||||||
|
currentPos += item.title.length
|
||||||
|
currentPos += System.lineSeparator().length
|
||||||
|
}
|
||||||
|
formattedText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user