package com.craigvg.lichun_android.managers import android.content.Context import android.content.SharedPreferences import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import javax.inject.Inject import javax.inject.Singleton data class TooltipData( val id: String, val message: String, val targetId: String? = null, val position: TooltipPosition = TooltipPosition.BOTTOM ) enum class TooltipPosition { TOP, BOTTOM, START, END } @Singleton class TooltipManager @Inject constructor( @ApplicationContext private val context: Context ) { private val prefs: SharedPreferences = context.getSharedPreferences("tooltip_prefs", Context.MODE_PRIVATE) private val _currentTooltip = MutableStateFlow(null) val currentTooltip: StateFlow = _currentTooltip.asStateFlow() private val _isVisible = MutableStateFlow(false) val isVisible: StateFlow = _isVisible.asStateFlow() /** * Show a tooltip if it hasn't been seen before. */ fun show(tooltip: TooltipData) { if (hasBeenSeen(tooltip.id)) return _currentTooltip.value = tooltip _isVisible.value = true } /** * Dismiss the current tooltip and mark it as seen. */ fun dismiss() { _currentTooltip.value?.let { markAsSeen(it.id) } _isVisible.value = false _currentTooltip.value = null } /** * Check if a tooltip has been seen. */ fun hasBeenSeen(tooltipId: String): Boolean { return prefs.getBoolean("tooltip_seen_$tooltipId", false) } private fun markAsSeen(tooltipId: String) { prefs.edit().putBoolean("tooltip_seen_$tooltipId", true).apply() } /** * Reset all seen tooltips (for testing). */ fun resetAll() { prefs.edit().clear().apply() _currentTooltip.value = null _isVisible.value = false } }