Create and load an HTML file with the Quill editor and Codox initialization logic using a WebView
In Kotlin, fetch the initial document state from the backend and initialize the Quill editor.
In Kotlin, set up listeners (callbacks) to respond to Codox client library session and error events.
Explicitly start Codox session via a javascript interface.
When Codox triggers hooks in the JavaScript code, corresponding callbacks in Kotlin are invoked, passing the necessary data.
Step-by-Step Integration Tutorial
Step 1: Set Up Local Files
The first step is to prepare the local files for your project. Create a directory app/src/main/assets/ in project root to store html and javascript files.
Navigate to created directory app/src/main/assets/ and create local html file:
Create a directory for Codox library files:
Navigate to the codoxLib/ directory and create a package.json file:
Install the library:
Copy the Codox lib to the app/src/main/assets/ directory:
The app/src/main/assets/ directory should now look like this:
Step 2: Initialize QuillJS Editor
Add the following code to quill.html to set up the Quill editor:
Step 3: Initialize WebView in Kotlin
In kotlin app in MainActivity.kt init WebView with local html with Quill editor load.
To display the HTML/Javascript app in Kotlin, we will use the WebView class. The following code in MainActivity.kt sets this up:
Step 4: Inject Codox library script
Inject Codox library script codox.js into WebView after local html page is loaded. The following code in MainActivity.kt sets this up:
Step 5: Initialize the Editor State
Before initiating or joining a Codox session, the latest version of the document content must be available and must be setup in editor. The following code shows how to set up this from Kotlin app.
Add an initialization function in your HTML/Javascript quill.html to expose a method for Kotlin to set up the editor with initial content.
Then, invoke this function from Kotlin after the page has been fully loaded using the onPageFinished method from WebView .
Start Codox Session
Setup start session code in quill.html.
To start or joining a Codox session, you need to explicitly call codox.start to connect to the session.
Setup start session code in quill.html:
Then, invoke this function from Kotlin after the page has been fully loaded using the onPageFinished callback from WebView, in MainActivity.kt . Note that starting the session proceeds after the initial document state has been passed into the editor.
Optional: Codox Hooks and Error events
You can listen to events from Codox to allow the Kotlin app to respond to content change notifications, member change notifications, and errors triggered within the Codox session.
In quill.html, define callback functions and include them in the config object passed to Codox. These callbacks are triggered internally when specific events occur and serve as bridges to invoke corresponding handlers in the Kotlin app.
On the Kotlin side you need to setup handlers to manage JavaScript messages sent from Codox, like the following example in MainActivity.kt: