fix: 贴子历史记录更新
This commit is contained in:
parent
6f0e82f0ef
commit
5db6a0cb2e
|
|
@ -1,5 +1,6 @@
|
||||||
package com.huanchengfly.tieba.post.ui.page.thread
|
package com.huanchengfly.tieba.post.ui.page.thread
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.animation.animateColorAsState
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
|
@ -555,7 +556,7 @@ fun ThreadPage(
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
data.firstOrNull { (post) ->
|
data.firstOrNull { (post) ->
|
||||||
val lastPostKey = lazyListState.layoutInfo.visibleItemsInfo.lastOrNull { info ->
|
val lastPostKey = lazyListState.layoutInfo.visibleItemsInfo.lastOrNull { info ->
|
||||||
info.key is String && (info.key as String).startsWith("Post")
|
info.key is String && (info.key as String).startsWith("Post_")
|
||||||
}?.key as String?
|
}?.key as String?
|
||||||
lastPostKey?.endsWith(post.get { id }.toString()) == true
|
lastPostKey?.endsWith(post.get { id }.toString()) == true
|
||||||
}?.post ?: firstPost
|
}?.post ?: firstPost
|
||||||
|
|
@ -773,8 +774,10 @@ fun ThreadPage(
|
||||||
data = threadId.toString(),
|
data = threadId.toString(),
|
||||||
type = HistoryUtil.TYPE_THREAD,
|
type = HistoryUtil.TYPE_THREAD,
|
||||||
extras = ThreadHistoryInfoBean(
|
extras = ThreadHistoryInfoBean(
|
||||||
|
isSeeLz = isSeeLz,
|
||||||
pid = lastVisibilityPostId.toString(),
|
pid = lastVisibilityPostId.toString(),
|
||||||
isSeeLz = seeLz
|
forumName = forum?.get { name },
|
||||||
|
floor = lastVisibilityPost?.get { floor }?.toString()
|
||||||
).toJson(),
|
).toJson(),
|
||||||
avatar = StringUtil.getAvatarUrl(author?.get { portrait }),
|
avatar = StringUtil.getAvatarUrl(author?.get { portrait }),
|
||||||
username = author?.get { nameShow }
|
username = author?.get { nameShow }
|
||||||
|
|
@ -782,6 +785,7 @@ fun ThreadPage(
|
||||||
async = true
|
async = true
|
||||||
)
|
)
|
||||||
savedHistory = true
|
savedHistory = true
|
||||||
|
Log.i("ThreadPage", "saveHistory $lastVisibilityPostId")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,15 +84,15 @@ object HistoryUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAsync(
|
private fun updateAsync(
|
||||||
data: String,
|
history: History,
|
||||||
callback: ((Boolean) -> Unit)? = null
|
callback: ((Boolean) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
where("data = ?", data).findFirstAsync<History?>()
|
where("data = ?", history.data).findFirstAsync<History?>()
|
||||||
.listen {
|
.listen {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
callback?.invoke(false)
|
callback?.invoke(false)
|
||||||
} else {
|
} else {
|
||||||
it.copy(
|
history.copy(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
count = it.count + 1
|
count = it.count + 1
|
||||||
).updateAsync(it.id).listen {
|
).updateAsync(it.id).listen {
|
||||||
|
|
@ -118,7 +118,7 @@ object HistoryUtil {
|
||||||
history: History,
|
history: History,
|
||||||
callback: ((Boolean) -> Unit)? = null
|
callback: ((Boolean) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
updateAsync(history.data) { success ->
|
updateAsync(history) { success ->
|
||||||
if (!success) {
|
if (!success) {
|
||||||
history.copy(count = 1, timestamp = System.currentTimeMillis())
|
history.copy(count = 1, timestamp = System.currentTimeMillis())
|
||||||
.saveAsync()
|
.saveAsync()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue