UndoRedoToolbarHelper

class UndoRedoToolbarHelper(host: UndoRedoToolbarHelper.UndoRedoToolbarHost, groupId: Int, undoItemId: Int, redoItemId: Int)

Helper class that encapsulates all undo/redo functionality for toolbars. This class handles undo/redo menu item creation, async button state updates, and undo/redo action execution.

This helper implements ANR prevention patterns to avoid blocking on Pdfium mutexes:

Constructors

Link copied to clipboard
constructor(host: UndoRedoToolbarHelper.UndoRedoToolbarHost, groupId: Int, undoItemId: Int, redoItemId: Int)

Types

Link copied to clipboard

Interface that must be implemented by toolbars using this helper.

Functions

Link copied to clipboard
fun addUndoRedoMenuItems(context: Context, configuration: PdfConfiguration?, undoStringId: Int, redoStringId: Int, @DrawableRes undoIcon: Int, @DrawableRes redoIcon: Int, @ColorInt iconColor: Int, @ColorInt iconColorActivated: Int): List<ContextualToolbarMenuItem>

Creates the undo/redo menu items for the toolbar. Returns a list of menu items to be added to the toolbar.

Link copied to clipboard
fun bindProvider(provider: UndoProvider)

Binds a custom undo/redo provider. Must be called when the toolbar's controller is bound. Use this for non-UndoManager providers (e.g., DocumentEditorUndoProvider). Note: Manual calls to updateUndoRedoButtons are required when the undo/redo state changes.

Link copied to clipboard
fun bindUndoManager(pdfFragment: PdfFragment)

Binds the undo manager from the given fragment. Must be called when the toolbar's controller is bound. Creates a UndoManagerUndoProvider wrapper automatically.

Link copied to clipboard

Executes a redo action on a background thread to prevent ANRs from Pdfium mutex blocking. The button enabled state should already ensure this is only called when redo is available and no other undo/redo operation is currently executing. This method is thread-safe and can be called from any thread.

Link copied to clipboard

Executes an undo action on a background thread to prevent ANRs from Pdfium mutex blocking. The button enabled state should already ensure this is only called when undo is available and no other undo/redo operation is currently executing. This method is thread-safe and can be called from any thread.

Link copied to clipboard

Unbinds the provider and cancels any pending state updates or executions. Must be called when the toolbar's controller is unbound.

Link copied to clipboard
fun updateUndoRedoButtons(onStateUpdated: (canUndo: Boolean, canRedo: Boolean) -> Unit? = null)

Updates the enabled state of undo/redo buttons asynchronously. Calls UndoProvider.canUndo and UndoProvider.canRedo on a background thread with a 500ms timeout fallback to prevent ANRs.