Skip to content

fix/ADFA-3613 externalize template strings#1218

Merged
jomen-adfa merged 4 commits into
stagefrom
fix/ADFA-3613-template-strings
Apr 20, 2026
Merged

fix/ADFA-3613 externalize template strings#1218
jomen-adfa merged 4 commits into
stagefrom
fix/ADFA-3613-template-strings

Conversation

@jomen-adfa
Copy link
Copy Markdown
Contributor

externalize template string

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@jomen-adfa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 13 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 38 minutes and 13 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 240aba15-6aaf-4de4-883a-630ae193a880

📥 Commits

Reviewing files that changed from the base of the PR and between 1b3bd9c and 04ff43b.

📒 Files selected for processing (6)
  • app/src/main/java/com/itsaky/androidide/fragments/TemplateListFragment.kt
  • resources/src/main/res/values/strings.xml
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateWarning.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt
📝 Walkthrough

Walkthrough

This PR changes template warning handling from plain strings to structured, localized TemplateWarning objects, updates template-loading/execution code to use string resources and non-null Context, and resolves warnings to localized messages in the UI before display.

Changes

Cohort / File(s) Summary
UI
app/src/main/java/com/itsaky/androidide/fragments/TemplateListFragment.kt
Resolve TemplateWarning entries to localized strings via getString(resId, *args) before calling flashError.
String resources
resources/src/main/res/values/strings.xml
Added multiple template_* string resources for info/warning/error messages used during template read/process/execution.
Warning model
templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateWarning.kt
New data class TemplateWarning(val resId: Int, val args: List<Any?>) to represent localized warnings.
Template provider / reader
templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt, templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt
Internal warning lists changed from String to TemplateWarning; exceptions now yield structured warnings built from string resource IDs and args.
Execution engine
templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
Execution now requires non-null Context, threads it through template param extraction, and replaces literal logs with resource-based info/warn/error calls and resource-backed exception wrapping.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant UI as TemplateListFragment
  participant Provider as TemplateProviderImpl
  participant Reader as ZipTemplateReader
  participant Executor as ZipRecipeExecutor
  participant Res as AndroidResources

  User->>UI: open Template list / reload
  UI->>Provider: request templates
  Provider->>Reader: read archive (collect TemplateWarning[])
  Reader-->>Provider: templates + warnings
  Provider->>UI: return templates + warnings
  UI->>Res: resolve each TemplateWarning (resId,args) -> localized string
  UI-->>User: display templates and localized warnings
  alt execute template
    UI->>Executor: execute recipe (requires non-null Context)
    Executor->>Res: fetch localized messages during processing
    Executor->>Reader: read entries / params (passes Context)
    Executor-->>UI: report localized info/warn/error messages
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • itsaky-adfa
  • davidschachterADFA
  • hal-eisen-adfa

Poem

🐇 I found warnings tucked in zips and streams,
I swapped them for keys and localized dreams,
With Context in paw and resources bright,
I hop and I map each message just right. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix/ADFA-3613 externalize template strings' accurately reflects the main change: externalizing hardcoded template strings to Android string resources for localization and better maintainability.
Description check ✅ Passed The PR description 'externalize template string' directly relates to the changeset, which replaces hardcoded strings with externalized Android string resources throughout the template system.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ADFA-3613-template-strings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/src/main/java/com/itsaky/androidide/fragments/TemplateListFragment.kt`:
- Around line 144-149: The flash message currently shows only the detailed
warning lines and drops the intended summary/prefix (msg_template_warnings) that
includes leading newlines for spacing; update the code around the warnings
handling in TemplateListFragment (where requireActivity().flashError is called)
to prepend the localized summary string
requireContext().getString(R.string.msg_template_warnings) (or similar resource
id msg_template_warnings) to the joined warning details so the final message is
getString(msg_template_warnings) + warnings.joinToString("\n") { ... },
preserving the leading spacing and original banner prefix.

In `@resources/src/main/res/values/strings.xml`:
- Around line 1297-1300: The user-facing string resources use
inconsistent/missing separators ("%1$s %2$s") and extra spaces; update each
template resource (e.g., template_exec_error_evaluate,
template_exec_error_write, template_exec_error_copy,
template_exec_error_process) to use a normalized separator like "%1$s: %2$s"
(single colon and single space) so messages render as "context: details"; apply
the same normalization to the other template_exec_error_* entries mentioned in
the comment.

In
`@templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt`:
- Around line 195-198: In ZipRecipeExecutor replace the write-specific error
resource with the copy-specific one in the catch handling the
input.copyTo(output) path: change the error(...) call that currently uses
R.string.template_exec_error_write to use R.string.template_exec_error_copy
(keep the same parameters like ctx, entry.name and e.toString()) so copy
failures log the correct string resource.
- Around line 52-57: The code currently force-unwraps executor.context with
"executor.context!!"; replace that with an explicit null-check using
requireNotNull(executor.context) { "Context required for template execution" }
and assign it to ctx (val ctx = requireNotNull(executor.context) { ... }) inside
the execute(RecipeExecutor) method so the contract is documented and any missing
context throws a clear error; reference the execute method and the ctx variable
when making this change (calling requireNotNull in place of the existing !!).

In
`@templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt`:
- Around line 40-43: The code currently adds a TemplateWarning for missing
ARCHIVE_JSON inside the requireNotNull lambda and then lets requireNotNull
throw, causing the outer catch to also add template_read_error_archive_load —
remove the warning from the requireNotNull call and either (A) perform an
explicit null check on zip.getEntry(ARCHIVE_JSON) to add a single
TemplateWarning and return/fail early, or (B) keep requireNotNull so it throws
and let the outer catch add the single template_read_error_archive_load; modify
the code around zip.getEntry(ARCHIVE_JSON), requireNotNull, and warnings so only
one warning is emitted for the missing ARCHIVE_JSON (reference ARCHIVE_JSON,
zip.getEntry, requireNotNull, warnings, TemplateWarning,
template_read_error_archive_json, template_read_error_archive_load).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65aa4f6b-f389-4763-b139-a260ddd88f60

📥 Commits

Reviewing files that changed from the base of the PR and between 1ff7076 and ad55542.

📒 Files selected for processing (6)
  • app/src/main/java/com/itsaky/androidide/fragments/TemplateListFragment.kt
  • resources/src/main/res/values/strings.xml
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateWarning.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipRecipeExecutor.kt
  • templates-impl/src/main/java/com/itsaky/androidide/templates/impl/zip/ZipTemplateReader.kt

Comment thread resources/src/main/res/values/strings.xml
@jomen-adfa jomen-adfa force-pushed the fix/ADFA-3613-template-strings branch from 745f216 to 04ff43b Compare April 20, 2026 21:20
@jomen-adfa jomen-adfa merged commit 611ca45 into stage Apr 20, 2026
2 checks passed
@jomen-adfa jomen-adfa deleted the fix/ADFA-3613-template-strings branch April 20, 2026 21:34
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