Skip to content

Commit

Permalink
Merge branch 'main' into achievement_revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-raoul authored Dec 6, 2024
2 parents 28ba71e + ae52267 commit 4e9d9e4
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AboutActivityTest {
fun testLaunchTranslate() {
Espresso.onView(ViewMatchers.withId(R.id.about_translate)).perform(ViewActions.click())
Espresso.onView(ViewMatchers.withId(android.R.id.button1)).perform(ViewActions.click())
val langCode = CommonsApplication.instance.languageLookUpTable!!.codes[0]
val langCode = CommonsApplication.instance.languageLookUpTable!!.getCodes()[0]
Intents.intended(
CoreMatchers.allOf(
IntentMatchers.hasAction(Intent.ACTION_VIEW),
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/fr/free/nrw/commons/di/NetworkingModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.HttpLoggingInterceptor.Level
import timber.log.Timber
import java.io.File
import java.util.Locale
import java.util.concurrent.TimeUnit
import javax.inject.Named
import javax.inject.Singleton
Expand Down Expand Up @@ -293,9 +292,8 @@ class NetworkingModule {
@Provides
@Singleton
@Named(NAMED_LANGUAGE_WIKI_PEDIA_WIKI_SITE)
fun provideLanguageWikipediaSite(): WikiSite {
return WikiSite.forLanguageCode(Locale.getDefault().language)
}
fun provideLanguageWikipediaSite(): WikiSite =
WikiSite.forDefaultLocaleLanguageCode()

companion object {
private const val WIKIDATA_SPARQL_QUERY_URL = "https://query.wikidata.org/sparql"
Expand Down

This file was deleted.

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 app/src/main/java/fr/free/nrw/commons/wikidata/model/Entities.java

This file was deleted.

64 changes: 64 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/wikidata/model/Entities.kt
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)
}
}
Loading

0 comments on commit 4e9d9e4

Please sign in to comment.