Undo Redo Toolbar Helper
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:
UndoProvider.canUndo and UndoProvider.canRedo are called on a background thread with a 500ms timeout fallback
UndoProvider.undo and UndoProvider.redo are executed on a background thread to prevent main thread blocking
Constructors
Types
Interface that must be implemented by toolbars using this helper.
Functions
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.
Binds the undo manager from the given fragment. Must be called when the toolbar's controller is bound. Creates a UndoManagerUndoProvider wrapper automatically.
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.
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.
Unbinds the provider and cancels any pending state updates or executions. Must be called when the toolbar's controller is unbound.
Recomputes undo/redo availability from the bound provider (on a background thread, since canUndo/canRedo might block) and applies it to the toolbar buttons.