Skip to content

Commit df3c55c

Browse files
committed
Fixed inserting inside the list
1 parent cb3278e commit df3c55c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/src/main/kotlin/org/fossify/notes/dialogs/NewChecklistItemDialog.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
5757
}
5858
}
5959

60-
private fun addNewEditText(initialText: String? = null) {
60+
private fun addNewEditText(initialText: String? = null, position: Int? = null) {
6161
ItemAddChecklistBinding.inflate(activity.layoutInflater).apply {
6262
titleEditText.setOnEditorActionListener { _, actionId, _ ->
6363
if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || actionId == KeyEvent.KEYCODE_ENTER) {
@@ -70,20 +70,26 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
7070
titleEditText.onTextChangeListener { text ->
7171
val lines = text.lines().filter { it.trim().isNotEmpty() }
7272
if (lines.size > 1) {
73+
val currentPosition = titles.indexOf(titleEditText)
7374
lines.forEachIndexed { i, line ->
7475
if (i == 0) {
7576
titleEditText.setText(line)
7677
} else {
77-
addNewEditText(line)
78+
addNewEditText(line, currentPosition + i)
7879
}
7980
}
8081
}
8182
}
8283
if (initialText != null) {
8384
titleEditText.setText(initialText)
8485
}
85-
titles.add(titleEditText)
86-
binding.checklistHolder.addView(this.root)
86+
if (position != null && position < titles.size) {
87+
titles.add(position, titleEditText)
88+
binding.checklistHolder.addView(this.root, position)
89+
} else {
90+
titles.add(titleEditText)
91+
binding.checklistHolder.addView(this.root)
92+
}
8793
activity.updateTextColors(binding.checklistHolder)
8894
binding.dialogHolder.post {
8995
binding.dialogHolder.fullScroll(View.FOCUS_DOWN)

0 commit comments

Comments
 (0)