Refactor duplicate chapter number formatters
This commit is contained in:
parent
7aa172c512
commit
2556e9f08c
6 changed files with 28 additions and 36 deletions
|
@ -21,12 +21,11 @@ import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.kanade.presentation.manga.components.MangaCover
|
import eu.kanade.presentation.manga.components.MangaCover
|
||||||
|
import eu.kanade.presentation.util.formatChapterNumber
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.lang.toTimestampString
|
import eu.kanade.tachiyomi.util.lang.toTimestampString
|
||||||
import tachiyomi.domain.history.model.HistoryWithRelations
|
import tachiyomi.domain.history.model.HistoryWithRelations
|
||||||
import tachiyomi.presentation.core.components.material.padding
|
import tachiyomi.presentation.core.components.material.padding
|
||||||
import java.text.DecimalFormat
|
|
||||||
import java.text.DecimalFormatSymbols
|
|
||||||
|
|
||||||
private val HISTORY_ITEM_HEIGHT = 96.dp
|
private val HISTORY_ITEM_HEIGHT = 96.dp
|
||||||
|
|
||||||
|
@ -68,7 +67,7 @@ fun HistoryItem(
|
||||||
text = if (history.chapterNumber > -1) {
|
text = if (history.chapterNumber > -1) {
|
||||||
stringResource(
|
stringResource(
|
||||||
R.string.recent_manga_time,
|
R.string.recent_manga_time,
|
||||||
chapterFormatter.format(history.chapterNumber),
|
formatChapterNumber(history.chapterNumber),
|
||||||
readAt,
|
readAt,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,8 +87,3 @@ fun HistoryItem(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val chapterFormatter = DecimalFormat(
|
|
||||||
"#.###",
|
|
||||||
DecimalFormatSymbols().apply { decimalSeparator = '.' },
|
|
||||||
)
|
|
||||||
|
|
|
@ -57,12 +57,12 @@ import eu.kanade.presentation.manga.components.MangaBottomActionMenu
|
||||||
import eu.kanade.presentation.manga.components.MangaChapterListItem
|
import eu.kanade.presentation.manga.components.MangaChapterListItem
|
||||||
import eu.kanade.presentation.manga.components.MangaInfoBox
|
import eu.kanade.presentation.manga.components.MangaInfoBox
|
||||||
import eu.kanade.presentation.manga.components.MangaToolbar
|
import eu.kanade.presentation.manga.components.MangaToolbar
|
||||||
|
import eu.kanade.presentation.util.formatChapterNumber
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.model.Download
|
import eu.kanade.tachiyomi.data.download.model.Download
|
||||||
import eu.kanade.tachiyomi.source.getNameForMangaInfo
|
import eu.kanade.tachiyomi.source.getNameForMangaInfo
|
||||||
import eu.kanade.tachiyomi.ui.manga.ChapterItem
|
import eu.kanade.tachiyomi.ui.manga.ChapterItem
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaScreenState
|
import eu.kanade.tachiyomi.ui.manga.MangaScreenState
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapterDecimalFormat
|
|
||||||
import eu.kanade.tachiyomi.util.lang.toRelativeString
|
import eu.kanade.tachiyomi.util.lang.toRelativeString
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
import tachiyomi.domain.chapter.model.Chapter
|
import tachiyomi.domain.chapter.model.Chapter
|
||||||
|
@ -722,7 +722,7 @@ private fun LazyListScope.sharedChapterItems(
|
||||||
title = if (manga.displayMode == Manga.CHAPTER_DISPLAY_NUMBER) {
|
title = if (manga.displayMode == Manga.CHAPTER_DISPLAY_NUMBER) {
|
||||||
stringResource(
|
stringResource(
|
||||||
R.string.display_mode_chapter,
|
R.string.display_mode_chapter,
|
||||||
chapterDecimalFormat.format(chapterItem.chapter.chapterNumber.toDouble()),
|
formatChapterNumber(chapterItem.chapter.chapterNumber),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
chapterItem.chapter.name
|
chapterItem.chapter.name
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package eu.kanade.presentation.util
|
||||||
|
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
import java.text.DecimalFormatSymbols
|
||||||
|
|
||||||
|
private val formatter = DecimalFormat(
|
||||||
|
"#.###",
|
||||||
|
DecimalFormatSymbols().apply { decimalSeparator = '.' },
|
||||||
|
)
|
||||||
|
|
||||||
|
fun formatChapterNumber(chapterNumber: Float): String {
|
||||||
|
return formatter.format(chapterNumber)
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import androidx.core.app.NotificationManagerCompat
|
||||||
import coil.imageLoader
|
import coil.imageLoader
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
import coil.transform.CircleCropTransformation
|
import coil.transform.CircleCropTransformation
|
||||||
|
import eu.kanade.presentation.util.formatChapterNumber
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||||
import eu.kanade.tachiyomi.data.download.Downloader
|
import eu.kanade.tachiyomi.data.download.Downloader
|
||||||
|
@ -29,8 +30,6 @@ import tachiyomi.core.util.lang.launchUI
|
||||||
import tachiyomi.domain.chapter.model.Chapter
|
import tachiyomi.domain.chapter.model.Chapter
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DecimalFormat
|
|
||||||
import java.text.DecimalFormatSymbols
|
|
||||||
|
|
||||||
class LibraryUpdateNotifier(private val context: Context) {
|
class LibraryUpdateNotifier(private val context: Context) {
|
||||||
|
|
||||||
|
@ -279,16 +278,10 @@ class LibraryUpdateNotifier(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNewChaptersDescription(chapters: Array<Chapter>): String {
|
private fun getNewChaptersDescription(chapters: Array<Chapter>): String {
|
||||||
val formatter = DecimalFormat(
|
|
||||||
"#.###",
|
|
||||||
DecimalFormatSymbols()
|
|
||||||
.apply { decimalSeparator = '.' },
|
|
||||||
)
|
|
||||||
|
|
||||||
val displayableChapterNumbers = chapters
|
val displayableChapterNumbers = chapters
|
||||||
.filter { it.isRecognizedNumber }
|
.filter { it.isRecognizedNumber }
|
||||||
.sortedBy { it.chapterNumber }
|
.sortedBy { it.chapterNumber }
|
||||||
.map { formatter.format(it.chapterNumber) }
|
.map { formatChapterNumber(it.chapterNumber) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
return when (displayableChapterNumbers.size) {
|
return when (displayableChapterNumbers.size) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ class MangaScreen(
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val haptic = LocalHapticFeedback.current
|
val haptic = LocalHapticFeedback.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val screenModel = rememberScreenModel { MangaInfoScreenModel(context, mangaId, fromSource) }
|
val screenModel = rememberScreenModel { MangaScreenModel(context, mangaId, fromSource) }
|
||||||
|
|
||||||
val state by screenModel.state.collectAsState()
|
val state by screenModel.state.collectAsState()
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class MangaScreen(
|
||||||
val onDismissRequest = { screenModel.dismissDialog() }
|
val onDismissRequest = { screenModel.dismissDialog() }
|
||||||
when (val dialog = successState.dialog) {
|
when (val dialog = successState.dialog) {
|
||||||
null -> {}
|
null -> {}
|
||||||
is MangaInfoScreenModel.Dialog.ChangeCategory -> {
|
is MangaScreenModel.Dialog.ChangeCategory -> {
|
||||||
ChangeCategoryDialog(
|
ChangeCategoryDialog(
|
||||||
initialSelection = dialog.initialSelection,
|
initialSelection = dialog.initialSelection,
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
|
@ -146,7 +146,7 @@ class MangaScreen(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is MangaInfoScreenModel.Dialog.DeleteChapters -> {
|
is MangaScreenModel.Dialog.DeleteChapters -> {
|
||||||
DeleteChaptersDialog(
|
DeleteChaptersDialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
onConfirm = {
|
onConfirm = {
|
||||||
|
@ -155,12 +155,12 @@ class MangaScreen(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is MangaInfoScreenModel.Dialog.DuplicateManga -> DuplicateMangaDialog(
|
is MangaScreenModel.Dialog.DuplicateManga -> DuplicateMangaDialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
onConfirm = { screenModel.toggleFavorite(onRemoved = {}, checkDuplicate = false) },
|
onConfirm = { screenModel.toggleFavorite(onRemoved = {}, checkDuplicate = false) },
|
||||||
onOpenManga = { navigator.push(MangaScreen(dialog.duplicate.id)) },
|
onOpenManga = { navigator.push(MangaScreen(dialog.duplicate.id)) },
|
||||||
)
|
)
|
||||||
MangaInfoScreenModel.Dialog.SettingsSheet -> ChapterSettingsDialog(
|
MangaScreenModel.Dialog.SettingsSheet -> ChapterSettingsDialog(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
manga = successState.manga,
|
manga = successState.manga,
|
||||||
onDownloadFilterChanged = screenModel::setDownloadedFilter,
|
onDownloadFilterChanged = screenModel::setDownloadedFilter,
|
||||||
|
@ -170,7 +170,7 @@ class MangaScreen(
|
||||||
onDisplayModeChanged = screenModel::setDisplayMode,
|
onDisplayModeChanged = screenModel::setDisplayMode,
|
||||||
onSetAsDefault = screenModel::setCurrentSettingsAsDefault,
|
onSetAsDefault = screenModel::setCurrentSettingsAsDefault,
|
||||||
)
|
)
|
||||||
MangaInfoScreenModel.Dialog.TrackSheet -> {
|
MangaScreenModel.Dialog.TrackSheet -> {
|
||||||
NavigatorAdaptiveSheet(
|
NavigatorAdaptiveSheet(
|
||||||
screen = TrackInfoDialogHomeScreen(
|
screen = TrackInfoDialogHomeScreen(
|
||||||
mangaId = successState.manga.id,
|
mangaId = successState.manga.id,
|
||||||
|
@ -181,7 +181,7 @@ class MangaScreen(
|
||||||
onDismissRequest = onDismissRequest,
|
onDismissRequest = onDismissRequest,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MangaInfoScreenModel.Dialog.FullCover -> {
|
MangaScreenModel.Dialog.FullCover -> {
|
||||||
val sm = rememberScreenModel { MangaCoverScreenModel(successState.manga.id) }
|
val sm = rememberScreenModel { MangaCoverScreenModel(successState.manga.id) }
|
||||||
val manga by sm.state.collectAsState()
|
val manga by sm.state.collectAsState()
|
||||||
if (manga != null) {
|
if (manga != null) {
|
||||||
|
|
|
@ -74,10 +74,8 @@ import tachiyomi.domain.track.interactor.GetTracks
|
||||||
import tachiyomi.source.local.isLocal
|
import tachiyomi.source.local.isLocal
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.text.DecimalFormat
|
|
||||||
import java.text.DecimalFormatSymbols
|
|
||||||
|
|
||||||
class MangaInfoScreenModel(
|
class MangaScreenModel(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
val mangaId: Long,
|
val mangaId: Long,
|
||||||
private val isFromSource: Boolean,
|
private val isFromSource: Boolean,
|
||||||
|
@ -984,7 +982,7 @@ sealed class MangaScreenState {
|
||||||
val chapters: List<ChapterItem>,
|
val chapters: List<ChapterItem>,
|
||||||
val trackItems: List<TrackItem> = emptyList(),
|
val trackItems: List<TrackItem> = emptyList(),
|
||||||
val isRefreshingData: Boolean = false,
|
val isRefreshingData: Boolean = false,
|
||||||
val dialog: MangaInfoScreenModel.Dialog? = null,
|
val dialog: MangaScreenModel.Dialog? = null,
|
||||||
val hasPromptedToAddBefore: Boolean = false,
|
val hasPromptedToAddBefore: Boolean = false,
|
||||||
) : MangaScreenState() {
|
) : MangaScreenState() {
|
||||||
|
|
||||||
|
@ -1025,9 +1023,3 @@ data class ChapterItem(
|
||||||
) {
|
) {
|
||||||
val isDownloaded = downloadState == Download.State.DOWNLOADED
|
val isDownloaded = downloadState == Download.State.DOWNLOADED
|
||||||
}
|
}
|
||||||
|
|
||||||
val chapterDecimalFormat = DecimalFormat(
|
|
||||||
"#.###",
|
|
||||||
DecimalFormatSymbols()
|
|
||||||
.apply { decimalSeparator = '.' },
|
|
||||||
)
|
|
||||||
|
|
Reference in a new issue