BookLibraryController

class BookLibraryController(context: Context, extraCompositions: Collection<String> = emptyList(), adManager: AdManager, tokenProvider: TokenProvider, editionsBooksContext: EditionsBooksContext? = null, bookOpening: BookOpening? = null, readingListHost: ReadingListHost? = null, articleOpener: ArticleOpener? = null, navigationDelegate: LibraryNavigationDelegate? = null, coverOverlayProvider: BookCoverOverlayProvider? = null, categoryListIconProvider: CategoryListIconProvider? = null, bindingOverrideAdapterFactory: BindingOverrideAdapterFactory? = null, fontProvider: DataBindingValueProvider.Fonts? = null, colorProvider: DataBindingValueProvider.Colors? = null, appdataNetworking: AppdataNetworking? = null, analyticsEventListener: BooksAnalyticsEventListener? = null)

The main entry point for the Book Library UI SDK.

Most interaction with the SDK is through this class. Call start as early as possible in your app's lifecycle to allow feeds to update as soon as possible.

In the activity that is going to host the book library, call showLibraryInView.

BookLibraryController needs to know about a few things that are going on in the host Activity's overridden methods (a more automated solution is pending, but for now this is required for correct functionality):

  • In onRestoreInstanceState, call BookLibraryController.verifyViewStateAfterActivityRestore().

  • In onBackPressed, call:

if (!BookLibraryController.handleBackPressed()) {
super.onBackPressed()
}

... or something similar, based on your own needs. This is required for proper back button handling in the SDK.

Important: currently, only one instance of BookLibraryController may be created during the lifetime of the hosting application. This may change in the future.

tokenProvider provides the token that's required for various access checks, either when downloading books or checking access to books on disk.

A BookOpening implementation can optionally be added if a token check is not sufficient for checking the user's access to a book. If bookOpening is null, a default implementation that always returns true is used.

By default, Book Library UI uses books on disk as the content of the library tab. Add readingListHost if you need to customize this to show a custom list of books, in addition to books on disk.

Books may have reviews or other extra articles attached to them. These articles may contain an id for opening the article in question in the host app or the web. Set articleOpener with your ArticleOpener implementation to be informed when the user clicks a button to open these articles.

navigationDelegate is an optional LibraryNavigationDelegate implementation. If using the default action bar controller, this informs the host app of when the user either navigates away from or back to the top level of navigation.

coverOverlayProvider is an optional BookCoverOverlayProvider implementation. When it returns a overlay description for a book, an overlay is drawn on top of the cover image.

categoryListIconProvider is an optional CategoryListIconProvider implementation. It's used in the category list view.

If passing in an Editions instance (editions), Editions.initialize must have been called before doing so. The SDK will call Editions.updateFeed on startup. Analytics events should be forwarded to fi.richie.booklibraryui.analytics.EditionsEventLogger. (or use the class directly)

You may provider font and color providers (fontProvider and colorProvider respectively), which will, as the names imply, used as sources for fonts and colors. This can be useful if your colors are defined via an external app config, for example. If no providers are given, defaults are used, which can also be overridden via XML resources. Note that the providers can only be set in start, so the providers should be able to update their value definitions themselves.

Constructors

Link copied to clipboard
constructor(context: Context, extraCompositions: Collection<String> = emptyList(), adManager: AdManager, tokenProvider: TokenProvider, editionsBooksContext: EditionsBooksContext? = null, bookOpening: BookOpening? = null, readingListHost: ReadingListHost? = null, articleOpener: ArticleOpener? = null, navigationDelegate: LibraryNavigationDelegate? = null, coverOverlayProvider: BookCoverOverlayProvider? = null, categoryListIconProvider: CategoryListIconProvider? = null, bindingOverrideAdapterFactory: BindingOverrideAdapterFactory? = null, fontProvider: DataBindingValueProvider.Fonts? = null, colorProvider: DataBindingValueProvider.Colors? = null, appdataNetworking: AppdataNetworking? = null, analyticsEventListener: BooksAnalyticsEventListener? = null)

Properties

Link copied to clipboard

Getter for AudioPlayerGateway. Use to check or listen to the audio player's state.

Link copied to clipboard

Getter for ContentState. Use to follow the state of the content feed.

Link copied to clipboard
val eventLogger: ProviderSingleWrapper<Optional<LibraryEventLogger>>

Analytics event logger.

Link copied to clipboard

Inform the SDK whether its view is currently being shown by the host app or not.

Link copied to clipboard

If the Books remote config has a books_review_prompt configuration, this Observable will be updated when its conditions are met.

Functions

Link copied to clipboard

Add an analytics event listener.

Link copied to clipboard

Close all books that are currently open. Can be useful if the user loses entitlements to content that was previously available.

Link copied to clipboard

Check if the SDK needed to react to the back button being pressed.

Link copied to clipboard
fun onDestroyView(activity: Activity)

Clears views when the library view is about to be destroyed, such as when the host activity is about to be destroyed.

Link copied to clipboard
fun openDetailView(itemId: Guid, tab: Tab = Tab.LIBRARY)
Link copied to clipboard

Notify the SDK that the reading list has changed.

Link copied to clipboard

Update content that's dependent on the user's login state. E.g. this refreshes the user's book ratings.

Link copied to clipboard

Remove an analytics event listener.

Link copied to clipboard

Resets all tabs to their default state, i.e. pops all tabs to the root view.

Link copied to clipboard

Resets content that's dependent on the user's login state. This means the following:

Link copied to clipboard
fun setAnalyticsExtraAttributes(extraAttributes: Map<String, Any>?)

Set the extra attributes for analytics events. A null extraAttributes clears it.

Link copied to clipboard
fun showLibraryInView(activity: Activity, containerView: ViewGroup, fragmentManager: FragmentManager, tabBarType: TabBarType = TabBarType.TOP, tabs: List<ITab> = Tab.defaultTabs, initialTab: ITab = Tab.FEATURED, uiConfiguration: BookLibraryUiConfiguration? = null, actionBarProvider: ActionBarProvider? = null, featuredHeaderViewUpdater: FeaturedHeaderViewUpdater? = null)

Show the library in the containerView in the host activity.

Link copied to clipboard
fun start(appconfigDataCallback: AppconfigDataCallback? = null)

Starts the Book Library UI SDK, including fetching feeds and initializing the book library.

Link copied to clipboard

Triggers an update to all active action bars.

Link copied to clipboard

If you have a custom DataBindingValueProvider.Colors or DataBindingValueProvider.Fonts, call this method if their contents have changed to update the UI.

Link copied to clipboard
fun updateTokenProvider(tokenProvider: TokenProvider)

Update the token provider used by Books.

Link copied to clipboard

Ensures that the SDK's view states are correct after the host activity has been restored.