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

@ -9,16 +9,13 @@ object ConfigUtils {
val isBetaFlavour: Boolean = BuildConfig.FLAVOR == "beta"
@JvmStatic
private fun Context.getVersionName(): String {
return try {
private fun Context.getVersionName(): String =
try {
packageManager.getPackageInfo(packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
BuildConfig.VERSION_NAME
}
}
@JvmStatic
fun Context.getVersionNameWithSha(): String {
return "${getVersionName()}~${BuildConfig.COMMIT_SHA}"
}
}
fun Context.getVersionNameWithSha(): String = "${getVersionName()}~${BuildConfig.COMMIT_SHA}"
}

View file

@ -5,8 +5,8 @@ import android.content.Context
import android.net.Uri
import androidx.exifinterface.media.ExifInterface
import fr.free.nrw.commons.customselector.model.Image
import fr.free.nrw.commons.filepicker.PickedFiles
import fr.free.nrw.commons.customselector.ui.selector.ImageLoader
import fr.free.nrw.commons.filepicker.PickedFiles
import fr.free.nrw.commons.media.MediaClient
import fr.free.nrw.commons.upload.FileProcessor
import fr.free.nrw.commons.upload.FileUtilsWrapper
@ -22,7 +22,6 @@ import java.net.UnknownHostException
*/
class CustomSelectorUtils {
companion object {
/**
* Get image sha1 from uri, used to retrieve the original image sha1.
*/
@ -30,10 +29,9 @@ class CustomSelectorUtils {
uri: Uri,
ioDispatcher: CoroutineDispatcher,
fileUtilsWrapper: FileUtilsWrapper,
contentResolver: ContentResolver
): String {
return withContext(ioDispatcher) {
contentResolver: ContentResolver,
): String =
withContext(ioDispatcher) {
try {
val result = fileUtilsWrapper.getSHA1(contentResolver.openInputStream(uri))
result
@ -42,7 +40,6 @@ class CustomSelectorUtils {
""
}
}
}
/**
* Generates modified SHA1 of an image
@ -52,37 +49,37 @@ class CustomSelectorUtils {
defaultDispatcher: CoroutineDispatcher,
context: Context,
fileProcessor: FileProcessor,
fileUtilsWrapper: FileUtilsWrapper
): String {
return withContext(defaultDispatcher) {
fileUtilsWrapper: FileUtilsWrapper,
): String =
withContext(defaultDispatcher) {
val uploadableFile = PickedFiles.pickedExistingPicture(context, image.uri)
val exifInterface: ExifInterface? = try {
ExifInterface(uploadableFile.file!!)
} catch (e: IOException) {
Timber.e(e)
null
}
val exifInterface: ExifInterface? =
try {
ExifInterface(uploadableFile.file!!)
} catch (e: IOException) {
Timber.e(e)
null
}
fileProcessor.redactExifTags(exifInterface, fileProcessor.getExifTagsToRedact())
val sha1 =
fileUtilsWrapper.getSHA1(
fileUtilsWrapper.getFileInputStream(uploadableFile.filePath)
fileUtilsWrapper.getFileInputStream(uploadableFile.filePath),
)
uploadableFile.file.delete()
sha1
}
}
/**
* Query SHA1, return result if previously queried, otherwise start a new query.
*
* @return true if the image exists on Commons, false otherwise.
*/
suspend fun checkWhetherFileExistsOnCommonsUsingSHA1(SHA1: String,
ioDispatcher : CoroutineDispatcher,
mediaClient: MediaClient
): ImageLoader.Result {
return withContext(ioDispatcher) {
suspend fun checkWhetherFileExistsOnCommonsUsingSHA1(
SHA1: String,
ioDispatcher: CoroutineDispatcher,
mediaClient: MediaClient,
): ImageLoader.Result =
withContext(ioDispatcher) {
var result: ImageLoader.Result = ImageLoader.Result.FALSE
try {
if (mediaClient.checkFileExistsUsingSha(SHA1).blockingGet()) {
@ -98,6 +95,5 @@ class CustomSelectorUtils {
}
result
}
}
}
}
}

View file

@ -12,8 +12,10 @@ object DialogUtil {
* @param activity the activity
* @param dialog the dialog to be shown
*/
private fun showSafely(activity: Activity?, dialog: AlertDialog?):AlertDialog? {
private fun showSafely(
activity: Activity?,
dialog: AlertDialog?,
): AlertDialog? {
if (activity == null || dialog == null) {
Timber.d("Show called with null activity / dialog. Ignoring.")
return null
@ -37,18 +39,17 @@ object DialogUtil {
title: String?,
message: String?,
onPositiveBtnClick: Runnable?,
onNegativeBtnClick: Runnable?
): AlertDialog? {
return createAndShowDialogSafely(
onNegativeBtnClick: Runnable?,
): AlertDialog? =
createAndShowDialogSafely(
activity = activity,
title = title,
message = message,
positiveButtonText = activity.getString(R.string.yes),
negativeButtonText = activity.getString(R.string.no),
onPositiveBtnClick = onPositiveBtnClick,
onNegativeBtnClick = onNegativeBtnClick
onNegativeBtnClick = onNegativeBtnClick,
)
}
@JvmStatic
fun showAlertDialog(
@ -59,17 +60,16 @@ object DialogUtil {
negativeButtonText: String?,
onPositiveBtnClick: Runnable?,
onNegativeBtnClick: Runnable?,
): AlertDialog? {
return createAndShowDialogSafely(
): AlertDialog? =
createAndShowDialogSafely(
activity = activity,
title = title,
message = message,
positiveButtonText = positiveButtonText,
negativeButtonText = negativeButtonText,
onPositiveBtnClick = onPositiveBtnClick,
onNegativeBtnClick = onNegativeBtnClick
onNegativeBtnClick = onNegativeBtnClick,
)
}
@JvmStatic
fun showAlertDialog(
@ -79,9 +79,9 @@ object DialogUtil {
onPositiveBtnClick: Runnable?,
onNegativeBtnClick: Runnable?,
customView: View?,
cancelable: Boolean
): AlertDialog? {
return createAndShowDialogSafely(
cancelable: Boolean,
): AlertDialog? =
createAndShowDialogSafely(
activity = activity,
title = title,
message = message,
@ -90,9 +90,8 @@ object DialogUtil {
onPositiveBtnClick = onPositiveBtnClick,
onNegativeBtnClick = onNegativeBtnClick,
customView = customView,
cancelable = cancelable
cancelable = cancelable,
)
}
@JvmStatic
fun showAlertDialog(
@ -104,9 +103,9 @@ object DialogUtil {
onPositiveBtnClick: Runnable?,
onNegativeBtnClick: Runnable?,
customView: View?,
cancelable: Boolean
): AlertDialog? {
return createAndShowDialogSafely(
cancelable: Boolean,
): AlertDialog? =
createAndShowDialogSafely(
activity = activity,
title = title,
message = message,
@ -115,9 +114,8 @@ object DialogUtil {
onPositiveBtnClick = onPositiveBtnClick,
onNegativeBtnClick = onNegativeBtnClick,
customView = customView,
cancelable = cancelable
cancelable = cancelable,
)
}
@JvmStatic
fun showAlertDialog(
@ -126,17 +124,16 @@ object DialogUtil {
message: String?,
positiveButtonText: String?,
onPositiveBtnClick: Runnable?,
cancelable: Boolean
): AlertDialog? {
return createAndShowDialogSafely(
cancelable: Boolean,
): AlertDialog? =
createAndShowDialogSafely(
activity = activity,
title = title,
message = message,
positiveButtonText = positiveButtonText,
onPositiveBtnClick = onPositiveBtnClick,
cancelable = cancelable
cancelable = cancelable,
)
}
/**
* show a dialog
@ -159,9 +156,8 @@ object DialogUtil {
onPositiveBtnClick: Runnable? = null,
onNegativeBtnClick: Runnable? = null,
customView: View? = null,
cancelable: Boolean = true
cancelable: Boolean = true,
): AlertDialog? {
/* If the custom view already has a parent, there is already a dialog showing with the view
* This happens for on resume - return to avoid creating a second dialog - the first one
* will still show
@ -170,17 +166,22 @@ object DialogUtil {
return null
}
return showSafely(activity, AlertDialog.Builder(activity).apply {
title?.also{setTitle(title)}
message?.also{setMessage(message)}
setView(customView)
setCancelable(cancelable)
positiveButtonText?.let {
setPositiveButton(it) { _, _ -> onPositiveBtnClick?.run() }
}
negativeButtonText?.let {
setNegativeButton(it) { _, _ -> onNegativeBtnClick?.run() }
}
}.create())
return showSafely(
activity,
AlertDialog
.Builder(activity)
.apply {
title?.also { setTitle(title) }
message?.also { setMessage(message) }
setView(customView)
setCancelable(cancelable)
positiveButtonText?.let {
setPositiveButton(it) { _, _ -> onPositiveBtnClick?.run() }
}
negativeButtonText?.let {
setNegativeButton(it) { _, _ -> onNegativeBtnClick?.run() }
}
}.create(),
)
}
}

View file

@ -1,6 +1,5 @@
package fr.free.nrw.commons.utils
import android.Manifest.permission
import android.app.Activity
import android.app.DownloadManager
import android.content.Context
@ -19,7 +18,10 @@ object DownloadUtils {
* @param m Media file to download
*/
@JvmStatic
fun downloadMedia(activity: Activity?, m: Media) {
fun downloadMedia(
activity: Activity?,
m: Media,
) {
val imageUrl = m.imageUrl
var fileName = m.filename
if (imageUrl == null || fileName == null || activity == null) {
@ -29,32 +31,37 @@ object DownloadUtils {
// Strip 'File:' from beginning of filename, we really shouldn't store it
fileName = fileName.substringAfter("File:")
val imageUri = Uri.parse(imageUrl)
val req = DownloadManager.Request(imageUri).apply {
setTitle(m.displayTitle)
setDescription(activity.getString(R.string.app_name))
setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
allowScanningByMediaScanner()
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
}
val req =
DownloadManager.Request(imageUri).apply {
setTitle(m.displayTitle)
setDescription(activity.getString(R.string.app_name))
setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
allowScanningByMediaScanner()
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
}
PermissionUtils.checkPermissionsAndPerformAction(
activity,
{ enqueueRequest(activity, req) },
{
Toast.makeText(
activity,
R.string.download_failed_we_cannot_download_the_file_without_storage_permission,
Toast.LENGTH_SHORT
).show()
Toast
.makeText(
activity,
R.string.download_failed_we_cannot_download_the_file_without_storage_permission,
Toast.LENGTH_SHORT,
).show()
},
R.string.storage_permission,
R.string.write_storage_permission_rationale,
*PermissionUtils.PERMISSIONS_STORAGE
)
*PermissionUtils.PERMISSIONS_STORAGE,
)
}
private fun enqueueRequest(activity: Activity, req: DownloadManager.Request) {
private fun enqueueRequest(
activity: Activity,
req: DownloadManager.Request,
) {
val systemService =
activity.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
systemService?.enqueue(req)
}
}
}

View file

@ -1,9 +1,14 @@
package fr.free.nrw.commons.utils.model
enum class ConnectionType(private val text: String) {
WIFI_NETWORK("wifi"), CELLULAR_4G("cellular-4g"), CELLULAR_3G("cellular-3g"), CELLULAR("cellular"), NO_INTERNET("no-internet");
enum class ConnectionType(
private val text: String,
) {
WIFI_NETWORK("wifi"),
CELLULAR_4G("cellular-4g"),
CELLULAR_3G("cellular-3g"),
CELLULAR("cellular"),
NO_INTERNET("no-internet"),
;
override fun toString(): String {
return text
}
}
override fun toString(): String = text
}

View file

@ -1,5 +1,9 @@
package fr.free.nrw.commons.utils.model
enum class NetworkConnectionType {
WIFI, TWO_G, THREE_G, FOUR_G, UNKNOWN
}
WIFI,
TWO_G,
THREE_G,
FOUR_G,
UNKNOWN,
}