kotlin-toolkit icon indicating copy to clipboard operation
kotlin-toolkit copied to clipboard

A better way to pass `Publication` objects around

Open mickael-menu opened this issue 3 years ago • 3 comments

Passing complex or large objects between Activity or Fragment instances is notoriously a pain. This is an issue with Readium's Publication objects, which can't be stored in an Intent or arguments Bundle.

The 2.0.0 version introduced a couple of helper extensions on Intent using an in-memory PublicationRepository. An alternative if you have a single-activity app would be to store the Publication into the shared ViewModel. But both of these solutions fail when the app process is killed and restored, which can cause crashes or plainly loose the reader state.

As this is an app architecture issue, and not related to Readium, I suggest we:

  1. Deprecate the Intent helper extensions.
  2. Show the best practice in the test app by:
    • Adding a custom PublicationRepository implementation which also owns a Streamer to open Publication objects on the fly when they are not cached (process death).
    • Passing a PublicationId between Fragment and Activity instances which can be used with the PublicationRepository.

mickael-menu avatar Dec 07 '21 18:12 mickael-menu

The three Bundle extensions should also be deprecated, all of which are also in Intent.kt. They are used the OPDS feeds to pass the Publication from the list to the detail screen of the one that is selected.

stevenzeck avatar Dec 09 '21 05:12 stevenzeck

Yes, I think that everything in this file should be deprecated eventually.

You're raising a good point about the OPDS feeds, the implemented solution should probably be different for OPDS, as there's no need for a Streamer. Maybe a "repository" implementation for this could be shipped with the lcp module.

I'm wondering if it's wise to return Publication objects from the OPDS parsers instead of the "dumb" Manifest data classes. This would simplify this issue (although TransactionTooLargeException could still occur). For a "streaming" OPDS feed serving publications with a full reading order, the Manifest could always be transformed into a Publication by a Streamer object, if needed.

mickael-menu avatar Dec 09 '21 10:12 mickael-menu

Yeah ideally we don't want to pass around those large objects in Intents/Bundles, plus Compose doesn't support that anyways. But the OPDS feed implementation is limited to the testapp, and not something developers should follow anyways as it's not greatly written (I know because I rewrote it 😆)

stevenzeck avatar Dec 10 '21 17:12 stevenzeck

Though it's not perfect, I guess this is done.

qnga avatar Jan 11 '24 22:01 qnga