UI调整
This commit is contained in:
@@ -4,8 +4,10 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.aiosman.ravenow.data.ListContainer
|
||||
import com.aiosman.ravenow.data.AgentService
|
||||
import com.aiosman.ravenow.data.MomentService
|
||||
import com.aiosman.ravenow.data.ServiceException
|
||||
import com.aiosman.ravenow.data.UploadImage
|
||||
import com.aiosman.ravenow.data.UserService
|
||||
import com.aiosman.ravenow.data.api.ApiClient
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
@@ -47,6 +49,79 @@ suspend fun createAgent(
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能体信息分页加载器
|
||||
*/
|
||||
class AgentPagingSource(
|
||||
private val agentRemoteDataSource: AgentRemoteDataSource,
|
||||
) : PagingSource<Int, AgentEntity>() {
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, AgentEntity> {
|
||||
return try {
|
||||
val currentPage = params.key ?: 1
|
||||
val users = agentRemoteDataSource.getAgent(
|
||||
pageNumber = currentPage
|
||||
)
|
||||
LoadResult.Page(
|
||||
data = users.list,
|
||||
prevKey = if (currentPage == 1) null else currentPage - 1,
|
||||
nextKey = if (users.list.isEmpty()) null else users.page + 1
|
||||
)
|
||||
} catch (exception: IOException) {
|
||||
return LoadResult.Error(exception)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getRefreshKey(state: PagingState<Int, AgentEntity>): Int? {
|
||||
return state.anchorPosition
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AgentRemoteDataSource(
|
||||
private val agentService: AgentService,
|
||||
) {
|
||||
suspend fun getAgent(
|
||||
pageNumber: Int,
|
||||
): ListContainer<AgentEntity> {
|
||||
return agentService.getAgent(
|
||||
pageNumber = pageNumber
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class AgentServiceImpl() : AgentService {
|
||||
val agentBackend = AgentBackend()
|
||||
|
||||
override suspend fun getAgent(pageNumber: Int, pageSize: Int): ListContainer<AgentEntity> {
|
||||
return agentBackend.getAgent(
|
||||
pageNumber = pageNumber,
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class AgentBackend {
|
||||
val DataBatchSize = 20
|
||||
suspend fun getAgent(
|
||||
pageNumber: Int,
|
||||
|
||||
): ListContainer<AgentEntity> {
|
||||
val resp = ApiClient.api.getMyAgent(
|
||||
pageSize = DataBatchSize,
|
||||
page = pageNumber,
|
||||
|
||||
)
|
||||
val body = resp.body() ?: throw ServiceException("Failed to get moments")
|
||||
return ListContainer(
|
||||
total = body.total,
|
||||
page = pageNumber,
|
||||
pageSize = DataBatchSize,
|
||||
list = body.list.map { it.toAgentEntity() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class AgentEntity(
|
||||
//val author: String,
|
||||
val avatar: String,
|
||||
|
||||
Reference in New Issue
Block a user