diff --git a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/PDFReader.kt b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/PDFReader.kt index eec27c4fb..348849246 100644 --- a/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/PDFReader.kt +++ b/android/Omnivore/app/src/main/java/app/omnivore/omnivore/ui/reader/PDFReader.kt @@ -53,7 +53,6 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan private lateinit var thumbnailBar: PdfThumbnailBar private lateinit var configuration: PdfConfiguration private lateinit var modularSearchView: PdfSearchViewModular - private lateinit var highlighter: SearchResultHighlighter val viewModel: PDFReaderViewModel by viewModels() @@ -177,32 +176,6 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan } private fun initModularSearchViewAndButton() { - // The search result highlighter will highlight any selected result. - highlighter = SearchResultHighlighter(this).also { - fragment.addDrawableProvider(it) - } - - modularSearchView = findViewById(R.id.modularSearchView) - ?: throw IllegalStateException("Error while loading CustomFragmentActivity. The example layout was missing the search view.") - - modularSearchView.setSearchViewListener(object : SimpleSearchResultListener() { - override fun onMoreSearchResults(results: List) { - highlighter.addSearchResults(results) - } - - override fun onSearchCleared() { - highlighter.clearSearchResults() - } - - override fun onSearchResultSelected(result: SearchResult?) { - // Pass on the search result to the highlighter. If 'null' the highlighter will clear any selection. - highlighter.setSelectedSearchResult(result) - if (result != null) { - fragment.scrollTo(PdfUtils.createPdfRectUnion(result.textBlock.pageRects), result.pageIndex, 250, false) - } - } - }) - // The search view is hidden by default (see layout). Set up a click listener that will show the view once pressed. val openSearchButton = findViewById(R.id.openSearchButton) ?: throw IllegalStateException( @@ -210,6 +183,25 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan "was missing the open search button with id `R.id.openSearchButton`." ) + val closeSearchButton = findViewById(R.id.closeSearchButton) + ?: throw IllegalStateException( + "Error while loading CustomFragmentActivity. The example layout " + + "was missing the close search button with id `R.id.closeSearchButton`." + ) + + modularSearchView = findViewById(R.id.modularSearchView) + ?: throw IllegalStateException("Error while loading CustomFragmentActivity. The example layout was missing the search view.") + + modularSearchView.setSearchViewListener(object : SimpleSearchResultListener() { + override fun onSearchResultSelected(result: SearchResult?) { + // Pass on the search result to the highlighter. If 'null' the highlighter will clear any selection. + if (result != null) { + closeSearchButton.visibility = View.INVISIBLE + fragment.scrollTo(PdfUtils.createPdfRectUnion(result.textBlock.pageRects), result.pageIndex, 250, false) + } + } + }) + openSearchButton.apply { setImageDrawable( tintDrawable( @@ -217,8 +209,24 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan ContextCompat.getColor(this@PDFReaderActivity, R.color.black) ) ) + setOnClickListener { - if (modularSearchView.isShown) modularSearchView.hide() else modularSearchView.show() + closeSearchButton.visibility = View.VISIBLE + modularSearchView.show() + } + } + + closeSearchButton.apply { + setImageDrawable( + tintDrawable( + drawable, + ContextCompat.getColor(this@PDFReaderActivity, R.color.white) + ) + ) + + setOnClickListener { + closeSearchButton.visibility = View.INVISIBLE + modularSearchView.hide() } } } diff --git a/android/Omnivore/app/src/main/res/drawable-v24/close.xml b/android/Omnivore/app/src/main/res/drawable-v24/close.xml new file mode 100644 index 000000000..a4f627f4b --- /dev/null +++ b/android/Omnivore/app/src/main/res/drawable-v24/close.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/android/Omnivore/app/src/main/res/drawable-v24/pdf_thumbnail_toggle.xml b/android/Omnivore/app/src/main/res/drawable-v24/pdf_thumbnail_toggle.xml new file mode 100644 index 000000000..772d8270e --- /dev/null +++ b/android/Omnivore/app/src/main/res/drawable-v24/pdf_thumbnail_toggle.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml b/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml index 03f6af258..401e22ae8 100644 --- a/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml +++ b/android/Omnivore/app/src/main/res/layout/pdf_reader_fragment.xml @@ -22,6 +22,24 @@ android:elevation="8dp" android:visibility="visible"/> + + + + + + android:src="@drawable/pdf_thumbnail_toggle" />