Skip to content

Conversation

@JuliusBairaktaris
Copy link

@JuliusBairaktaris JuliusBairaktaris commented Dec 26, 2025

Description

This PR implements native-feeling text search functionality within the PDF viewer and resolves a long-standing deprecation warning regarding Toasts.

Changes

Search Feature

  • Core Logic: Introduced a SearchController class in JavaScript that interfaces directly with the PDF.js text layer.
    • Utilizes a non-blocking indexing loop (via requestAnimationFrame) to ensure the UI remains responsive even during large document scans.
    • Performs case-insensitive substring matching against normalized text content.
  • Native Integration: Added a search action to the top toolbar menu using a native SearchView, providing a familiar Android UX.
  • Bridge Communication: Established a robust bi-directional bridge:
    • Java to JS: Uses evaluateJavascript to inject JSON command objects (find, findNext, closesearch) into a new onMessage handler.
    • JS to Java: Uses @JavascriptInterface callbacks to report search progress and match counts to the native UI.
  • Visuals: Implemented Adobe-style highlight overlays (.search-highlight) that scale correctly with zoom.
  • Navigation: Implemented "Next"/"Previous" navigation with circular (wrapping) logic, auto-scrolling to matches, and focus management.

UI Improvements

  • Deprecation Fix: Replaced the deprecated Toast.setView() API with a custom, high-performance TextView overlay.
    • This eliminates the API warning and provides better control over z-index and visibility, resolving layout overlap issues.
  • Assets: Added search icon vectors and necessary string translations.

Maintenance

  • Cleaned up PdfViewer.java, removing legacy boilerplate and enforcing stricter type safety in bridge calls.

Fixes

  • Resolves the Toast.setView() deprecation warning.
  • Fixes occasional layout overlaps by properly managing the page number visibility and elevation.

Disclaimer: This PR was implemented with the assistance of Gemini 3 Pro.

Copilot AI review requested due to automatic review settings December 26, 2025 00:37
@JuliusBairaktaris JuliusBairaktaris changed the title feat: Search (fixes: #4) feat: Search (Fixes #4) Dec 26, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a comprehensive text search feature for the PDF viewer application and addresses a Toast deprecation warning by replacing the custom Toast view with a TextView overlay.

Key Changes:

  • Added full-text search functionality with visual highlighting and navigation across PDF pages
  • Replaced deprecated Toast.setView() with a custom TextView overlay for page number display
  • Implemented bidirectional JavaScript-Android bridge communication for search operations

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
viewer/main.css Added CSS classes for search highlight containers and selected/unselected highlight styling
viewer/js/search_controller.js New search controller implementing asynchronous text indexing, substring matching, and DOM-based highlight rendering
viewer/js/index.js Integrated search controller with PDF.js rendering pipeline and added message handler for Android bridge communication
viewer/css/text_layer.css Code formatting improvements (spacing, line breaks)
app/src/main/res/values/strings.xml Added search-related string resources (action_search, search_hint, no_matches, match_status)
app/src/main/res/menu/pdf_viewer.xml Added search action menu item with SearchView configuration
app/src/main/res/layout/pdfviewer.xml Added page_number_view TextView to replace deprecated Toast implementation
app/src/main/res/drawable/ic_search_24dp.xml New search icon vector drawable
app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java Implemented search UI logic, replaced Toast with TextView, added JSON-based WebView bridge methods, and integrated search navigation with existing prev/next buttons

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JuliusBairaktaris JuliusBairaktaris marked this pull request as draft December 26, 2025 01:59
@JuliusBairaktaris JuliusBairaktaris marked this pull request as ready for review December 26, 2025 03:37
@JuliusBairaktaris JuliusBairaktaris mentioned this pull request Dec 26, 2025
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.

1 participant