新增动态
This commit is contained in:
@@ -2,6 +2,7 @@ package com.aiosman.riderpro.data
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.aiosman.riderpro.R
|
||||
import com.aiosman.riderpro.model.MomentItem
|
||||
import com.aiosman.riderpro.test.TestDatabase
|
||||
import java.io.IOException
|
||||
@@ -16,6 +17,12 @@ interface MomentService {
|
||||
author: Int? = null,
|
||||
timelineId: Int? = null
|
||||
): ListContainer<MomentItem>
|
||||
|
||||
suspend fun createMoment(
|
||||
content: String,
|
||||
authorId: Int,
|
||||
imageUriList: List<String>
|
||||
): MomentItem
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +93,14 @@ class TestMomentServiceImpl() : MomentService {
|
||||
testMomentBackend.dislikeMoment(id)
|
||||
}
|
||||
|
||||
override suspend fun createMoment(
|
||||
content: String,
|
||||
authorId: Int,
|
||||
imageUriList: List<String>
|
||||
): MomentItem {
|
||||
return testMomentBackend.createMoment(content, authorId, imageUriList)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestMomentBackend(
|
||||
@@ -98,6 +113,7 @@ class TestMomentBackend(
|
||||
timelineId: Int?
|
||||
): ListContainer<MomentItem> {
|
||||
var rawList = TestDatabase.momentData
|
||||
rawList = rawList.sortedBy { it.id }.reversed()
|
||||
if (author != null) {
|
||||
rawList = rawList.filter { it.authorId == author }
|
||||
}
|
||||
@@ -105,7 +121,7 @@ class TestMomentBackend(
|
||||
val followIdList = TestDatabase.followList.filter {
|
||||
it.first == timelineId
|
||||
}.map { it.second }
|
||||
rawList = rawList.filter { it.authorId in followIdList }
|
||||
rawList = rawList.filter { it.authorId in followIdList || it.authorId == 1 }
|
||||
}
|
||||
val from = (pageNumber - 1) * DataBatchSize
|
||||
val to = (pageNumber) * DataBatchSize
|
||||
@@ -119,11 +135,13 @@ class TestMomentBackend(
|
||||
}
|
||||
val currentSublist = rawList.subList(from, min(to, rawList.size))
|
||||
currentSublist.forEach {
|
||||
val myLikeIdList = TestDatabase.likeMomentList.filter { it.second == 1 }.map { it.first }
|
||||
val myLikeIdList =
|
||||
TestDatabase.likeMomentList.filter { it.second == 1 }.map { it.first }
|
||||
if (myLikeIdList.contains(it.id)) {
|
||||
it.liked = true
|
||||
}
|
||||
}
|
||||
|
||||
// delay
|
||||
kotlinx.coroutines.delay(loadDelay)
|
||||
return ListContainer(
|
||||
@@ -153,6 +171,7 @@ class TestMomentBackend(
|
||||
TestDatabase.updateMomentById(id, newMoment)
|
||||
TestDatabase.likeMomentList += Pair(id, 1)
|
||||
}
|
||||
|
||||
suspend fun dislikeMoment(id: Int) {
|
||||
val oldMoment = TestDatabase.momentData.first {
|
||||
it.id == id
|
||||
@@ -164,4 +183,33 @@ class TestMomentBackend(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createMoment(
|
||||
content: String,
|
||||
authorId: Int,
|
||||
imageUriList: List<String>
|
||||
): MomentItem {
|
||||
TestDatabase.momentIdCounter += 1
|
||||
val person = TestDatabase.accountData.first {
|
||||
it.id == authorId
|
||||
}
|
||||
val newMoment = MomentItem(
|
||||
id = TestDatabase.momentIdCounter,
|
||||
avatar = person.avatar,
|
||||
nickname = person.nickName,
|
||||
location = person.country,
|
||||
time = "2023.02.02 11:23",
|
||||
followStatus = false,
|
||||
momentTextContent = content,
|
||||
momentPicture = R.drawable.default_moment_img,
|
||||
likeCount = 0,
|
||||
commentCount = 0,
|
||||
shareCount = 0,
|
||||
favoriteCount = 0,
|
||||
images = imageUriList,
|
||||
authorId = person.id
|
||||
)
|
||||
TestDatabase.momentData += newMoment
|
||||
return newMoment
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user