Skip to content

Commit 553c7d3

Browse files
authored
Fix test app UI issues (#11)
* The Outline fragment (ToC, bookmarks, etc) now has a back button in the toolbar that returns to the reader screen without changing the page * The height of the toolbar is no longer being used to pad the UI. For screens that need that padding because the contents are underneath the toolbar, android:layout_marginTop="?attr/actionBarSize" should be added to the root element * When the insets were being applied, it was using statusBars instead of systemBars and caused the TTS screen to not render the control buttons properly.
1 parent 3243d5c commit 553c7d3

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

test-app/src/main/java/org/readium/r2/testapp/outline/NavigationFragment.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import android.widget.LinearLayout
1414
import androidx.fragment.app.Fragment
1515
import androidx.fragment.app.setFragmentResult
1616
import androidx.lifecycle.ViewModelProvider
17-
import androidx.recyclerview.widget.DiffUtil
18-
import androidx.recyclerview.widget.LinearLayoutManager
19-
import androidx.recyclerview.widget.ListAdapter
20-
import androidx.recyclerview.widget.RecyclerView
17+
import androidx.recyclerview.widget.*
2118
import org.readium.r2.shared.publication.Link
2219
import org.readium.r2.shared.publication.Publication
2320
import org.readium.r2.shared.publication.toLocator
@@ -75,6 +72,12 @@ class NavigationFragment : Fragment() {
7572
setHasFixedSize(true)
7673
layoutManager = LinearLayoutManager(requireContext())
7774
adapter = navAdapter
75+
addItemDecoration(
76+
DividerItemDecoration(
77+
requireContext(),
78+
LinearLayoutManager.VERTICAL
79+
)
80+
)
7881
}
7982
navAdapter.submitList(flatLinks)
8083
}

test-app/src/main/java/org/readium/r2/testapp/outline/OutlineFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.readium.r2.shared.publication.epub.pageList
2222
import org.readium.r2.shared.publication.opds.images
2323
import org.readium.r2.testapp.R
2424
import org.readium.r2.testapp.databinding.FragmentOutlineBinding
25+
import org.readium.r2.testapp.reader.ReaderActivity
2526
import org.readium.r2.testapp.reader.ReaderViewModel
2627

2728
class OutlineFragment : Fragment() {
@@ -38,6 +39,8 @@ class OutlineFragment : Fragment() {
3839
publication = it.publication
3940
}
4041

42+
(activity as ReaderActivity?)?.supportActionBar?.setDisplayHomeAsUpEnabled(true)
43+
4144
childFragmentManager.setFragmentResultListener(
4245
OutlineContract.REQUEST_KEY,
4346
this,

test-app/src/main/java/org/readium/r2/testapp/reader/ReaderActivity.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package org.readium.r2.testapp.reader
99
import android.app.Activity
1010
import android.os.Build
1111
import android.os.Bundle
12+
import android.view.MenuItem
1213
import android.view.WindowManager
1314
import android.widget.Toast
1415
import androidx.appcompat.app.AppCompatActivity
@@ -120,6 +121,9 @@ open class ReaderActivity : AppCompatActivity() {
120121
is DrmManagementFragment -> getString(R.string.title_fragment_drm_management)
121122
else -> null
122123
}
124+
if (supportFragmentManager.fragments.last() !is OutlineFragment) {
125+
supportActionBar?.setDisplayHomeAsUpEnabled(false)
126+
}
123127
}
124128

125129
override fun getDefaultViewModelProviderFactory(): ViewModelProvider.Factory {
@@ -156,12 +160,27 @@ open class ReaderActivity : AppCompatActivity() {
156160

157161
private fun showDrmManagementFragment() {
158162
supportFragmentManager.commit {
159-
add(R.id.activity_container, DrmManagementFragment::class.java, Bundle(), DRM_FRAGMENT_TAG)
163+
add(
164+
R.id.activity_container,
165+
DrmManagementFragment::class.java,
166+
Bundle(),
167+
DRM_FRAGMENT_TAG
168+
)
160169
hide(readerFragment)
161170
addToBackStack(null)
162171
}
163172
}
164173

174+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
175+
when (item.itemId) {
176+
android.R.id.home -> {
177+
supportFragmentManager.popBackStack()
178+
return true
179+
}
180+
}
181+
return super.onOptionsItemSelected(item)
182+
}
183+
165184
companion object {
166185
const val READER_FRAGMENT_TAG = "reader"
167186
const val OUTLINE_FRAGMENT_TAG = "outline"

test-app/src/main/java/org/readium/r2/testapp/utils/SystemUiManagement.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package org.readium.r2.testapp.utils
99
import android.app.Activity
1010
import android.view.View
1111
import android.view.WindowInsets
12-
import androidx.appcompat.app.AppCompatActivity
1312
import androidx.core.view.WindowInsetsCompat
1413

1514
// Using ViewCompat and WindowInsetsCompat does not work properly in all versions of Android
@@ -56,10 +55,10 @@ fun Activity.toggleSystemUi() {
5655
/** Set padding around view so that content doesn't overlap system UI */
5756
fun View.padSystemUi(insets: WindowInsets, activity: Activity) =
5857
WindowInsetsCompat.toWindowInsetsCompat(insets, this)
59-
.getInsets(WindowInsetsCompat.Type.statusBars()).apply {
58+
.getInsets(WindowInsetsCompat.Type.systemBars()).apply {
6059
setPadding(
6160
left,
62-
top + (activity as AppCompatActivity).supportActionBar!!.height,
61+
top,
6362
right,
6463
bottom
6564
)

test-app/src/main/res/layout/fragment_outline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
xmlns:app="http://schemas.android.com/apk/res-auto"
1313
android:layout_width="match_parent"
1414
android:layout_height="match_parent"
15+
android:layout_marginTop="?attr/actionBarSize"
1516
android:orientation="vertical">
1617

1718
<com.google.android.material.tabs.TabLayout

test-app/src/main/res/layout/fragment_screen_reader.xml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
android:id="@+id/tts_overlay"
1111
android:layout_width="match_parent"
1212
android:layout_height="match_parent"
13+
android:layout_marginTop="?attr/actionBarSize"
1314
android:background="@color/colorAccent">
1415

1516
<androidx.constraintlayout.widget.ConstraintLayout
@@ -82,8 +83,8 @@
8283

8384
<ImageButton
8485
android:id="@+id/prev_chapter"
85-
android:layout_width="30dp"
86-
android:layout_height="30dp"
86+
android:layout_width="48dp"
87+
android:layout_height="48dp"
8788
android:layout_weight="1"
8889
android:background="@android:color/transparent"
8990
android:contentDescription="@string/previous_chapter"
@@ -93,8 +94,8 @@
9394

9495
<ImageButton
9596
android:id="@+id/fast_back"
96-
android:layout_width="30dp"
97-
android:layout_height="30dp"
97+
android:layout_width="48dp"
98+
android:layout_height="48dp"
9899
android:layout_weight="1"
99100
android:background="@android:color/transparent"
100101
android:contentDescription="@string/previous_sentence"
@@ -116,8 +117,8 @@
116117

117118
<ImageButton
118119
android:id="@+id/fast_forward"
119-
android:layout_width="30dp"
120-
android:layout_height="30dp"
120+
android:layout_width="48dp"
121+
android:layout_height="48dp"
121122
android:layout_weight="1"
122123
android:background="@android:color/transparent"
123124
android:contentDescription="@string/next_sentence"
@@ -127,8 +128,8 @@
127128

128129
<ImageButton
129130
android:id="@+id/next_chapter"
130-
android:layout_width="30dp"
131-
android:layout_height="30dp"
131+
android:layout_width="48dp"
132+
android:layout_height="48dp"
132133
android:layout_weight="1"
133134
android:background="@android:color/transparent"
134135
android:contentDescription="@string/next_chapter"

0 commit comments

Comments
 (0)