Skip to content

Fix AI Literacy Course lesson-item ordering#36

Merged
hal-eisen-adfa merged 1 commit into
mainfrom
fix/ai-literacy-course-item-order
Jul 1, 2026
Merged

Fix AI Literacy Course lesson-item ordering#36
hal-eisen-adfa merged 1 commit into
mainfrom
fix/ai-literacy-course-item-order

Conversation

@hal-eisen-adfa

Copy link
Copy Markdown
Contributor

Problem

The AI Literacy Course presented lesson items in the wrong order — it did not match the numbered sequence in the course bundle (1-objectives.mp4, 2-what-is-ai.mp4, … 7-lesson-1-worksheet.zip).

Root cause

CourseShell.itemsOf() sorted with compareBy({ leadingNumber(it.title) }, { it.title }), but Item.title had already had its N- ordering prefix stripped by itemTitle(). The old leadingNumber regex (\d+) then matched the first digit anywhere in the stripped title. Two failures compounded:

  • Genuinely-first items like 1-objectives"Objectives" had no digit left → Int.MAX_VALUE → sorted last.
  • Items whose text contains a number, e.g. 5-lesson-1-recap-quiz"Lesson 1 Recap Quiz", picked up the embedded 1 → sorted first.

Result for Lesson 1 (buggy): Project Time → Recap Quiz → Worksheet → AI Or Not Quiz → How AI Can Help Us → Objectives → What Is AI.

Section-level ordering was already correct (sectionOrder() keys off the raw folder name); only intra-section item order was broken.

Fix

  • Add order: Int to Item, computed via leadingNumber(...) from the original file/dir name (before itemTitle() strips the prefix), and sort by it.order then title.
  • Anchor leadingNumber to ^(\d+) so it can only read the leading ordering prefix, never a digit embedded later in the name.

After the fix, Lesson 1 renders: Objectives → What Is AI → AI Or Not Quiz → How AI Can Help Us → Lesson 1 Recap Quiz → Lesson 1 Project Time → Lesson 1 Worksheet.

CourseShell.generate() only runs during CourseInstaller.ensureInstalled(), which is gated by an install-version marker, so INSTALL_VERSION is bumped 2 → 3 to force existing installs to re-extract and regenerate index.html with the corrected order.

Verification

  • Ported the exact old vs. new sort to a mock lesson tree: BEFORE reproduced the scramble, AFTER matched the numeric-prefix order exactly.
  • Built the .cgp and installed on device (Samsung S22). Confirmed lessons now list items in numbered order. (Surfaced and fixed a separate pre-existing issue in the process: pdfjs.zip is a build-time downloaded asset, and a bare assemblePlugin without a prior downloadAssets ships a viewer-less .cgp; re-fetched before the device test — see note below.)

Note / possible follow-up

./gradlew assemblePlugin silently produces a broken plugin if the downloaded assets (pdfjs.zip, ai-literacy-course.zip) aren't present, with no build-time warning — only scripts/update-libs.sh runs downloadAssets first. A follow-up could make assemblePlugin fail fast (or depend on downloadAssets) when those assets are missing. Not included here to keep this PR scoped to the ordering fix.

CourseShell.itemsOf() sorted items by leadingNumber(it.title), but the
title had already had its "N-" ordering prefix stripped by itemTitle().
The leadingNumber regex (\d+) then matched the first digit anywhere in the
stripped title, so items whose text contains a number (e.g.
"5-lesson-1-recap-quiz" -> "Lesson 1 Recap Quiz") sorted on that embedded
"1" and jumped ahead of the genuinely-first items (e.g. "1-objectives" ->
"Objectives", which had no digit left and sorted last). Every lesson came
out scrambled and no longer matched the numbered course sequence.

Sort instead by the numeric prefix of the original file/dir name, captured
into Item.order before itemTitle() strips it, and anchor leadingNumber to
^(\d+) so it can only read the ordering prefix.

Bump CourseInstaller.INSTALL_VERSION 2 -> 3 so existing installs re-extract
and regenerate index.html with the corrected order.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@hal-eisen-adfa hal-eisen-adfa merged commit fe64ebc into main Jul 1, 2026
@hal-eisen-adfa hal-eisen-adfa deleted the fix/ai-literacy-course-item-order branch July 1, 2026 01:50
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.

1 participant