show close icon on pdf search view

This commit is contained in:
Satindar Dhillon
2022-11-14 13:13:46 -08:00
parent 31ac8f6023
commit 6747ea4191
4 changed files with 57 additions and 29 deletions

View File

@ -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<SearchResult>) {
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<ImageView>(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<ImageView>(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()
}
}
}

View File

@ -0,0 +1 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="#000" android:pathData="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"/></vector>

View File

@ -0,0 +1 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24"><path android:fillColor="#000" android:pathData="M21 4H3C2.45 4 2 4.45 2 5V19C2 19.55 2.45 20 3 20H21C21.55 20 22 19.55 22 19V5C22 4.45 21.55 4 21 4M8 18H4V6H8V18M14 18H10V6H14V18M20 18H16V6H20V18Z"/></vector>

View File

@ -22,6 +22,24 @@
android:elevation="8dp"
android:visibility="visible"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal"
android:elevation="16dp"
android:splitMotionEvents="false">
<ImageView
android:id="@+id/closeSearchButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="12dp"
android:elevation="16dp"
android:visibility="invisible"
android:src="@drawable/close" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -41,6 +59,6 @@
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="12dp"
android:src="@drawable/pspdf__ic_thumbnails" />
android:src="@drawable/pdf_thumbnail_toggle" />
</LinearLayout>
</FrameLayout>