From d4ababc0a518179e18c3f9f9a0d184a2cf21f951 Mon Sep 17 00:00:00 2001 From: Akshay Komar <146421342+Akshaykomar890@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:36:52 +0530 Subject: [PATCH] Refactor: Rename Constants to Follow CamelCase Naming Convention (#6126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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() 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(...)) 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 --- .../fr/free/nrw/commons/quiz/QuizController.kt | 14 +++++++++----- .../fr/free/nrw/commons/review/ReviewActivity.kt | 8 ++++---- .../free/nrw/commons/review/ReviewImageFragment.kt | 6 +++--- .../free/nrw/commons/settings/SettingsFragment.kt | 8 +++----- .../nrw/commons/upload/ImageProcessingService.kt | 5 ++--- .../fr/free/nrw/commons/utils/SwipableCardView.kt | 7 ++++++- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/quiz/QuizController.kt b/app/src/main/java/fr/free/nrw/commons/quiz/QuizController.kt index 3cb4f52a6..d9b6b7e52 100644 --- a/app/src/main/java/fr/free/nrw/commons/quiz/QuizController.kt +++ b/app/src/main/java/fr/free/nrw/commons/quiz/QuizController.kt @@ -14,11 +14,15 @@ class QuizController { private val quiz: ArrayList = ArrayList() - private val URL_FOR_SELFIE = "https://i.imgur.com/0fMYcpM.jpg" - private val URL_FOR_TAJ_MAHAL = "https://upload.wikimedia.org/wikipedia/commons/1/15/Taj_Mahal-03.jpg" - private val URL_FOR_BLURRY_IMAGE = "https://i.imgur.com/Kepb5jR.jpg" - 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" - private val URL_FOR_EVENT = "https://upload.wikimedia.org/wikipedia/commons/5/51/HouseBuildingInNorthernVietnam.jpg" + companion object{ + + const val URL_FOR_SELFIE = "https://i.imgur.com/0fMYcpM.jpg" + const val URL_FOR_TAJ_MAHAL = "https://upload.wikimedia.org/wikipedia/commons/1/15/Taj_Mahal-03.jpg" + const val URL_FOR_BLURRY_IMAGE = "https://i.imgur.com/Kepb5jR.jpg" + 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" + const val URL_FOR_EVENT = "https://upload.wikimedia.org/wikipedia/commons/5/51/HouseBuildingInNorthernVietnam.jpg" + } + fun initialize(context: Context) { val q1 = QuizQuestion( diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt b/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt index 40eb24ed0..209f991fb 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.kt @@ -45,12 +45,12 @@ class ReviewActivity : BaseActivity() { private var hasNonHiddenCategories = false var media: Media? = null - private val SAVED_MEDIA = "saved_media" + private val savedMedia = "saved_media" override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) media?.let { - outState.putParcelable(SAVED_MEDIA, it) + outState.putParcelable(savedMedia, it) } } @@ -90,8 +90,8 @@ class ReviewActivity : BaseActivity() { PorterDuff.Mode.SRC_IN ) - if (savedInstanceState?.getParcelable(SAVED_MEDIA) != null) { - updateImage(savedInstanceState.getParcelable(SAVED_MEDIA)!!) + if (savedInstanceState?.getParcelable(savedMedia) != null) { + updateImage(savedInstanceState.getParcelable(savedMedia)!!) setUpMediaDetailOnOrientation() } else { runRandomizer() diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.kt b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.kt index f6da76bba..2bc333505 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.kt @@ -31,7 +31,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() { lateinit var sessionManager: SessionManager // Constant variable used to store user's key name for onSaveInstanceState method - private val SAVED_USER = "saved_user" + private val savedUser = "saved_user" // Variable that stores the value of user private var user: String? = null @@ -129,7 +129,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() { question = getString(R.string.review_thanks) user = reviewActivity.reviewController.firstRevision?.user() - ?: savedInstanceState?.getString(SAVED_USER) + ?: savedInstanceState?.getString(savedUser) //if the user is null because of whatsoever reason, review will not be sent anyways if (!user.isNullOrEmpty()) { @@ -172,7 +172,7 @@ class ReviewImageFragment : CommonsDaggerSupportFragment() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) //Save user name when configuration changes happen - outState.putString(SAVED_USER, user) + outState.putString(savedUser, user) } private val reviewCallback: ReviewController.ReviewCallback diff --git a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt index 17f4c00c2..161927d03 100644 --- a/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt +++ b/app/src/main/java/fr/free/nrw/commons/settings/SettingsFragment.kt @@ -86,7 +86,6 @@ class SettingsFragment : PreferenceFragmentCompat() { private var languageHistoryListView: ListView? = null private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher> - private val GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content" private val cameraPickLauncherForResult: ActivityResultLauncher = registerForActivityResult(StartActivityForResult()) { result -> @@ -513,10 +512,9 @@ class SettingsFragment : PreferenceFragmentCompat() { @Suppress("LongLine") companion object { - // TODO: consider changing these to MOBILE_HOME_URL after the following task is resolved: - // https://phabricator.wikimedia.org/T380527 - private const val VANISH_ACCOUNT_URL = MOBILE_META_URL + "Special:GlobalVanishRequest" - private const val VANISH_ACCOUNT_SUCCESS_URL = MOBILE_META_URL + "Special:GlobalVanishRequest/vanished" + const val GET_CONTENT_PICKER_HELP_URL = "https://commons-app.github.io/docs.html#get-content" + private const val VANISH_ACCOUNT_URL = "https://meta.m.wikimedia.org/wiki/Special:Contact/accountvanishapps" + private const val VANISH_ACCOUNT_SUCCESS_URL = "https://meta.m.wikimedia.org/wiki/Special:GlobalVanishRequest/vanished" /** * Create Locale based on different types of language codes * @param languageCode diff --git a/app/src/main/java/fr/free/nrw/commons/upload/ImageProcessingService.kt b/app/src/main/java/fr/free/nrw/commons/upload/ImageProcessingService.kt index ba9dc147c..fca10be1e 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/ImageProcessingService.kt +++ b/app/src/main/java/fr/free/nrw/commons/upload/ImageProcessingService.kt @@ -10,7 +10,6 @@ import fr.free.nrw.commons.utils.ImageUtils.IMAGE_KEEP import fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK import fr.free.nrw.commons.utils.ImageUtilsWrapper import io.reactivex.Single -import io.reactivex.functions.Function import io.reactivex.schedulers.Schedulers import org.apache.commons.lang3.StringUtils import timber.log.Timber @@ -26,7 +25,7 @@ class ImageProcessingService @Inject constructor( private val fileUtilsWrapper: FileUtilsWrapper, private val imageUtilsWrapper: ImageUtilsWrapper, private val readFBMD: ReadFBMD, - private val EXIFReader: EXIFReader, + private val exifReader: EXIFReader, private val mediaClient: MediaClient ) { /** @@ -94,7 +93,7 @@ class ImageProcessingService @Inject constructor( * the presence of some basic Exif metadata. */ private fun checkEXIF(filepath: String): Single = - EXIFReader.processMetadata(filepath) + exifReader.processMetadata(filepath) /** diff --git a/app/src/main/java/fr/free/nrw/commons/utils/SwipableCardView.kt b/app/src/main/java/fr/free/nrw/commons/utils/SwipableCardView.kt index 5a8261c24..bde575386 100644 --- a/app/src/main/java/fr/free/nrw/commons/utils/SwipableCardView.kt +++ b/app/src/main/java/fr/free/nrw/commons/utils/SwipableCardView.kt @@ -21,9 +21,14 @@ abstract class SwipableCardView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : CardView(context, attrs, defStyleAttr) { + + companion object{ + const val MINIMUM_THRESHOLD_FOR_SWIPE = 100f + } + private var x1 = 0f private var x2 = 0f - private val MINIMUM_THRESHOLD_FOR_SWIPE = 100f + init { interceptOnTouchListener()