2022-07-18 08:17:40 +06:00
|
|
|
package eu.kanade.presentation.updates
|
|
|
|
|
2022-08-29 14:57:25 -04:00
|
|
|
import android.text.format.DateUtils
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.combinedClickable
|
2022-08-29 14:57:25 -04:00
|
|
|
import androidx.compose.foundation.layout.Box
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.foundation.layout.sizeIn
|
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
|
import androidx.compose.foundation.lazy.LazyListScope
|
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
import androidx.compose.material.icons.filled.Bookmark
|
|
|
|
import androidx.compose.material3.Icon
|
2022-08-29 14:57:25 -04:00
|
|
|
import androidx.compose.material3.LocalTextStyle
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
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.alpha
|
|
|
|
import androidx.compose.ui.graphics.Color
|
2022-07-30 21:50:00 +06:00
|
|
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.ui.platform.LocalDensity
|
2022-07-30 21:50:00 +06:00
|
|
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.ui.res.stringResource
|
2022-08-29 14:57:25 -04:00
|
|
|
import androidx.compose.ui.text.font.FontStyle
|
2022-07-18 08:17:40 +06:00
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import eu.kanade.domain.updates.model.UpdatesWithRelations
|
|
|
|
import eu.kanade.presentation.components.ChapterDownloadAction
|
|
|
|
import eu.kanade.presentation.components.ChapterDownloadIndicator
|
|
|
|
import eu.kanade.presentation.components.MangaCover
|
|
|
|
import eu.kanade.presentation.components.RelativeDateHeader
|
|
|
|
import eu.kanade.presentation.util.ReadItemAlpha
|
|
|
|
import eu.kanade.presentation.util.horizontalPadding
|
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
import eu.kanade.tachiyomi.data.download.model.Download
|
|
|
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesItem
|
|
|
|
import java.text.DateFormat
|
2022-08-29 14:57:25 -04:00
|
|
|
import java.util.Date
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun UpdatesLastUpdatedItem(
|
|
|
|
lastUpdated: Long,
|
|
|
|
) {
|
|
|
|
val time = remember(lastUpdated) {
|
|
|
|
DateUtils.getRelativeTimeSpanString(lastUpdated, Date().time, DateUtils.MINUTE_IN_MILLIS)
|
|
|
|
}
|
|
|
|
|
|
|
|
Box(
|
|
|
|
modifier = Modifier
|
|
|
|
.padding(horizontal = horizontalPadding, vertical = 8.dp),
|
|
|
|
) {
|
|
|
|
Text(
|
|
|
|
text = stringResource(R.string.updates_last_update_info, time),
|
|
|
|
style = LocalTextStyle.current.copy(
|
|
|
|
fontStyle = FontStyle.Italic,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-07-18 08:17:40 +06:00
|
|
|
|
|
|
|
fun LazyListScope.updatesUiItems(
|
|
|
|
uiModels: List<UpdatesUiModel>,
|
2022-07-30 21:50:00 +06:00
|
|
|
selectionMode: Boolean,
|
|
|
|
onUpdateSelected: (UpdatesItem, Boolean, Boolean, Boolean) -> Unit,
|
2022-07-18 08:17:40 +06:00
|
|
|
onClickCover: (UpdatesItem) -> Unit,
|
|
|
|
onClickUpdate: (UpdatesItem) -> Unit,
|
|
|
|
onDownloadChapter: (List<UpdatesItem>, ChapterDownloadAction) -> Unit,
|
|
|
|
relativeTime: Int,
|
|
|
|
dateFormat: DateFormat,
|
|
|
|
) {
|
|
|
|
items(
|
|
|
|
items = uiModels,
|
|
|
|
contentType = {
|
|
|
|
when (it) {
|
|
|
|
is UpdatesUiModel.Header -> "header"
|
|
|
|
is UpdatesUiModel.Item -> "item"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
key = {
|
|
|
|
when (it) {
|
|
|
|
is UpdatesUiModel.Header -> it.hashCode()
|
|
|
|
is UpdatesUiModel.Item -> it.item.update.chapterId
|
|
|
|
}
|
|
|
|
},
|
|
|
|
) { item ->
|
|
|
|
when (item) {
|
|
|
|
is UpdatesUiModel.Header -> {
|
|
|
|
RelativeDateHeader(
|
|
|
|
modifier = Modifier.animateItemPlacement(),
|
|
|
|
date = item.date,
|
|
|
|
relativeTime = relativeTime,
|
|
|
|
dateFormat = dateFormat,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
is UpdatesUiModel.Item -> {
|
2022-07-30 21:50:00 +06:00
|
|
|
val updatesItem = item.item
|
|
|
|
val update = updatesItem.update
|
2022-07-18 08:17:40 +06:00
|
|
|
UpdatesUiItem(
|
|
|
|
modifier = Modifier.animateItemPlacement(),
|
|
|
|
update = update,
|
2022-07-30 21:50:00 +06:00
|
|
|
selected = updatesItem.selected,
|
2022-07-18 08:17:40 +06:00
|
|
|
onLongClick = {
|
2022-07-30 21:50:00 +06:00
|
|
|
onUpdateSelected(updatesItem, !updatesItem.selected, true, true)
|
|
|
|
},
|
|
|
|
onClick = {
|
|
|
|
when {
|
|
|
|
selectionMode -> onUpdateSelected(updatesItem, !updatesItem.selected, true, false)
|
|
|
|
else -> onClickUpdate(updatesItem)
|
|
|
|
}
|
2022-07-18 08:17:40 +06:00
|
|
|
},
|
2022-07-30 21:50:00 +06:00
|
|
|
onClickCover = { if (selectionMode.not()) onClickCover(updatesItem) },
|
2022-07-18 08:17:40 +06:00
|
|
|
onDownloadChapter = {
|
2022-07-30 21:50:00 +06:00
|
|
|
if (selectionMode.not()) onDownloadChapter(listOf(updatesItem), it)
|
2022-07-18 08:17:40 +06:00
|
|
|
},
|
2022-07-30 21:50:00 +06:00
|
|
|
downloadStateProvider = updatesItem.downloadStateProvider,
|
|
|
|
downloadProgressProvider = updatesItem.downloadProgressProvider,
|
2022-07-18 08:17:40 +06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun UpdatesUiItem(
|
|
|
|
modifier: Modifier,
|
|
|
|
update: UpdatesWithRelations,
|
|
|
|
selected: Boolean,
|
|
|
|
onClick: () -> Unit,
|
|
|
|
onLongClick: () -> Unit,
|
|
|
|
onClickCover: () -> Unit,
|
|
|
|
onDownloadChapter: (ChapterDownloadAction) -> Unit,
|
|
|
|
// Download Indicator
|
|
|
|
downloadStateProvider: () -> Download.State,
|
|
|
|
downloadProgressProvider: () -> Int,
|
|
|
|
) {
|
2022-07-30 21:50:00 +06:00
|
|
|
val haptic = LocalHapticFeedback.current
|
2022-07-18 08:17:40 +06:00
|
|
|
Row(
|
|
|
|
modifier = modifier
|
|
|
|
.background(if (selected) MaterialTheme.colorScheme.surfaceVariant else Color.Transparent)
|
|
|
|
.combinedClickable(
|
|
|
|
onClick = onClick,
|
2022-07-30 21:50:00 +06:00
|
|
|
onLongClick = {
|
|
|
|
onLongClick()
|
|
|
|
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
|
|
|
|
},
|
2022-07-18 08:17:40 +06:00
|
|
|
)
|
|
|
|
.height(56.dp)
|
|
|
|
.padding(horizontal = horizontalPadding),
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
) {
|
|
|
|
MangaCover.Square(
|
|
|
|
modifier = Modifier
|
|
|
|
.padding(vertical = 6.dp)
|
|
|
|
.fillMaxHeight(),
|
|
|
|
data = update.coverData,
|
|
|
|
onClick = onClickCover,
|
|
|
|
)
|
|
|
|
Column(
|
|
|
|
modifier = Modifier
|
|
|
|
.padding(horizontal = horizontalPadding)
|
|
|
|
.weight(1f),
|
|
|
|
) {
|
|
|
|
val bookmark = remember(update.bookmark) { update.bookmark }
|
|
|
|
val read = remember(update.read) { update.read }
|
|
|
|
|
|
|
|
val textAlpha = remember(read) { if (read) ReadItemAlpha else 1f }
|
|
|
|
|
|
|
|
val secondaryTextColor = if (bookmark && !read) {
|
|
|
|
MaterialTheme.colorScheme.primary
|
|
|
|
} else {
|
|
|
|
MaterialTheme.colorScheme.onSurface
|
|
|
|
}
|
|
|
|
|
|
|
|
Text(
|
|
|
|
text = update.mangaTitle,
|
|
|
|
maxLines = 1,
|
|
|
|
style = MaterialTheme.typography.bodyMedium,
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
modifier = Modifier.alpha(textAlpha),
|
|
|
|
)
|
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
|
var textHeight by remember { mutableStateOf(0) }
|
|
|
|
if (bookmark) {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.Default.Bookmark,
|
|
|
|
contentDescription = stringResource(R.string.action_filter_bookmarked),
|
|
|
|
modifier = Modifier
|
|
|
|
.sizeIn(maxHeight = with(LocalDensity.current) { textHeight.toDp() - 2.dp }),
|
|
|
|
tint = MaterialTheme.colorScheme.primary,
|
|
|
|
)
|
|
|
|
Spacer(modifier = Modifier.width(2.dp))
|
|
|
|
}
|
|
|
|
Text(
|
|
|
|
text = update.chapterName,
|
|
|
|
maxLines = 1,
|
|
|
|
style = MaterialTheme.typography.bodySmall
|
|
|
|
.copy(color = secondaryTextColor),
|
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
|
onTextLayout = { textHeight = it.size.height },
|
|
|
|
modifier = Modifier.alpha(textAlpha),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ChapterDownloadIndicator(
|
|
|
|
modifier = Modifier.padding(start = 4.dp),
|
|
|
|
downloadStateProvider = downloadStateProvider,
|
|
|
|
downloadProgressProvider = downloadProgressProvider,
|
|
|
|
onClick = onDownloadChapter,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|