Skip to content

Commit 64a13d9

Browse files
committed
Improve PDF reader labelling
Affects: https://ebce-lyrasis.atlassian.net/browse/PP-4021
1 parent f57f9e0 commit 64a13d9

3 files changed

Lines changed: 56 additions & 24 deletions

File tree

palace-viewer-pdf-pdfjs/src/main/java/org/librarysimplified/viewer/pdf/pdfjs/PdfReaderActivity.kt

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class PdfReaderActivity : AppCompatActivity() {
7979
private val profilesController =
8080
this.services.requireService(ProfilesControllerType::class.java)
8181

82+
private lateinit var toolbarTOC: View
83+
private lateinit var toolbarSettings: View
84+
private lateinit var toolbarBack: View
85+
private lateinit var toolbarText: TextView
86+
private lateinit var toolbar: ViewGroup
8287
private lateinit var account: AccountType
8388
private lateinit var accountId: AccountID
8489
private lateinit var bookFormat: BookFormat.BookFormatPDF
@@ -91,7 +96,8 @@ class PdfReaderActivity : AppCompatActivity() {
9196

9297
private var backgroundThread: ExecutorService? = null
9398
private var pdfServer: PdfServer? = null
94-
private var isSidebarOpen = false
99+
private var isSidebarOpen = true
100+
private var isSettingsOpen: Boolean = false
95101
private var documentPageIndex: Int = 0
96102

97103
override fun onCreate(savedInstanceState: Bundle?) {
@@ -199,28 +205,28 @@ class PdfReaderActivity : AppCompatActivity() {
199205
private fun createToolbar(
200206
title: String
201207
) {
202-
val toolbar =
203-
this.findViewById<ViewGroup>(R.id.pdfToolbar)
204-
val toolbarText =
205-
toolbar.findViewById<TextView>(R.id.pdfToolbarText)
206-
val toolbarBack =
207-
toolbar.findViewById<View>(R.id.pdfToolbarLogoTouch)
208-
val toolbarSettings =
209-
toolbar.findViewById<View>(R.id.pdfToolbarSettingsIconTouch)
210-
val toolbarTOC =
211-
toolbar.findViewById<View>(R.id.pdfToolbarTOCIconTouch)
212-
213-
toolbarBack.setOnClickListener {
208+
this.toolbar =
209+
this.findViewById(R.id.pdfToolbar)
210+
this.toolbarText =
211+
this.toolbar.findViewById(R.id.pdfToolbarText)
212+
this.toolbarBack =
213+
this.toolbar.findViewById(R.id.pdfToolbarLogoTouch)
214+
this.toolbarSettings =
215+
this.toolbar.findViewById(R.id.pdfToolbarSettingsIconTouch)
216+
this.toolbarTOC =
217+
this.toolbar.findViewById(R.id.pdfToolbarTOCIconTouch)
218+
219+
this.toolbarBack.setOnClickListener {
214220
this.finish()
215221
}
216-
toolbarSettings.setOnClickListener {
222+
this.toolbarSettings.setOnClickListener {
217223
this.onReaderMenuSettingsSelected()
218224
}
219-
toolbarTOC.setOnClickListener {
225+
this.toolbarTOC.setOnClickListener {
220226
this.onReaderMenuTOCSelected()
221227
}
222-
toolbarText.text = title
223-
toolbarBack.requestFocus()
228+
this.toolbarText.text = title
229+
this.toolbarBack.requestFocus()
224230
}
225231

226232
private fun createWebView() {
@@ -314,20 +320,44 @@ class PdfReaderActivity : AppCompatActivity() {
314320
}
315321

316322
private fun toggleSidebar() {
317-
if (::webView.isInitialized) {
323+
if (this::webView.isInitialized) {
318324
this.webView.evaluateJavascript("toggleSidebar()") { result ->
319325
this.isSidebarOpen = (result == "true")
326+
this.setSidebarButtonContentDescription()
320327
}
321328
}
322329
}
323330

331+
private fun setSidebarButtonContentDescription() {
332+
if (this.isSidebarOpen) {
333+
this.toolbarTOC.contentDescription =
334+
this.resources.getString(R.string.accessibility_toc_close)
335+
} else {
336+
this.toolbarTOC.contentDescription =
337+
this.resources.getString(R.string.accessibility_toc_open)
338+
}
339+
}
340+
324341
private fun onReaderMenuSettingsSelected(): Boolean {
325-
if (::webView.isInitialized) {
326-
this.webView.evaluateJavascript("toggleSecondaryToolbar()", null)
342+
if (this::webView.isInitialized) {
343+
this.webView.evaluateJavascript("toggleSecondaryToolbar()") { result ->
344+
this.isSettingsOpen = (result == "true")
345+
this.setSettingsButtonContentDescription()
346+
}
327347
}
328348
return true
329349
}
330350

351+
private fun setSettingsButtonContentDescription() {
352+
if (this.isSettingsOpen) {
353+
this.toolbarTOC.contentDescription =
354+
this.resources.getString(R.string.accessibility_settings_close)
355+
} else {
356+
this.toolbarTOC.contentDescription =
357+
this.resources.getString(R.string.accessibility_settings_open)
358+
}
359+
}
360+
331361
override fun onDestroy() {
332362
try {
333363
this.pdfServer?.stop()

palace-viewer-pdf-pdfjs/src/main/res/layout/pdfjs_reader.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
android:layout_height="64dp"
5959
android:background="?attr/selectableItemBackground"
6060
android:clickable="true"
61-
android:contentDescription="@string/accessibility_toc"
61+
android:contentDescription="@string/accessibility_toc_close"
6262
android:focusable="true"
6363
app:layout_constraintBottom_toBottomOf="parent"
6464
app:layout_constraintEnd_toStartOf="@id/pdfToolbarSettingsIconTouch"
@@ -81,7 +81,7 @@
8181
android:layout_height="64dp"
8282
android:background="?attr/selectableItemBackground"
8383
android:clickable="true"
84-
android:contentDescription="@string/accessibility_settings"
84+
android:contentDescription="@string/accessibility_settings_open"
8585
android:focusable="true"
8686
app:layout_constraintBottom_toBottomOf="parent"
8787
app:layout_constraintEnd_toEndOf="parent"

palace-viewer-pdf-pdfjs/src/main/res/values/strings.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<resources>
44
<string name="Dismiss">Dismiss</string>
55
<string name="accessibility_back">Close book and go back.</string>
6-
<string name="accessibility_settings">Open the settings menu</string>
7-
<string name="accessibility_toc">Open the table of contents and bookmarks screen.</string>
6+
<string name="accessibility_settings_close">Close the settings menu</string>
7+
<string name="accessibility_settings_open">Open the settings menu</string>
8+
<string name="accessibility_toc_open">Open the table of contents and bookmarks screen</string>
9+
<string name="accessibility_toc_close">Close the table of contents and bookmarks screen</string>
810
<string name="content_description_back">Back</string>
911
<string name="settings_title">Settings</string>
1012
<string name="table_of_contents_empty_message">No Table of Contents available for this work</string>

0 commit comments

Comments
 (0)