Skip to content

Refactor: Use Notebook.getPageIndex() extension function#200

Merged
Ethran merged 4 commits intomainfrom
dev
Feb 5, 2026
Merged

Refactor: Use Notebook.getPageIndex() extension function#200
Ethran merged 4 commits intomainfrom
dev

Conversation

@Ethran
Copy link
Copy Markdown
Owner

@Ethran Ethran commented Feb 5, 2026

Create a getPageIndex(pageId) extension function for the Notebook class to centralize the logic for finding a page's index.

Corrected in Toolbar.kt how page number are retrieved, fixed issue #192

Create a `getPageIndex(pageId)` extension function for the `Notebook` class to centralize the logic for finding a page's index.

Corrected in Toolbar.kt how page number are retrieved, fixed issue #192
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors page index retrieval logic by introducing a centralized Notebook.getPageIndex(pageId) extension function and fixes a critical NullPointerException reported in issue #192.

Changes:

  • Created Notebook.getPageIndex(pageId) extension function to centralize the logic for finding a page's index within a notebook
  • Fixed NullPointerException in Toolbar.kt by adding proper null-safe handling when retrieving page numbers
  • Improved null safety in AppRepository.kt navigation methods (getNextPageIdFromBookAndPage and getPreviousPageIdFromBookAndPage)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
app/src/main/java/com/ethran/notable/data/db/Notebook.kt Added getPageIndex() extension function that wraps pageIds.indexOf()
app/src/main/java/com/ethran/notable/editor/ui/toolbar/Toolbar.kt Fixed NPE by using safe calls and fallback values when computing page numbers; cached repository instance in remember block
app/src/main/java/com/ethran/notable/ui/views/PagesView.kt Refactored to use new extension function; removed intermediate pageIds variable and access book.pageIds directly
app/src/main/java/com/ethran/notable/data/AppRepository.kt Improved null handling and index validation; refactored to use new extension function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ethran and others added 3 commits February 5, 2026 23:22
Wrap AppRepository instantiation in `remember {}` to avoid creating a new instance on every recomposition.
- Use `rememberCoroutineScope` instead of creating a new `CoroutineScope` on each recomposition.
- Hoist `stringResource` calls to the top level of the composable to avoid repeated lookups.
- Launch export coroutines on `Dispatchers.IO` directly from the UI thread scope.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Ethran Ethran merged commit 2828ac4 into main Feb 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants