更改目录结构

This commit is contained in:
2024-07-23 15:25:00 +08:00
parent 82f58d4b9c
commit dfbc151e4e
47 changed files with 1007 additions and 533 deletions

View File

@@ -0,0 +1,11 @@
package com.aiosman.riderpro.model
import androidx.annotation.DrawableRes
data class ChatNotificationData(
@DrawableRes val avatar: Int,
val name: String,
val message: String,
val time: String,
val unread: Int
)

View File

@@ -0,0 +1,50 @@
package com.aiosman.riderpro.model
import androidx.paging.PagingSource
import androidx.paging.PagingState
import kotlin.math.ceil
import kotlinx.coroutines.delay
internal class TestChatBackend(
private val backendDataList: List<ChatNotificationData>,
private val loadDelay: Long = 500,
) {
val DataBatchSize = 1
class DesiredLoadResultPageResponse(val data: List<ChatNotificationData>)
/** Returns [DataBatchSize] items for a key */
fun searchItemsByKey(key: Int): DesiredLoadResultPageResponse {
val maxKey = ceil(backendDataList.size.toFloat() / DataBatchSize).toInt()
if (key >= maxKey) {
return DesiredLoadResultPageResponse(emptyList())
}
val from = key * DataBatchSize
val to = minOf((key + 1) * DataBatchSize, backendDataList.size)
val currentSublist = backendDataList.subList(from, to)
return DesiredLoadResultPageResponse(currentSublist)
}
fun getAllData() = TestChatPagingSource(this, loadDelay)
}
internal class TestChatPagingSource(
private val backend: TestChatBackend,
private val loadDelay: Long,
) : PagingSource<Int, ChatNotificationData>() {
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ChatNotificationData> {
// Simulate latency
delay(loadDelay)
val pageNumber = params.key ?: 0
val response = backend.searchItemsByKey(pageNumber)
// Since 0 is the lowest page number, return null to signify no more pages should
// be loaded before it.
val prevKey = if (pageNumber > 0) pageNumber - 1 else null
// This API defines that it's out of data when a page returns empty. When out of
// data, we return `null` to signify no more pages should be loaded
val nextKey = if (response.data.isNotEmpty()) pageNumber + 1 else null
return LoadResult.Page(data = response.data, prevKey = prevKey, nextKey = nextKey)
}
override fun getRefreshKey(state: PagingState<Int, ChatNotificationData>): Int? {
return state.anchorPosition?.let {
state.closestPageToPosition(it)?.prevKey?.plus(1)
?: state.closestPageToPosition(it)?.nextKey?.minus(1)
}
}
}

View File

@@ -0,0 +1,75 @@
package com.aiosman.riderpro.model
import androidx.annotation.DrawableRes
import com.aiosman.riderpro.R
data class MomentItem(
val id: Int,
@DrawableRes val avatar: Int,
val nickname: String,
val location: String,
val time: String,
val followStatus: Boolean,
val momentTextContent: String,
@DrawableRes val momentPicture: Int,
val likeCount: Int,
val commentCount: Int,
val shareCount: Int,
val favoriteCount: Int
)
val momentTestItem = MomentItem(
id = 1,
avatar = R.drawable.default_avatar,
nickname = "Onyama Limba",
location = "Japan",
time = "2023.02.02 11:23",
followStatus = false,
momentTextContent = "By strongarming Ducati into giving him the factory seat.Marquez effectively …",
momentPicture = R.drawable.default_moment_img,
likeCount = 21,
commentCount = 43,
shareCount = 33,
favoriteCount = 211)
val profileMomentItems = listOf(
MomentItem(
id = 1,
avatar = R.drawable.default_avatar,
nickname = "Onyama Limba",
location = "Japan",
time = "2024.06.08 12:23",
followStatus = false,
momentTextContent = "Modifications that are made to make your motorbike more like you",
momentPicture = R.drawable.rider_pro_moment_demo_1,
likeCount = 2345,
commentCount = 12,
shareCount = 33,
favoriteCount = 211),
MomentItem(
id = 2,
avatar = R.drawable.default_avatar,
nickname = "Onyama Limba",
location = "Japan",
time = "2024.03.03 12:31",
followStatus = false,
momentTextContent = "At least 500 units will be made, to meet homologation requirements.",
momentPicture = R.drawable.rider_pro_moment_demo_2,
likeCount = 211,
commentCount = 33,
shareCount = 33,
favoriteCount = 211),
MomentItem(
id = 3,
avatar = R.drawable.default_avatar,
nickname = "Onyama Limba",
location = "Japan",
time = "2024.02.02 11:23",
followStatus = false,
momentTextContent = "The bike is already FIM legal (and soon-to-be MotoAmerica legal as well).",
momentPicture = R.drawable.rider_pro_moment_demo_3,
likeCount = 987,
commentCount = 21,
shareCount = 33,
favoriteCount = 211)
)