Skip to content

Commit

Permalink
Fixed detekt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sirlag committed Feb 18, 2024
1 parent 0096618 commit e78ab8e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ fun UpcomingItem(
Icon(
imageVector = Icons.AutoMirrored.Outlined.OpenInNew,
contentDescription = "View Manga",

)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import eu.kanade.presentation.components.UpIcon
import eu.kanade.presentation.components.relativeDateText
import eu.kanade.presentation.updates.components.calendar.Calendar
import eu.kanade.tachiyomi.ui.updates.UpdateUpcomingScreenModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.launch
import tachiyomi.domain.manga.model.Manga
import tachiyomi.i18n.MR
Expand All @@ -30,14 +33,14 @@ import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.i18n.stringResource
import java.time.LocalDate


@Composable
fun UpdateUpcomingScreen(
state: UpdateUpcomingScreenModel.State,
modifier: Modifier = Modifier,
onClickUpcoming: (manga: Manga) -> Unit = {},
) {

Scaffold(
modifier = modifier,
topBar = {
UpdateUpcomingToolbar()
},
Expand All @@ -52,12 +55,16 @@ fun UpdateUpcomingScreen(
}
}

const val HELP_URL = "https://mihon.app/docs/faq/upcoming"
const val HelpUrl = "https://mihon.app/docs/faq/upcoming"

@Composable
internal fun UpdateUpcomingToolbar() {
internal fun UpdateUpcomingToolbar(
modifier: Modifier = Modifier,
) {
val navigator = LocalNavigator.currentOrThrow
Column {
Column(
modifier = modifier,
) {
TopAppBar(
navigationIcon = {
val canPop = remember { navigator.canPop }
Expand All @@ -70,7 +77,7 @@ internal fun UpdateUpcomingToolbar() {
title = { AppBarTitle(stringResource(MR.strings.label_upcoming)) },
actions = {
val uriHandler = LocalUriHandler.current
IconButton(onClick = { uriHandler.openUri(HELP_URL) }) {
IconButton(onClick = { uriHandler.openUri(HelpUrl) }) {
Icon(
imageVector = Icons.AutoMirrored.Outlined.HelpOutline,
contentDescription = stringResource(MR.strings.upcoming_guide),
Expand All @@ -83,12 +90,12 @@ internal fun UpdateUpcomingToolbar() {

@Composable
internal fun UpdateUpcomingContent(
upcoming: List<UpcomingUIModel>,
events: Map<LocalDate, Int> = mapOf(),
onClickUpcoming: (manga: Manga) -> Unit,
upcoming: ImmutableList<UpcomingUIModel>,
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
onClickUpcoming: (manga: Manga) -> Unit,
) {

val listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()

Expand All @@ -100,18 +107,18 @@ internal fun UpdateUpcomingContent(
FastScrollLazyColumn(
contentPadding = contentPadding,
state = listState,
modifier = modifier,
) {
item {
Calendar(
events = events,
onClickDay = { date ->
dateToHeaderMap[date]?.let {
coroutineScope.launch {
listState.animateScrollToItem(it)
}
) { date ->
dateToHeaderMap[date]?.let {
coroutineScope.launch {
listState.animateScrollToItem(it)
}
},
)
}
}
}
items(
items = upcoming,
Expand All @@ -138,7 +145,6 @@ internal fun UpdateUpcomingContent(
)
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.collections.immutable.ImmutableMap
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.Month
Expand All @@ -28,17 +29,18 @@ import java.util.Locale
private val CalenderPadding = 8.dp
private val FontSize = 16.sp
private val CalculatedHeight = 302.dp
private const val DAYS_OF_WEEK = 7
private const val DaysOfWeek = 7

@Composable
fun Calendar(
events: ImmutableMap<LocalDate, Int>,
modifier: Modifier = Modifier,
labelFormat: (DayOfWeek) -> String = {
it.getDisplayName(
TextStyle.SHORT,
Locale.getDefault(),
)
},
events: Map<LocalDate, Int>,
onClickDay: (day: LocalDate) -> Unit = {},
) {
val today = LocalDate.now()
Expand All @@ -53,7 +55,7 @@ fun Calendar(
val firstDayOfMonth = startDayOfMonth.dayOfWeek

Column(
modifier = Modifier
modifier = modifier
.wrapContentHeight()
.fillMaxWidth()
.padding(all = CalenderPadding),
Expand All @@ -75,7 +77,7 @@ fun Calendar(
modifier = Modifier
.fillMaxWidth()
.height(CalculatedHeight),
columns = GridCells.Fixed(DAYS_OF_WEEK),
columns = GridCells.Fixed(DaysOfWeek),
) {
items(weekValue) { item ->
Text(
Expand All @@ -88,7 +90,7 @@ fun Calendar(
}

items((getFirstDayOfMonth(firstDayOfMonth)..daysInMonth).toList()) {
if (it > 0 ) {
if (it > 0) {
val localDate = LocalDate.of(currentYear, currentMonth, it)
CalendarDay(
date = localDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import java.time.LocalDate

private const val MAX_EVENTS = 3
private const val MaxEvents = 3

@Composable
fun CalendarDay(
Expand All @@ -33,7 +33,6 @@ fun CalendarDay(
modifier: Modifier = Modifier,
events: Int = 0,
) {

val today = LocalDate.now()

val inThePast = date.isBefore(today)
Expand Down Expand Up @@ -67,7 +66,7 @@ fun CalendarDay(
fontWeight = FontWeight.SemiBold,
)
Row {
val size = minOf(events, MAX_EVENTS)
val size = minOf(events, MaxEvents)
for (i in (1..size)) {
Row {
CalendarIndicator(
Expand All @@ -77,7 +76,6 @@ fun CalendarDay(
)
}
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import java.time.Month
import java.time.format.TextStyle
import java.util.Locale


private val HEADER_PADDING = 8.dp

@Composable
Expand All @@ -51,7 +50,6 @@ fun CalenderHeader(
onNextClick: () -> Unit = {},
arrowShown: Boolean = true,
) {

var isNext by remember { mutableStateOf(true) }

Row(
Expand All @@ -61,8 +59,6 @@ fun CalenderHeader(
.padding(all = HEADER_PADDING),
horizontalArrangement = Arrangement.SpaceBetween,
) {


val titleText = remember(month, year) { getTitleText(month, year) }

AnimatedContent(
Expand All @@ -80,7 +76,6 @@ fun CalenderHeader(
)
}


if (arrowShown) {
Row(
modifier = Modifier
Expand Down Expand Up @@ -109,17 +104,12 @@ fun CalenderHeader(
modifier = Modifier
.wrapContentSize()
.clip(CircleShape),

) {
) {
Icon(Icons.Default.KeyboardArrowRight, stringResource(MR.strings.upcoming_calendar_next))
}
}
}


}


}

/**
Expand All @@ -139,7 +129,6 @@ private fun addAnimation(duration: Int = 200, isNext: Boolean): ContentTransform
) { height -> if (isNext) -height else height } + fadeOut(
animationSpec = tween(durationMillis = duration),
)

}

/**
Expand All @@ -159,9 +148,9 @@ private fun getTitleText(month: Month, year: Int): String {

@Preview
@Composable
fun CalenderHeaderPreview() {
private fun CalenderHeaderPreview() {
CalenderHeader(
month = Month.APRIL,
year = 2024
year = 2024,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

private const val INDICATOR_SCALE = 12
private const val IndicatorScale = 12

@Composable
fun CalendarIndicator(
Expand All @@ -26,6 +26,6 @@ fun CalendarIndicator(
.padding(horizontal = 1.dp)
.clip(shape = CircleShape)
.background(color = color.copy(alpha = (index + 1) * 0.3f))
.size(size = size.div(INDICATOR_SCALE)),
.size(size = size.div(IndicatorScale)),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.compose.runtime.getValue
import cafe.adriel.voyager.core.model.rememberScreenModel
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.util.Screen
import eu.kanade.presentation.updates.UpdateUpcomingScreen
import eu.kanade.presentation.util.Screen
import eu.kanade.tachiyomi.ui.manga.MangaScreen

class UpdateUpcomingScreen : Screen() {
Expand All @@ -26,6 +26,4 @@ class UpdateUpcomingScreen : Screen() {
onClickUpcoming = { navigator.push(MangaScreen(it.id)) },
)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import cafe.adriel.voyager.core.model.screenModelScope
import eu.kanade.core.util.insertSeparators
import eu.kanade.presentation.updates.UpcomingUIModel
import eu.kanade.tachiyomi.util.lang.toLocalDate
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import tachiyomi.domain.manga.interactor.GetUpcomingManga
Expand All @@ -15,7 +19,6 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.time.LocalDate


class UpdateUpcomingScreenModel(
private val getUpcomingManga: GetUpcomingManga = Injekt.get(),
) : StateScreenModel<UpdateUpcomingScreenModel.State>(State()) {
Expand All @@ -31,12 +34,11 @@ class UpdateUpcomingScreenModel(
events = events,
)
}

}
}

private fun List<Manga>.toUpcomingUIModels(): List<UpcomingUIModel> {
return mapIndexed { i, item -> UpcomingUIModel.Item(item) }
private fun List<Manga>.toUpcomingUIModels(): ImmutableList<UpcomingUIModel> {
return map { UpcomingUIModel.Item(it) }
.insertSeparators { before, after ->
val beforeDate = before?.item?.expectedNextUpdate?.toLocalDate() ?: LocalDate.MAX
val afterDate = after?.item?.expectedNextUpdate?.toLocalDate() ?: LocalDate.MAX
Expand All @@ -49,16 +51,18 @@ class UpdateUpcomingScreenModel(
else -> null
}
}
.toImmutableList()
}

private fun List<Manga>.toEvents(): Map<LocalDate, Int> {
private fun List<Manga>.toEvents(): ImmutableMap<LocalDate, Int> {
return groupBy { it.expectedNextUpdate?.toLocalDate() ?: LocalDate.MAX }
.mapValues { it.value.size }
.toImmutableMap()
}

data class State(
val items: List<UpcomingUIModel> = persistentListOf(),
val events: Map<LocalDate, Int> = persistentMapOf(),
val items: ImmutableList<UpcomingUIModel> = persistentListOf(),
val events: ImmutableMap<LocalDate, Int> = persistentMapOf(),
val headerIndexes: Map<LocalDate, Int> = persistentMapOf(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun Long.toLocalDate(): LocalDate {
}

fun Instant.toLocalDate(zoneId: ZoneId = ZoneId.systemDefault()): LocalDate {
return LocalDate.ofInstant(this, zoneId);
return LocalDate.ofInstant(this, zoneId)
}

fun LocalDate.toRelativeString(
Expand Down

0 comments on commit e78ab8e

Please sign in to comment.