refactor: Improve keyboard handling and update dependencies#13
refactor: Improve keyboard handling and update dependencies#13samyak2403 merged 1 commit intosamyak2403:mainfrom
Conversation
- Automatically show the keyboard when the SearchFragment is opened. - Use the `toUri()` extension function for creating Uris.
📝 WalkthroughWalkthroughTwo files are modified: one refactors URI parsing to use Kotlin extension functions, another fixes keyboard display by deferring focus request and explicitly showing the input method editor. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@app/src/main/java/com/samyak/repostore/ui/fragment/SearchFragment.kt`:
- Around line 72-81: The posted runnable uses requireActivity() which can throw
if the fragment is detached; update the binding.etSearch.post block to guard
against detachment by checking isAdded or using activity?.let { act -> ... }
before calling WindowCompat.getInsetsController and controller.show, and bail
out if the fragment/activity is null; specifically protect the runnable that
references requireActivity(), WindowCompat.getInsetsController(...,
binding.etSearch) and controller.show(WindowInsetsCompat.Type.ime()).
| binding.etSearch.post { | ||
| binding.etSearch.requestFocus() | ||
|
|
||
| val controller = WindowCompat.getInsetsController( | ||
| requireActivity().window, | ||
| binding.etSearch | ||
| ) | ||
|
|
||
| controller.show(WindowInsetsCompat.Type.ime()) | ||
| } |
There was a problem hiding this comment.
Guard against fragment detachment in the posted runnable.
If the user navigates away before the posted runnable executes, requireActivity() will throw IllegalStateException. Consider using activity?.let { } or checking isAdded to handle this edge case safely.
🛡️ Proposed fix
binding.etSearch.post {
+ if (!isAdded) return@post
binding.etSearch.requestFocus()
- val controller = WindowCompat.getInsetsController(
- requireActivity().window,
- binding.etSearch
- )
-
- controller.show(WindowInsetsCompat.Type.ime())
+ activity?.let { activity ->
+ val controller = WindowCompat.getInsetsController(
+ activity.window,
+ binding.etSearch
+ )
+ controller.show(WindowInsetsCompat.Type.ime())
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| binding.etSearch.post { | |
| binding.etSearch.requestFocus() | |
| val controller = WindowCompat.getInsetsController( | |
| requireActivity().window, | |
| binding.etSearch | |
| ) | |
| controller.show(WindowInsetsCompat.Type.ime()) | |
| } | |
| binding.etSearch.post { | |
| if (!isAdded) return@post | |
| binding.etSearch.requestFocus() | |
| activity?.let { activity -> | |
| val controller = WindowCompat.getInsetsController( | |
| activity.window, | |
| binding.etSearch | |
| ) | |
| controller.show(WindowInsetsCompat.Type.ime()) | |
| } | |
| } |
🤖 Prompt for AI Agents
In `@app/src/main/java/com/samyak/repostore/ui/fragment/SearchFragment.kt` around
lines 72 - 81, The posted runnable uses requireActivity() which can throw if the
fragment is detached; update the binding.etSearch.post block to guard against
detachment by checking isAdded or using activity?.let { act -> ... } before
calling WindowCompat.getInsetsController and controller.show, and bail out if
the fragment/activity is null; specifically protect the runnable that references
requireActivity(), WindowCompat.getInsetsController(..., binding.etSearch) and
controller.show(WindowInsetsCompat.Type.ime()).
toUri()extension function for creating Uris.Fixes: #12
Summary by CodeRabbit
Refactor
Bug Fixes