Skip to content

Commit 5c76747

Browse files
author
Pavol Franek
committed
- fixed style config and code format
1 parent f66c90e commit 5c76747

File tree

2 files changed

+163
-144
lines changed

2 files changed

+163
-144
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copying and distribution of this file, with or without modification,
2+
# are permitted in any medium without royalty provided this notice is
3+
# preserved. This file is offered as-is, without any warranty.
4+
# Names of contributors must not be used to endorse or promote products
5+
# derived from this file without specific prior written permission.
6+
7+
# EditorConfig
8+
# http://EditorConfig.org
9+
10+
# top-most EditorConfig file
11+
root = true
12+
13+
# LF end-of-line, insert an empty new line and UTF-8
14+
[*]
15+
end_of_line = lf
16+
insert_final_newline = true
17+
charset = utf-8
18+
indent_style = space
19+
indent_size = 4

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

Lines changed: 144 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -23,160 +23,160 @@ import kotlinx.android.synthetic.main.fragment_checklist.view.*
2323

2424
class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
2525

26-
private var noteId = 0L
27-
private var items = ArrayList<ChecklistItem>()
28-
private var note: Note? = null
26+
private var noteId = 0L
27+
private var items = ArrayList<ChecklistItem>()
28+
private var note: Note? = null
2929

30-
lateinit var view: ViewGroup
30+
lateinit var view: ViewGroup
3131

32-
val checklistItems get(): String = Gson().toJson(items)
32+
val checklistItems get(): String = Gson().toJson(items)
3333

34-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
35-
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
36-
noteId = arguments!!.getLong(NOTE_ID, 0L)
37-
return view
38-
}
34+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
35+
view = inflater.inflate(R.layout.fragment_checklist, container, false) as ViewGroup
36+
noteId = arguments!!.getLong(NOTE_ID, 0L)
37+
return view
38+
}
3939

40-
override fun onResume() {
41-
super.onResume()
40+
override fun onResume() {
41+
super.onResume()
4242

43-
loadNoteById(noteId)
44-
}
43+
loadNoteById(noteId)
44+
}
4545

