Skip to content

Conversation

@ovitrif
Copy link
Collaborator

@ovitrif ovitrif commented Jan 16, 2026

This PR refactors the toast system to improve architecture, API consistency, and localization.

Changes

Architecture

  • Replace ToastEventBus singleton with injectable Toaster using SharedFlow
  • Add ToastText sealed interface with Resource, Literal, and Parameterized subtypes
  • Inject Toaster in MainActivity via Hilt, provide via LocalToaster
  • Rename ToastQueueManagerToastQueue

API Consolidation

  • Factory constructors: ToastText(resId), ToastText(string), ToastText(resId, params)
  • Composable parameter pattern: toaster: Toaster = LocalToaster.current
  • Remove app.toast() API, use toaster.*() directly
  • Rename: descriptionbody, visibilityTimeduration, warning()warn()

String Replacement

  • ToastText.Parameterized(resId, mapOf("key" to "value")) replaces {key} in strings

Localization

  • Migrate all hardcoded toast strings to string resources
  • Add ToastText.asString() extensions (composable and Context)

Cleanup

  • Rename ToastViewToastContent, ToastOverlayToastHost

Usage

// Simple
toaster.success(title = ToastText(R.string.success))

// With body
toaster.error(
    title = ToastText(R.string.error_title),
    body = ToastText(R.string.error_body),
)

// With string replacement
toaster.warn(
    body = ToastText(R.string.amount_exceeded, mapOf("amount" to "1000")),
)

// In composables
@Composable
fun MyScreen(toaster: Toaster = LocalToaster.current) {
    Button(onClick = { toaster.success(ToastText(R.string.done)) }) { ... }
}

QA Notes

  1. Toast Functionality: Trigger various toast types, verify styling and auto-dismiss
  2. Queue Behavior: Trigger multiple toasts rapidly, verify sequential display
  3. Drag Interactions: Drag toast to pause timer, release to resume
  4. Localization: Change device language, verify translated messages

ovitrif and others added 15 commits January 16, 2026 19:48
- Add ToastText sealed interface for type-safe messages
- Create Toaster singleton with convenience APIs
- Move ToastType to top-level with @stable annotation
- Migrate all ViewModels and Repos to use Toaster
- Delete ToastEventBus in favor of DI pattern

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ovitrif ovitrif changed the title refactor: improve toast system internals refactor: improve toast apis and internals Jan 17, 2026
ovitrif and others added 14 commits January 17, 2026 03:14
- Add ToastText() factory constructors (invoke operators)
- Remove redundant @stable from ToastType enum and value classes
- Rename titleRes/bodyRes → title/body in @stringres overloads
- Rename warning() → warn() across all overloads
- Update all call sites for the API changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace ToastText.Literal() and ToastText.Resource() calls
with the cleaner ToastText() factory constructor.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change emit() to use tryEmit() on SharedFlow
- Remove suspend modifier from all toast methods
- Make LocalToaster non-nullable with error default

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace all app.toast() and appViewModel.toast() calls
in Screen composables with direct toaster method calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ovitrif and others added 2 commits January 17, 2026 15:03
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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