mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Some correction in the code
This commit is contained in:
parent
058c0482da
commit
e60037300a
3 changed files with 87 additions and 95 deletions
|
|
@ -481,7 +481,7 @@ class UploadWorker(
|
||||||
contribution.media.captions,
|
contribution.media.captions,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (revisionID != null) {
|
if (null != revisionID) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
// Fetch and update place details
|
// Fetch and update place details
|
||||||
val place = placesRepository.fetchPlace(wikiDataPlace.id)
|
val place = placesRepository.fetchPlace(wikiDataPlace.id)
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ import javax.inject.Singleton
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
class WikiBaseClient
|
class WikiBaseClient
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val wikiBaseInterface: WikiBaseInterface,
|
private val wikiBaseInterface: WikiBaseInterface,
|
||||||
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
@param:Named(NetworkingModule.NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||||
) {
|
) {
|
||||||
fun postEditEntity(
|
fun postEditEntity(
|
||||||
fileEntityId: String?,
|
fileEntityId: String?,
|
||||||
data: String?,
|
data: String?,
|
||||||
|
|
@ -81,20 +81,19 @@ class WikiBaseClient
|
||||||
fun addLabelsToWikidata(
|
fun addLabelsToWikidata(
|
||||||
fileEntityId: Long,
|
fileEntityId: Long,
|
||||||
languageCode: String?,
|
languageCode: String?,
|
||||||
captionValue: String?
|
captionValue: String?,
|
||||||
): Observable<MwPostResponse> {
|
): Observable<MwPostResponse> =
|
||||||
return csrfToken().switchMap { editToken ->
|
csrfToken().switchMap { editToken ->
|
||||||
wikiBaseInterface.addLabelstoWikidata(
|
wikiBaseInterface.addLabelstoWikidata(
|
||||||
PAGE_ID_PREFIX + fileEntityId,
|
PAGE_ID_PREFIX + fileEntityId,
|
||||||
editToken,
|
editToken,
|
||||||
languageCode,
|
languageCode,
|
||||||
captionValue
|
captionValue,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun csrfToken(): Observable<String> =
|
private fun csrfToken(): Observable<String> =
|
||||||
Observable.fromCallable {
|
Observable.fromCallable {
|
||||||
csrfTokenClient.getTokenBlocking()
|
csrfTokenClient.getTokenBlocking()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -37,6 +37,7 @@ import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is meant to handle the Wikidata edits made through the app It will talk with MediaWiki
|
* This class is meant to handle the Wikidata edits made through the app It will talk with MediaWiki
|
||||||
* Apis to make the necessary calls, log the edits and fire listeners on successful edits
|
* Apis to make the necessary calls, log the edits and fire listeners on successful edits
|
||||||
|
|
@ -54,7 +55,6 @@ class WikidataEditService @Inject constructor(
|
||||||
fileEntityId: String,
|
fileEntityId: String,
|
||||||
depictedItems: List<String>
|
depictedItems: List<String>
|
||||||
): Observable<Boolean> {
|
): Observable<Boolean> {
|
||||||
|
|
||||||
val data = EditClaim.from(
|
val data = EditClaim.from(
|
||||||
if (isBetaFlavour) listOf("Q10") else depictedItems, DEPICTS.propertyName
|
if (isBetaFlavour) listOf("Q10") else depictedItems, DEPICTS.propertyName
|
||||||
)
|
)
|
||||||
|
|
@ -79,7 +79,6 @@ class WikidataEditService @Inject constructor(
|
||||||
fileEntityId: String?,
|
fileEntityId: String?,
|
||||||
depictedItems: List<String>
|
depictedItems: List<String>
|
||||||
): Observable<Boolean> {
|
): Observable<Boolean> {
|
||||||
|
|
||||||
val entityId: String = PAGE_ID_PREFIX + fileEntityId
|
val entityId: String = PAGE_ID_PREFIX + fileEntityId
|
||||||
val claimIds = getDepictionsClaimIds(entityId)
|
val claimIds = getDepictionsClaimIds(entityId)
|
||||||
|
|
||||||
|
|
@ -164,8 +163,7 @@ class WikidataEditService @Inject constructor(
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val result = addImageAndMediaLegends(wikidataPlace!!, fileName, captions)
|
return addImageAndMediaLegends(wikidataPlace!!, fileName, captions)
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addImageAndMediaLegends(
|
fun addImageAndMediaLegends(
|
||||||
|
|
@ -197,8 +195,7 @@ class WikidataEditService @Inject constructor(
|
||||||
), Arrays.asList(MEDIA_LEGENDS.propertyName)
|
), Arrays.asList(MEDIA_LEGENDS.propertyName)
|
||||||
)
|
)
|
||||||
|
|
||||||
val result = wikidataClient.setClaim(claim, COMMONS_APP_TAG).blockingSingle()
|
return wikidataClient.setClaim(claim, COMMONS_APP_TAG).blockingSingle()
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleImageClaimResult(wikidataItem: WikidataItem, revisionId: Long?) {
|
fun handleImageClaimResult(wikidataItem: WikidataItem, revisionId: Long?) {
|
||||||
|
|
@ -242,22 +239,18 @@ class WikidataEditService @Inject constructor(
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private fun captionEdits(contribution: Contribution, fileEntityId: Long): Observable<Boolean> {
|
private fun captionEdits(contribution: Contribution, fileEntityId: Long): Observable<Boolean> {
|
||||||
val result = Observable.fromIterable(contribution.media.captions.entries)
|
return Observable.fromIterable(contribution.media.captions.entries)
|
||||||
.concatMap { addCaption(fileEntityId, it.key, it.value) }
|
.concatMap { addCaption(fileEntityId, it.key, it.value) }
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun depictionEdits(
|
private fun depictionEdits(
|
||||||
contribution: Contribution,
|
contribution: Contribution,
|
||||||
fileEntityId: Long
|
fileEntityId: Long
|
||||||
): Observable<Boolean> {
|
): Observable<Boolean> = addDepictsProperty(fileEntityId.toString(), buildList {
|
||||||
val result = addDepictsProperty(fileEntityId.toString(), buildList {
|
|
||||||
for ((_, _, _, _, _, _, id) in contribution.depictedItems) {
|
for ((_, _, _, _, _, _, id) in contribution.depictedItems) {
|
||||||
add(id)
|
add(id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val COMMONS_APP_TAG: String = "wikimedia-commons-app"
|
const val COMMONS_APP_TAG: String = "wikimedia-commons-app"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue