Skip to content

Commit 78666cc

Browse files
Refactor Dialog View Initialization with Null-Safe Calls (commons-app#6114)
* 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.
1 parent 39b513d commit 78666cc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class CustomSelectorActivity :
271271
dialog.setCancelable(false)
272272
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
273273
dialog.setContentView(R.layout.custom_selector_info_dialog)
274-
(dialog.findViewById(R.id.btn_ok) as Button).setOnClickListener { dialog.dismiss() }
274+
(dialog.findViewById<Button>(R.id.btn_ok))?.setOnClickListener { dialog.dismiss() }
275275
dialog.show()
276276
}
277277

@@ -687,8 +687,8 @@ class CustomSelectorActivity :
687687
dialog.setCancelable(false)
688688
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
689689
dialog.setContentView(R.layout.custom_selector_limit_dialog)
690-
(dialog.findViewById(R.id.btn_dismiss_limit_warning) as Button).setOnClickListener { dialog.dismiss() }
691-
(dialog.findViewById(R.id.upload_limit_warning) as TextView).text =
690+
(dialog.findViewById<Button>(R.id.btn_dismiss_limit_warning))?.setOnClickListener { dialog.dismiss() }
691+
(dialog.findViewById<TextView>(R.id.upload_limit_warning))?.text =
692692
resources.getString(
693693
R.string.custom_selector_over_limit_warning,
694694
uploadLimit,

0 commit comments

Comments
 (0)