Refactor variable names to adhere to naming conventions (#6111)

* Rename Constants to Follow Kotlin Naming Conventions

>This PR refactors constant names in the project to adhere to Kotlin's UPPERCASE_SNAKE_CASE naming convention, improving code readability and maintaining consistency across the codebase.

>Renamed the following constants in LoginActivity:
>saveProgressDialog → SAVE_PROGRESS_DIALOG
>saveErrorMessage → SAVE_ERROR_MESSAGE
>saveUsername → SAVE_USERNAME
>savePassword → SAVE_PASSWORD

>Updated all references to these constants throughout the project.

* Update Project_Default.xml

* Refactor variable names to adhere to naming conventions

Renamed variables to use camel case:
-UPLOAD_COUNT_THRESHOLD → uploadCountThreshold
-REVERT_PERCENTAGE_FOR_MESSAGE → revertPercentageForMessage
-REVERT_SHARED_PREFERENCE → revertSharedPreference
-UPLOAD_SHARED_PREFERENCE → uploadSharedPreference

Renamed variables with uppercase initials to lowercase for alignment with Kotlin conventions:
-Latitude → latitude
-Longitude → longitude
-Accuracy → accuracy

Refactored the following variable names:
-NUMBER_OF_QUESTIONS → numberOfQuestions
-MULTIPLIER_TO_GET_PERCENTAGE → multiplierToGetPercentage
This commit is contained in:
Akshay Komar 2025-01-09 13:52:42 +05:30 committed by GitHub
parent 87a453cb72
commit 3e7565c7e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 32 deletions

View file

@ -61,16 +61,16 @@ class CoordinateEditHelper @Inject constructor(
/** /**
* Replaces new coordinates * Replaces new coordinates
* @param media to be added * @param media to be added
* @param Latitude to be added * @param latitude to be added
* @param Longitude to be added * @param longitude to be added
* @param Accuracy to be added * @param accuracy to be added
* @return Observable<Boolean> * @return Observable<Boolean>
*/ */
private fun addCoordinates( private fun addCoordinates(
media: Media, media: Media,
Latitude: String, latitude: String,
Longitude: String, longitude: String,
Accuracy: String accuracy: String
): Observable<Boolean>? { ): Observable<Boolean>? {
Timber.d("thread is coordinates adding %s", Thread.currentThread().getName()) Timber.d("thread is coordinates adding %s", Thread.currentThread().getName())
val summary = "Adding Coordinates" val summary = "Adding Coordinates"
@ -83,9 +83,9 @@ class CoordinateEditHelper @Inject constructor(
.blockingGet() .blockingGet()
} }
if (Latitude != null) { if (latitude != null) {
buffer.append("\n{{Location|").append(Latitude).append("|").append(Longitude) buffer.append("\n{{Location|").append(latitude).append("|").append(longitude)
.append("|").append(Accuracy).append("}}") .append("|").append(accuracy).append("}}")
} }
val editedLocation = buffer.toString() val editedLocation = buffer.toString()
@ -141,7 +141,7 @@ class CoordinateEditHelper @Inject constructor(
* @param media to be added * @param media to be added
* @param latitude to be added * @param latitude to be added
* @param longitude to be added * @param longitude to be added
* @param Accuracy to be added * @param accuracy to be added
* @param result to be added * @param result to be added
* @return boolean * @return boolean
*/ */
@ -150,7 +150,7 @@ class CoordinateEditHelper @Inject constructor(
media: Media, media: Media,
latitude: String, latitude: String,
longitude: String, longitude: String,
Accuracy: String, accuracy: String,
result: Boolean result: Boolean
): Boolean { ): Boolean {
val message: String val message: String
@ -160,7 +160,7 @@ class CoordinateEditHelper @Inject constructor(
media.coordinates = fr.free.nrw.commons.location.LatLng( media.coordinates = fr.free.nrw.commons.location.LatLng(
latitude.toDouble(), latitude.toDouble(),
longitude.toDouble(), longitude.toDouble(),
Accuracy.toFloat() accuracy.toFloat()
) )
title += ": " + context.getString(R.string.coordinates_edit_helper_show_edit_title_success) title += ": " + context.getString(R.string.coordinates_edit_helper_show_edit_title_success)
val coordinatesInMessage = StringBuilder() val coordinatesInMessage = StringBuilder()

View file

@ -40,10 +40,10 @@ class QuizChecker @Inject constructor(
private val compositeDisposable = CompositeDisposable() private val compositeDisposable = CompositeDisposable()
private val UPLOAD_COUNT_THRESHOLD = 5 private val uploadCountThreshold = 5
private val REVERT_PERCENTAGE_FOR_MESSAGE = "50%" private val revertPercentageForMessage = "50%"
private val REVERT_SHARED_PREFERENCE = "revertCount" private val revertSharedPreference = "revertCount"
private val UPLOAD_SHARED_PREFERENCE = "uploadCount" private val uploadSharedPreference = "uploadCount"
/** /**
* Initializes quiz check by calculating revert parameters and showing quiz if necessary * Initializes quiz check by calculating revert parameters and showing quiz if necessary
@ -80,12 +80,12 @@ class QuizChecker @Inject constructor(
*/ */
private fun setTotalUploadCount(uploadCount: Int) { private fun setTotalUploadCount(uploadCount: Int) {
totalUploadCount = uploadCount - revertKvStore.getInt( totalUploadCount = uploadCount - revertKvStore.getInt(
UPLOAD_SHARED_PREFERENCE, uploadSharedPreference,
0 0
) )
if (totalUploadCount < 0) { if (totalUploadCount < 0) {
totalUploadCount = 0 totalUploadCount = 0
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0) revertKvStore.putInt(uploadSharedPreference, 0)
} }
isUploadCountFetched = true isUploadCountFetched = true
} }
@ -112,10 +112,10 @@ class QuizChecker @Inject constructor(
* @param revertCountFetched Count of deleted uploads * @param revertCountFetched Count of deleted uploads
*/ */
private fun setRevertParameter(revertCountFetched: Int) { private fun setRevertParameter(revertCountFetched: Int) {
revertCount = revertCountFetched - revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0) revertCount = revertCountFetched - revertKvStore.getInt(revertSharedPreference, 0)
if (revertCount < 0) { if (revertCount < 0) {
revertCount = 0 revertCount = 0
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0) revertKvStore.putInt(revertSharedPreference, 0)
} }
isRevertCountFetched = true isRevertCountFetched = true
} }
@ -128,13 +128,13 @@ class QuizChecker @Inject constructor(
setRevertCount() setRevertCount()
if (revertCount < 0 || totalUploadCount < 0) { if (revertCount < 0 || totalUploadCount < 0) {
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, 0) revertKvStore.putInt(revertSharedPreference, 0)
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, 0) revertKvStore.putInt(uploadSharedPreference, 0)
return return
} }
if (isRevertCountFetched && isUploadCountFetched && if (isRevertCountFetched && isUploadCountFetched &&
totalUploadCount >= UPLOAD_COUNT_THRESHOLD && totalUploadCount >= uploadCountThreshold &&
(revertCount * 100) / totalUploadCount >= 50 (revertCount * 100) / totalUploadCount >= 50
) { ) {
callQuiz(activity) callQuiz(activity)
@ -149,7 +149,7 @@ class QuizChecker @Inject constructor(
DialogUtil.showAlertDialog( DialogUtil.showAlertDialog(
activity, activity,
activity.getString(R.string.quiz), activity.getString(R.string.quiz),
activity.getString(R.string.quiz_alert_message, REVERT_PERCENTAGE_FOR_MESSAGE), activity.getString(R.string.quiz_alert_message, revertPercentageForMessage),
activity.getString(R.string.about_translate_proceed), activity.getString(R.string.about_translate_proceed),
activity.getString(android.R.string.cancel), activity.getString(android.R.string.cancel),
{ startQuizActivity(activity) }, { startQuizActivity(activity) },
@ -161,11 +161,11 @@ class QuizChecker @Inject constructor(
* Starts the quiz activity and updates preferences for revert and upload counts * Starts the quiz activity and updates preferences for revert and upload counts
*/ */
private fun startQuizActivity(activity: Activity) { private fun startQuizActivity(activity: Activity) {
val newRevertSharedPrefs = revertCount + revertKvStore.getInt(REVERT_SHARED_PREFERENCE, 0) val newRevertSharedPrefs = revertCount + revertKvStore.getInt(revertSharedPreference, 0)
revertKvStore.putInt(REVERT_SHARED_PREFERENCE, newRevertSharedPrefs) revertKvStore.putInt(revertSharedPreference, newRevertSharedPrefs)
val newUploadCount = totalUploadCount + revertKvStore.getInt(UPLOAD_SHARED_PREFERENCE, 0) val newUploadCount = totalUploadCount + revertKvStore.getInt(uploadSharedPreference, 0)
revertKvStore.putInt(UPLOAD_SHARED_PREFERENCE, newUploadCount) revertKvStore.putInt(uploadSharedPreference, newUploadCount)
val intent = Intent(activity, WelcomeActivity::class.java).apply { val intent = Intent(activity, WelcomeActivity::class.java).apply {
putExtra("isQuiz", true) putExtra("isQuiz", true)

View file

@ -30,8 +30,8 @@ import fr.free.nrw.commons.contributions.MainActivity
class QuizResultActivity : AppCompatActivity() { class QuizResultActivity : AppCompatActivity() {
private var binding: ActivityQuizResultBinding? = null private var binding: ActivityQuizResultBinding? = null
private val NUMBER_OF_QUESTIONS = 5 private val numberOfQuestions = 5
private val MULTIPLIER_TO_GET_PERCENTAGE = 20 private val multiplierToGetPercentage = 20
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -67,9 +67,9 @@ class QuizResultActivity : AppCompatActivity() {
*/ */
@SuppressLint("StringFormatInvalid", "SetTextI18n") @SuppressLint("StringFormatInvalid", "SetTextI18n")
fun setScore(score: Int) { fun setScore(score: Int) {
val scorePercent = score * MULTIPLIER_TO_GET_PERCENTAGE val scorePercent = score * multiplierToGetPercentage
binding?.resultProgressBar?.progress = scorePercent binding?.resultProgressBar?.progress = scorePercent
binding?.tvResultProgress?.text = "$score / $NUMBER_OF_QUESTIONS" binding?.tvResultProgress?.text = "$score / $numberOfQuestions"
val message = resources.getString(R.string.congratulatory_message_quiz, "$scorePercent%") val message = resources.getString(R.string.congratulatory_message_quiz, "$scorePercent%")
binding?.congratulatoryMessage?.text = message binding?.congratulatoryMessage?.text = message
} }