From 570ed58b6667879f3f86ed9c02044a5ea2802a43 Mon Sep 17 00:00:00 2001 From: Akshay Komar Date: Fri, 10 Jan 2025 23:17:26 +0530 Subject: [PATCH] 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. --- .../customselector/ui/selector/CustomSelectorActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt index 52b615175..4e2d58bab 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt @@ -271,7 +271,7 @@ class CustomSelectorActivity : dialog.setCancelable(false) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setContentView(R.layout.custom_selector_info_dialog) - (dialog.findViewById(R.id.btn_ok) as Button).setOnClickListener { dialog.dismiss() } + (dialog.findViewById