refactor: 移动 Protobuf Beans 的扩展属性到另一个文件
This commit is contained in:
parent
ecaf79afc5
commit
140f8b84cb
|
|
@ -1,33 +1,8 @@
|
||||||
package com.huanchengfly.tieba.post.api
|
package com.huanchengfly.tieba.post.api
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.foundation.text.appendInlineContent
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.text.ExperimentalTextApi
|
|
||||||
import androidx.compose.ui.text.SpanStyle
|
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
|
||||||
import androidx.compose.ui.text.withAnnotation
|
|
||||||
import androidx.compose.ui.text.withStyle
|
|
||||||
import com.huanchengfly.tieba.post.App
|
import com.huanchengfly.tieba.post.App
|
||||||
import com.huanchengfly.tieba.post.App.ScreenInfo
|
import com.huanchengfly.tieba.post.App.ScreenInfo
|
||||||
import com.huanchengfly.tieba.post.R
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.PbContent
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Post
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SubPostList
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
|
||||||
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.PbContentRender
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.PicContentRender
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.TextContentRender.Companion.appendText
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.VideoContentRender
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.VoiceContentRender
|
|
||||||
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
|
||||||
import com.huanchengfly.tieba.post.ui.utils.getPhotoViewData
|
|
||||||
import com.huanchengfly.tieba.post.utils.EmoticonManager
|
|
||||||
import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString
|
|
||||||
import com.huanchengfly.tieba.post.utils.ImageUtil
|
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
|
||||||
|
|
||||||
|
|
||||||
private val defaultUserAgent: String =
|
private val defaultUserAgent: String =
|
||||||
|
|
@ -43,307 +18,3 @@ fun getScreenHeight(): Int = ScreenInfo.EXACT_SCREEN_HEIGHT
|
||||||
fun getScreenWidth(): Int = ScreenInfo.EXACT_SCREEN_WIDTH
|
fun getScreenWidth(): Int = ScreenInfo.EXACT_SCREEN_WIDTH
|
||||||
|
|
||||||
fun Boolean.booleanToString(): String = if (this) "1" else "0"
|
fun Boolean.booleanToString(): String = if (this) "1" else "0"
|
||||||
|
|
||||||
val ThreadInfo.abstractText: String
|
|
||||||
get() = richAbstract.joinToString(separator = "") {
|
|
||||||
when (it.type) {
|
|
||||||
0 -> it.text.replace(Regex(" {2,}"), " ")
|
|
||||||
2 -> {
|
|
||||||
EmoticonManager.registerEmoticon(it.text, it.c)
|
|
||||||
"#(${it.c})"
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val ThreadInfo.hasAgree: Int
|
|
||||||
get() = agree?.hasAgree ?: 0
|
|
||||||
|
|
||||||
val ThreadInfo.hasAgreed: Boolean
|
|
||||||
get() = hasAgree == 1
|
|
||||||
|
|
||||||
val ThreadInfo.hasAbstract: Boolean
|
|
||||||
get() = richAbstract.any { (it.type == 0 && it.text.isNotBlank()) || it.type == 2 }
|
|
||||||
|
|
||||||
fun ThreadInfo.updateAgreeStatus(
|
|
||||||
hasAgree: Int
|
|
||||||
) = if (agree != null) {
|
|
||||||
if (hasAgree != agree.hasAgree) {
|
|
||||||
if (hasAgree == 1) {
|
|
||||||
copy(
|
|
||||||
agreeNum = agreeNum + 1,
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum + 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum + 1,
|
|
||||||
hasAgree = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
copy(
|
|
||||||
agreeNum = agreeNum - 1,
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum - 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum - 1,
|
|
||||||
hasAgree = 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
copy(
|
|
||||||
agreeNum = if (hasAgree == 1) agreeNum + 1 else agreeNum - 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ThreadInfo.updateCollectStatus(
|
|
||||||
newStatus: Int,
|
|
||||||
markPostId: Long
|
|
||||||
) = if (collectStatus != newStatus) {
|
|
||||||
this.copy(
|
|
||||||
collectStatus = newStatus,
|
|
||||||
collectMarkPid = markPostId.toString()
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Post.updateAgreeStatus(
|
|
||||||
hasAgree: Int
|
|
||||||
) = if (agree != null) {
|
|
||||||
if (hasAgree != agree.hasAgree) {
|
|
||||||
if (hasAgree == 1) {
|
|
||||||
copy(
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum + 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum + 1,
|
|
||||||
hasAgree = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
copy(
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum - 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum - 1,
|
|
||||||
hasAgree = 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun SubPostList.updateAgreeStatus(
|
|
||||||
hasAgree: Int
|
|
||||||
) = if (agree != null) {
|
|
||||||
if (hasAgree != agree.hasAgree) {
|
|
||||||
if (hasAgree == 1) {
|
|
||||||
copy(
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum + 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum + 1,
|
|
||||||
hasAgree = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
copy(
|
|
||||||
agree = agree.copy(
|
|
||||||
agreeNum = agree.agreeNum - 1,
|
|
||||||
diffAgreeNum = agree.diffAgreeNum - 1,
|
|
||||||
hasAgree = 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
private val PbContent.picUrl: String
|
|
||||||
get() =
|
|
||||||
ImageUtil.getUrl(
|
|
||||||
App.INSTANCE,
|
|
||||||
true,
|
|
||||||
originSrc,
|
|
||||||
bigCdnSrc,
|
|
||||||
bigSrc,
|
|
||||||
dynamic_,
|
|
||||||
cdnSrc,
|
|
||||||
cdnSrcActive,
|
|
||||||
src
|
|
||||||
)
|
|
||||||
|
|
||||||
val List<PbContent>.plainText: String
|
|
||||||
get() = joinToString(separator = "") {
|
|
||||||
when (it.type) {
|
|
||||||
0, 1, 4, 9, 27 -> it.text
|
|
||||||
2 -> "#(${it.c})"
|
|
||||||
3, 20 -> "[图片]"
|
|
||||||
5 -> "[视频]"
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalTextApi::class)
|
|
||||||
val List<PbContent>.renders: ImmutableList<PbContentRender>
|
|
||||||
get() {
|
|
||||||
val renders = mutableListOf<PbContentRender>()
|
|
||||||
|
|
||||||
forEach {
|
|
||||||
when (it.type) {
|
|
||||||
0, 9, 27 -> {
|
|
||||||
renders.appendText(it.text)
|
|
||||||
}
|
|
||||||
|
|
||||||
1 -> {
|
|
||||||
val text = buildAnnotatedString {
|
|
||||||
appendInlineContent("link_icon", alternateText = "🔗")
|
|
||||||
withAnnotation(tag = "url", annotation = it.link) {
|
|
||||||
withStyle(
|
|
||||||
SpanStyle(
|
|
||||||
color = Color(
|
|
||||||
ThemeUtils.getColorByAttr(
|
|
||||||
App.INSTANCE,
|
|
||||||
R.attr.colorPrimary
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
append(it.text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
renders.appendText(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
2 -> {
|
|
||||||
EmoticonManager.registerEmoticon(
|
|
||||||
it.text,
|
|
||||||
it.c
|
|
||||||
)
|
|
||||||
val emoticonText = "#(${it.c})".emoticonString
|
|
||||||
renders.appendText(emoticonText)
|
|
||||||
}
|
|
||||||
|
|
||||||
3 -> {
|
|
||||||
val width = it.bsize.split(",")[0].toInt()
|
|
||||||
val height = it.bsize.split(",")[1].toInt()
|
|
||||||
renders.add(
|
|
||||||
PicContentRender(
|
|
||||||
picUrl = it.picUrl,
|
|
||||||
originUrl = it.originSrc,
|
|
||||||
showOriginBtn = it.showOriginalBtn == 1,
|
|
||||||
originSize = it.originSize,
|
|
||||||
picId = ImageUtil.getPicId(it.originSrc),
|
|
||||||
width = width,
|
|
||||||
height = height
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
4 -> {
|
|
||||||
val text = buildAnnotatedString {
|
|
||||||
withAnnotation(tag = "user", annotation = "${it.uid}") {
|
|
||||||
withStyle(
|
|
||||||
SpanStyle(
|
|
||||||
color = Color(
|
|
||||||
ThemeUtils.getColorByAttr(
|
|
||||||
App.INSTANCE,
|
|
||||||
R.attr.colorPrimary
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
append(it.text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
renders.appendText(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
5 -> {
|
|
||||||
if (it.src.isNotBlank()) {
|
|
||||||
val width = it.bsize.split(",")[0].toInt()
|
|
||||||
val height = it.bsize.split(",")[1].toInt()
|
|
||||||
renders.add(
|
|
||||||
VideoContentRender(
|
|
||||||
videoUrl = it.link,
|
|
||||||
picUrl = it.src,
|
|
||||||
webUrl = it.text,
|
|
||||||
width = width,
|
|
||||||
height = height
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val text = buildAnnotatedString {
|
|
||||||
appendInlineContent("video_icon", alternateText = "🎥")
|
|
||||||
withAnnotation(tag = "url", annotation = it.text) {
|
|
||||||
withStyle(
|
|
||||||
SpanStyle(
|
|
||||||
color = Color(
|
|
||||||
ThemeUtils.getColorByAttr(
|
|
||||||
App.INSTANCE,
|
|
||||||
R.attr.colorPrimary
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
append(App.INSTANCE.getString(R.string.tag_video))
|
|
||||||
append(it.text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
renders.appendText(text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
10 -> {
|
|
||||||
renders.add(VoiceContentRender(it.voiceMD5, it.duringTime))
|
|
||||||
}
|
|
||||||
|
|
||||||
20 -> {
|
|
||||||
val width = it.bsize.split(",")[0].toInt()
|
|
||||||
val height = it.bsize.split(",")[1].toInt()
|
|
||||||
renders.add(
|
|
||||||
PicContentRender(
|
|
||||||
picUrl = it.src,
|
|
||||||
originUrl = it.src,
|
|
||||||
showOriginBtn = it.showOriginalBtn == 1,
|
|
||||||
originSize = it.originSize,
|
|
||||||
picId = ImageUtil.getPicId(it.src),
|
|
||||||
width = width,
|
|
||||||
height = height
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return renders.toImmutableList()
|
|
||||||
}
|
|
||||||
|
|
||||||
val Post.contentRenders: ImmutableList<PbContentRender>
|
|
||||||
get() {
|
|
||||||
val renders = content.renders
|
|
||||||
|
|
||||||
return renders.map {
|
|
||||||
if (it is PicContentRender) {
|
|
||||||
val data = getPhotoViewData(
|
|
||||||
this,
|
|
||||||
it.picId,
|
|
||||||
it.picUrl,
|
|
||||||
it.originUrl,
|
|
||||||
it.showOriginBtn,
|
|
||||||
it.originSize
|
|
||||||
)
|
|
||||||
if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it
|
|
||||||
} else it
|
|
||||||
}.toImmutableList()
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,327 @@
|
||||||
|
package com.huanchengfly.tieba.post.api.models.protos
|
||||||
|
|
||||||
|
import androidx.compose.foundation.text.appendInlineContent
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.ExperimentalTextApi
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
|
import androidx.compose.ui.text.withAnnotation
|
||||||
|
import androidx.compose.ui.text.withStyle
|
||||||
|
import com.huanchengfly.tieba.post.App
|
||||||
|
import com.huanchengfly.tieba.post.R
|
||||||
|
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.PbContentRender
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.PicContentRender
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.TextContentRender.Companion.appendText
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.VideoContentRender
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.VoiceContentRender
|
||||||
|
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
||||||
|
import com.huanchengfly.tieba.post.ui.utils.getPhotoViewData
|
||||||
|
import com.huanchengfly.tieba.post.utils.EmoticonManager
|
||||||
|
import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString
|
||||||
|
import com.huanchengfly.tieba.post.utils.ImageUtil
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
|
val ThreadInfo.abstractText: String
|
||||||
|
get() = richAbstract.joinToString(separator = "") {
|
||||||
|
when (it.type) {
|
||||||
|
0 -> it.text.replace(Regex(" {2,}"), " ")
|
||||||
|
2 -> {
|
||||||
|
EmoticonManager.registerEmoticon(it.text, it.c)
|
||||||
|
"#(${it.c})"
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val ThreadInfo.hasAgree: Int
|
||||||
|
get() = agree?.hasAgree ?: 0
|
||||||
|
val ThreadInfo.hasAgreed: Boolean
|
||||||
|
get() = hasAgree == 1
|
||||||
|
val ThreadInfo.hasAbstract: Boolean
|
||||||
|
get() = richAbstract.any { (it.type == 0 && it.text.isNotBlank()) || it.type == 2 }
|
||||||
|
|
||||||
|
fun ThreadInfo.updateAgreeStatus(
|
||||||
|
hasAgree: Int
|
||||||
|
) = if (agree != null) {
|
||||||
|
if (hasAgree != agree.hasAgree) {
|
||||||
|
if (hasAgree == 1) {
|
||||||
|
copy(
|
||||||
|
agreeNum = agreeNum + 1,
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum + 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum + 1,
|
||||||
|
hasAgree = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
copy(
|
||||||
|
agreeNum = agreeNum - 1,
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum - 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum - 1,
|
||||||
|
hasAgree = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
copy(
|
||||||
|
agreeNum = if (hasAgree == 1) agreeNum + 1 else agreeNum - 1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ThreadInfo.updateCollectStatus(
|
||||||
|
newStatus: Int,
|
||||||
|
markPostId: Long
|
||||||
|
) = if (collectStatus != newStatus) {
|
||||||
|
this.copy(
|
||||||
|
collectStatus = newStatus,
|
||||||
|
collectMarkPid = markPostId.toString()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Post.updateAgreeStatus(
|
||||||
|
hasAgree: Int
|
||||||
|
) = if (agree != null) {
|
||||||
|
if (hasAgree != agree.hasAgree) {
|
||||||
|
if (hasAgree == 1) {
|
||||||
|
copy(
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum + 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum + 1,
|
||||||
|
hasAgree = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
copy(
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum - 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum - 1,
|
||||||
|
hasAgree = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun SubPostList.updateAgreeStatus(
|
||||||
|
hasAgree: Int
|
||||||
|
) = if (agree != null) {
|
||||||
|
if (hasAgree != agree.hasAgree) {
|
||||||
|
if (hasAgree == 1) {
|
||||||
|
copy(
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum + 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum + 1,
|
||||||
|
hasAgree = 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
copy(
|
||||||
|
agree = agree.copy(
|
||||||
|
agreeNum = agree.agreeNum - 1,
|
||||||
|
diffAgreeNum = agree.diffAgreeNum - 1,
|
||||||
|
hasAgree = 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
private val PbContent.picUrl: String
|
||||||
|
get() =
|
||||||
|
ImageUtil.getUrl(
|
||||||
|
App.INSTANCE,
|
||||||
|
true,
|
||||||
|
originSrc,
|
||||||
|
bigCdnSrc,
|
||||||
|
bigSrc,
|
||||||
|
dynamic_,
|
||||||
|
cdnSrc,
|
||||||
|
cdnSrcActive,
|
||||||
|
src
|
||||||
|
)
|
||||||
|
val List<PbContent>.plainText: String
|
||||||
|
get() = joinToString(separator = "") {
|
||||||
|
when (it.type) {
|
||||||
|
0, 1, 4, 9, 27 -> it.text
|
||||||
|
2 -> "#(${it.c})"
|
||||||
|
3, 20 -> "[图片]"
|
||||||
|
5 -> "[视频]"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTextApi::class)
|
||||||
|
val List<PbContent>.renders: ImmutableList<PbContentRender>
|
||||||
|
get() {
|
||||||
|
val renders = mutableListOf<PbContentRender>()
|
||||||
|
|
||||||
|
forEach {
|
||||||
|
when (it.type) {
|
||||||
|
0, 9, 27 -> {
|
||||||
|
renders.appendText(it.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
1 -> {
|
||||||
|
val text = buildAnnotatedString {
|
||||||
|
appendInlineContent("link_icon", alternateText = "🔗")
|
||||||
|
withAnnotation(tag = "url", annotation = it.link) {
|
||||||
|
withStyle(
|
||||||
|
SpanStyle(
|
||||||
|
color = Color(
|
||||||
|
ThemeUtils.getColorByAttr(
|
||||||
|
App.INSTANCE,
|
||||||
|
R.attr.colorPrimary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
append(it.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renders.appendText(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
2 -> {
|
||||||
|
EmoticonManager.registerEmoticon(
|
||||||
|
it.text,
|
||||||
|
it.c
|
||||||
|
)
|
||||||
|
val emoticonText = "#(${it.c})".emoticonString
|
||||||
|
renders.appendText(emoticonText)
|
||||||
|
}
|
||||||
|
|
||||||
|
3 -> {
|
||||||
|
val width = it.bsize.split(",")[0].toInt()
|
||||||
|
val height = it.bsize.split(",")[1].toInt()
|
||||||
|
renders.add(
|
||||||
|
PicContentRender(
|
||||||
|
picUrl = it.picUrl,
|
||||||
|
originUrl = it.originSrc,
|
||||||
|
showOriginBtn = it.showOriginalBtn == 1,
|
||||||
|
originSize = it.originSize,
|
||||||
|
picId = ImageUtil.getPicId(it.originSrc),
|
||||||
|
width = width,
|
||||||
|
height = height
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
4 -> {
|
||||||
|
val text = buildAnnotatedString {
|
||||||
|
withAnnotation(tag = "user", annotation = "${it.uid}") {
|
||||||
|
withStyle(
|
||||||
|
SpanStyle(
|
||||||
|
color = Color(
|
||||||
|
ThemeUtils.getColorByAttr(
|
||||||
|
App.INSTANCE,
|
||||||
|
R.attr.colorPrimary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
append(it.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renders.appendText(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
5 -> {
|
||||||
|
if (it.src.isNotBlank()) {
|
||||||
|
val width = it.bsize.split(",")[0].toInt()
|
||||||
|
val height = it.bsize.split(",")[1].toInt()
|
||||||
|
renders.add(
|
||||||
|
VideoContentRender(
|
||||||
|
videoUrl = it.link,
|
||||||
|
picUrl = it.src,
|
||||||
|
webUrl = it.text,
|
||||||
|
width = width,
|
||||||
|
height = height
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val text = buildAnnotatedString {
|
||||||
|
appendInlineContent("video_icon", alternateText = "🎥")
|
||||||
|
withAnnotation(tag = "url", annotation = it.text) {
|
||||||
|
withStyle(
|
||||||
|
SpanStyle(
|
||||||
|
color = Color(
|
||||||
|
ThemeUtils.getColorByAttr(
|
||||||
|
App.INSTANCE,
|
||||||
|
R.attr.colorPrimary
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
append(App.INSTANCE.getString(R.string.tag_video))
|
||||||
|
append(it.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renders.appendText(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
10 -> {
|
||||||
|
renders.add(VoiceContentRender(it.voiceMD5, it.duringTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
20 -> {
|
||||||
|
val width = it.bsize.split(",")[0].toInt()
|
||||||
|
val height = it.bsize.split(",")[1].toInt()
|
||||||
|
renders.add(
|
||||||
|
PicContentRender(
|
||||||
|
picUrl = it.src,
|
||||||
|
originUrl = it.src,
|
||||||
|
showOriginBtn = it.showOriginalBtn == 1,
|
||||||
|
originSize = it.originSize,
|
||||||
|
picId = ImageUtil.getPicId(it.src),
|
||||||
|
width = width,
|
||||||
|
height = height
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return renders.toImmutableList()
|
||||||
|
}
|
||||||
|
val Post.contentRenders: ImmutableList<PbContentRender>
|
||||||
|
get() {
|
||||||
|
val renders = content.renders
|
||||||
|
|
||||||
|
return renders.map {
|
||||||
|
if (it is PicContentRender) {
|
||||||
|
val data = getPhotoViewData(
|
||||||
|
this,
|
||||||
|
it.picId,
|
||||||
|
it.picUrl,
|
||||||
|
it.originUrl,
|
||||||
|
it.showOriginBtn,
|
||||||
|
it.originSize
|
||||||
|
)
|
||||||
|
if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it
|
||||||
|
} else it
|
||||||
|
}.toImmutableList()
|
||||||
|
}
|
||||||
|
val User.bawuType: String?
|
||||||
|
get() = if (is_bawu == 1) {
|
||||||
|
if (bawu_type == "manager") "吧主" else "小吧主"
|
||||||
|
} else null
|
||||||
|
|
@ -38,8 +38,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.api.abstractText
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.abstractText
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
||||||
import com.huanchengfly.tieba.post.arch.BaseComposeActivity.Companion.LocalWindowSizeClass
|
import com.huanchengfly.tieba.post.arch.BaseComposeActivity.Companion.LocalWindowSizeClass
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
import com.huanchengfly.tieba.post.api.models.protos.frsPage.FrsPageResponse
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.updateAgreeStatus
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
|
||||||
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
||||||
import com.huanchengfly.tieba.post.arch.CommonUiEvent
|
import com.huanchengfly.tieba.post.arch.CommonUiEvent
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.huanchengfly.tieba.post.api.hasAgree
|
import com.huanchengfly.tieba.post.api.models.protos.hasAgree
|
||||||
import com.huanchengfly.tieba.post.arch.BaseComposeActivity
|
import com.huanchengfly.tieba.post.arch.BaseComposeActivity
|
||||||
import com.huanchengfly.tieba.post.arch.CommonUiEvent.ScrollToTop.bindScrollToTopEvent
|
import com.huanchengfly.tieba.post.arch.CommonUiEvent.ScrollToTop.bindScrollToTopEvent
|
||||||
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ import androidx.compose.runtime.Stable
|
||||||
import com.huanchengfly.tieba.post.App
|
import com.huanchengfly.tieba.post.App
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.updateAgreeStatus
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.userLike.ConcernData
|
import com.huanchengfly.tieba.post.api.models.protos.userLike.ConcernData
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.userLike.UserLikeResponse
|
import com.huanchengfly.tieba.post.api.models.protos.userLike.UserLikeResponse
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
|
||||||
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
||||||
import com.huanchengfly.tieba.post.arch.CommonUiEvent
|
import com.huanchengfly.tieba.post.arch.CommonUiEvent
|
||||||
import com.huanchengfly.tieba.post.arch.PartialChange
|
import com.huanchengfly.tieba.post.arch.PartialChange
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.google.accompanist.placeholder.material.placeholder
|
import com.google.accompanist.placeholder.material.placeholder
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.api.hasAgree
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.hasAgree
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
||||||
import com.huanchengfly.tieba.post.arch.onEvent
|
import com.huanchengfly.tieba.post.arch.onEvent
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ package com.huanchengfly.tieba.post.ui.page.subposts
|
||||||
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.contentRenders
|
|
||||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Post
|
import com.huanchengfly.tieba.post.api.models.protos.Post
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SubPostList
|
import com.huanchengfly.tieba.post.api.models.protos.SubPostList
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.contentRenders
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.pbFloor.PbFloorResponse
|
import com.huanchengfly.tieba.post.api.models.protos.pbFloor.PbFloorResponse
|
||||||
import com.huanchengfly.tieba.post.api.renders
|
import com.huanchengfly.tieba.post.api.models.protos.renders
|
||||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
import com.huanchengfly.tieba.post.api.models.protos.updateAgreeStatus
|
||||||
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
import com.huanchengfly.tieba.post.arch.PartialChange
|
import com.huanchengfly.tieba.post.arch.PartialChange
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,8 @@ import com.huanchengfly.tieba.post.api.models.protos.Post
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.User
|
import com.huanchengfly.tieba.post.api.models.protos.User
|
||||||
import com.huanchengfly.tieba.post.api.renders
|
import com.huanchengfly.tieba.post.api.models.protos.bawuType
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.renders
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,19 @@ package com.huanchengfly.tieba.post.ui.page.thread
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.huanchengfly.tieba.post.api.TiebaApi
|
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||||
import com.huanchengfly.tieba.post.api.contentRenders
|
|
||||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Anti
|
import com.huanchengfly.tieba.post.api.models.protos.Anti
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Post
|
import com.huanchengfly.tieba.post.api.models.protos.Post
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.User
|
import com.huanchengfly.tieba.post.api.models.protos.User
|
||||||
import com.huanchengfly.tieba.post.api.renders
|
import com.huanchengfly.tieba.post.api.models.protos.contentRenders
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.renders
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.updateAgreeStatus
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.updateCollectStatus
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaUnknownException
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
||||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
|
||||||
import com.huanchengfly.tieba.post.api.updateCollectStatus
|
|
||||||
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
import com.huanchengfly.tieba.post.arch.BaseViewModel
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
import com.huanchengfly.tieba.post.arch.PartialChange
|
import com.huanchengfly.tieba.post.arch.PartialChange
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,11 @@ import com.google.accompanist.placeholder.material.placeholder
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
import com.huanchengfly.tieba.post.R
|
import com.huanchengfly.tieba.post.R
|
||||||
import com.huanchengfly.tieba.post.activities.UserActivity
|
import com.huanchengfly.tieba.post.activities.UserActivity
|
||||||
import com.huanchengfly.tieba.post.api.abstractText
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Media
|
import com.huanchengfly.tieba.post.api.models.protos.Media
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.User
|
import com.huanchengfly.tieba.post.api.models.protos.User
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.abstractText
|
||||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||||
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
import com.huanchengfly.tieba.post.arch.wrapImmutable
|
||||||
import com.huanchengfly.tieba.post.findActivity
|
import com.huanchengfly.tieba.post.findActivity
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package com.huanchengfly.tieba.post.utils
|
package com.huanchengfly.tieba.post.utils
|
||||||
|
|
||||||
import com.huanchengfly.tieba.post.api.abstractText
|
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.Post
|
import com.huanchengfly.tieba.post.api.models.protos.Post
|
||||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||||
import com.huanchengfly.tieba.post.api.plainText
|
import com.huanchengfly.tieba.post.api.models.protos.abstractText
|
||||||
|
import com.huanchengfly.tieba.post.api.models.protos.plainText
|
||||||
import com.huanchengfly.tieba.post.models.database.Block
|
import com.huanchengfly.tieba.post.models.database.Block
|
||||||
import com.huanchengfly.tieba.post.models.database.Block.Companion.getKeywords
|
import com.huanchengfly.tieba.post.models.database.Block.Companion.getKeywords
|
||||||
import org.litepal.LitePal
|
import org.litepal.LitePal
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue