Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More cleanup #372

Merged
merged 12 commits into from
Aug 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* available in the top-level LICENSE file of the project.
*/

// Everything in this file will be deprecated
@file:Suppress("DEPRECATION")

package org.readium.navigator.media2

import android.net.Uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* available in the top-level LICENSE file of the project.
*/

// Everything in this file will be deprecated
@file:Suppress("DEPRECATION")

package org.readium.navigator.media2

import android.app.PendingIntent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ internal open class R2BasicWebView(context: Context, attrs: AttributeSet) : WebV

// Set an elevation value for popup window
// Call requires API level 21
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mPopupWindow.elevation = 5.0f
}
mPopupWindow.elevation = 5.0f

val textView = customView.findViewById(R.id.footnote) as TextView
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
}
}

private val USE_CACHE = false

private val MAX_SETTLE_DURATION = 600 // ms
private val MIN_DISTANCE_FOR_FLING = 25 // dips
private val MIN_FLING_VELOCITY = 400 // dips
Expand Down Expand Up @@ -106,8 +104,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
private val mFirstOffset = -java.lang.Float.MAX_VALUE
private val mLastOffset = java.lang.Float.MAX_VALUE

private var mScrollingCacheEnabled: Boolean = false

private var mIsBeingDragged: Boolean = false
private var mGutterSize: Int = 30
private var mTouchSlop: Int = 0
Expand Down Expand Up @@ -396,7 +392,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
sx = if (mIsScrollStarted) mScroller!!.currX else mScroller!!.startX
// And abort the current scrolling.
mScroller!!.abortAnimation()
setScrollingCacheEnabled(false)
} else {
sx = scrollX
}
Expand All @@ -409,7 +404,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
return
}

setScrollingCacheEnabled(true)
setScrollState(SCROLL_STATE_SETTLING)

val halfWidth = width / 2
Expand Down Expand Up @@ -662,8 +656,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
private fun completeScroll(postEvents: Boolean) {
val needPopulate = mScrollState == SCROLL_STATE_SETTLING
if (needPopulate) {
// Done with scroll, no longer want to cache view drawing.
setScrollingCacheEnabled(false)
val wasScrolling = !mScroller!!.isFinished
if (wasScrolling) {
mScroller!!.abortAnimation()
Expand Down Expand Up @@ -730,7 +722,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
else
mInitialMotionX - mTouchSlop
setScrollState(SCROLL_STATE_DRAGGING)
setScrollingCacheEnabled(true)
}
}
}
Expand Down Expand Up @@ -885,21 +876,6 @@ internal class R2WebView(context: Context, attrs: AttributeSet) : R2BasicWebView
}
}

private fun setScrollingCacheEnabled(enabled: Boolean) {
if (mScrollingCacheEnabled != enabled) {
mScrollingCacheEnabled = enabled
if (USE_CACHE) {
val size = childCount
for (i in 0 until size) {
val child = getChildAt(i)
if (child.visibility != View.GONE) {
child.isDrawingCacheEnabled = enabled
}
}
}
}
}

override fun dispatchKeyEvent(event: KeyEvent): Boolean {
// Let the focused view and/or our descendants get the key first
return super.dispatchKeyEvent(event) || executeKeyEvent(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* available in the top-level LICENSE file of the project.
*/

// Everything in this file will be deprecated
@file:Suppress("DEPRECATION")

package org.readium.r2.navigator.audio

import android.net.Uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.collection.forEach
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.BundleCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentFactory
Expand Down Expand Up @@ -482,7 +483,8 @@ public class EpubNavigatorFragment internal constructor(
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
val locator = savedInstanceState?.let { BundleCompat.getParcelable(it, "locator", Locator::class.java) }
?: initialLocator
if (locator != null) {
go(locator)
}
Expand Down Expand Up @@ -1038,6 +1040,7 @@ public class EpubNavigatorFragment internal constructor(
* @param config Additional configuration.
*/
@Deprecated("Use `EpubNavigatorFactory().createFragmentFactory()` instead", level = DeprecationLevel.ERROR)
@Suppress("UNUSED_PARAMETER")
public fun createFactory(
publication: Publication,
baseUrl: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public class ImageNavigatorFragment private constructor(
override val publicationView: View
get() = requireView()

@Suppress("DEPRECATION")
@Deprecated(
"Use `presentation.value.readingProgression` instead",
replaceWith = ReplaceWith("presentation.value.readingProgression"),
Expand All @@ -229,7 +230,7 @@ public class ImageNavigatorFragment private constructor(
override val presentation: StateFlow<VisualNavigator.Presentation> =
MutableStateFlow(
SimplePresentation(
readingProgression = when (publication.metadata.effectiveReadingProgression) {
readingProgression = when (publication.metadata.readingProgression) {
PublicationReadingProgression.RTL -> ReadingProgression.RTL
else -> ReadingProgression.LTR
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* available in the top-level LICENSE file of the project.
*/

// Everything in this file will be deprecated
@file:Suppress("DEPRECATION")

package org.readium.r2.navigator.media

import android.app.Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import android.os.ResultReceiver
import android.support.v4.media.MediaBrowserCompat
import android.support.v4.media.session.MediaSessionCompat
import android.widget.Toast
import androidx.core.app.ServiceCompat
import androidx.core.os.BundleCompat
import androidx.media.MediaBrowserServiceCompat
import kotlin.reflect.KMutableProperty0
import kotlinx.coroutines.*
Expand Down Expand Up @@ -151,7 +153,7 @@ public open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by
return null
}

val locator = (extras?.getParcelable(EXTRA_LOCATOR) as? Locator)
val locator = extras?.let { BundleCompat.getParcelable(it, EXTRA_LOCATOR, Locator::class.java) }
?: href
?.let { navigator.publication.linkWithHref(it) }
?.let { navigator.publication.locatorFromLink(it) }
Expand All @@ -178,7 +180,7 @@ public open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by
override fun onNotificationCancelled(notificationId: Int) {
[email protected] = null
[email protected] = null
stopForeground(true)
ServiceCompat.stopForeground(this@MediaService, ServiceCompat.STOP_FOREGROUND_REMOVE)

if (currentNavigator.value?.isPlaying == false) {
onPlayerStopped()
Expand Down Expand Up @@ -249,7 +251,7 @@ public open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by
startForeground(id, note)
}
} else {
stopForeground(false)
ServiceCompat.stopForeground(this@MediaService, ServiceCompat.STOP_FOREGROUND_DETACH)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.core.os.BundleCompat
import androidx.core.view.ViewCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -38,7 +39,7 @@ internal class R2CbzPageFragment(
get() = Dispatchers.Main

private val link: Link
get() = requireArguments().getParcelable("link")!!
get() = BundleCompat.getParcelable(requireArguments(), "link", Link::class.java)!!

private lateinit var containerView: View
private lateinit var photoView: PhotoView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.view.*
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import androidx.core.os.BundleCompat
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand Down Expand Up @@ -50,7 +51,7 @@ internal class R2EpubPageFragment : Fragment() {
get() = requireArguments().getString("url")

internal val link: Link?
get() = requireArguments().getParcelable("link")
get() = BundleCompat.getParcelable(requireArguments(), "link", Link::class.java)

private var pendingLocator: Locator? = null

Expand Down Expand Up @@ -118,7 +119,7 @@ internal class R2EpubPageFragment : Fragment() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pendingLocator = requireArguments().getParcelable("initialLocator")
pendingLocator = BundleCompat.getParcelable(requireArguments(), "initialLocator", Locator::class.java)
}

@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
Expand Down Expand Up @@ -170,9 +171,8 @@ internal class R2EpubPageFragment : Fragment() {
clampedX: Boolean,
clampedY: Boolean
) {
val activity = activity ?: return
activity ?: return
val metrics = DisplayMetrics()
activity.windowManager.defaultDisplay.getMetrics(metrics)

val topDecile = webView.contentHeight - 1.15 * metrics.heightPixels
val bottomDecile = (webView.contentHeight - metrics.heightPixels).toDouble()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import android.os.Parcelable
import android.view.View
import android.view.ViewGroup
import androidx.collection.LongSparseArray
import androidx.core.os.BundleCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.viewpager.widget.PagerAdapter

// This class will be going away when the navigator is rewritten
@Suppress("DEPRECATION")
internal abstract class R2FragmentPagerAdapter(private val mFragmentManager: FragmentManager) : androidx.fragment.app.FragmentStatePagerAdapter(mFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

val mFragments = LongSparseArray<Fragment>()
Expand Down Expand Up @@ -148,7 +151,7 @@ internal abstract class R2FragmentPagerAdapter(private val mFragmentManager: Fra
mFragments.clear()
if (fss != null) {
for (fs in fss) {
mSavedStates.put(fs, bundle.getParcelable<Parcelable>(fs.toString()) as Fragment.SavedState)
mSavedStates.put(fs, BundleCompat.getParcelable(bundle, fs.toString(), Fragment.SavedState::class.java))
}
}
val keys = bundle.keySet()
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pluginManagement {
plugins {
id("com.android.application") version ("8.1.0")
id("com.android.library") version ("8.1.0")
id("io.github.gradle-nexus.publish-plugin") version ("1.1.0")
id("io.github.gradle-nexus.publish-plugin") version ("1.3.0")
id("org.jetbrains.dokka") version ("1.8.20")
id("org.jetbrains.kotlin.android") version ("1.9.0")
id("org.jetbrains.kotlin.plugin.serialization") version ("1.9.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.os.BundleCompat
import androidx.core.os.bundleOf
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
Expand Down Expand Up @@ -50,7 +51,8 @@ class CatalogFragment : Fragment() {
): View {

catalogViewModel.eventChannel.receive(this) { handleEvent(it) }
catalog = arguments?.get(CATALOGFEED) as Catalog

catalog = arguments?.let { BundleCompat.getParcelable(it, CATALOGFEED, Catalog::class.java) }!!
binding = FragmentCatalogBinding.inflate(inflater, container, false)
return binding.root
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.core.os.BundleCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -41,7 +42,7 @@ class NavigationFragment : Fragment() {
publication = it.publication
}

links = requireNotNull(requireArguments().getParcelableArrayList(LINKS_ARG))
links = requireNotNull(BundleCompat.getParcelableArrayList(requireArguments(), LINKS_ARG, Link::class.java))
}

override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.readium.r2.testapp.outline

import android.os.Bundle
import androidx.core.os.BundleCompat
import org.readium.r2.shared.publication.Locator

object OutlineContract {
Expand All @@ -21,7 +22,7 @@ object OutlineContract {
Bundle().apply { putParcelable(DESTINATION_KEY, locator) }

fun parseResult(result: Bundle): Result {
val destination = requireNotNull(result.getParcelable<Locator>(DESTINATION_KEY))
val destination = requireNotNull(BundleCompat.getParcelable(result, DESTINATION_KEY, Locator::class.java))
return Result(destination)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import androidx.annotation.ColorInt
import androidx.appcompat.widget.SearchView
import androidx.core.os.BundleCompat
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.FragmentResultListener
Expand Down Expand Up @@ -101,7 +102,7 @@ class EpubReaderFragment : VisualReaderFragment(), EpubNavigatorFragment.Listene
this,
FragmentResultListener { _, result ->
menuSearch.collapseActionView()
result.getParcelable<Locator>(SearchFragment::class.java.name)?.let {
BundleCompat.getParcelable(result, SearchFragment::class.java.name, Locator::class.java)?.let {
navigator.go(it)
}
}
Expand Down Expand Up @@ -241,7 +242,7 @@ class EpubReaderFragment : VisualReaderFragment(), EpubNavigatorFragment.Listene
menuSearchView.setQuery("", false)

(activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)?.showSoftInput(
this.view, InputMethodManager.SHOW_FORCED
this.view, 0
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.Build
import android.os.IBinder
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService
Expand Down Expand Up @@ -53,13 +54,14 @@ class MediaService : MediaSessionService() {
sessionMutable.asStateFlow()

fun closeSession() {
stopForeground(true)
ServiceCompat.stopForeground(this@MediaService, ServiceCompat.STOP_FOREGROUND_REMOVE)
session.value?.mediaSession?.release()
session.value?.navigator?.close()
session.value?.coroutineScope?.cancel()
sessionMutable.value = null
}

@OptIn(FlowPreview::class)
fun <N> openSession(
navigator: N,
bookId: Long
Expand Down
Loading