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,6 +1,5 @@
|
|||
package fr.free.nrw.commons.description
|
||||
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
|
|
@ -29,11 +28,12 @@ import io.reactivex.schedulers.Schedulers
|
|||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
/**
|
||||
* Activity for populating and editing existing description and caption
|
||||
*/
|
||||
class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventListener {
|
||||
class DescriptionEditActivity :
|
||||
BaseActivity(),
|
||||
UploadMediaDetailAdapter.EventListener {
|
||||
/**
|
||||
* Adapter for showing UploadMediaDetail in the activity
|
||||
*/
|
||||
|
|
@ -70,7 +70,7 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
|
||||
private lateinit var binding: ActivityDescriptionEditBinding
|
||||
|
||||
private val REQUEST_CODE_FOR_VOICE_INPUT = 1213
|
||||
private val requestCodeForVoiceInput = 1213
|
||||
|
||||
private var descriptionAndCaptions: ArrayList<UploadMediaDetail>? = null
|
||||
|
||||
|
|
@ -78,7 +78,6 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
|
||||
@Inject lateinit var sessionManager: SessionManager
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
|
@ -110,12 +109,17 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
* @param descriptionAndCaptions list of description and caption
|
||||
*/
|
||||
private fun initRecyclerView(descriptionAndCaptions: ArrayList<UploadMediaDetail>?) {
|
||||
uploadMediaDetailAdapter = UploadMediaDetailAdapter(this,
|
||||
savedLanguageValue, descriptionAndCaptions, recentLanguagesDao)
|
||||
uploadMediaDetailAdapter =
|
||||
UploadMediaDetailAdapter(
|
||||
this,
|
||||
savedLanguageValue,
|
||||
descriptionAndCaptions,
|
||||
recentLanguagesDao,
|
||||
)
|
||||
uploadMediaDetailAdapter.setCallback { titleStringID: Int, messageStringId: Int ->
|
||||
showInfoAlert(
|
||||
titleStringID,
|
||||
messageStringId
|
||||
messageStringId,
|
||||
)
|
||||
}
|
||||
uploadMediaDetailAdapter.setEventListener(this)
|
||||
|
|
@ -129,11 +133,17 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
* @param titleStringID Title ID
|
||||
* @param messageStringId Message ID
|
||||
*/
|
||||
private fun showInfoAlert(titleStringID: Int, messageStringId: Int) {
|
||||
private fun showInfoAlert(
|
||||
titleStringID: Int,
|
||||
messageStringId: Int,
|
||||
) {
|
||||
showAlertDialog(
|
||||
this, getString(titleStringID),
|
||||
getString(messageStringId), getString(android.R.string.ok),
|
||||
null, true
|
||||
this,
|
||||
getString(titleStringID),
|
||||
getString(messageStringId),
|
||||
getString(android.R.string.ok),
|
||||
null,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -144,13 +154,13 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
*/
|
||||
override fun addLanguage() {
|
||||
val uploadMediaDetail = UploadMediaDetail()
|
||||
uploadMediaDetail.isManuallyAdded = true //This was manually added by the user
|
||||
uploadMediaDetail.isManuallyAdded = true // This was manually added by the user
|
||||
uploadMediaDetailAdapter.addDescription(uploadMediaDetail)
|
||||
rvDescriptions!!.smoothScrollToPosition(uploadMediaDetailAdapter.itemCount - 1)
|
||||
}
|
||||
|
||||
private fun onBackButtonClicked(view: View) {
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
|
||||
private fun onSubmitButtonClicked(view: View) {
|
||||
|
|
@ -174,10 +184,11 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
val descriptionStart = wikiText!!.substring(0, descriptionIndex + 12)
|
||||
val descriptionToEnd = wikiText!!.substring(descriptionIndex + 12)
|
||||
val descriptionEndIndex = descriptionToEnd.indexOf("\n")
|
||||
val descriptionEnd = wikiText!!.substring(
|
||||
descriptionStart.length
|
||||
+ descriptionEndIndex
|
||||
)
|
||||
val descriptionEnd =
|
||||
wikiText!!.substring(
|
||||
descriptionStart.length +
|
||||
descriptionEndIndex,
|
||||
)
|
||||
buffer.append(descriptionStart)
|
||||
for (i in uploadMediaDetails.indices) {
|
||||
val uploadDetails = uploadMediaDetails[i]
|
||||
|
|
@ -203,65 +214,72 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
* @param updatedWikiText updated wiki text
|
||||
* @param uploadMediaDetails descriptions and captions
|
||||
*/
|
||||
private fun editDescription(media : Media, updatedWikiText : String, uploadMediaDetails : ArrayList<UploadMediaDetail>){
|
||||
|
||||
private fun editDescription(
|
||||
media: Media,
|
||||
updatedWikiText: String,
|
||||
uploadMediaDetails: ArrayList<UploadMediaDetail>,
|
||||
) {
|
||||
try {
|
||||
descriptionEditHelper?.addDescription(
|
||||
applicationContext, media,
|
||||
updatedWikiText
|
||||
)
|
||||
?.subscribeOn(Schedulers.io())
|
||||
descriptionEditHelper
|
||||
?.addDescription(
|
||||
applicationContext,
|
||||
media,
|
||||
updatedWikiText,
|
||||
)?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(Consumer<Boolean> { s: Boolean? -> Timber.d("Descriptions are added.") })?.let {
|
||||
?.subscribe(Consumer<Boolean> { s: Boolean? -> Timber.d("Descriptions are added.") })
|
||||
?.let {
|
||||
compositeDisposable.add(
|
||||
it
|
||||
it,
|
||||
)
|
||||
}
|
||||
} catch (e : InvalidLoginTokenException) {
|
||||
} catch (e: InvalidLoginTokenException) {
|
||||
val username: String? = sessionManager?.userName
|
||||
val logoutListener = CommonsApplication.BaseLogoutListener(
|
||||
this,
|
||||
getString(R.string.invalid_login_message),
|
||||
username
|
||||
)
|
||||
val logoutListener =
|
||||
CommonsApplication.BaseLogoutListener(
|
||||
this,
|
||||
getString(R.string.invalid_login_message),
|
||||
username,
|
||||
)
|
||||
|
||||
val commonsApplication = CommonsApplication.getInstance()
|
||||
if (commonsApplication != null ){
|
||||
commonsApplication.clearApplicationData(this,logoutListener)
|
||||
if (commonsApplication != null) {
|
||||
commonsApplication.clearApplicationData(this, logoutListener)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val updatedCaptions = LinkedHashMap<String, String>()
|
||||
for (mediaDetail in uploadMediaDetails) {
|
||||
try {
|
||||
compositeDisposable.add(
|
||||
descriptionEditHelper!!.addCaption(
|
||||
applicationContext, media,
|
||||
mediaDetail.languageCode, mediaDetail.captionText
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
descriptionEditHelper!!
|
||||
.addCaption(
|
||||
applicationContext,
|
||||
media,
|
||||
mediaDetail.languageCode,
|
||||
mediaDetail.captionText,
|
||||
).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { s: Boolean? ->
|
||||
updatedCaptions[mediaDetail.languageCode!!] = mediaDetail.captionText
|
||||
media.captions = updatedCaptions
|
||||
Timber.d("Caption is added.")
|
||||
})
|
||||
}
|
||||
catch (e : InvalidLoginTokenException) {
|
||||
val username = sessionManager.userName
|
||||
val logoutListener = CommonsApplication.BaseLogoutListener(
|
||||
this,
|
||||
getString(R.string.invalid_login_message),
|
||||
username
|
||||
},
|
||||
)
|
||||
} catch (e: InvalidLoginTokenException) {
|
||||
val username = sessionManager.userName
|
||||
val logoutListener =
|
||||
CommonsApplication.BaseLogoutListener(
|
||||
this,
|
||||
getString(R.string.invalid_login_message),
|
||||
username,
|
||||
)
|
||||
|
||||
val commonsApplication = CommonsApplication.getInstance()
|
||||
if (commonsApplication != null ){
|
||||
commonsApplication.clearApplicationData(this,logoutListener)
|
||||
if (commonsApplication != null) {
|
||||
commonsApplication.clearApplicationData(this, logoutListener)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,23 +292,29 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
|
|||
progressDialog!!.show()
|
||||
}
|
||||
|
||||
override
|
||||
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE_FOR_VOICE_INPUT) {
|
||||
override fun onActivityResult(
|
||||
requestCode: Int,
|
||||
resultCode: Int,
|
||||
data: Intent?,
|
||||
) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == requestCodeForVoiceInput) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
val result = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS )
|
||||
uploadMediaDetailAdapter.handleSpeechResult(result!![0]) }
|
||||
else { Timber.e("Error %s", resultCode) }
|
||||
val result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
|
||||
uploadMediaDetailAdapter.handleSpeechResult(result!![0])
|
||||
} else {
|
||||
Timber.e("Error %s", resultCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
|
||||
outState.putParcelableArrayList(LIST_OF_DESCRIPTION_AND_CAPTION, uploadMediaDetailAdapter.items as ArrayList<out Parcelable?>)
|
||||
outState.putString(WIKITEXT, wikiText)
|
||||
outState.putString(Prefs.DESCRIPTION_LANGUAGE, savedLanguageValue)
|
||||
//save Media
|
||||
// save Media
|
||||
outState.putParcelable("media", media)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ package fr.free.nrw.commons.description
|
|||
object EditDescriptionConstants {
|
||||
const val LIST_OF_DESCRIPTION_AND_CAPTION = "description.descriptionAndCaption"
|
||||
const val WIKITEXT = "description.wikiText"
|
||||
const val UPDATED_WIKITEXT = "description.updatedWikiText";
|
||||
}
|
||||
const val UPDATED_WIKITEXT = "description.updatedWikiText"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue