diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt index b1d117186..08ce2635b 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt @@ -21,12 +21,11 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import eu.kanade.presentation.manga.components.MangaCover +import eu.kanade.presentation.util.formatChapterNumber import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.lang.toTimestampString import tachiyomi.domain.history.model.HistoryWithRelations import tachiyomi.presentation.core.components.material.padding -import java.text.DecimalFormat -import java.text.DecimalFormatSymbols private val HISTORY_ITEM_HEIGHT = 96.dp @@ -68,7 +67,7 @@ fun HistoryItem( text = if (history.chapterNumber > -1) { stringResource( R.string.recent_manga_time, - chapterFormatter.format(history.chapterNumber), + formatChapterNumber(history.chapterNumber), readAt, ) } else { @@ -88,8 +87,3 @@ fun HistoryItem( } } } - -private val chapterFormatter = DecimalFormat( - "#.###", - DecimalFormatSymbols().apply { decimalSeparator = '.' }, -) diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index 2a1c9882a..7b2696561 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -57,12 +57,12 @@ import eu.kanade.presentation.manga.components.MangaBottomActionMenu import eu.kanade.presentation.manga.components.MangaChapterListItem import eu.kanade.presentation.manga.components.MangaInfoBox import eu.kanade.presentation.manga.components.MangaToolbar +import eu.kanade.presentation.util.formatChapterNumber import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.source.getNameForMangaInfo import eu.kanade.tachiyomi.ui.manga.ChapterItem 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.system.copyToClipboard import tachiyomi.domain.chapter.model.Chapter @@ -722,7 +722,7 @@ private fun LazyListScope.sharedChapterItems( title = if (manga.displayMode == Manga.CHAPTER_DISPLAY_NUMBER) { stringResource( R.string.display_mode_chapter, - chapterDecimalFormat.format(chapterItem.chapter.chapterNumber.toDouble()), + formatChapterNumber(chapterItem.chapter.chapterNumber), ) } else { chapterItem.chapter.name diff --git a/app/src/main/java/eu/kanade/presentation/util/ChapterNumberFormatter.kt b/app/src/main/java/eu/kanade/presentation/util/ChapterNumberFormatter.kt new file mode 100644 index 000000000..eafeb3884 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/util/ChapterNumberFormatter.kt @@ -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) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index 8eb1bbb75..6b530a171 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -13,6 +13,7 @@ import androidx.core.app.NotificationManagerCompat import coil.imageLoader import coil.request.ImageRequest import coil.transform.CircleCropTransformation +import eu.kanade.presentation.util.formatChapterNumber import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.core.security.SecurityPreferences 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.manga.model.Manga import uy.kohesive.injekt.injectLazy -import java.text.DecimalFormat -import java.text.DecimalFormatSymbols class LibraryUpdateNotifier(private val context: Context) { @@ -279,16 +278,10 @@ class LibraryUpdateNotifier(private val context: Context) { } private fun getNewChaptersDescription(chapters: Array): String { - val formatter = DecimalFormat( - "#.###", - DecimalFormatSymbols() - .apply { decimalSeparator = '.' }, - ) - val displayableChapterNumbers = chapters .filter { it.isRecognizedNumber } .sortedBy { it.chapterNumber } - .map { formatter.format(it.chapterNumber) } + .map { formatChapterNumber(it.chapterNumber) } .toSet() return when (displayableChapterNumbers.size) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index 33244db67..7792de3e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -71,7 +71,7 @@ class MangaScreen( val context = LocalContext.current val haptic = LocalHapticFeedback.current val scope = rememberCoroutineScope() - val screenModel = rememberScreenModel { MangaInfoScreenModel(context, mangaId, fromSource) } + val screenModel = rememberScreenModel { MangaScreenModel(context, mangaId, fromSource) } val state by screenModel.state.collectAsState() @@ -136,7 +136,7 @@ class MangaScreen( val onDismissRequest = { screenModel.dismissDialog() } when (val dialog = successState.dialog) { null -> {} - is MangaInfoScreenModel.Dialog.ChangeCategory -> { + is MangaScreenModel.Dialog.ChangeCategory -> { ChangeCategoryDialog( initialSelection = dialog.initialSelection, onDismissRequest = onDismissRequest, @@ -146,7 +146,7 @@ class MangaScreen( }, ) } - is MangaInfoScreenModel.Dialog.DeleteChapters -> { + is MangaScreenModel.Dialog.DeleteChapters -> { DeleteChaptersDialog( onDismissRequest = onDismissRequest, onConfirm = { @@ -155,12 +155,12 @@ class MangaScreen( }, ) } - is MangaInfoScreenModel.Dialog.DuplicateManga -> DuplicateMangaDialog( + is MangaScreenModel.Dialog.DuplicateManga -> DuplicateMangaDialog( onDismissRequest = onDismissRequest, onConfirm = { screenModel.toggleFavorite(onRemoved = {}, checkDuplicate = false) }, onOpenManga = { navigator.push(MangaScreen(dialog.duplicate.id)) }, ) - MangaInfoScreenModel.Dialog.SettingsSheet -> ChapterSettingsDialog( + MangaScreenModel.Dialog.SettingsSheet -> ChapterSettingsDialog( onDismissRequest = onDismissRequest, manga = successState.manga, onDownloadFilterChanged = screenModel::setDownloadedFilter, @@ -170,7 +170,7 @@ class MangaScreen( onDisplayModeChanged = screenModel::setDisplayMode, onSetAsDefault = screenModel::setCurrentSettingsAsDefault, ) - MangaInfoScreenModel.Dialog.TrackSheet -> { + MangaScreenModel.Dialog.TrackSheet -> { NavigatorAdaptiveSheet( screen = TrackInfoDialogHomeScreen( mangaId = successState.manga.id, @@ -181,7 +181,7 @@ class MangaScreen( onDismissRequest = onDismissRequest, ) } - MangaInfoScreenModel.Dialog.FullCover -> { + MangaScreenModel.Dialog.FullCover -> { val sm = rememberScreenModel { MangaCoverScreenModel(successState.manga.id) } val manga by sm.state.collectAsState() if (manga != null) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index cb8a6e527..c1662c697 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -74,10 +74,8 @@ import tachiyomi.domain.track.interactor.GetTracks import tachiyomi.source.local.isLocal import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import java.text.DecimalFormat -import java.text.DecimalFormatSymbols -class MangaInfoScreenModel( +class MangaScreenModel( val context: Context, val mangaId: Long, private val isFromSource: Boolean, @@ -984,7 +982,7 @@ sealed class MangaScreenState { val chapters: List, val trackItems: List = emptyList(), val isRefreshingData: Boolean = false, - val dialog: MangaInfoScreenModel.Dialog? = null, + val dialog: MangaScreenModel.Dialog? = null, val hasPromptedToAddBefore: Boolean = false, ) : MangaScreenState() { @@ -1025,9 +1023,3 @@ data class ChapterItem( ) { val isDownloaded = downloadState == Download.State.DOWNLOADED } - -val chapterDecimalFormat = DecimalFormat( - "#.###", - DecimalFormatSymbols() - .apply { decimalSeparator = '.' }, -)