Skip to content

ADFA-4500 | Show snippet dialogs and toasts through PluginWindows - #83

Open
Daniel-ADFA wants to merge 2 commits into
mainfrom
ADFA-4500
Open

ADFA-4500 | Show snippet dialogs and toasts through PluginWindows#83
Daniel-ADFA wants to merge 2 commits into
mainfrom
ADFA-4500

Conversation

@Daniel-ADFA

Copy link
Copy Markdown
Collaborator

Plugin half of ADFA-4500. Host PR: appdevforall/CodeOnTheGo#1771.

Blocked until the host lands

This does not compile against the current libs/plugin-api.jar, which has no PluginWindows. It needs CodeOnTheGo#1771 merged and a chore: update libs refresh first. Draft until then.

What was wrong

Undocking Snippets into a floating window and tapping Add crashed the app. After that was fixed host-side, saving a filled-in snippet crashed it again, after the file had already been written, so the snippet persisted and the process died.

An undocked fragment runs against a window context created for TYPE_APPLICATION_OVERLAY, and the platform requires every window added through it to carry that same type. MaterialAlertDialogBuilder(ctx).show() builds a TYPE_APPLICATION window and Toast.makeText a TYPE_TOAST one, so both threw IllegalArgumentException while floating:

Window type mismatch. Window Context's window type is 2038,
while LayoutParams' type is set to 2005
  at android.widget.ToastPresenter.addToastView

Docked, ctx is the activity, so the same code worked. That is why this only ever reproduced undocked.

Change

Both dialogs and all three toasts go through PluginWindows. Dialogs are built with create() and shown via showDialog; toasts use showToast, which posts against the application context. Both are no-ops while docked, so one call site is correct in either state.

min_ide_version moves from 1.0.0 to 26.36, the release that ships PluginWindows.

Sites changed

Site Was
showEditor MaterialAlertDialogBuilder(ctx).show()
confirmDelete MaterialAlertDialogBuilder(ctx).show()
showEditor validation Toast.makeText(ctx, ...)
save success Toast.makeText(requireContext(), ...)
save failure Toast.makeText(requireContext(), ...)

No remaining Toast.makeText or android.widget.Toast import in the file.

Verification

Device (arm64 emulator, API 36), against a host build of CodeOnTheGo#1771:

  • Undock, tap Add: dialog opens above the floating window, no crash.
  • Fill and Save: snippet count 5 to 6, process PID unchanged, zero Window type mismatch, zero fatals.
  • Save with empty fields: validation toast fires, no crash, count unchanged.
  • Checked at font scale 1.0 and 2.0: no clipping, list scrolls.

Undocking Snippets into a floating window and tapping Add crashed the app, and
saving a filled-in snippet crashed it again after the file had already been
written.

An undocked fragment runs against a window context created for
TYPE_APPLICATION_OVERLAY, and the platform requires every window added through
it to carry that type. MaterialAlertDialogBuilder(ctx).show() builds a
TYPE_APPLICATION window and Toast.makeText a TYPE_TOAST one, so both threw
IllegalArgumentException while floating. Docked, ctx is the activity, so the
same code worked.

Route both through PluginWindows: showDialog applies the type the context
requires, showToast posts against the application context, which imposes no
window type. Both are no-ops while docked, so a single call site is correct in
either state. Applied to both dialogs (the editor and the delete confirmation)
and all three toasts.

min_ide_version moves to 26.36, the release that ships PluginWindows.
@Daniel-ADFA
Daniel-ADFA marked this pull request as ready for review September 2, 2026 08:07

@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 for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

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

Comment thread snippets/src/main/kotlin/com/codeonthego/snippets/ui/SnippetManagerFragment.kt Outdated
Comment thread snippets/src/main/kotlin/com/codeonthego/snippets/ui/SnippetManagerFragment.kt Outdated
Comment thread snippets/src/main/kotlin/com/codeonthego/snippets/ui/SnippetManagerFragment.kt Outdated
Review feedback: user-facing text belongs in resources.

Covers every user-facing literal in the two functions this PR touches, not only
the three toasts flagged, so the file is not left half converted: the editor and
delete dialog titles, their Save/Cancel/Delete buttons and the delete
confirmation, alongside the validation and save toasts. The delete confirmation
takes the prefix as a positional argument rather than interpolating it.

The Log.e message is left as it is; it is not user-facing.
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.

3 participants