Compare commits

...

4 Commits

Author SHA1 Message Date
Matthew Witman
61afdbb9c3 Cleaned up date formatter 2024-03-23 14:05:54 -04:00
Matthew Witman
8b7b53b36f Switched to Date Formatter 2024-03-23 14:05:02 -04:00
Matthew Witman
376dcdc4e3 Merge branch 'update-calendar' of https://github.com/sirlag/mihon into update-calendar 2024-03-23 12:22:17 -04:00
Matthew Witman
41c04f9b06 Tweaks to query, refactored to flow, comments on calendar 2024-03-23 12:20:24 -04:00
11 changed files with 45 additions and 43 deletions

View File

@@ -27,6 +27,7 @@ import eu.kanade.presentation.components.AppBarTitle
import eu.kanade.presentation.components.UpIcon
import eu.kanade.presentation.components.relativeDateText
import eu.kanade.presentation.updates.components.calendar.Calendar
import eu.kanade.presentation.util.isTabletUi
import eu.kanade.tachiyomi.ui.updates.UpdateUpcomingScreenModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableMap
@@ -45,19 +46,18 @@ import java.time.LocalDate
fun UpdateUpcomingScreen(
state: UpdateUpcomingScreenModel.State,
modifier: Modifier = Modifier,
isTabletUi: Boolean = false,
onClickUpcoming: (manga: Manga) -> Unit = {},
) {
if (!isTabletUi) {
UpdateUpcomingScreenSmallImpl(
if (isTabletUi()) {
UpdateUpcomingScreenLargeImpl(
state = state,
isTabletUi = true,
modifier = modifier,
onClickUpcoming = onClickUpcoming,
)
} else {
UpdateUpcomingScreenLargeImpl(
UpdateUpcomingScreenSmallImpl(
state = state,
isTabletUi = isTabletUi,
modifier = modifier,
onClickUpcoming = onClickUpcoming,
)

View File

@@ -97,19 +97,18 @@ private fun getBorder(currentDay: Boolean, color: Color): BorderStroke {
}
}
private fun Modifier.circleLayout() =
layout { measurable, constraints ->
// Measure the composable
val placeable = measurable.measure(constraints)
private fun Modifier.circleLayout() = layout { measurable, constraints ->
// Measure the composable
val placeable = measurable.measure(constraints)
// get the current max dimension to assign width=height
val currentHeight = placeable.height
val currentWidth = placeable.width
val newDiameter = maxOf(currentHeight, currentWidth)
// get the current max dimension to assign width=height
val currentHeight = placeable.height
val currentWidth = placeable.width
val newDiameter = maxOf(currentHeight, currentWidth)
// assign the dimension and the center position
layout(newDiameter, newDiameter) {
// Where the composable gets placed
placeable.placeRelative((newDiameter - currentWidth) / 2, (newDiameter - currentHeight) / 2)
}
// assign the dimension and the center position
layout(newDiameter, newDiameter) {
// Where the composable gets placed
placeable.placeRelative((newDiameter - currentWidth) / 2, (newDiameter - currentHeight) / 2)
}
}

View File

@@ -35,8 +35,9 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
import java.time.LocalDate
import java.time.Month
import java.time.format.TextStyle
import java.time.format.DateTimeFormatter
import java.util.Locale
private val HEADER_PADDING = 8.dp
@@ -119,15 +120,17 @@ fun CalenderHeader(
* @return The content transformation with the specified animation.
*/
private fun addAnimation(duration: Int = 200, isNext: Boolean): ContentTransform {
return slideInVertically(
val enterTransition = slideInVertically(
animationSpec = tween(durationMillis = duration),
) { height -> if (isNext) height else -height } + fadeIn(
animationSpec = tween(durationMillis = duration),
) togetherWith slideOutVertically(
)
val exitTransition = slideOutVertically(
animationSpec = tween(durationMillis = duration),
) { height -> if (isNext) -height else height } + fadeOut(
animationSpec = tween(durationMillis = duration),
)
return enterTransition togetherWith exitTransition
}
/**
@@ -138,11 +141,8 @@ private fun addAnimation(duration: Int = 200, isNext: Boolean): ContentTransform
* @return The formatted title text.
*/
private fun getTitleText(month: Month, year: Int): String {
val monthDisplayName = month.getDisplayName(TextStyle.FULL, Locale.getDefault())
.lowercase()
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
val shortYear = year.toString().takeLast(2)
return "$monthDisplayName '$shortYear"
val formatter = DateTimeFormatter.ofPattern("MMMM yy", Locale.getDefault())
return formatter.format(LocalDate.of(year, month, 1))
}
@Preview

View File

@@ -13,6 +13,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
private const val IndicatorScale = 12
private const val IndicatorAlphaMultiplier = 0.3f
@Composable
fun CalendarIndicator(
@@ -25,7 +26,7 @@ fun CalendarIndicator(
modifier = modifier
.padding(horizontal = 1.dp)
.clip(shape = CircleShape)
.background(color = color.copy(alpha = (index + 1) * 0.3f))
.background(color = color.copy(alpha = (index + 1) * IndicatorAlphaMultiplier))
.size(size = size.div(IndicatorScale)),
)
}

View File

@@ -8,7 +8,6 @@ import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.updates.UpdateUpcomingScreen
import eu.kanade.presentation.util.Screen
import eu.kanade.presentation.util.isTabletUi
import eu.kanade.tachiyomi.ui.manga.MangaScreen
class UpdateUpcomingScreen : Screen() {
@@ -24,7 +23,6 @@ class UpdateUpcomingScreen : Screen() {
UpdateUpcomingScreen(
state = state,
isTabletUi = isTabletUi(),
onClickUpcoming = { navigator.push(MangaScreen(it.id)) },
)
}

View File

@@ -11,6 +11,7 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import tachiyomi.domain.manga.interactor.GetUpcomingManga
@@ -25,14 +26,15 @@ class UpdateUpcomingScreenModel(
init {
screenModelScope.launch {
val manga = getUpcomingManga.await()
val items = manga.toUpcomingUIModels()
val events = manga.toEvents()
mutableState.update {
it.copy(
items = items,
events = events,
)
getUpcomingManga.subscribe().collectLatest {
val items = it.toUpcomingUIModels()
val events = it.toEvents()
mutableState.update { state ->
state.copy(
items = items,
events = events,
)
}
}
}
}

View File

@@ -65,9 +65,9 @@ class MangaRepositoryImpl(
}
}
override suspend fun getUpcomingManga(statues: Set<Long>): List<Manga> {
return handler.awaitList {
mangasQueries.getUpcomingManga(statues, MangaMapper::mapManga)
override suspend fun getUpcomingManga(statuses: Set<Long>): Flow<List<Manga>> {
return handler.subscribeToList {
mangasQueries.getUpcomingManga(statuses, MangaMapper::mapManga)
}
}

View File

@@ -117,7 +117,7 @@ SELECT *
FROM mangas
WHERE next_update > 0
AND favorite = 1
AND status IN ?
AND status IN :statuses
ORDER BY next_update ASC;
resetViewerFlags:

View File

@@ -1,6 +1,7 @@
package tachiyomi.domain.manga.interactor
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.manga.repository.MangaRepository
@@ -13,7 +14,7 @@ class GetUpcomingManga(
SManga.PUBLISHING_FINISHED.toLong(),
)
suspend fun await(): List<Manga> {
suspend fun subscribe(): Flow<List<Manga>> {
return mangaRepository.getUpcomingManga(includedStatuses)
}
}

View File

@@ -25,7 +25,7 @@ interface MangaRepository {
suspend fun getDuplicateLibraryManga(id: Long, title: String): List<Manga>
suspend fun getUpcomingManga(statues: Set<Long>): List<Manga>
suspend fun getUpcomingManga(statuses: Set<Long>): Flow<List<Manga>>
suspend fun resetViewerFlags(): Boolean

View File

@@ -790,6 +790,7 @@
<string name="action_view_upcoming">View Upcoming Updates</string>
<!-- Upcoming -->
<string name="calendar_title_format">%1$s %2$s</string>
<string name="upcoming_guide">Upcoming Guide</string>
<string name="upcoming_calendar_next">Next Month</string>
<string name="upcoming_calendar_prev">Previous Month</string>