mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-01 17:30:11 +02:00
- fixed style config and code format
This commit is contained in:
parent
f66c90e495
commit
5c7674744d
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Copying and distribution of this file, with or without modification,
|
||||||
|
# are permitted in any medium without royalty provided this notice is
|
||||||
|
# preserved. This file is offered as-is, without any warranty.
|
||||||
|
# Names of contributors must not be used to endorse or promote products
|
||||||
|
# derived from this file without specific prior written permission.
|
||||||
|
|
||||||
|
# EditorConfig
|
||||||
|
# http://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# LF end-of-line, insert an empty new line and UTF-8
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
@ -23,160 +23,160 @@ import kotlinx.android.synthetic.main.fragment_checklist.view.*
|
|||||||
|
|
||||||
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
|
||||||
|
|
||||||
private var noteId = 0L
|
private var noteId = 0L
|
||||||
private var items = ArrayList<ChecklistItem>()
|
private var items = ArrayList<ChecklistItem>()
|
||||||
private var note: Note? = null
|
private var note: Note? = null
|
||||||
|
|
||||||
lateinit var view: ViewGroup
|
lateinit var view: ViewGroup
|
||||||
|
|
||||||
val checklistItems get(): String = Gson().toJson(items)
|
val checklistItems get(): String = Gson().toJson(items)
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
|
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
|
||||||
noteId = arguments!!.getLong(NOTE_ID, 0L)
|
noteId = arguments!!.getLong(NOTE_ID, 0L)
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
loadNoteById(noteId)
|
loadNoteById(noteId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setMenuVisibility(menuVisible: Boolean) {
|
override fun setMenuVisibility(menuVisible: Boolean) {
|
||||||
super.setMenuVisibility(menuVisible)
|
super.setMenuVisibility(menuVisible)
|
||||||
|
|
||||||
if (menuVisible) {
|
if (menuVisible) {
|
||||||
activity?.hideKeyboard()
|
activity?.hideKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadNoteById(noteId: Long) {
|
private fun loadNoteById(noteId: Long) {
|
||||||
NotesHelper(requiredActivity).getNoteWithId(noteId) { storedNote ->
|
NotesHelper(requiredActivity).getNoteWithId(noteId) { storedNote ->
|
||||||
if (storedNote != null && activity?.isDestroyed == false) {
|
if (storedNote != null && activity?.isDestroyed == false) {
|
||||||
note = storedNote
|
note = storedNote
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
|
||||||
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
|
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
|
||||||
?: ArrayList(1)
|
?: ArrayList(1)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
migrateCheckListOnFailure(storedNote)
|
migrateCheckListOnFailure(storedNote)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config?.moveUndoneChecklistItems == true) {
|
if (config?.moveUndoneChecklistItems == true) {
|
||||||
items.sortBy { it.isDone }
|
items.sortBy { it.isDone }
|
||||||
}
|
}
|
||||||
|
|
||||||
requiredActivity.updateTextColors(view.checklist_holder)
|
requiredActivity.updateTextColors(view.checklist_holder)
|
||||||
setupFragment()
|
setupFragment()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun migrateCheckListOnFailure(note: Note) {
|
private fun migrateCheckListOnFailure(note: Note) {
|
||||||
items.clear()
|
items.clear()
|
||||||
|
|
||||||
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
|
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
|
||||||
items.add(ChecklistItem(
|
items.add(ChecklistItem(
|
||||||
id = index,
|
id = index,
|
||||||
title = value,
|
title = value,
|
||||||
isDone = false
|
isDone = false
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
saveChecklist()
|
saveChecklist()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupFragment() {
|
private fun setupFragment() {
|
||||||
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (requiredActivity.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
|
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (requiredActivity.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
|
||||||
|
|
||||||
view.apply {
|
view.apply {
|
||||||
with(checklist_fab) {
|
with(checklist_fab) {
|
||||||
setImageDrawable(plusIcon)
|
setImageDrawable(plusIcon)
|
||||||
background.applyColorFilter(requiredActivity.getAdjustedPrimaryColor())
|
background.applyColorFilter(requiredActivity.getAdjustedPrimaryColor())
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showNewItemDialog()
|
showNewItemDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
with(fragment_placeholder_2) {
|
with(fragment_placeholder_2) {
|
||||||
setTextColor(requiredActivity.getAdjustedPrimaryColor())
|
setTextColor(requiredActivity.getAdjustedPrimaryColor())
|
||||||
underlineText()
|
underlineText()
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
showNewItemDialog()
|
showNewItemDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNewItemDialog() {
|
private fun showNewItemDialog() {
|
||||||
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
|
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
|
||||||
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
|
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
|
||||||
|
|
||||||
titles.forEach { title ->
|
titles.forEach { title ->
|
||||||
title.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEach { row ->
|
title.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEach { row ->
|
||||||
items.add(ChecklistItem(currentMaxId + 1, row, false))
|
items.add(ChecklistItem(currentMaxId + 1, row, false))
|
||||||
currentMaxId++
|
currentMaxId++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveNote()
|
saveNote()
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
|
|
||||||
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
|
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAdapter() {
|
private fun setupAdapter() {
|
||||||
with(view) {
|
with(view) {
|
||||||
fragment_placeholder.beVisibleIf(items.isEmpty())
|
fragment_placeholder.beVisibleIf(items.isEmpty())
|
||||||
fragment_placeholder_2.beVisibleIf(items.isEmpty())
|
fragment_placeholder_2.beVisibleIf(items.isEmpty())
|
||||||
checklist_list.beVisibleIf(items.isNotEmpty())
|
checklist_list.beVisibleIf(items.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
ChecklistAdapter(
|
ChecklistAdapter(
|
||||||
activity = activity as SimpleActivity,
|
activity = activity as SimpleActivity,
|
||||||
items = items,
|
items = items,
|
||||||
listener = this,
|
listener = this,
|
||||||
recyclerView = view.checklist_list,
|
recyclerView = view.checklist_list,
|
||||||
showIcons = true
|
showIcons = true
|
||||||
) { item ->
|
) { item ->
|
||||||
val clickedNote = item as ChecklistItem
|
val clickedNote = item as ChecklistItem
|
||||||
clickedNote.isDone = !clickedNote.isDone
|
clickedNote.isDone = !clickedNote.isDone
|
||||||
|
|
||||||
saveNote(items.indexOfFirst { it.id == clickedNote.id })
|
saveNote(items.indexOfFirst { it.id == clickedNote.id })
|
||||||
context?.updateWidgets()
|
context?.updateWidgets()
|
||||||
}.apply {
|
}.apply {
|
||||||
view.checklist_list.adapter = this
|
view.checklist_list.adapter = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveNote(refreshIndex: Int = -1) {
|
private fun saveNote(refreshIndex: Int = -1) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
note?.let { currentNote ->
|
note?.let { currentNote ->
|
||||||
if (refreshIndex != -1) {
|
if (refreshIndex != -1) {
|
||||||
view.checklist_list.post {
|
view.checklist_list.post {
|
||||||
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
|
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNote.value = checklistItems
|
currentNote.value = checklistItems
|
||||||
ctx.notesDB.insertOrUpdate(currentNote)
|
ctx.notesDB.insertOrUpdate(currentNote)
|
||||||
ctx.updateWidgets()
|
ctx.updateWidgets()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveChecklist() {
|
override fun saveChecklist() {
|
||||||
saveNote()
|
saveNote()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshItems() {
|
override fun refreshItems() {
|
||||||
setupAdapter()
|
setupAdapter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user