mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Fixed the issue added tests (#4933)
This commit is contained in:
parent
31d63d1a2a
commit
17ac591233
2 changed files with 80 additions and 17 deletions
|
|
@ -51,26 +51,42 @@ class DepictsClient @Inject constructor(private val depictsInterface: DepictsInt
|
|||
flatMap(::getEntities)
|
||||
.map { entities ->
|
||||
entities.entities().values.map { entity ->
|
||||
if (entity.descriptions().byLanguageOrFirstOrEmpty() == "") {
|
||||
val entities: Entities = getEntities(entity[WikidataProperties.INSTANCE_OF]
|
||||
.toIds()[0]).blockingGet()
|
||||
val nameAsDescription = entities.entities().values.first().labels()
|
||||
.byLanguageOrFirstOrEmpty()
|
||||
DepictedItem(
|
||||
entity,
|
||||
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||
nameAsDescription
|
||||
)
|
||||
} else {
|
||||
DepictedItem(
|
||||
entity,
|
||||
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||
entity.descriptions().byLanguageOrFirstOrEmpty()
|
||||
)
|
||||
}
|
||||
mapToDepictItem(entity)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert different entities into DepictedItem
|
||||
*/
|
||||
private fun mapToDepictItem(entity: Entities.Entity): DepictedItem {
|
||||
return if (entity.descriptions().byLanguageOrFirstOrEmpty() == "") {
|
||||
val instanceOfIDs = entity[WikidataProperties.INSTANCE_OF]
|
||||
.toIds()
|
||||
if (instanceOfIDs.isNotEmpty()) {
|
||||
val entities: Entities = getEntities(instanceOfIDs[0]).blockingGet()
|
||||
val nameAsDescription = entities.entities().values.first().labels()
|
||||
.byLanguageOrFirstOrEmpty()
|
||||
DepictedItem(
|
||||
entity,
|
||||
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||
nameAsDescription
|
||||
)
|
||||
} else {
|
||||
DepictedItem(
|
||||
entity,
|
||||
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||
""
|
||||
)
|
||||
}
|
||||
} else {
|
||||
DepictedItem(
|
||||
entity,
|
||||
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||
entity.descriptions().byLanguageOrFirstOrEmpty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get Entities.Label by default language from the map.
|
||||
* If that returns null, Tries to retrieve first element from the map.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue