Skip to content
Merged
22 changes: 12 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
[versions]

accompanist = "0.30.1"

androidx-activity = "1.7.2"
androidx-appcompat = "1.6.1"
androidx-browser = "1.5.0"
androidx-cardview = "1.0.0"
androidx-compose-compiler = "1.5.0"
androidx-compose-compiler = "1.5.1"
androidx-compose-animation = "1.4.3"
androidx-compose-foundation = "1.4.3"
androidx-compose-material = "1.4.3"
androidx-compose-material3 = "1.1.1"
androidx-compose-runtime = "1.4.3"
androidx-compose-theme-adapter = "1.1.19"
androidx-compose-ui = "1.4.3"
androidx-constraintlayout = "2.1.4"
androidx-core = "1.10.1"
androidx-datastore = "1.0.0"
androidx-expresso-core = "3.5.1"
androidx-ext-junit = "1.1.5"
androidx-fragment-ktx = "1.6.0"
androidx-fragment-ktx = "1.6.1"
androidx-legacy = "1.0.0"
androidx-lifecycle = "2.6.1"
androidx-lifecycle-extensions = "2.2.0"
androidx-media = "1.6.0"
androidx-media2 = "1.2.1"
androidx-media3 = "1.1.0"
androidx-navigation = "2.5.2"
androidx-paging = "3.1.1"
androidx-recyclerview = "1.3.0"
androidx-navigation = "2.6.0"
androidx-paging = "3.2.0"
androidx-recyclerview = "1.3.1"
androidx-room = "2.5.2"
androidx-viewpager2 = "1.0.0"
androidx-webkit = "1.7.0"
Expand All @@ -43,8 +44,8 @@ jsoup = "1.16.1"
junit = "4.13.2"

kotlin = "1.9.0"
kotlinx-coroutines = "1.7.2"
kotlinx-coroutines-test = "1.7.2"
kotlinx-coroutines = "1.7.3"
kotlinx-coroutines-test = "1.7.3"
kotlinx-serialization-json = "1.5.1"

pdfium = "1.8.2"
Expand All @@ -57,6 +58,8 @@ robolectric = "4.10.3"
timber = "5.0.1"

[libraries]
accompanist-themeadapter-material = { group = "com.google.accompanist", name = "accompanist-themeadapter-material", version.ref = "accompanist" }

androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "androidx-activity" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
androidx-browser = { group = "androidx.browser", name = "browser", version.ref = "androidx-browser" }
Expand All @@ -67,7 +70,6 @@ androidx-compose-foundation = { group = "androidx.compose.foundation", name = "f
androidx-compose-material = { group = "androidx.compose.material", name = "material", version.ref = "androidx-compose-material" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidx-compose-material3" }
androidx-compose-material-icons = { group = "androidx.compose.material", name = "material-icons-extended", version.ref = "androidx-compose-material" }
androidx-compose-theme-adapter = { group ="com.google.android.material", name = "compose-theme-adapter", version.ref = "androidx-compose-theme-adapter" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "androidx-compose-ui" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidx-compose-ui" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" }
Expand Down Expand Up @@ -137,7 +139,7 @@ timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "tim


[bundles]
compose = ["androidx-compose-activity", "androidx-compose-animation", "androidx-compose-foundation", "androidx-compose-material", "androidx-compose-material3", "androidx-compose-material-icons", "androidx-compose-theme-adapter", "androidx-compose-ui", "androidx-compose-ui-tooling"]
compose = ["androidx-compose-activity", "androidx-compose-animation", "androidx-compose-foundation", "androidx-compose-material", "androidx-compose-material3", "androidx-compose-material-icons", "androidx-compose-ui", "androidx-compose-ui-tooling"]
coroutines = ["kotlinx-coroutines-core", "kotlinx-coroutines-android"]
exoplayer = ["google-exoplayer-core", "google-exoplayer-ui", "google-exoplayer-mediasession", "google-exoplayer-workmanager", "google-exoplayer-extension-media2"]
lifecycle = ["androidx-lifecycle-common", "androidx-lifecycle-extensions", "androidx-lifecycle-livedata", "androidx-lifecycle-runtime", "androidx-lifecycle-viewmodel", "androidx-lifecycle-vmsavedstate", "androidx-lifecycle-viewmodel-compose"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal class PsPdfKitDocumentFragment(
if (field == value) return

field = value
reloadDocumentAtPage(pageIndex)
reloadDocumentAtPage()
}

private lateinit var pdfFragment: PdfFragment
Expand All @@ -73,10 +73,10 @@ internal class PsPdfKitDocumentFragment(

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
reloadDocumentAtPage(initialPageIndex)
reloadDocumentAtPage()
}

private fun reloadDocumentAtPage(pageIndex: Int) {
private fun reloadDocumentAtPage() {
pdfFragment = createPdfFragment()

childFragmentManager.commitNow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.lifecycle.whenStarted
import androidx.lifecycle.withStarted
import androidx.viewpager.widget.ViewPager
import kotlin.math.ceil
import kotlin.reflect.KClass
Expand Down Expand Up @@ -479,7 +479,7 @@ public class EpubNavigatorFragment internal constructor(
}

viewLifecycleOwner.lifecycleScope.launch {
whenStarted {
withStarted {
// Restore the last locator before a configuration change (e.g. screen rotation), or the
// initial locator when given.
val locator = savedInstanceState?.getParcelable("locator") ?: initialLocator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ internal class TtsSessionAdapter<E : TtsEngine.Error>(

COMMAND_GET_AUDIO_ATTRIBUTES,
COMMAND_GET_DEVICE_VOLUME,
COMMAND_SET_DEVICE_VOLUME,
COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS,

COMMAND_SET_SPEED_AND_PITCH,
COMMAND_GET_CURRENT_MEDIA_ITEM,
COMMAND_GET_MEDIA_ITEMS_METADATA,
COMMAND_GET_METADATA,
COMMAND_GET_TEXT
).build()

Expand Down Expand Up @@ -825,11 +825,12 @@ internal class TtsSessionAdapter<E : TtsEngine.Error>(
}

private fun createDeviceInfo(streamVolumeManager: StreamVolumeManager): DeviceInfo {
val newDeviceInfo = DeviceInfo(
DeviceInfo.PLAYBACK_TYPE_LOCAL,
streamVolumeManager.minVolume,
streamVolumeManager.maxVolume
val newDeviceInfo = DeviceInfo.Builder(
DeviceInfo.PLAYBACK_TYPE_LOCAL
)
.setMinVolume(streamVolumeManager.minVolume)
.setMaxVolume(streamVolumeManager.maxVolume)
.build()
deviceInfo = newDeviceInfo
return newDeviceInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.core.view.ViewCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.github.chrisbanes.photoview.PhotoView
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -85,25 +87,27 @@ internal class R2CbzPageFragment(
}

private fun updatePadding() {
viewLifecycleOwner.lifecycleScope.launchWhenResumed {
val window = activity?.window ?: return@launchWhenResumed
var top = 0
var bottom = 0

// Add additional padding to take into account the display cutout, if needed.
if (
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P &&
window.attributes.layoutInDisplayCutoutMode != WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
) {
// Request the display cutout insets from the decor view because the ones given by
// setOnApplyWindowInsetsListener are not always correct for preloaded views.
window.decorView.rootWindowInsets?.displayCutout?.let { displayCutoutInsets ->
top += displayCutoutInsets.safeInsetTop
bottom += displayCutoutInsets.safeInsetBottom
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
val window = activity?.window ?: return@repeatOnLifecycle
var top = 0
var bottom = 0

// Add additional padding to take into account the display cutout, if needed.
if (
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P &&
window.attributes.layoutInDisplayCutoutMode != WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
) {
// Request the display cutout insets from the decor view because the ones given by
// setOnApplyWindowInsetsListener are not always correct for preloaded views.
window.decorView.rootWindowInsets?.displayCutout?.let { displayCutoutInsets ->
top += displayCutoutInsets.safeInsetTop
bottom += displayCutoutInsets.safeInsetBottom
}
}
}

photoView.setPadding(0, top, 0, bottom)
photoView.setPadding(0, top, 0, bottom)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import android.webkit.WebView
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.webkit.WebViewClientCompat
import kotlin.math.roundToInt
import kotlinx.coroutines.flow.*
Expand Down Expand Up @@ -124,7 +126,7 @@ internal class R2EpubPageFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
_binding = ReadiumNavigatorViewpagerFragmentEpubBinding.inflate(inflater, container, false)
containerView = binding.root
preferences = activity?.getSharedPreferences("org.readium.r2.settings", Context.MODE_PRIVATE)!!
Expand Down Expand Up @@ -294,32 +296,36 @@ internal class R2EpubPageFragment : Fragment() {
private fun updatePadding() {
if (view == null) return

viewLifecycleOwner.lifecycleScope.launchWhenResumed {
val window = activity?.window ?: return@launchWhenResumed
var top = 0
var bottom = 0
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
val window = activity?.window ?: return@repeatOnLifecycle
var top = 0
var bottom = 0

// Add additional padding to take into account the display cutout, if needed.
if (
shouldApplyInsetsPadding &&
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P &&
window.attributes.layoutInDisplayCutoutMode != WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
) {
// Request the display cutout insets from the decor view because the ones given by
// setOnApplyWindowInsetsListener are not always correct for preloaded views.
window.decorView.rootWindowInsets?.displayCutout?.let { displayCutoutInsets ->
top += displayCutoutInsets.safeInsetTop
bottom += displayCutoutInsets.safeInsetBottom
}
}

// Add additional padding to take into account the display cutout, if needed.
if (
shouldApplyInsetsPadding &&
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P &&
window.attributes.layoutInDisplayCutoutMode != WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
) {
// Request the display cutout insets from the decor view because the ones given by
// setOnApplyWindowInsetsListener are not always correct for preloaded views.
window.decorView.rootWindowInsets?.displayCutout?.let { displayCutoutInsets ->
top += displayCutoutInsets.safeInsetTop
bottom += displayCutoutInsets.safeInsetBottom
if (!viewModel.isScrollEnabled.value) {
val margin =
resources.getDimension(R.dimen.readium_navigator_epub_vertical_padding)
.toInt()
top += margin
bottom += margin
}
}

if (!viewModel.isScrollEnabled.value) {
val margin = resources.getDimension(R.dimen.readium_navigator_epub_vertical_padding).toInt()
top += margin
bottom += margin
containerView.setPadding(0, top, 0, bottom)
}

containerView.setPadding(0, top, 0, bottom)
}
}

Expand All @@ -339,17 +345,23 @@ internal class R2EpubPageFragment : Fragment() {

if (view == null) return

viewLifecycleOwner.lifecycleScope.launchWhenCreated {
val webView = requireNotNull(webView)
webView.visibility = View.VISIBLE

pendingLocator
?.let { locator ->
loadLocator(webView, requireNotNull(navigator).presentation.value.readingProgression, locator)
}
.also { pendingLocator = null }
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
val webView = requireNotNull(webView)
webView.visibility = View.VISIBLE

pendingLocator
?.let { locator ->
loadLocator(
webView,
requireNotNull(navigator).presentation.value.readingProgression,
locator
)
}
.also { pendingLocator = null }

webView.listener?.onPageLoaded()
webView.listener?.onPageLoaded()
}
}
}

Expand All @@ -359,11 +371,13 @@ internal class R2EpubPageFragment : Fragment() {
return
}

viewLifecycleOwner.lifecycleScope.launchWhenCreated {
val webView = requireNotNull(webView)
val epubNavigator = requireNotNull(navigator)
loadLocator(webView, epubNavigator.presentation.value.readingProgression, locator)
webView.listener?.onProgressionChanged()
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
val webView = requireNotNull(webView)
val epubNavigator = requireNotNull(navigator)
loadLocator(webView, epubNavigator.presentation.value.readingProgression, locator)
webView.listener?.onProgressionChanged()
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion test-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android.txt"))
}
}
packagingOptions {
packaging {
resources.excludes.add("META-INF/*")
}

Expand All @@ -76,6 +76,8 @@ dependencies {
// Only required if you want to support PDF files using PDFium.
implementation(project(":readium:adapters:pdfium"))

implementation(libs.accompanist.themeadapter.material)

implementation(libs.androidx.compose.activity)
implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.appcompat)
Expand Down
Loading