Skip to content

Commit 7b85d33

Browse files
fix(ui): Prevent index out of bounds in AppDrawerAdapter
This commit addresses a potential crash in `AppDrawerAdapter` by adding a check to ensure that the `position` is within the bounds of `appFilteredList` before accessing it in `onBindViewHolder`. Additionally, the initialization of `BiometricHelper` has been moved from `onBindViewHolder` to `onCreateViewHolder` to avoid redundant object creation. Signed-off-by: CreativeCodeCat <[email protected]>
1 parent 36f97c8 commit 7b85d33

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/AppDrawerAdapter.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class AppDrawerAdapter(
7373
private var isBangSearch = false
7474

7575
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
76-
binding =
77-
AdapterAppDrawerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
76+
binding = AdapterAppDrawerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
7877
prefs = Prefs(parent.context)
78+
biometricHelper = BiometricHelper(fragment)
7979
val fontColor = prefs.appColor
8080
binding.appTitle.setTextColor(fontColor)
8181

@@ -91,8 +91,8 @@ class AppDrawerAdapter(
9191

9292
@SuppressLint("RecyclerView")
9393
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
94-
if (appFilteredList.isEmpty()) {
95-
AppLogger.d("AppListDebug", "⚠️ onBindViewHolder called but appFilteredList is empty")
94+
if (appFilteredList.isEmpty() || position !in appFilteredList.indices) {
95+
AppLogger.d("AppListDebug", "⚠️ onBindViewHolder called but appFilteredList is empty or position out of bounds")
9696
return
9797
}
9898

@@ -117,8 +117,6 @@ class AppDrawerAdapter(
117117
val currentLockedApps = prefs.lockedApps
118118

119119
if (currentLockedApps.contains(appName)) {
120-
biometricHelper = BiometricHelper(fragment)
121-
122120
biometricHelper.startBiometricAuth(appModel, object : BiometricHelper.CallbackApp {
123121
override fun onAuthenticationSucceeded(appListItem: AppListItem) {
124122
AppLogger.d("AppListDebug", "🔓 Auth succeeded for $appName - unlocking")

0 commit comments

Comments
 (0)