添加业务逻辑
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
data class AccountProfile(
|
||||
val id: Int,
|
||||
val followerCount: Int,
|
||||
val followingCount: Int,
|
||||
val nickName: String,
|
||||
val avatar: String,
|
||||
val bio: String,
|
||||
val country: String,
|
||||
)
|
||||
|
||||
interface AccountService {
|
||||
suspend fun getAccountProfile(): AccountProfile
|
||||
}
|
||||
|
||||
class TestAccountServiceImpl : AccountService {
|
||||
override suspend fun getAccountProfile(): AccountProfile {
|
||||
return AccountProfile(
|
||||
id = 1,
|
||||
followerCount = 100,
|
||||
followingCount = 200,
|
||||
nickName = "Aiosman",
|
||||
avatar = "https://img.freepik.com/free-photo/white-billboard-template_23-2147726635.jpg?t=st=1722150015~exp=1722153615~hmac=5540620196d7898215d822be26353c87a63d51bbfb2b814e032626e1948a1583&w=740",
|
||||
bio = "I am a software engineer",
|
||||
country = "Nigeria"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.aiosman.riderpro.data.comment
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.aiosman.riderpro.data.ListContainer
|
||||
import java.io.IOException
|
||||
import kotlin.random.Random
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package com.aiosman.riderpro.data.moment
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import com.aiosman.riderpro.R
|
||||
import com.aiosman.riderpro.data.ListContainer
|
||||
import com.aiosman.riderpro.model.MomentItem
|
||||
import com.aiosman.riderpro.test.TestDatabase
|
||||
import java.io.IOException
|
||||
import kotlin.random.Random
|
||||
|
||||
class MomentPagingSource(
|
||||
private val remoteDataSource: MomentRemoteDataSource,
|
||||
) : PagingSource<Int, MomentItem>() {
|
||||
|
||||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MomentItem> {
|
||||
return try {
|
||||
val currentPage = params.key ?: 1
|
||||
@@ -46,6 +44,7 @@ class MomentRemoteDataSource(
|
||||
interface MomentService {
|
||||
suspend fun getMoments(pageNumber: Int): ListContainer<MomentItem>
|
||||
suspend fun getMomentById(id: Int): MomentItem
|
||||
suspend fun likeMoment(id: Int)
|
||||
}
|
||||
|
||||
class TestMomentServiceImpl() : MomentService {
|
||||
@@ -54,23 +53,7 @@ class TestMomentServiceImpl() : MomentService {
|
||||
"https://img.freepik.com/free-photo/minimal-clothing-label-fashion-brands_53876-111053.jpg?w=1060&t=st=1722150122~exp=1722150722~hmac=67f8a2b6abfe3d08714cf0cc0085485c3221e1ba00dda14378b03753dce39153",
|
||||
"https://img.freepik.com/free-photo/marketing-strategy-planning-strategy-concept_53876-42950.jpg"
|
||||
)
|
||||
val mockData = (0..300).toList().mapIndexed { idx, _ ->
|
||||
MomentItem(
|
||||
id = idx,
|
||||
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,
|
||||
images = imageList.shuffled().take(3),
|
||||
)
|
||||
}
|
||||
var mockData = TestDatabase.momentData
|
||||
val testMomentBackend = TestMomentBackend(mockData)
|
||||
override suspend fun getMoments(pageNumber: Int): ListContainer<MomentItem> {
|
||||
return testMomentBackend.fetchMomentItems(pageNumber)
|
||||
@@ -79,6 +62,18 @@ class TestMomentServiceImpl() : MomentService {
|
||||
override suspend fun getMomentById(id: Int): MomentItem {
|
||||
return mockData[id]
|
||||
}
|
||||
|
||||
override suspend fun likeMoment(id: Int) {
|
||||
// mockData = mockData.map {
|
||||
// if (it.id == id) {
|
||||
// it.copy(likeCount = it.likeCount + 1)
|
||||
// } else {
|
||||
// it
|
||||
// }
|
||||
// }
|
||||
// mockData
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestMomentBackend(
|
||||
18
app/src/main/java/com/aiosman/riderpro/data/UserService.kt
Normal file
18
app/src/main/java/com/aiosman/riderpro/data/UserService.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.aiosman.riderpro.data
|
||||
|
||||
import com.aiosman.riderpro.test.TestDatabase
|
||||
|
||||
interface UserService {
|
||||
suspend fun getUserProfile(id:String): AccountProfile
|
||||
}
|
||||
|
||||
class TestUserServiceImpl : UserService {
|
||||
override suspend fun getUserProfile(id: String): AccountProfile {
|
||||
TestDatabase.accountData.forEach {
|
||||
if (it.id == id.toInt()) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return AccountProfile(0, 0, 0, "", "", "", "")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user