148 lines
6.8 KiB
Kotlin
148 lines
6.8 KiB
Kotlin
package com.aiosman.riderpro.test
|
|
|
|
import com.aiosman.riderpro.R
|
|
import com.aiosman.riderpro.data.AccountProfile
|
|
import com.aiosman.riderpro.data.Comment
|
|
import com.aiosman.riderpro.model.MomentItem
|
|
import com.google.gson.Gson
|
|
import com.google.gson.GsonBuilder
|
|
import io.github.serpro69.kfaker.faker
|
|
import java.io.File
|
|
|
|
object TestDatabase {
|
|
var momentData = emptyList<MomentItem>()
|
|
var accountData = emptyList<AccountProfile>()
|
|
var comment = emptyList<Comment>()
|
|
var commentIdCounter = 0
|
|
var selfId = 1
|
|
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>>()
|
|
var likeCommentList = emptyList<Pair<Int, Int>>()
|
|
var likeMomentList = emptyList<Pair<Int, Int>>()
|
|
init {
|
|
val faker = faker {
|
|
this.fakerConfig {
|
|
locale = "en"
|
|
}
|
|
}
|
|
accountData = (0..20).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..100) {
|
|
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..60).toList().mapIndexed { idx, _ ->
|
|
val person = accountData.random()
|
|
// make fake comment
|
|
val commentCount = faker.random.nextInt(0, 50)
|
|
for (i in 0..commentCount) {
|
|
commentIdCounter += 1
|
|
val commentPerson = accountData.random()
|
|
var newComment = Comment(
|
|
name = commentPerson.nickName,
|
|
comment = "this is comment ${commentIdCounter}",
|
|
date = "2023-02-02 11:23",
|
|
likes = 0,
|
|
replies = emptyList(),
|
|
postId = idx,
|
|
avatar = commentPerson.avatar,
|
|
author = commentPerson.id,
|
|
id = commentIdCounter,
|
|
liked = false
|
|
)
|
|
// generate like comment list
|
|
for (likeIdx in 0..faker.random.nextInt(0, 5)) {
|
|
val likePerson = accountData.random()
|
|
likeCommentList += Pair(commentIdCounter, likePerson.id)
|
|
newComment = newComment.copy(likes = newComment.likes + 1)
|
|
}
|
|
comment += newComment
|
|
}
|
|
val likeCount = faker.random.nextInt(0, 5)
|
|
for (i in 0..likeCount) {
|
|
val likePerson = accountData.random()
|
|
likeMomentList += Pair(idx, likePerson.id)
|
|
}
|
|
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 = likeCount,
|
|
commentCount = commentCount + 1,
|
|
shareCount = faker.random.nextInt(0, 100),
|
|
favoriteCount = faker.random.nextInt(0, 100),
|
|
images = imageList.shuffled().take(3),
|
|
authorId = person.id
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
fun updateMomentById(id: Int, momentItem: MomentItem) {
|
|
momentData = momentData.map {
|
|
if (it.id == id) {
|
|
momentItem
|
|
} else {
|
|
it
|
|
}
|
|
}
|
|
}
|
|
|
|
fun saveResultToJsonFile() {
|
|
val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
|
|
|
// save accountData to json file
|
|
File("accountData.json").writeText(accountData.toString())
|
|
// save momentData to json file
|
|
// save comment to json file
|
|
}
|
|
} |