Skip to content

Commit

Permalink
fix(log): split adhesive log item
Browse files Browse the repository at this point in the history
  • Loading branch information
xchacha20-poly1305 committed Aug 31, 2024
1 parent 46a182e commit 9160e0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions app/src/main/java/io/nekohasekai/sagernet/ui/LogcatFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ class LogcatFragment : ToolbarFragment(R.layout.layout_logcat),
override fun getItemCount(): Int {
return logList.size
}

fun notifyItemInserted(): Int {
val position = logList.size - 1
notifyItemInserted(position)
return position
}
}

inner class LogViewHolder(val binding: ViewLogItemBinding) :
Expand Down Expand Up @@ -176,10 +170,11 @@ class LogcatFragment : ToolbarFragment(R.layout.layout_logcat),
.split(Libcore.LogSplitFlag)
.filterNot { it.isBlank() }
if (lines.isNotEmpty()) {
val startPosition = logAdapter.logList.size
logAdapter.logList.addAll(lines)
runOnMainDispatcher {
val position = logAdapter.notifyItemInserted()
if (!pinLog) binding.logView.scrollToPosition(position)
logAdapter.notifyItemRangeInserted(startPosition, lines.size)
if (!pinLog) binding.logView.scrollToPosition(logAdapter.itemCount - 1)
}
}
lastPosition = file.filePointer
Expand Down
4 changes: 2 additions & 2 deletions libcore/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ const LogSplitFlag = "\n\n"

func (w *logWriter) WriteMessage(_ log.Level, message string) {
// Prevent add extra LogSplitFlag
if !strings.HasSuffix(message, LogSplitFlag) {
message += LogSplitFlag
if !strings.HasPrefix(message, LogSplitFlag) {
message = LogSplitFlag + message
}
_, _ = io.WriteString(w.writer, message)
}
Expand Down

0 comments on commit 9160e0e

Please sign in to comment.