DetailTopBar.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/detail/DetailTopBar.kt
1package eu.friedcutlet.yokan.ui.screens.detail23import androidx.compose.foundation.layout.Box4import androidx.compose.material.icons.Icons5import androidx.compose.material.icons.automirrored.filled.ArrowBack6import androidx.compose.material.icons.automirrored.filled.Label7import androidx.compose.material.icons.filled.Download8import androidx.compose.material.icons.filled.FilterList9import androidx.compose.material.icons.filled.Groups10import androidx.compose.material.icons.filled.Info11import androidx.compose.material.icons.filled.MoreVert12import androidx.compose.material.icons.filled.Refresh13import androidx.compose.material.icons.filled.SaveAlt14import androidx.compose.material.icons.filled.Settings15import androidx.compose.material.icons.filled.Share16import androidx.compose.material.icons.filled.SyncAlt17import androidx.compose.material3.DropdownMenu18import androidx.compose.material3.DropdownMenuItem19import androidx.compose.material3.ExperimentalMaterial3Api20import androidx.compose.material3.Icon21import androidx.compose.material3.IconButton22import androidx.compose.material3.MaterialTheme23import androidx.compose.material3.Text24import androidx.compose.material3.TopAppBar25import androidx.compose.material3.TopAppBarDefaults26import androidx.compose.runtime.Composable27import androidx.compose.runtime.getValue28import androidx.compose.runtime.mutableStateOf29import androidx.compose.runtime.remember30import androidx.compose.runtime.setValue31import androidx.compose.ui.graphics.Color32import androidx.compose.ui.graphics.vector.ImageVector33import androidx.compose.ui.text.style.TextOverflow34import eu.friedcutlet.yokan.domain.ItemType35import eu.friedcutlet.yokan.domain.Manga36import eu.friedcutlet.yokan.domain.Source37import eu.friedcutlet.yokan.services.together.RoomState38import eu.friedcutlet.yokan.ui.navigation.Route39import org.jetbrains.compose.resources.stringResource40import yokan.composeapp.generated.resources.Res41import yokan.composeapp.generated.resources.action_back42import yokan.composeapp.generated.resources.action_refresh43import yokan.composeapp.generated.resources.detail_notes44import yokan.composeapp.generated.resources.source_related_entries4546/** The detail app bar: back, bulk-download menu, chapter filter sheet, and the title's overflow actions. */47@OptIn(ExperimentalMaterial3Api::class)48@Composable49internal fun DetailTopBar(50 manga: Manga,51 source: Source?,52 showTitle: Boolean,53 showRemoteActions: Boolean,54 filteringActive: Boolean,55 metadataEnabled: Boolean,56 canSetCategories: Boolean,57 togetherRoom: RoomState?,58 onBack: () -> Unit,59 onDownload: (DetailDownloadOption) -> Unit,60 onFilter: () -> Unit,61 onSetCategories: () -> Unit,62 onEvent: (DetailEvent) -> Unit,63 onNavigate: (Route) -> Unit,64) {65 var downloadMenuOpen by remember { mutableStateOf(false) }66 var overflowOpen by remember { mutableStateOf(false) }67 TopAppBar(68 title = {69 if (showTitle) {70 Text(71 manga.name,72 style = MaterialTheme.typography.bodyLarge,73 maxLines = 1,74 overflow = TextOverflow.Ellipsis,75 )76 }77 },78 navigationIcon = {79 IconButton(onClick = onBack) {80 Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(Res.string.action_back))81 }82 },83 actions = {84 if (showRemoteActions) {85 Box {86 IconButton(onClick = { downloadMenuOpen = true }) {87 Icon(Icons.Filled.Download, contentDescription = "Download")88 }89 DropdownMenu(90 expanded = downloadMenuOpen,91 onDismissRequest = { downloadMenuOpen = false },92 ) {93 DetailDownloadOption.entries94 .filterNot { it == DetailDownloadOption.Selected }95 .forEach { option ->96 DropdownMenuItem(97 text = { Text(downloadOptionLabel(option, manga.itemType)) },98 leadingIcon = { Icon(Icons.Filled.Download, contentDescription = null) },99 onClick = {100 downloadMenuOpen = false101 onDownload(option)102 },103 )104 }105 }106 }107 }108 IconButton(onClick = onFilter) {109 Icon(110 Icons.Filled.FilterList,111 contentDescription = "Filter chapters",112 tint = if (filteringActive) Color(0xFFFFEB3B) else MaterialTheme.colorScheme.onSurfaceVariant,113 )114 }115 Box {116 IconButton(onClick = { overflowOpen = true }) {117 Icon(Icons.Filled.MoreVert, contentDescription = "More")118 }119 DropdownMenu(120 expanded = overflowOpen,121 onDismissRequest = { overflowOpen = false },122 ) {123 // Every entry closes the menu before acting.124 @Composable125 fun Entry(label: String, icon: ImageVector?, enabled: Boolean = true, onClick: () -> Unit) = DropdownMenuItem(126 text = { Text(label) },127 leadingIcon = icon?.let { { Icon(it, contentDescription = null) } },128 enabled = enabled,129 onClick = {130 overflowOpen = false131 onClick()132 },133 )134 if (showRemoteActions) Entry(stringResource(Res.string.action_refresh), Icons.Filled.Refresh) { onEvent(DetailEvent.Refresh) }135 Entry("Refresh metadata", Icons.Filled.Info, enabled = metadataEnabled) { onEvent(DetailEvent.RefreshMetadata) }136 if (canSetCategories) Entry("Set categories", Icons.AutoMirrored.Filled.Label, onClick = onSetCategories)137 if (manga.favorite) Entry(stringResource(Res.string.detail_notes), null) { onEvent(DetailEvent.EditNote) }138 if (showRemoteActions) {139 Entry(stringResource(Res.string.source_related_entries), null) { onNavigate(Route.SourceRelated(manga.id)) }140 Entry("Share", Icons.Filled.Share) { onEvent(DetailEvent.Share) }141 }142 Entry(143 when {144 togetherRoom == null -> if (manga.itemType == ItemType.Anime) "Watch together" else "Read together"145 togetherRoom.canAddToPlaylist -> "Add to room playlist"146 else -> "Suggest to room"147 },148 Icons.Filled.Groups,149 ) { onEvent(DetailEvent.Together) }150 Entry("Mass migrate", Icons.Filled.SyncAlt) {151 onNavigate(source?.let { Route.MassMigrationPreview(it.id) } ?: Route.MassMigration(manga.itemType))152 }153 if (showRemoteActions) {154 Entry("Extension settings", Icons.Filled.Settings, enabled = source != null) {155 source?.let { onNavigate(Route.ExtensionDetail(it.id)) }156 }157 }158 Entry("Export metadata", Icons.Filled.SaveAlt) { onEvent(DetailEvent.ExportMetadata) }159 }160 }161 },162 colors = TopAppBarDefaults.topAppBarColors(163 containerColor = if (showTitle) {164 MaterialTheme.colorScheme.surface.copy(alpha = 0.96f)165 } else {166 Color.Transparent167 },168 ),169 )170}171