Skip to content

Commit d4ababc

Browse files
Refactor: Rename Constants to Follow CamelCase Naming Convention (commons-app#6126)
* 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 * Refactor Dialog View Initialization with Null-Safe Calls This PR refactors the dialog setup code in CustomSelectorActivity to improve safety and readability by replacing explicit casts with null-safe generic calls for findViewById. >Replaced explicit casting (as Button and as TextView) with the generic findViewById<T>() method for improved type safety. >Added null-safety (?.) to avoid potential crashes if a view is not found in the dialog layout. why changed:- >Prevents runtime crashes caused by NullPointerException when a view is missing in the layout. * Refactor Unit Test: Replace Unsafe Casting with Type-Safe Mocking for findViewById >PR refactors the unit test for NearbyParentFragment by replacing unsafe casting in the findViewById mocking statements with type-safe >Ensured all findViewById mocks now use a consistent, type-safe format (findViewById<View>(...)) to reduce verbosity and potential casting errors. >Verified the functionality of prepareViewsForSheetPosition remains unchanged, ensuring no regression in test behavior. * Update NearbyParentFragmentUnitTest.kt * Refactor: Rename Constants to Follow CamelCase Naming Convention >Updated all constant variable names to follow the camelCase naming convention, removing underscores in the middle or end. >Ensured variable names remain descriptive and align with code readability best practices. * Replace private val with const val for URL constants in QuizController * Renaming the constant to use UPPER_SNAKE_CASE * Renaming the constant to use UPPER_SNAKE_CASE * Update Done * **Refactor: Convert `minimumThresholdForSwipe` to a compile-time constant** --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 1c6ebaf commit d4ababc

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

app/src/main/java/fr/free/nrw/commons/quiz/QuizController.kt

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ class QuizController {
1414

1515
private val quiz: ArrayList<QuizQuestion> = ArrayList()
1616

17-
private val URL_FOR_SELFIE = "https://i.imgur.com/0fMYcpM.jpg"
18-
private val URL_FOR_TAJ_MAHAL = "https://upload.wikimedia.org/wikipedia/commons/1/15/Taj_Mahal-03.jpg"
19-
private val URL_FOR_BLURRY_IMAGE = "https://i.imgur.com/Kepb5jR.jpg"
20-
private val URL_FOR_SCREENSHOT = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Social_media_app_mockup_screenshot.svg/500px-Social_media_app_mockup_screenshot.svg.png"
21-
private val URL_FOR_EVENT = "https://upload.wikimedia.org/wikipedia/commons/5/51/HouseBuildingInNorthernVietnam.jpg"
17+
companion object{
18+
19+
const val URL_FOR_SELFIE = "https://i.imgur.com/0fMYcpM.jpg"
20+
const val URL_FOR_TAJ_MAHAL = "https://upload.wikimedia.org/wikipedia/commons/1/15/Taj_Mahal-03.jpg"
21+
const val URL_FOR_BLURRY_IMAGE = "https://i.imgur.com/Kepb5jR.jpg"
22+
const val URL_FOR_SCREENSHOT = "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Social_media_app_mockup_screenshot.svg/500px-Social_media_app_mockup_screenshot.svg.png"
23+
const val URL_FOR_EVENT = "https://upload.wikimedia.org/wikipedia/commons/5/51/HouseBuildingInNorthernVietnam.jpg"
24+
}
25+
2226

2327
fun initialize(context: Context) {
2428
val q1 = QuizQuestion(

app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class ReviewActivity : BaseActivity() {
4545
private var hasNonHiddenCategories = false
4646
var media: Media? = null
4747

48-
private val SAVED_MEDIA = "saved_media"
48+
private val savedMedia = "saved_media"
4949

5050
override fun onSaveInstanceState(outState: Bundle) {
5151
super.onSaveInstanceState(outState)
5252
media?.let {
53-
outState.putParcelable(SAVED_MEDIA, it)
53+
outState.putParcelable(savedMedia, it)
5454
}
5555
}
5656

@@ -90,8 +90,8 @@ class ReviewActivity : BaseActivity() {
9090
PorterDuff.Mode.SRC_IN
9191
)
9292

93-
if (savedInstanceState?.getParcelable<Media>(SAVED_MEDIA) != null) {
94-
updateImage(savedInstanceState.getParcelable(SAVED_MEDIA)!!)
93+
if (savedInstanceState?.getParcelable<Media>(savedMedia) != null) {
94+
updateImage(savedInstanceState.getParcelable(savedMedia)!!)
9595
setUpMediaDetailOnOrientation()
9696
} else {
9797
runRandomizer()

app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() {
3131
lateinit var sessionManager: SessionManager
3232

3333
// Constant variable used to store user's key name for onSaveInstanceState method
34-
private val SAVED_USER = "saved_user"
34+
private val savedUser = "saved_user"
3535

3636
// Variable that stores the value of user
3737
private var user: String? = null
@@ -129,7 +129,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() {
129129
question = getString(R.string.review_thanks)
130130

131131
user = reviewActivity.reviewController.firstRevision?.user()
132-
?: savedInstanceState?.getString(SAVED_USER)
132+
?: savedInstanceState?.getString(savedUser)
133133

134134
//if the user is null because of whatsoever reason, review will not be sent anyways
135135
if (!user.isNullOrEmpty()) {
@@ -172,7 +172,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() {
172172
override fun onSaveInstanceState(outState: Bundle) {
173173
super.onSaveInstanceState(outState)
174174
//Save user name when configuration changes happen
175-
outState.putString(SAVED_USER, user)
175+
outState.putString(savedUser, user)
176176
}
177177

178178
private val reviewCallback: ReviewController.ReviewCallback

app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class SettingsFragment : PreferenceFragmentCompat() {
8686
private var languageHistoryListView: ListView? = null
8787

8888
private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
89-
private val GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content"
9089

9190
private val cameraPickLauncherForResult: ActivityResultLauncher<Intent> =
9291
registerForActivityResult(StartActivityForResult()) { result ->
@@ -513,10 +512,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
513512

514513
@Suppress("LongLine")
515514
companion object {
516-
// TODO: consider changing these to MOBILE_HOME_URL after the following task is resolved:
517-
// https://phabricator.wikimedia.org/T380527
518-
private const val VANISH_ACCOUNT_URL = MOBILE_META_URL + "Special:GlobalVanishRequest"
519-
private const val VANISH_ACCOUNT_SUCCESS_URL = MOBILE_META_URL + "Special:GlobalVanishRequest/vanished"
515+
const val GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content"
516+
private const val VANISH_ACCOUNT_URL = "https://meta.m.wikimedia.org/wiki/Special:Contact/accountvanishapps"
517+
private const val VANISH_ACCOUNT_SUCCESS_URL = "https://meta.m.wikimedia.org/wiki/Special:GlobalVanishRequest/vanished"
520518
/**
521519
* Create Locale based on different types of language codes
522520
* @param languageCode

app/src/main/java/fr/free/nrw/commons/upload/ImageProcessingService.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import fr.free.nrw.commons.utils.ImageUtils.IMAGE_KEEP
1010
import fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK
1111
import fr.free.nrw.commons.utils.ImageUtilsWrapper
1212
import io.reactivex.Single
13-
import io.reactivex.functions.Function
1413
import io.reactivex.schedulers.Schedulers
1514
import org.apache.commons.lang3.StringUtils
1615
import timber.log.Timber
@@ -26,7 +25,7 @@ class ImageProcessingService @Inject constructor(
2625
private val fileUtilsWrapper: FileUtilsWrapper,
2726
private val imageUtilsWrapper: ImageUtilsWrapper,
2827
private val readFBMD: ReadFBMD,
29-
private val EXIFReader: EXIFReader,
28+
private val exifReader: EXIFReader,
3029
private val mediaClient: MediaClient
3130
) {
3231
/**
@@ -94,7 +93,7 @@ class ImageProcessingService @Inject constructor(
9493
* the presence of some basic Exif metadata.
9594
*/
9695
private fun checkEXIF(filepath: String): Single<Int> =
97-
EXIFReader.processMetadata(filepath)
96+
exifReader.processMetadata(filepath)
9897

9998

10099
/**

app/src/main/java/fr/free/nrw/commons/utils/SwipableCardView.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ abstract class SwipableCardView @JvmOverloads constructor(
2121
defStyleAttr: Int = 0
2222
) : CardView(context, attrs, defStyleAttr) {
2323

24+
25+
companion object{
26+
const val MINIMUM_THRESHOLD_FOR_SWIPE = 100f
27+
}
28+
2429
private var x1 = 0f
2530
private var x2 = 0f
26-
private val MINIMUM_THRESHOLD_FOR_SWIPE = 100f
31+
2732

2833
init {
2934
interceptOnTouchListener()

0 commit comments

Comments
 (0)