Skip to content

refactor: Improve keyboard handling and update dependencies#13

Merged
samyak2403 merged 1 commit intosamyak2403:mainfrom
Harshshah6:main
Feb 7, 2026
Merged

refactor: Improve keyboard handling and update dependencies#13
samyak2403 merged 1 commit intosamyak2403:mainfrom
Harshshah6:main

Conversation

@Harshshah6
Copy link
Copy Markdown
Contributor

@Harshshah6 Harshshah6 commented Feb 6, 2026

  • Automatically show the keyboard when the SearchFragment is opened.
  • Use the toUri() extension function for creating Uris.

Fixes: #12

Summary by CodeRabbit

  • Refactor

    • Updated internal code patterns for consistency
  • Bug Fixes

    • Improved search field keyboard focus and display behavior

- Automatically show the keyboard when the SearchFragment is opened.
- Use the `toUri()` extension function for creating Uris.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Two 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

Cohort / File(s) Summary
URI Parsing Refactoring
app/src/main/java/com/samyak/repostore/ui/activity/GitHubTokenActivity.kt
Replaces Uri.parse() with .toUri() extension function and adds corresponding import from androidx.core.net.
Keyboard Focus Fix
app/src/main/java/com/samyak/repostore/ui/fragment/SearchFragment.kt
Fixes keyboard not displaying by deferring focus request via post() and explicitly showing IME through WindowInsetsController. Removes unused Chip import and adds window insets imports.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A token link shines bright with Kotlin's grace,
While keyboards dance when focus finds its place,
Two little tweaks, so focused and so neat,
Make the UI flow much more complete! 🎯

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title partially describes the main changes but is overly broad and doesn't clearly highlight the primary focus, which is fixing keyboard/IME visibility in SearchFragment. Consider a more specific title like 'fix: Show keyboard when SearchFragment opens' to better reflect the main objective from issue #12.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully implements the proposed fix from issue #12, adding focus posting with explicit IME display via WindowInsetsController in SearchFragment, and uses toUri() as a secondary improvement.
Out of Scope Changes check ✅ Passed The GitHubTokenActivity refactoring (Uri.parse to toUri()) is a minor secondary change unrelated to the main objective (issue #12), though it doesn't significantly impact scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()).

Comment on lines +72 to +81
binding.etSearch.post {
binding.etSearch.requestFocus()

val controller = WindowCompat.getInsetsController(
requireActivity().window,
binding.etSearch
)

controller.show(WindowInsetsCompat.Type.ime())
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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()).

@samyak2403 samyak2403 merged commit a15a61b into samyak2403:main Feb 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto Focus Doesn't show keyboard in SearchFragment.kt + fix for it

2 participants