mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Issue-5662-kotlinstyle (#5833)
* *.kt: bulk correction of formatting using ktlint --format * *.kt: replace wildcard imports and second stage auto format ktlint --format * QuizQuestionTest.kt: modified property names to camel case to meet ktlint standard * LevelControllerTest.kt: modified property names to camel case to meet ktlint standard * QuizActivityUnitTest.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: modified property names to camel case to meet ktlint standard * UploadWorker.kt: modified property names to camel case to meet ktlint standard * UploadClient.kt: modified property names to camel case to meet ktlint standard * BasePagingPresenter.kt: modified property names to camel case to meet ktlint standard * DescriptionEditActivity.kt: modified property names to camel case to meet ktlint standard * OnSwipeTouchListener.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: corrected excessive line length to meet ktlint standard * DepictedItem.kt: corrected property name format and catch format to for ktlint standard * UploadCategoryAdapter.kt: corrected class definition format to meet ktlint standard * CustomSelectorActivity.kt: reformatted function names to first letter lowercase to meet ktlint standard * MediaDetailFragmentUnitTests.kt: fix string literal indentation to meet ktlint standard * NotForUploadDao.kt: file renamed to match class name, new file NotForUploadStatusDao.kt * UploadedDao.kt: file renamed to match class name, new file UploadedStatusDao.kt * Urls.kt: fixed excessive line length for ktLint standard * Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard * *.kt: fixed consecutive KDOC error for ktLint * PageableBaseDataSourceTest.kt & UploadPresenterTest.kt: fixed excessive line lengths to meet ktLint standard * CheckboxTriStatesTest.kt: renamed file to match class name to meet ktLint standard * .kt: resolved backing-property-naming error in ktLint, made matching properties public, matched names and refactored * TestConnectionFactory.kt: fixed property naming to adhere to ktLint standard
This commit is contained in:
parent
950539c55c
commit
2d82a430c4
405 changed files with 11032 additions and 9137 deletions
|
|
@ -1,10 +1,9 @@
|
|||
package fr.free.nrw.commons.actions
|
||||
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* This class acts as a Client to facilitate wiki page editing
|
||||
|
|
@ -15,9 +14,8 @@ import timber.log.Timber
|
|||
*/
|
||||
class PageEditClient(
|
||||
private val csrfTokenClient: CsrfTokenClient,
|
||||
private val pageEditInterface: PageEditInterface
|
||||
private val pageEditInterface: PageEditInterface,
|
||||
) {
|
||||
|
||||
/**
|
||||
* Replace the content of a wiki page
|
||||
* @param pageTitle Title of the page to edit
|
||||
|
|
@ -25,12 +23,17 @@ class PageEditClient(
|
|||
* @param summary Edit summary
|
||||
* @return whether the edit was successful
|
||||
*/
|
||||
fun edit(pageTitle: String, text: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postEdit(pageTitle, summary, text, csrfTokenClient.getTokenBlocking())
|
||||
fun edit(
|
||||
pageTitle: String,
|
||||
text: String,
|
||||
summary: String,
|
||||
): Observable<Boolean> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postEdit(pageTitle, summary, text, csrfTokenClient.getTokenBlocking())
|
||||
.map { editResponse ->
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
throw throwable
|
||||
|
|
@ -38,7 +41,6 @@ class PageEditClient(
|
|||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new page with the given title, text, and summary.
|
||||
|
|
@ -49,20 +51,25 @@ class PageEditClient(
|
|||
* @return An observable that emits true if the page creation succeeded, false otherwise.
|
||||
* @throws InvalidLoginTokenException If an invalid login token is encountered during the process.
|
||||
*/
|
||||
fun postCreate(pageTitle: String, text: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postCreate(
|
||||
pageTitle,
|
||||
summary,
|
||||
text,
|
||||
"text/x-wiki",
|
||||
"wikitext",
|
||||
true,
|
||||
true,
|
||||
csrfTokenClient.getTokenBlocking()
|
||||
).map { editResponse ->
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
fun postCreate(
|
||||
pageTitle: String,
|
||||
text: String,
|
||||
summary: String,
|
||||
): Observable<Boolean> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postCreate(
|
||||
pageTitle,
|
||||
summary,
|
||||
text,
|
||||
"text/x-wiki",
|
||||
"wikitext",
|
||||
true,
|
||||
true,
|
||||
csrfTokenClient.getTokenBlocking(),
|
||||
).map { editResponse ->
|
||||
editResponse.edit()!!.editSucceeded()
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
throw throwable
|
||||
|
|
@ -70,7 +77,6 @@ class PageEditClient(
|
|||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append text to the end of a wiki page
|
||||
|
|
@ -79,9 +85,14 @@ class PageEditClient(
|
|||
* @param summary Edit summary
|
||||
* @return whether the edit was successful
|
||||
*/
|
||||
fun appendEdit(pageTitle: String, appendText: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postAppendEdit(pageTitle, summary, appendText, csrfTokenClient.getTokenBlocking())
|
||||
fun appendEdit(
|
||||
pageTitle: String,
|
||||
appendText: String,
|
||||
summary: String,
|
||||
): Observable<Boolean> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postAppendEdit(pageTitle, summary, appendText, csrfTokenClient.getTokenBlocking())
|
||||
.map { editResponse -> editResponse.edit()!!.editSucceeded() }
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
|
|
@ -90,7 +101,6 @@ class PageEditClient(
|
|||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend text to the beginning of a wiki page
|
||||
|
|
@ -99,9 +109,14 @@ class PageEditClient(
|
|||
* @param summary Edit summary
|
||||
* @return whether the edit was successful
|
||||
*/
|
||||
fun prependEdit(pageTitle: String, prependText: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postPrependEdit(pageTitle, summary, prependText, csrfTokenClient.getTokenBlocking())
|
||||
fun prependEdit(
|
||||
pageTitle: String,
|
||||
prependText: String,
|
||||
summary: String,
|
||||
): Observable<Boolean> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postPrependEdit(pageTitle, summary, prependText, csrfTokenClient.getTokenBlocking())
|
||||
.map { editResponse -> editResponse.edit()?.editSucceeded() ?: false }
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
|
|
@ -110,8 +125,6 @@ class PageEditClient(
|
|||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends a new section to the wiki page
|
||||
|
|
@ -121,9 +134,15 @@ class PageEditClient(
|
|||
* @param summary Edit summary
|
||||
* @return whether the edit was successful
|
||||
*/
|
||||
fun createNewSection(pageTitle: String, sectionTitle: String, sectionText: String, summary: String): Observable<Boolean> {
|
||||
return try {
|
||||
pageEditInterface.postNewSection(pageTitle, summary, sectionTitle, sectionText, csrfTokenClient.getTokenBlocking())
|
||||
fun createNewSection(
|
||||
pageTitle: String,
|
||||
sectionTitle: String,
|
||||
sectionText: String,
|
||||
summary: String,
|
||||
): Observable<Boolean> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postNewSection(pageTitle, summary, sectionTitle, sectionText, csrfTokenClient.getTokenBlocking())
|
||||
.map { editResponse -> editResponse.edit()!!.editSucceeded() }
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
|
|
@ -132,8 +151,6 @@ class PageEditClient(
|
|||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set new labels to Wikibase server of commons
|
||||
|
|
@ -143,12 +160,21 @@ class PageEditClient(
|
|||
* @param value label
|
||||
* @return 1 when the edit was successful
|
||||
*/
|
||||
fun setCaptions(summary: String, title: String,
|
||||
language: String, value: String) : Observable<Int>{
|
||||
return try {
|
||||
pageEditInterface.postCaptions(summary, title, language,
|
||||
value, csrfTokenClient.getTokenBlocking()
|
||||
).map { it.success }
|
||||
fun setCaptions(
|
||||
summary: String,
|
||||
title: String,
|
||||
language: String,
|
||||
value: String,
|
||||
): Observable<Int> =
|
||||
try {
|
||||
pageEditInterface
|
||||
.postCaptions(
|
||||
summary,
|
||||
title,
|
||||
language,
|
||||
value,
|
||||
csrfTokenClient.getTokenBlocking(),
|
||||
).map { it.success }
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
throw throwable
|
||||
|
|
@ -156,16 +182,20 @@ class PageEditClient(
|
|||
Observable.just(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whole WikiText of required file
|
||||
* @param title : Name of the file
|
||||
* @return Observable<MwQueryResult>
|
||||
*/
|
||||
fun getCurrentWikiText(title: String): Single<String?> {
|
||||
return pageEditInterface.getWikiText(title).map {
|
||||
it.query()?.pages()?.get(0)?.revisions()?.get(0)?.content()
|
||||
fun getCurrentWikiText(title: String): Single<String?> =
|
||||
pageEditInterface.getWikiText(title).map {
|
||||
it
|
||||
.query()
|
||||
?.pages()
|
||||
?.get(0)
|
||||
?.revisions()
|
||||
?.get(0)
|
||||
?.content()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,15 @@ package fr.free.nrw.commons.actions
|
|||
import fr.free.nrw.commons.wikidata.WikidataConstants.MW_API_PREFIX
|
||||
import fr.free.nrw.commons.wikidata.model.Entities
|
||||
import fr.free.nrw.commons.wikidata.model.edit.Edit
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Single
|
||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
|
||||
import retrofit2.http.*
|
||||
import retrofit2.http.Field
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Query
|
||||
|
||||
/**
|
||||
* This interface facilitates wiki commons page editing services to the Networking module
|
||||
|
|
@ -33,7 +38,7 @@ interface PageEditInterface {
|
|||
@Field("summary") summary: String,
|
||||
@Field("text") text: String,
|
||||
// NOTE: This csrf shold always be sent as the last field of form data
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Edit>
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +65,7 @@ interface PageEditInterface {
|
|||
@Field("minor") minor: Boolean,
|
||||
@Field("recreate") recreate: Boolean,
|
||||
// NOTE: This csrf shold always be sent as the last field of form data
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Edit>
|
||||
|
||||
/**
|
||||
|
|
@ -79,7 +84,7 @@ interface PageEditInterface {
|
|||
@Field("title") title: String,
|
||||
@Field("summary") summary: String,
|
||||
@Field("appendtext") appendText: String,
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Edit>
|
||||
|
||||
/**
|
||||
|
|
@ -98,7 +103,7 @@ interface PageEditInterface {
|
|||
@Field("title") title: String,
|
||||
@Field("summary") summary: String,
|
||||
@Field("prependtext") prependText: String,
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Edit>
|
||||
|
||||
@FormUrlEncoded
|
||||
|
|
@ -109,7 +114,7 @@ interface PageEditInterface {
|
|||
@Field("summary") summary: String,
|
||||
@Field("sectiontitle") sectionTitle: String,
|
||||
@Field("text") sectionText: String,
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Edit>
|
||||
|
||||
@FormUrlEncoded
|
||||
|
|
@ -120,7 +125,7 @@ interface PageEditInterface {
|
|||
@Field("title") title: String,
|
||||
@Field("language") language: String,
|
||||
@Field("value") value: String,
|
||||
@Field("token") token: String
|
||||
@Field("token") token: String,
|
||||
): Observable<Entities>
|
||||
|
||||
/**
|
||||
|
|
@ -130,6 +135,6 @@ interface PageEditInterface {
|
|||
*/
|
||||
@GET(MW_API_PREFIX + "action=query&prop=revisions&rvprop=content|timestamp&rvlimit=1&converttitles=")
|
||||
fun getWikiText(
|
||||
@Query("titles") title: String
|
||||
@Query("titles") title: String,
|
||||
): Single<MwQueryResponse?>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
package fr.free.nrw.commons.actions
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication
|
||||
import fr.free.nrw.commons.di.NetworkingModule.NAMED_COMMONS_CSRF
|
||||
import io.reactivex.Observable
|
||||
import fr.free.nrw.commons.auth.csrf.CsrfTokenClient
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
|
||||
import fr.free.nrw.commons.auth.login.LoginFailedException
|
||||
import fr.free.nrw.commons.di.NetworkingModule.NAMED_COMMONS_CSRF
|
||||
import io.reactivex.Observable
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
import javax.inject.Singleton
|
||||
|
|
@ -15,34 +14,33 @@ import javax.inject.Singleton
|
|||
* Thanks are used by a user to show gratitude to another user for their contributions
|
||||
*/
|
||||
@Singleton
|
||||
class ThanksClient @Inject constructor(
|
||||
@param:Named(NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
private val service: ThanksInterface
|
||||
) {
|
||||
/**
|
||||
* Thanks a user for a particular revision
|
||||
* @param revisionId The revision ID the user would like to thank someone for
|
||||
* @return if thanks was successfully sent to intended recipient
|
||||
*/
|
||||
fun thank(revisionId: Long): Observable<Boolean> {
|
||||
return try {
|
||||
service.thank(
|
||||
revisionId.toString(), // Rev
|
||||
null, // Log
|
||||
csrfTokenClient.getTokenBlocking(), // Token
|
||||
CommonsApplication.getInstance().userAgent // Source
|
||||
).map {
|
||||
mwThankPostResponse -> mwThankPostResponse.result?.success == 1
|
||||
class ThanksClient
|
||||
@Inject
|
||||
constructor(
|
||||
@param:Named(NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
private val service: ThanksInterface,
|
||||
) {
|
||||
/**
|
||||
* Thanks a user for a particular revision
|
||||
* @param revisionId The revision ID the user would like to thank someone for
|
||||
* @return if thanks was successfully sent to intended recipient
|
||||
*/
|
||||
fun thank(revisionId: Long): Observable<Boolean> =
|
||||
try {
|
||||
service
|
||||
.thank(
|
||||
revisionId.toString(), // Rev
|
||||
null, // Log
|
||||
csrfTokenClient.getTokenBlocking(), // Token
|
||||
CommonsApplication.getInstance().userAgent, // Source
|
||||
).map { mwThankPostResponse ->
|
||||
mwThankPostResponse.result?.success == 1
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
Observable.error(throwable)
|
||||
} else {
|
||||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (throwable: Throwable) {
|
||||
if (throwable is InvalidLoginTokenException) {
|
||||
Observable.error(throwable)
|
||||
}
|
||||
else {
|
||||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ interface ThanksInterface {
|
|||
@Field("rev") rev: String?,
|
||||
@Field("log") log: String?,
|
||||
@Field("token") token: String,
|
||||
@Field("source") source: String?
|
||||
@Field("source") source: String?,
|
||||
): Observable<MwThankPostResponse?>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue