Skip to content

Commit

Permalink
Add Quantity Badge to Upcoming Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Animeboynz committed Sep 18, 2024
1 parent be671b4 commit 16e8298
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions app/src/main/java/mihon/feature/upcoming/UpcomingScreenContent.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package mihon.feature.upcoming

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material3.Badge
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.font.FontWeight
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.relativeDateText
import eu.kanade.presentation.util.isTabletUi
import eu.kanade.tachiyomi.util.lang.toLocalDate
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.coroutines.launch
Expand All @@ -27,9 +35,9 @@ import tachiyomi.core.common.Constants
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.components.FastScrollLazyColumn
import tachiyomi.presentation.core.components.ListGroupHeader
import tachiyomi.presentation.core.components.TwoPanelBox
import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.components.material.padding
import tachiyomi.presentation.core.i18n.stringResource
import java.time.LocalDate
import java.time.YearMonth
Expand Down Expand Up @@ -99,6 +107,37 @@ private fun UpcomingToolbar() {
)
}

@Composable
private fun DateHeading(
date: LocalDate,
mangaCount: Int,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = relativeDateText(date),
modifier = Modifier
.padding(
start = MaterialTheme.padding.medium,
end = MaterialTheme.padding.small,
top = MaterialTheme.padding.small,
bottom = MaterialTheme.padding.small,
),
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontWeight = FontWeight.SemiBold,
style = MaterialTheme.typography.bodyMedium,
)
Badge(
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary,
) {
Text("$mangaCount")
}
}
}

@Composable
private fun UpcomingScreenSmallImpl(
listState: LazyListState,
Expand Down Expand Up @@ -140,7 +179,13 @@ private fun UpcomingScreenSmallImpl(
)
}
is UpcomingUIModel.Header -> {
ListGroupHeader(text = relativeDateText(item.date))
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }

DateHeading(
date = item.date,
mangaCount = mangaCount,
)
}
}
}
Expand Down Expand Up @@ -188,7 +233,13 @@ private fun UpcomingScreenLargeImpl(
)
}
is UpcomingUIModel.Header -> {
ListGroupHeader(text = relativeDateText(item.date))
val mangaCount = items.filterIsInstance<UpcomingUIModel.Item>()
.count { it.manga.expectedNextUpdate?.toLocalDate() == item.date }

DateHeading(
date = item.date,
mangaCount = mangaCount,
)
}
}
}
Expand Down

0 comments on commit 16e8298

Please sign in to comment.