Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Player Property by lazy #90

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@ import java.time.LocalDate
import java.time.Period

data class Player(
val id :Int,
val name : String = "",
val backNumber : Int = 0,
val birthDate : String = "",
val height : Int = 0,
val weight : Int = 0,
val imageUrl : String = "",
val contractStartDate : String = "",
val contractEndDate : String = "",
val position : String = "",
val positionInitial : String = "",
val positionCategory : String = "",
val nationality : String = "",
val id: Int,
val name: String = "",
val backNumber: Int = 0,
val birthDate: String = "",
val height: Int = 0,
val weight: Int = 0,
val imageUrl: String = "",
val contractStartDate: String = "",
val contractEndDate: String = "",
val position: String = "",
val positionInitial: String = "",
val positionCategory: String = "",
val nationality: String = "",
val nationalityImageUrl: String = ""
) {
private val names : List<String>
private val names: List<String>
get() = name.split(" ")

val firstName : String
private val firstName: String
get() = names.firstOrNull() ?: ""

val lastNames : String
private val lastNames: String
get() = names.let {
if(it.size > 1) names.subList(1, names.lastIndex + 1).joinToString(" ")
if (it.size > 1) names.subList(1, names.lastIndex + 1).joinToString(" ")
else ""
}

val displayName : String
get() = firstName + (if(lastNames.isEmpty()) "" else "\n${lastNames}")
val displayName: String by lazy(LazyThreadSafetyMode.NONE) {
firstName + (if (lastNames.isEmpty()) "" else "\n${lastNames}")
}

fun getAge() : Int {
return Period.between(
val age: Int by lazy(LazyThreadSafetyMode.NONE) {
Period.between(
getYearAndMonthAndDateLocalDate(birthDate),
LocalDate.now()
).years
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fun PlayerDetailScreen(
) {
PlayerDetailInfo(
title = "Age",
content = "${player.getAge()}"
content = "${player.age}"
)
PlayerDetailInfo(
title = "Games",
Expand Down
Loading