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()
  • Rename queue methods: dismissCurrentToast()dismiss(), pauseCurrentToast()pause(), resumeCurrentToast()resume()

String Replacement

  • Added ToastText.Parameterized(resId, mapOf("key" to "value")) to replace params

Localization

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

Cleanup

  • Rename ToastViewToastContent, ToastOverlayToastHost
  • Remove unnecessary viewModelScope.launch wrappers around toaster calls
  • Use AppError instead of generic Exception for error toasts
  • Simplify error handling with toaster.error(throwable)

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")),
)

// Error from throwable
toaster.error(exception)

// 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 <[email protected]>
@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 <[email protected]>
Replace ToastText.Literal() and ToastText.Resource() calls
with the cleaner ToastText() factory constructor.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- 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 <[email protected]>
Replace all app.toast() and appViewModel.toast() calls
in Screen composables with direct toaster method calls.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ovitrif ovitrif marked this pull request as ready for review January 17, 2026 18:16
@ovitrif ovitrif self-assigned this Jan 17, 2026
@claude

This comment has been minimized.

@claude

This comment has been minimized.

@claude
Copy link

claude bot commented Jan 17, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

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