Skip to content
Snippets Groups Projects
Commit d4a1192a authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Implements day change messages

parent a73811df
Branches
Tags
No related merge requests found
......@@ -104,13 +104,15 @@ class MessageAdapter(
expansionListener: ((QuasselDatabase.DatabaseMessage) -> Unit)? = null
) : RecyclerView.ViewHolder(itemView) {
@BindView(R.id.time)
lateinit var time: TextView
@JvmField
var time: TextView? = null
@BindView(R.id.content)
lateinit var content: TextView
@BindView(R.id.markerline)
lateinit var markerline: View
@JvmField
var markerline: View? = null
private var message: FormattedMessage? = null
......@@ -142,9 +144,9 @@ class MessageAdapter(
fun bind(message: FormattedMessage) {
this.message = message
time.text = message.time
time?.text = message.time
content.text = message.content
markerline.visibleIf(message.isMarkerLine)
markerline?.visibleIf(message.isMarkerLine)
this.itemView.isSelected = message.isSelected
}
......
......@@ -20,6 +20,7 @@ import de.kuschku.libquassel.quassel.syncables.BufferSyncer
import de.kuschku.libquassel.util.helpers.value
import de.kuschku.quasseldroid.R
import de.kuschku.quasseldroid.persistence.QuasselDatabase
import de.kuschku.quasseldroid.persistence.findByBufferIdPagedWithDayChange
import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.BacklogSettings
import de.kuschku.quasseldroid.util.helper.*
......@@ -126,8 +127,7 @@ class MessageListFragment : ServiceBoundFragment() {
private val boundaryCallback = object :
PagedList.BoundaryCallback<DisplayMessage>() {
override fun onItemAtFrontLoaded(itemAtFront: DisplayMessage) = Unit
override fun onItemAtEndLoaded(itemAtEnd: DisplayMessage) =
loadMore(lastMessageId = itemAtEnd.content.messageId)
override fun onItemAtEndLoaded(itemAtEnd: DisplayMessage) = loadMore()
}
override fun onCreateView(
......@@ -162,6 +162,9 @@ class MessageListFragment : ServiceBoundFragment() {
messageList.layoutManager = linearLayoutManager
messageList.itemAnimator = null
messageList.setItemViewCacheSize(20)
messageList.addItemDecoration(object : RecyclerView.ItemDecoration() {
})
var isScrolling = false
messageList.addOnScrollListener(
......@@ -189,8 +192,9 @@ class MessageListFragment : ServiceBoundFragment() {
viewModel.markerLine)
.toLiveData().switchMapNotNull { (buffer, selected, expanded, markerLine) ->
database.filtered().listen(accountId, buffer).switchMapNotNull { filtered ->
LivePagedListBuilder(
database.message().findByBufferIdPaged(buffer, filtered).map {
database.message().findByBufferIdPagedWithDayChange(buffer, filtered).map {
DisplayMessage(
content = it,
isSelected = selected.contains(it.messageId),
......
......@@ -26,6 +26,7 @@ import de.kuschku.quasseldroid.viewmodel.data.FormattedMessage
import org.intellij.lang.annotations.Language
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle
import javax.inject.Inject
class QuasselMessageRenderer @Inject constructor(
......@@ -36,6 +37,8 @@ class QuasselMessageRenderer @Inject constructor(
timePattern(appearanceSettings.showSeconds, appearanceSettings.use24hClock)
)
private val dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
val monospaceItalic = Typeface.create(Typeface.MONOSPACE, Typeface.ITALIC)
private fun timePattern(showSeconds: Boolean,
......@@ -57,8 +60,9 @@ class QuasselMessageRenderer @Inject constructor(
Error -> R.layout.widget_chatmessage_error
Action -> R.layout.widget_chatmessage_action
Plain -> R.layout.widget_chatmessage_plain
Nick, Mode, Join, Part, Quit, Kick, Kill, Info, DayChange, Topic, NetsplitJoin, NetsplitQuit,
Nick, Mode, Join, Part, Quit, Kick, Kill, Info, Topic, NetsplitJoin, NetsplitQuit,
Invite -> R.layout.widget_chatmessage_info
DayChange -> R.layout.widget_chatmessage_daychange
else -> R.layout.widget_chatmessage_placeholder
}
......@@ -69,7 +73,7 @@ class QuasselMessageRenderer @Inject constructor(
viewHolder.itemView.context.theme.styledAttributes(
R.attr.colorForegroundHighlight, R.attr.colorBackgroundHighlight
) {
viewHolder.time.setTextColor(getColor(0, 0))
viewHolder.time?.setTextColor(getColor(0, 0))
viewHolder.content.setTextColor(getColor(0, 0))
viewHolder.itemView.setBackgroundColor(getColor(1, 0))
}
......@@ -83,7 +87,7 @@ class QuasselMessageRenderer @Inject constructor(
}
}
val textSize = appearanceSettings.textSize.toFloat()
viewHolder.time.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
viewHolder.time?.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
viewHolder.content.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
}
......@@ -338,6 +342,14 @@ class QuasselMessageRenderer @Inject constructor(
isExpanded = message.isExpanded,
isSelected = message.isSelected
)
DayChange -> FormattedMessage(
message.content.messageId,
"",
dateFormatter.format(message.content.time.atZone(zoneId)),
isMarkerLine = false,
isExpanded = false,
isSelected = false
)
else -> FormattedMessage(
message.content.messageId,
timeFormatter.format(message.content.time.atZone(zoneId)),
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/backgroundMenuItem"
android:orientation="vertical"
android:textAppearance="?android:attr/textAppearanceListItemSmall">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?colorDivider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="@dimen/message_vertical"
android:paddingEnd="@dimen/message_horizontal"
android:paddingLeft="@dimen/message_horizontal"
android:paddingRight="@dimen/message_horizontal"
android:paddingStart="@dimen/message_horizontal"
android:paddingTop="@dimen/message_vertical">
<TextView
android:id="@+id/content"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textColor="?attr/colorForeground"
android:textStyle="bold"
tools:text="27.03.2018" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -2,7 +2,9 @@ package de.kuschku.quasseldroid.persistence
import android.arch.lifecycle.LiveData
import android.arch.paging.DataSource
import android.arch.persistence.db.SimpleSQLiteQuery
import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.db.SupportSQLiteQuery
import android.arch.persistence.room.*
import android.arch.persistence.room.migration.Migration
import android.content.Context
......@@ -60,6 +62,15 @@ abstract class QuasselDatabase : RoomDatabase() {
)
fun findByBufferIdPaged(bufferId: Int, type: Int): DataSource.Factory<Int, DatabaseMessage>
@RawQuery(observedEntities = [DatabaseMessage::class])
fun findMessagesRawPaged(query: SupportSQLiteQuery): DataSource.Factory<Int, DatabaseMessage>
@RawQuery
fun findDaysRaw(query: SupportSQLiteQuery): List<Instant>
@RawQuery
fun findMessagesRaw(query: SupportSQLiteQuery): List<DatabaseMessage>
@Query("SELECT * FROM message WHERE bufferId = :bufferId ORDER BY messageId DESC LIMIT 1")
fun findLastByBufferId(bufferId: Int): DatabaseMessage?
......@@ -164,3 +175,71 @@ fun QuasselDatabase.MessageDao.clearMessages(
) {
this.clearMessages(bufferId, idRange.first, idRange.last)
}
fun QuasselDatabase.MessageDao.findByBufferIdPagedWithDayChange(bufferId: Int, type: Int) =
this.findMessagesRawPaged(SimpleSQLiteQuery("""
SELECT t.*
FROM
(
SELECT
messageId,
time,
type,
flag,
bufferId,
sender,
senderPrefixes,
content
FROM message
WHERE bufferId = ?
AND type & ~? > 0
UNION ALL
SELECT DISTINCT
strftime('%s', date(datetime(time / 1000, 'unixepoch')), 'utc') * -1000 AS messageId,
strftime('%s', date(datetime(time / 1000, 'unixepoch')), 'utc') * 1000 AS time,
8192 AS type,
0 AS flag,
? AS bufferId,
'' AS sender,
'' AS senderPrefixes,
'' AS content
FROM message
WHERE bufferId = ?
AND type & ~? > 0
) t
ORDER BY time DESC
""", arrayOf(bufferId, type, bufferId, bufferId, type)))
fun QuasselDatabase.MessageDao.findByBufferIdWithDayChange(bufferId: Int, type: Int) =
this.findMessagesRaw(SimpleSQLiteQuery("""
SELECT t.*
FROM
(
SELECT
messageId,
time,
type,
flag,
bufferId,
sender,
senderPrefixes,
content
FROM message
WHERE bufferId = ?
AND type & ~? > 0
UNION ALL
SELECT DISTINCT
strftime('%s', date(datetime(time / 1000, 'unixepoch'))) * -1000 AS messageId,
strftime('%s', date(datetime(time / 1000, 'unixepoch'))) * 1000 AS time,
8192 AS type,
0 AS flag,
? AS bufferId,
'' AS sender,
'' AS senderPrefixes,
'' AS content
FROM message
WHERE bufferId = ?
AND type & ~? > 0
) t
ORDER BY time DESC
""", arrayOf(bufferId, type, bufferId, bufferId, type)))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment