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:
tristan 2024-09-19 14:56:45 +10:00 committed by GitHub
parent 950539c55c
commit 2d82a430c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
405 changed files with 11032 additions and 9137 deletions

View file

@ -7,32 +7,29 @@ import fr.free.nrw.commons.upload.UploadResult
data class ChunkInfo(
val uploadResult: UploadResult?,
val indexOfNextChunkToUpload: Int,
val totalChunks: Int
val totalChunks: Int,
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(UploadResult::class.java.classLoader),
parcel.readInt(),
parcel.readInt()
parcel.readInt(),
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
override fun writeToParcel(
parcel: Parcel,
flags: Int,
) {
parcel.writeParcelable(uploadResult, flags)
parcel.writeInt(indexOfNextChunkToUpload)
parcel.writeInt(totalChunks)
}
override fun describeContents(): Int {
return 0
}
override fun describeContents(): Int = 0
companion object CREATOR : Parcelable.Creator<ChunkInfo> {
override fun createFromParcel(parcel: Parcel): ChunkInfo {
return ChunkInfo(parcel)
}
override fun createFromParcel(parcel: Parcel): ChunkInfo = ChunkInfo(parcel)
override fun newArray(size: Int): Array<ChunkInfo?> {
return arrayOfNulls(size)
}
override fun newArray(size: Int): Array<ChunkInfo?> = arrayOfNulls(size)
}
}
}

View file

@ -5,7 +5,6 @@ import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import fr.free.nrw.commons.CommonsApplication
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.auth.SessionManager
import fr.free.nrw.commons.upload.UploadItem
@ -31,8 +30,7 @@ data class Contribution constructor(
var errorInfo: String? = null,
/**
* @return array list of entityids for the depictions
*/
/**
*
* Each depiction loaded in depictions activity is associated with a wikidata entity id, this Id
* is in turn used to upload depictions to wikibase
*/
@ -44,26 +42,23 @@ data class Contribution constructor(
var dateCreatedString: String? = null,
var dateModified: Date? = null,
var dateUploadStarted: Date? = null,
var hasInvalidLocation : Int = 0,
var hasInvalidLocation: Int = 0,
var contentUri: Uri? = null,
var countryCode : String? = null,
var imageSHA1 : String? = null,
var countryCode: String? = null,
var imageSHA1: String? = null,
/**
* Number of times a contribution has been retried after a failure
*/
var retries: Int = 0
var retries: Int = 0,
) : Parcelable {
fun completeWith(media: Media): Contribution {
return copy(pageId = media.pageId, media = media, state = STATE_COMPLETED)
}
fun completeWith(media: Media): Contribution = copy(pageId = media.pageId, media = media, state = STATE_COMPLETED)
constructor(
item: UploadItem,
sessionManager: SessionManager,
depictedItems: List<DepictedItem>,
categories: List<String>,
imageSHA1: String
imageSHA1: String,
) : this(
Media(
formatCaptions(item.uploadMediaDetails),
@ -71,7 +66,7 @@ data class Contribution constructor(
item.fileName,
formatDescriptions(item.uploadMediaDetails),
sessionManager.userName,
sessionManager.userName
sessionManager.userName,
),
localUri = item.mediaUri,
decimalCoords = item.gpsCoords.decimalCoords,
@ -80,7 +75,7 @@ data class Contribution constructor(
wikidataPlace = from(item.place),
contentUri = item.contentUri,
dateCreatedString = item.fileCreatedDateString,
imageSHA1 = imageSHA1
imageSHA1 = imageSHA1,
)
/**
@ -91,9 +86,7 @@ data class Contribution constructor(
this.hasInvalidLocation = if (hasInvalidLocation) 1 else 0
}
fun hasInvalidLocation(): Boolean {
return hasInvalidLocation == 1
}
fun hasInvalidLocation(): Boolean = hasInvalidLocation == 1
companion object {
const val STATE_COMPLETED = -1
@ -107,7 +100,8 @@ data class Contribution constructor(
* @param uploadMediaDetails list of media Details
*/
fun formatCaptions(uploadMediaDetails: List<UploadMediaDetail>) =
uploadMediaDetails.associate { it.languageCode!! to it.captionText }
uploadMediaDetails
.associate { it.languageCode!! to it.captionText }
.filter { it.value.isNotBlank() }
/**
@ -117,19 +111,15 @@ data class Contribution constructor(
* @return a string with the pattern of {{en|1=descriptionText}}
*/
fun formatDescriptions(descriptions: List<UploadMediaDetail>) =
descriptions.filter { it.descriptionText.isNotEmpty() }
descriptions
.filter { it.descriptionText.isNotEmpty() }
.joinToString(separator = "") { "{{${it.languageCode}|1=${it.descriptionText}}}" }
}
val fileKey : String? get() = chunkInfo?.uploadResult?.filekey
val fileKey: String? get() = chunkInfo?.uploadResult?.filekey
val localUriPath: File? get() = localUri?.path?.let { File(it) }
fun isCompleted(): Boolean {
return chunkInfo != null && chunkInfo!!.totalChunks == chunkInfo!!.indexOfNextChunkToUpload
}
fun dateUploadStartedInMillis(): Long {
return dateUploadStarted!!.time
}
fun isCompleted(): Boolean = chunkInfo != null && chunkInfo!!.totalChunks == chunkInfo!!.indexOfNextChunkToUpload
fun dateUploadStartedInMillis(): Long = dateUploadStarted!!.time
}

View file

@ -14,88 +14,90 @@ import javax.inject.Named
* Class that extends PagedList.BoundaryCallback for contributions list It defines the action that
* is triggered for various boundary conditions in the list
*/
class ContributionBoundaryCallback @Inject constructor(
private val repository: ContributionsRepository,
private val sessionManager: SessionManager,
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler
) : BoundaryCallback<Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
class ContributionBoundaryCallback
@Inject
constructor(
private val repository: ContributionsRepository,
private val sessionManager: SessionManager,
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler,
) : BoundaryCallback<Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
/**
* It is triggered when the list has no items User's Contributions are then fetched from the
* network
*/
override fun onZeroItemsLoaded() {
if (sessionManager.userName != null) {
mediaClient.resetUserNameContinuation(sessionManager.userName!!)
/**
* It is triggered when the list has no items User's Contributions are then fetched from the
* network
*/
override fun onZeroItemsLoaded() {
if (sessionManager.userName != null) {
mediaClient.resetUserNameContinuation(sessionManager.userName!!)
}
fetchContributions()
}
fetchContributions()
}
/**
* It is triggered when the user scrolls to the top of the list
* */
override fun onItemAtFrontLoaded(itemAtFront: Contribution) {
/**
* It is triggered when the user scrolls to the top of the list
* */
override fun onItemAtFrontLoaded(itemAtFront: Contribution) {
}
}
/**
* It is triggered when the user scrolls to the end of the list. User's Contributions are then
* fetched from the network
*/
override fun onItemAtEndLoaded(itemAtEnd: Contribution) {
fetchContributions()
}
/**
* It is triggered when the user scrolls to the end of the list. User's Contributions are then
* fetched from the network
*/
override fun onItemAtEndLoaded(itemAtEnd: Contribution) {
fetchContributions()
}
/**
* Fetches contributions using the MediaWiki API
*/
private fun fetchContributions() {
if (sessionManager.userName != null) {
userName?.let { userName ->
mediaClient.getMediaListForUser(userName)
.map { mediaList ->
mediaList.map { media ->
Contribution(media = media, state = Contribution.STATE_COMPLETED)
}
}
.subscribeOn(ioThreadScheduler)
.subscribe(::saveContributionsToDB) { error: Throwable ->
Timber.e(
"Failed to fetch contributions: %s",
error.message
/**
* Fetches contributions using the MediaWiki API
*/
private fun fetchContributions() {
if (sessionManager.userName != null) {
userName
?.let { userName ->
mediaClient
.getMediaListForUser(userName)
.map { mediaList ->
mediaList.map { media ->
Contribution(media = media, state = Contribution.STATE_COMPLETED)
}
}.subscribeOn(ioThreadScheduler)
.subscribe(::saveContributionsToDB) { error: Throwable ->
Timber.e(
"Failed to fetch contributions: %s",
error.message,
)
}
}?.let {
compositeDisposable.add(
it,
)
}
}?.let {
compositeDisposable.add(
it
)
} else {
compositeDisposable.clear()
}
}else {
compositeDisposable.clear()
}
/**
* Saves the contributions the the local DB
*/
private fun saveContributionsToDB(contributions: List<Contribution>) {
compositeDisposable.add(
repository
.save(contributions)
.subscribeOn(ioThreadScheduler)
.subscribe { longs: List<Long?>? ->
repository["last_fetch_timestamp"] = System.currentTimeMillis()
},
)
}
/**
* Clean up
*/
fun dispose() {
compositeDisposable.dispose()
}
}
/**
* Saves the contributions the the local DB
*/
private fun saveContributionsToDB(contributions: List<Contribution>) {
compositeDisposable.add(
repository.save(contributions)
.subscribeOn(ioThreadScheduler)
.subscribe { longs: List<Long?>? ->
repository["last_fetch_timestamp"] = System.currentTimeMillis()
}
)
}
/**
* Clean up
*/
fun dispose() {
compositeDisposable.dispose()
}
}

View file

@ -12,62 +12,61 @@ import javax.inject.Named
/**
* Data-Source which acts as mediator for contributions-data from the API
*/
class ContributionsRemoteDataSource @Inject constructor(
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler
) : ItemKeyedDataSource<Int, Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
class ContributionsRemoteDataSource
@Inject
constructor(
private val mediaClient: MediaClient,
@param:Named(CommonsApplicationModule.IO_THREAD) private val ioThreadScheduler: Scheduler,
) : ItemKeyedDataSource<Int, Contribution>() {
private val compositeDisposable: CompositeDisposable = CompositeDisposable()
var userName: String? = null
override fun loadInitial(
params: LoadInitialParams<Int>,
callback: LoadInitialCallback<Contribution>
) {
fetchContributions(callback)
override fun loadInitial(
params: LoadInitialParams<Int>,
callback: LoadInitialCallback<Contribution>,
) {
fetchContributions(callback)
}
override fun loadAfter(
params: LoadParams<Int>,
callback: LoadCallback<Contribution>,
) {
fetchContributions(callback)
}
override fun loadBefore(
params: LoadParams<Int>,
callback: LoadCallback<Contribution>,
) {
}
override fun getKey(item: Contribution): Int = item.pageId.hashCode()
/**
* Fetches contributions using the MediaWiki API
*/
private fun fetchContributions(callback: LoadCallback<Contribution>) {
compositeDisposable.add(
mediaClient
.getMediaListForUser(userName!!)
.map { mediaList ->
mediaList.map {
Contribution(media = it, state = Contribution.STATE_COMPLETED)
}
}.subscribeOn(ioThreadScheduler)
.subscribe({
callback.onResult(it)
}) { error: Throwable ->
Timber.e(
"Failed to fetch contributions: %s",
error.message,
)
},
)
}
fun dispose() {
compositeDisposable.dispose()
}
}
override fun loadAfter(
params: LoadParams<Int>,
callback: LoadCallback<Contribution>
) {
fetchContributions(callback)
}
override fun loadBefore(
params: LoadParams<Int>,
callback: LoadCallback<Contribution>
) {
}
override fun getKey(item: Contribution): Int {
return item.pageId.hashCode()
}
/**
* Fetches contributions using the MediaWiki API
*/
private fun fetchContributions(callback: LoadCallback<Contribution>) {
compositeDisposable.add(
mediaClient.getMediaListForUser(userName!!)
.map { mediaList ->
mediaList.map {
Contribution(media = it, state = Contribution.STATE_COMPLETED)
}
}
.subscribeOn(ioThreadScheduler)
.subscribe({
callback.onResult(it)
}) { error: Throwable ->
Timber.e(
"Failed to fetch contributions: %s",
error.message
)
}
)
}
fun dispose() {
compositeDisposable.dispose()
}
}

View file

@ -13,26 +13,30 @@ import fr.free.nrw.commons.databinding.DialogAddToWikipediaInstructionsBinding
* Dialog fragment for displaying instructions for editing wikipedia
*/
class WikipediaInstructionsDialogFragment : DialogFragment() {
var callback: Callback? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = DialogAddToWikipediaInstructionsBinding.inflate(inflater, container, false).apply {
val contribution: Contribution? = arguments!!.getParcelable(ARG_CONTRIBUTION)
tvWikicode.setText(contribution?.media?.wikiCode)
instructionsCancel.setOnClickListener { dismiss() }
instructionsConfirm.setOnClickListener {
callback?.onConfirmClicked(contribution, checkboxCopyWikicode.isChecked)
}
}.root
savedInstanceState: Bundle?,
) = DialogAddToWikipediaInstructionsBinding
.inflate(inflater, container, false)
.apply {
val contribution: Contribution? = arguments!!.getParcelable(ARG_CONTRIBUTION)
tvWikicode.setText(contribution?.media?.wikiCode)
instructionsCancel.setOnClickListener { dismiss() }
instructionsConfirm.setOnClickListener {
callback?.onConfirmClicked(contribution, checkboxCopyWikicode.isChecked)
}
}.root
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
dialog!!.window?.setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN,
)
}
@ -40,15 +44,19 @@ class WikipediaInstructionsDialogFragment : DialogFragment() {
* Callback for handling confirm button clicked
*/
interface Callback {
fun onConfirmClicked(contribution: Contribution?, copyWikicode: Boolean)
fun onConfirmClicked(
contribution: Contribution?,
copyWikicode: Boolean,
)
}
companion object {
const val ARG_CONTRIBUTION = "contribution"
@JvmStatic
fun newInstance(contribution: Contribution) = WikipediaInstructionsDialogFragment().apply {
arguments = bundleOf(ARG_CONTRIBUTION to contribution)
}
fun newInstance(contribution: Contribution) =
WikipediaInstructionsDialogFragment().apply {
arguments = bundleOf(ARG_CONTRIBUTION to contribution)
}
}
}