Skip to content

Commit

Permalink
Move things around a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
nonproto committed Jan 16, 2025
1 parent 3bddd90 commit 3598f52
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class FeedPresenter(
downloadOnlyOnWifi = preferences.downloadOnlyOverWifi().get(),
)
)

val feedScreenState: StateFlow<FeedScreenState> = _feedScreenState.asStateFlow()

private var searchJob: Job? = null
Expand Down Expand Up @@ -259,7 +260,7 @@ class FeedPresenter(
it.copy(
allFeedManga =
it.allFeedManga
.filter { fm -> fm.mangaId != feedManga.mangaId }
.filter { fm -> (fm as FeedManga).mangaId != feedManga.mangaId }
.toImmutableList()
)
}
Expand Down Expand Up @@ -512,7 +513,7 @@ class FeedPresenter(
chapterId,
mangaId,
download,
_feedScreenState.value.searchFeedManga.toMutableList(),
_feedScreenState.value.searchFeedManga.map { it as FeedManga }.toList(),
)
if (searchFeedUpdated) {
_feedScreenState.update {
Expand All @@ -525,7 +526,7 @@ class FeedPresenter(
chapterId,
mangaId,
download,
_feedScreenState.value.allFeedManga.toMutableList(),
_feedScreenState.value.allFeedManga.map { it as FeedManga }.toList(),
)
if (feedUpdated) {
_feedScreenState.update { it.copy(allFeedManga = feedMangaList.toImmutableList()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data class FeedScreenState(
)

enum class FeedScreenType {
Summary,
History,
Updates,
}
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/java/org/nekomanga/presentation/screens/FeedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import eu.kanade.tachiyomi.ui.feed.DownloadScreenActions
import eu.kanade.tachiyomi.ui.feed.FeedHistoryGroup
import eu.kanade.tachiyomi.ui.feed.FeedScreenActions
import eu.kanade.tachiyomi.ui.feed.FeedScreenState
import eu.kanade.tachiyomi.ui.feed.FeedScreenType
Expand Down Expand Up @@ -234,9 +232,6 @@ fun FeedScreen(
contentPadding = recyclerContentPadding,
feedMangaList = feedManga,
hasMoreResults = hasMoreResults,
groupedBySeries =
feedScreenState.value.historyGrouping ==
FeedHistoryGroup.Series,
feedScreenType = feedScreenState.value.feedScreenType,
historyGrouping = feedScreenState.value.historyGrouping,
outlineCovers = feedScreenState.value.outlineCovers,
Expand Down Expand Up @@ -307,10 +302,18 @@ private fun ScreenFooter(
) {
LazyRow(
modifier = modifier.fillMaxWidth().padding(bottom = Size.smedium),
horizontalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(Size.tiny),
verticalAlignment = Alignment.CenterVertically,
) {
item { Gap(8.dp) }
item { Gap(Size.tiny) }

/* item {
FooterFilterChip(
selected = screenType == FeedScreenType.Summary && downloadsSelected == false,
onClick = { screenTypeClick(FeedScreenType.Summary) },
name = stringResource(R.string.summary),
)
}*/

item {
FooterFilterChip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private fun LazyListScope.historyContent(
modifier = Modifier.menuAnchor(),
)
ExposedDropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) {
FeedHistoryGroup.values().forEach { entry ->
FeedHistoryGroup.entries.forEach { entry ->
val textRes =
when (entry) {
FeedHistoryGroup.No -> R.string.group_no
Expand Down
197 changes: 30 additions & 167 deletions app/src/main/java/org/nekomanga/presentation/screens/feed/FeedPage.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package org.nekomanga.presentation.screens.feed

import android.text.format.DateUtils
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Bookmark
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -42,14 +32,15 @@ import eu.kanade.tachiyomi.ui.feed.FeedHistoryGroup
import eu.kanade.tachiyomi.ui.feed.FeedManga
import eu.kanade.tachiyomi.ui.feed.FeedScreenActions
import eu.kanade.tachiyomi.ui.feed.FeedScreenType
import java.util.Date
import jp.wasabeef.gap.Gap
import kotlinx.collections.immutable.ImmutableList
import org.nekomanga.R
import org.nekomanga.domain.manga.Artwork
import org.nekomanga.logging.TimberKt
import org.nekomanga.presentation.components.MangaCover
import org.nekomanga.presentation.components.NekoColors
import org.nekomanga.presentation.screens.feed.history.FeedHistoryPage
import org.nekomanga.presentation.screens.feed.summary.FeedSummaryPage
import org.nekomanga.presentation.screens.feed.updates.FeedUpdatesPage
import org.nekomanga.presentation.theme.Shapes
import org.nekomanga.presentation.theme.Size

Expand All @@ -59,168 +50,41 @@ fun FeedPage(
outlineCovers: Boolean,
outlineCards: Boolean,
hasMoreResults: Boolean,
groupedBySeries: Boolean,
updatesFetchSort: Boolean,
feedScreenActions: FeedScreenActions,
loadNextPage: () -> Unit,
feedScreenType: FeedScreenType,
historyGrouping: FeedHistoryGroup,
contentPadding: PaddingValues = PaddingValues(),
) {
val scrollState = rememberLazyListState()

val now = Date().time

var timeSpan by remember { mutableStateOf("") }
LazyColumn(
modifier = Modifier.fillMaxWidth(),
state = scrollState,
contentPadding = contentPadding,
) {
when (feedScreenType) {
FeedScreenType.History -> {
feedMangaList.forEach { feedManga ->
val dateString =
getDateString(
feedManga.chapters.first().chapter.lastRead,
now,
historyGrouping,
)
if (dateString.isNotEmpty() && timeSpan != dateString) {
timeSpan = dateString

item {
Text(
text = dateString,
style =
MaterialTheme.typography.labelLarge.copy(
color = MaterialTheme.colorScheme.tertiary
),
modifier =
Modifier.fillMaxWidth()
.padding(
start = Size.small,
end = Size.small,
top = Size.small,
bottom = Size.small,
),
)
}
} else {
item { Gap(Size.small) }
}

item {
HistoryCard(
feedManga = feedManga,
outlineCover = outlineCovers,
outlineCard = outlineCards,
groupedBySeries = groupedBySeries,
mangaClick = { feedScreenActions.mangaClick(feedManga.mangaId) },
chapterClick = { chapterId ->
feedScreenActions.chapterClick(feedManga.mangaId, chapterId)
},
deleteAllHistoryClick = {
feedScreenActions.deleteAllHistoryClick(feedManga)
},
deleteHistoryClick = { chp ->
feedScreenActions.deleteHistoryClick(feedManga, chp)
},
)
Gap(Size.tiny)
LaunchedEffect(scrollState) {
if (
hasMoreResults &&
feedMangaList.indexOf(feedManga) >= feedMangaList.size - 10
) {
loadNextPage()
}
}
}
}
}
FeedScreenType.Updates -> {
feedMangaList.forEach { feedManga ->
val dateString = getDateString(feedManga.date, now, isRecent = true)
// there should only ever be 1
feedManga.chapters.forEach { chapterItem ->
if (dateString.isNotEmpty() && timeSpan != dateString) {
timeSpan = dateString

val prefix =
when (updatesFetchSort) {
true -> R.string.fetched_
false -> R.string.updated_
}

item {
Text(
text = stringResource(id = prefix, dateString),
style =
MaterialTheme.typography.labelLarge.copy(
color = MaterialTheme.colorScheme.primary
),
modifier =
Modifier.padding(
start = Size.small,
top = Size.small,
end = Size.small,
),
)
}
}
item {
UpdatesCard(
chapterItem = chapterItem,
mangaTitle = feedManga.mangaTitle,
artwork = feedManga.artwork,
outlineCovers = outlineCovers,
mangaClick = { feedScreenActions.mangaClick(feedManga.mangaId) },
chapterClick = { chapterId ->
feedScreenActions.chapterClick(feedManga.mangaId, chapterId)
},
downloadClick = { action ->
feedScreenActions.downloadClick(chapterItem, feedManga, action)
},
)
LaunchedEffect(scrollState) {
if (
hasMoreResults &&
feedMangaList.indexOf(feedManga) >= feedMangaList.size - 10
) {
loadNextPage()
}
}
}
}
}
}
when (feedScreenType) {
FeedScreenType.Summary -> {
FeedSummaryPage(modifier = Modifier.fillMaxSize(), contentPadding = contentPadding)
}
}
}

private fun getDateString(
date: Long,
currentDate: Long,
historyGroupType: FeedHistoryGroup = FeedHistoryGroup.Day,
isRecent: Boolean = false,
): String {
if (historyGroupType == FeedHistoryGroup.No || historyGroupType == FeedHistoryGroup.Series) {
return ""
}

val dateType =
if (isRecent || historyGroupType == FeedHistoryGroup.Day) {
DateUtils.DAY_IN_MILLIS
} else {
DateUtils.WEEK_IN_MILLIS
FeedScreenType.History -> {
FeedHistoryPage(
modifier = Modifier.fillMaxSize(),
contentPadding = contentPadding,
feedHistoryMangaList = feedMangaList,
outlineCovers = outlineCovers,
outlineCards = outlineCards,
feedScreenActions = feedScreenActions,
loadNextPage = loadNextPage,
historyGrouping = historyGrouping,
)
}
FeedScreenType.Updates -> {
FeedUpdatesPage(
modifier = Modifier.fillMaxSize(),
contentPadding = contentPadding,
feedUpdatesMangaList = feedMangaList,
outlineCovers = outlineCovers,
hasMoreResults = hasMoreResults,
updatesFetchSort = updatesFetchSort,
feedScreenActions = feedScreenActions,
loadNextPage = loadNextPage,
)
}

val dateString = DateUtils.getRelativeTimeSpanString(date, currentDate, dateType).toString()
return if (dateString == "0 weeks ago") {
"This week"
} else {
dateString
}
}

Expand Down Expand Up @@ -257,7 +121,6 @@ fun FeedCover(
fun FeedChapterTitleLine(
language: String,
isBookmarked: Boolean,
chapterNumber: Float,
title: String,
style: TextStyle,
textColor: Color,
Expand Down
Loading

0 comments on commit 3598f52

Please sign in to comment.