46-
override fun setMenuVisibility(menuVisible: Boolean) {
47-
super.setMenuVisibility(menuVisible)
46+
override fun setMenuVisibility(menuVisible: Boolean) {
47+
super.setMenuVisibility(menuVisible)
4848

49-
if (menuVisible) {
49+
if (menuVisible) {
5050
activity?.hideKeyboard()
5151
}
52-
}
53-
54-
private fun loadNoteById(noteId: Long) {
55-
NotesHelper(requiredActivity).getNoteWithId(noteId) { storedNote ->
56-
if (storedNote != null && activity?.isDestroyed == false) {
57-
note = storedNote
58-
59-
try {
60-
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
61-
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
62-
?: ArrayList(1)
63-
} catch (e: Exception) {
64-
migrateCheckListOnFailure(storedNote)
65-
}
66-
67-
if (config?.moveUndoneChecklistItems == true) {
52+
}
53+
54+
private fun loadNoteById(noteId: Long) {
55+
NotesHelper(requiredActivity).getNoteWithId(noteId) { storedNote ->
56+
if (storedNote != null && activity?.isDestroyed == false) {
57+
note = storedNote
58+
59+
try {
60+
val checklistItemType = object : TypeToken<List<ChecklistItem>>() {}.type
61+
items = Gson().fromJson<ArrayList<ChecklistItem>>(storedNote.value, checklistItemType)
62+
?: ArrayList(1)
63+
} catch (e: Exception) {
64+
migrateCheckListOnFailure(storedNote)
65+
}
66+
67+
if (config?.moveUndoneChecklistItems == true) {
6868
items.sortBy { it.isDone }
6969
}
7070

71-
requiredActivity.updateTextColors(view.checklist_holder)
72-
setupFragment()
73-
}
74-
}
75-
}
76-
77-
private fun migrateCheckListOnFailure(note: Note) {
78-
items.clear()
79-
80-
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
81-
items.add(ChecklistItem(
82-
id = index,
83-
title = value,
84-
isDone = false
85-
))
86-
}
87-
88-
saveChecklist()
89-
}
90-
91-
private fun setupFragment() {
92-
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (requiredActivity.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
93-
94-
view.apply {
95-
with(checklist_fab) {
96-
setImageDrawable(plusIcon)
97-
background.applyColorFilter(requiredActivity.getAdjustedPrimaryColor())
98-
setOnClickListener {
99-
showNewItemDialog()
100-
}
101-
}
102-
103-
with(fragment_placeholder_2) {
104-
setTextColor(requiredActivity.getAdjustedPrimaryColor())
105-
underlineText()
106-
setOnClickListener {
107-
showNewItemDialog()
108-
}
109-
}
110-
}
111-
112-
setupAdapter()
113-
}
114-
115-
private fun showNewItemDialog() {
116-
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
117-
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
118-
119-
titles.forEach { title ->
120-
title.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEach { row ->
121-
items.add(ChecklistItem(currentMaxId + 1, row, false))
122-
currentMaxId++
123-
}
124-
}
125-
126-
saveNote()
127-
setupAdapter()
128-
129-
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
130-
}
131-
}
132-
133-
private fun setupAdapter() {
134-
with(view) {
135-
fragment_placeholder.beVisibleIf(items.isEmpty())
136-
fragment_placeholder_2.beVisibleIf(items.isEmpty())
137-
checklist_list.beVisibleIf(items.isNotEmpty())
138-
}
139-
140-
ChecklistAdapter(
141-
activity = activity as SimpleActivity,
142-
items = items,
143-
listener = this,
144-
recyclerView = view.checklist_list,
145-
showIcons = true
146-
) { item ->
147-
val clickedNote = item as ChecklistItem
148-
clickedNote.isDone = !clickedNote.isDone
149-
150-
saveNote(items.indexOfFirst { it.id == clickedNote.id })
151-
context?.updateWidgets()
152-
}.apply {
153-
view.checklist_list.adapter = this
154-
}
155-
}
156-
157-
private fun saveNote(refreshIndex: Int = -1) {
158-
ensureBackgroundThread {
159-
context?.let { ctx ->
160-
note?.let { currentNote ->
161-
if (refreshIndex != -1) {
162-
view.checklist_list.post {
163-
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
164-
}
165-
}
166-
167-
currentNote.value = checklistItems
168-
ctx.notesDB.insertOrUpdate(currentNote)
169-
ctx.updateWidgets()
170-
}
171-
}
172-
}
173-
}
174-
175-
override fun saveChecklist() {
176-
saveNote()
177-
}
178-
179-
override fun refreshItems() {
180-
setupAdapter()
181-
}
71+
requiredActivity.updateTextColors(view.checklist_holder)
72+
setupFragment()
73+
}
74+
}
75+
}
76+
77+
private fun migrateCheckListOnFailure(note: Note) {
78+
items.clear()
79+
80+
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
81+
items.add(ChecklistItem(
82+
id = index,
83+
title = value,
84+
isDone = false
85+
))
86+
}
87+
88+
saveChecklist()
89+
}
90+
91+
private fun setupFragment() {
92+
val plusIcon = resources.getColoredDrawableWithColor(R.drawable.ic_plus_vector, if (requiredActivity.isBlackAndWhiteTheme()) Color.BLACK else Color.WHITE)
93+
94+
view.apply {
95+
with(checklist_fab) {
96+
setImageDrawable(plusIcon)
97+
background.applyColorFilter(requiredActivity.getAdjustedPrimaryColor())
98+
setOnClickListener {
99+
showNewItemDialog()
100+
}
101+
}
102+
103+
with(fragment_placeholder_2) {
104+
setTextColor(requiredActivity.getAdjustedPrimaryColor())
105+
underlineText()
106+
setOnClickListener {
107+
showNewItemDialog()
108+
}
109+
}
110+
}
111+
112+
setupAdapter()
113+
}
114+
115+
private fun showNewItemDialog() {
116+
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
117+
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
118+
119+
titles.forEach { title ->
120+
title.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEach { row ->
121+
items.add(ChecklistItem(currentMaxId + 1, row, false))
122+
currentMaxId++
123+
}
124+
}
125+
126+
saveNote()
127+
setupAdapter()
128+
129+
(view.checklist_list.adapter as? ChecklistAdapter)?.notifyDataSetChanged()
130+
}
131+
}
132+
133+
private fun setupAdapter() {
134+
with(view) {
135+
fragment_placeholder.beVisibleIf(items.isEmpty())
136+
fragment_placeholder_2.beVisibleIf(items.isEmpty())
137+
checklist_list.beVisibleIf(items.isNotEmpty())
138+
}
139+
140+
ChecklistAdapter(
141+
activity = activity as SimpleActivity,
142+
items = items,
143+
listener = this,
144+
recyclerView = view.checklist_list,
145+
showIcons = true
146+
) { item ->
147+
val clickedNote = item as ChecklistItem
148+
clickedNote.isDone = !clickedNote.isDone
149+
150+
saveNote(items.indexOfFirst { it.id == clickedNote.id })
151+
context?.updateWidgets()
152+
}.apply {
153+
view.checklist_list.adapter = this
154+
}
155+
}
156+
157+
private fun saveNote(refreshIndex: Int = -1) {
158+
ensureBackgroundThread {
159+
context?.let { ctx ->
160+
note?.let { currentNote ->
161+
if (refreshIndex != -1) {
162+
view.checklist_list.post {
163+
view.checklist_list.adapter?.notifyItemChanged(refreshIndex)
164+
}
165+
}
166+
167+
currentNote.value = checklistItems
168+
ctx.notesDB.insertOrUpdate(currentNote)
169+
ctx.updateWidgets()
170+
}
171+
}
172+
}
173+
}
174+
175+
override fun saveChecklist() {
176+
saveNote()
177+
}
178+
179+
override fun refreshItems() {
180+
setupAdapter()
181+
}
182182
}

0 commit comments

Comments
 (0)