From 06ed00c9eb2731e4e4509bb4ea3a116898a48993 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sat, 19 Jun 2021 17:32:39 +0200 Subject: [PATCH] Obey day_change property for date line --- .../ubergeek42/WeechatAndroid/relay/Buffer.kt | 8 +++-- .../ubergeek42/WeechatAndroid/relay/Lines.kt | 35 ++++++++++--------- .../ubergeek42/WeechatAndroid/relay/Spec.kt | 4 ++- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Buffer.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Buffer.kt index c054f743..40d67945 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Buffer.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Buffer.kt @@ -25,6 +25,7 @@ class Buffer @WorkerThread constructor( @JvmField var shortName: String = "" @JvmField var hidden: Boolean = false @JvmField var type = BufferSpec.Type.Other + @JvmField var displayDayChange: Boolean = false private var notify: Notify = Notify.default @@ -34,6 +35,7 @@ class Buffer @WorkerThread constructor( internal var updateHidden = false internal var updateType = false internal var updateNotifyLevel = false + internal var updateDayChange = false var number: Int by updatable(::updateName, this@Buffer::number) var fullName: String by updatable(::updateName, this@Buffer::fullName) @@ -42,6 +44,7 @@ class Buffer @WorkerThread constructor( var hidden: Boolean by updatable(::updateHidden) var type: BufferSpec.Type by updatable(::updateType) var notify: Notify? by updatable(::updateNotifyLevel) + var displayDayChange: Boolean by updatable(::updateDayChange) } fun update(block: Updater.() -> Unit) { @@ -65,6 +68,7 @@ class Buffer @WorkerThread constructor( if (updater.updateNotifyLevel) notify = updater.notify ?: Notify.default if (updater.updateHidden) hidden = updater.hidden if (updater.updateType) type = updater.type + if (updater.updateDayChange) displayDayChange = updater.displayDayChange } //////////////////////////////////////////////////////////////////////////////////////////////// @@ -215,7 +219,7 @@ class Buffer @WorkerThread constructor( } synchronized(this) { - lines.replaceLines(newLines) + lines.replaceLines(newLines, displayDayChange) } } @@ -227,7 +231,7 @@ class Buffer @WorkerThread constructor( val notifyPmOrMessage = line.notifyLevel == LineSpec.NotifyLevel.Message || notifyPm synchronized(this) { - lines.addLast(line) + lines.addLast(line, displayDayChange) // notify levels: 0 none 1 highlight 2 message 3 all // treat hidden lines and lines that are not supposed to generate a “notification” as read diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt index 864d51fc..25c11fcd 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Lines.kt @@ -99,7 +99,7 @@ class Lines { // in very rare cases status might not be FETCHING here, particularly when closing buffers // while the app is connecting and has already requested lines - fun replaceLines(lines: Collection) { + fun replaceLines(lines: Collection, displayDayChange: Boolean) { if (status != Status.Fetching) return unfiltered.clear() filtered.clear() @@ -107,7 +107,7 @@ class Lines { dateOfLastFilteredLine = null for (line in lines) { - addLast(line) + addLast(line, displayDayChange) } } @@ -135,26 +135,29 @@ class Lines { return lastDateLine } - fun addLast(line: Line) { + fun addLast(line: Line, displayDayChange: Boolean) { if (shouldAddSquiggleOnNewLine) { shouldAddSquiggleOnNewLine = false - if (status == Status.Init && unfiltered.size > 0) addLast(SquiggleLine()) // invisible + if (status == Status.Init && unfiltered.size > 0) + addLast(SquiggleLine(), displayDayChange) // invisible } - val newDate = Instant.ofEpochSecond(line.timestamp / 1000) - .atZone(ZoneId.systemDefault()) - .toLocalDate() + if(displayDayChange) { + val newDate = Instant.ofEpochSecond(line.timestamp / 1000) + .atZone(ZoneId.systemDefault()) + .toLocalDate() - if (dateOfLastUnfilteredLine != newDate) { - unfiltered.addLast(obtainDateChangeLine(dateOfLastUnfilteredLine, newDate)) - dateOfLastUnfilteredLine = newDate - skipUnfiltered++ - } + if (dateOfLastUnfilteredLine != newDate) { + unfiltered.addLast(obtainDateChangeLine(dateOfLastUnfilteredLine, newDate)) + dateOfLastUnfilteredLine = newDate + skipUnfiltered++ + } - if (line.isVisible && dateOfLastFilteredLine != newDate) { - filtered.addLast(obtainDateChangeLine(dateOfLastFilteredLine, newDate)) - dateOfLastFilteredLine = newDate - skipFiltered++ + if (line.isVisible && dateOfLastFilteredLine != newDate) { + filtered.addLast(obtainDateChangeLine(dateOfLastFilteredLine, newDate)) + dateOfLastFilteredLine = newDate + skipFiltered++ + } } if (shouldAddSquiggleOnNewVisibleLine && line.isVisible) { diff --git a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Spec.kt b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Spec.kt index 7559ac4f..191c3d45 100644 --- a/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Spec.kt +++ b/app/src/main/java/com/ubergeek42/WeechatAndroid/relay/Spec.kt @@ -39,6 +39,7 @@ enum class Notify(val value: Int) { inline val notify: Notify? get() = Notify::value.find(entry.getIntOrNull("notify")) inline val type get() = Type.fromLocalVariables(entry.getHashtable("local_variables")) inline val hidden get() = entry.getIntOrNull("hidden") == 1 + inline val displayDayChange get() = entry.getIntOrNull("day_change") == 1 // todo get rid of openWhileRunning fun toBuffer(openWhileRunning: Boolean) = Buffer(pointer).apply { @@ -50,6 +51,7 @@ enum class Notify(val value: Int) { notify = this@BufferSpec.notify hidden = this@BufferSpec.hidden type = this@BufferSpec.type + displayDayChange = this@BufferSpec.displayDayChange } if (P.isBufferOpen(pointer)) setOpen(open = true, syncHotlistOnOpen = false) @@ -67,7 +69,7 @@ enum class Notify(val value: Int) { companion object { const val listBuffersRequest = "(listbuffers) hdata buffer:gui_buffers(*) " + - "number,full_name,short_name,type,title,nicklist,local_variables,notify,hidden" + "number,full_name,short_name,type,title,nicklist,local_variables,notify,hidden,day_change" const val renumberRequest = "(renumber) hdata buffer:gui_buffers(*) number" }