Skip to content

Commit

Permalink
ui: do not notify entire dataset when adding log items
Browse files Browse the repository at this point in the history
Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
zx2c4 committed Mar 28, 2023
1 parent 2da80e8 commit ec126a9
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,18 @@ class LogViewerActivity : AppCompatActivity() {
recyclerView?.let {
val shouldScroll = haveScrolled && !it.canScrollVertically(1)
logLines.add(logLine)
if (haveScrolled) logAdapter.notifyDataSetChanged()
if (haveScrolled) logAdapter.notifyItemInserted(logLines.size - 1)
if (shouldScroll)
it.scrollToPosition(logLines.size - 1)
}
} else {
logLines.lastOrNull()?.msg += "\n$line"
if (haveScrolled) logAdapter.notifyDataSetChanged()
if (haveScrolled) logAdapter.notifyItemChanged(logLines.size - 1)
}
if (!haveScrolled) {
val end = System.nanoTime()
val scroll = (end - start) > 1000000000L * 2.5 || !stdout.ready()
if (logLines.isNotEmpty() && (scroll || (end - startPeriod) > 1000000000L / 4)) {
logAdapter.notifyDataSetChanged()
recyclerView?.scrollToPosition(logLines.size - 1)
startPeriod = end
}
Expand Down

0 comments on commit ec126a9

Please sign in to comment.