forked from commons-app/apps-android-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into achievement_revamp
- Loading branch information
Showing
8 changed files
with
348 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/src/main/java/fr/free/nrw/commons/wikidata/model/DepictSearchResponse.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
app/src/main/java/fr/free/nrw/commons/wikidata/model/DepictSearchResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fr.free.nrw.commons.wikidata.model | ||
|
||
/** | ||
* Model class for API response obtained from search for depictions | ||
*/ | ||
class DepictSearchResponse( | ||
/** | ||
* @return List<DepictSearchItem> for the DepictSearchResponse | ||
</DepictSearchItem> | ||
*/ | ||
val search: List<DepictSearchItem> | ||
) |
106 changes: 0 additions & 106 deletions
106
app/src/main/java/fr/free/nrw/commons/wikidata/model/Entities.java
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
app/src/main/java/fr/free/nrw/commons/wikidata/model/Entities.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package fr.free.nrw.commons.wikidata.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import fr.free.nrw.commons.wikidata.mwapi.MwResponse | ||
import org.apache.commons.lang3.StringUtils | ||
|
||
class Entities : MwResponse() { | ||
private val entities: Map<String, Entity>? = null | ||
val success: Int = 0 | ||
|
||
fun entities(): Map<String, Entity> = entities ?: emptyMap() | ||
|
||
private val first : Entity? | ||
get() = entities?.values?.iterator()?.next() | ||
|
||
override fun postProcess() { | ||
first?.let { | ||
if (it.isMissing()) throw RuntimeException("The requested entity was not found.") | ||
} | ||
} | ||
|
||
class Entity { | ||
private val type: String? = null | ||
private val id: String? = null | ||
private val labels: Map<String, Label>? = null | ||
private val descriptions: Map<String, Label>? = null | ||
private val sitelinks: Map<String, SiteLink>? = null | ||
|
||
@SerializedName(value = "statements", alternate = ["claims"]) | ||
val statements: Map<String, List<StatementPartial>>? = null | ||
private val missing: String? = null | ||
|
||
fun id(): String = | ||
StringUtils.defaultString(id) | ||
|
||
fun labels(): Map<String, Label> = | ||
labels ?: emptyMap() | ||
|
||
fun descriptions(): Map<String, Label> = | ||
descriptions ?: emptyMap() | ||
|
||
fun sitelinks(): Map<String, SiteLink> = | ||
sitelinks ?: emptyMap() | ||
|
||
fun isMissing(): Boolean = | ||
"-1" == id && missing != null | ||
} | ||
|
||
class Label(private val language: String?, private val value: String?) { | ||
fun language(): String = | ||
StringUtils.defaultString(language) | ||
|
||
fun value(): String = | ||
StringUtils.defaultString(value) | ||
} | ||
|
||
class SiteLink { | ||
val site: String? = null | ||
get() = StringUtils.defaultString(field) | ||
|
||
private val title: String? = null | ||
get() = StringUtils.defaultString(field) | ||
} | ||
} |
Oops, something went wrong.