添加业务逻辑
This commit is contained in:
92
app/src/main/java/com/aiosman/riderpro/test/TestDatabase.kt
Normal file
92
app/src/main/java/com/aiosman/riderpro/test/TestDatabase.kt
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.aiosman.riderpro.test
|
||||
|
||||
import com.aiosman.riderpro.R
|
||||
import com.aiosman.riderpro.data.AccountProfile
|
||||
import com.aiosman.riderpro.model.MomentItem
|
||||
import io.github.serpro69.kfaker.faker
|
||||
|
||||
object TestDatabase {
|
||||
var momentData = emptyList<MomentItem>()
|
||||
var accountData = emptyList<AccountProfile>()
|
||||
var imageList = listOf(
|
||||
"https://img.freepik.com/free-photo/white-billboard-template_23-2147726635.jpg?t=st=1722150015~exp=1722153615~hmac=5540620196d7898215d822be26353c87a63d51bbfb2b814e032626e1948a1583&w=740",
|
||||
"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",
|
||||
"https://t4.ftcdn.net/jpg/02/27/00/89/240_F_227008949_5O7yXuEqTwUgs3BGqdcvrNutM5MSxs1t.jpg",
|
||||
|
||||
"https://t4.ftcdn.net/jpg/01/86/86/49/240_F_186864971_NixcoDg1zBjjN7soUNhpEVraI4vdzOFD.jpg",
|
||||
"https://t3.ftcdn.net/jpg/00/84/01/30/240_F_84013057_fsOdzBgskSFUyWyD6YKjIAdtKdBPiKRD.jpg",
|
||||
"https://t4.ftcdn.net/jpg/00/93/89/23/240_F_93892312_SNyGGruVaWKpJQiVG314gIQmS4EAghdy.jpg",
|
||||
"https://t3.ftcdn.net/jpg/02/94/56/58/240_F_294565895_IOqZC2OpcHGEibWF04MPEP09KZaewEl5.jpg",
|
||||
"https://t3.ftcdn.net/jpg/01/01/66/84/240_F_101668484_FopHBSMBq4t6BlvwI9awPMzUdi501sJ7.jpg",
|
||||
"https://t3.ftcdn.net/jpg/05/65/11/60/240_F_565116019_oHbZ6Hc8VYCMcZWpexXF7Z5lOWeNNYtD.jpg",
|
||||
"https://t3.ftcdn.net/jpg/03/52/21/48/240_F_352214843_dQ3JtTJrKyqrh2yd1emYCDPSrzrwqaNK.jpg",
|
||||
"https://t3.ftcdn.net/jpg/07/22/47/16/240_F_722471661_T25r329RFRxgK88S6oBJ9dUksOC2arLl.jpg",
|
||||
"https://t3.ftcdn.net/jpg/02/18/11/26/240_F_218112603_jBChzLJGuz8smPZsdFsy17wB0O0QF3Xo.jpg",
|
||||
"https://t4.ftcdn.net/jpg/04/11/49/07/240_F_411490703_KRvV0aRyxHWYVUO8bGXxuQGo2mHblYnv.jpg",
|
||||
"https://img.freepik.com/premium-photo/man-wearing-orange-helmet-white-background_466494-5539.jpg?ga=GA1.1.1334458544.1722150011&semt=sph",
|
||||
"https://img.freepik.com/premium-photo/motorcycle-vehicle-3d-modelling_274824-502.jpg?ga=GA1.1.1334458544.1722150011&semt=sph",
|
||||
"https://t3.ftcdn.net/jpg/01/68/26/06/240_F_168260687_UfaDjjs6TxcIB6BdsquSeCmYWEFmN1Sh.jpg",
|
||||
"https://t3.ftcdn.net/jpg/03/48/50/34/240_F_348503435_On7Tt5Eqn7IP9QWYTQL0H1smubU8gvLv.jpg",
|
||||
"https://t3.ftcdn.net/jpg/02/76/70/70/240_F_276707060_WpP9bwHWv0Wdqqn0pEgtSuIgXUvgkbs7.jpg",
|
||||
"https://t3.ftcdn.net/jpg/02/65/43/04/240_F_265430460_DIHqnrziar7WL2rmW0qbDO07TbxjlPQo.jpg"
|
||||
)
|
||||
var followList = emptyList<Pair<Int, Int>>()
|
||||
|
||||
init {
|
||||
val faker = faker {
|
||||
this.fakerConfig {
|
||||
locale = "en"
|
||||
}
|
||||
}
|
||||
accountData = (0..300).toList().mapIndexed { idx, _ ->
|
||||
AccountProfile(
|
||||
id = idx,
|
||||
followerCount = 0,
|
||||
followingCount = 0,
|
||||
nickName = faker.name.name(),
|
||||
avatar = imageList.random(),
|
||||
bio = "I am a software engineer",
|
||||
country = faker.address.country()
|
||||
|
||||
)
|
||||
}
|
||||
// make a random follow rel
|
||||
for (i in 0..10000) {
|
||||
var person1 = accountData.random()
|
||||
var persion2 = accountData.random()
|
||||
followList += Pair(person1.id, persion2.id)
|
||||
// update followerCount and followingCount
|
||||
accountData = accountData.map {
|
||||
if (it.id == person1.id) {
|
||||
it.copy(followingCount = it.followingCount + 1)
|
||||
} else if (it.id == persion2.id) {
|
||||
it.copy(followerCount = it.followerCount + 1)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
momentData = (0..300).toList().mapIndexed { idx, _ ->
|
||||
val person = accountData.random()
|
||||
MomentItem(
|
||||
id = idx,
|
||||
avatar = person.avatar,
|
||||
nickname = person.nickName,
|
||||
location = person.country,
|
||||
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 = faker.random.nextInt(0, 100),
|
||||
commentCount = faker.random.nextInt(0, 100),
|
||||
shareCount = faker.random.nextInt(0, 100),
|
||||
favoriteCount = faker.random.nextInt(0, 100),
|
||||
images = imageList.shuffled().take(3),
|
||||
authorId = person.id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user