Automatic Lint

This commit is contained in:
Syer10
2024-03-29 00:16:52 +00:00
parent 253095fab1
commit b93c96a85b
48 changed files with 204 additions and 145 deletions

View File

@@ -117,12 +117,14 @@ fun ChapterDownloadIcon(
onClick = { onClickDelete(chapter.chapter) },
)
}
ChapterDownloadState.Downloading -> {
DownloadingIconButton(
downloadChapter,
onClick = { onClickStop(chapter.chapter) },
)
}
ChapterDownloadState.NotDownloaded -> {
DownloadIconButton(onClick = { onClickDownload(chapter.chapter) })
}
@@ -172,6 +174,7 @@ private fun DownloadingIconButton(
LocalContentColor.current.copy(alpha = ContentAlpha.disabled),
2.dp,
)
DownloadState.Downloading -> if (downloadChapter.progress != 0.0F) {
val animatedProgress by animateFloatAsState(
targetValue = downloadChapter.progress,
@@ -202,6 +205,7 @@ private fun DownloadingIconButton(
2.dp,
)
}
DownloadState.Error -> Surface(shape = CircleShape, color = LocalContentColor.current) {
Icon(
Icons.Rounded.Error,
@@ -212,6 +216,7 @@ private fun DownloadingIconButton(
Color.Red,
)
}
DownloadState.Finished -> Surface(shape = CircleShape, color = LocalContentColor.current) {
Icon(
Icons.Rounded.Check,

View File

@@ -40,8 +40,8 @@ class ImageLoaderProvider
@OptIn(DelicateCoroutinesApi::class)
val serverUrl = serverPreferences.serverUrl().stateIn(GlobalScope)
fun get(imageCache: ImageCache): ImageLoader {
return ImageLoader {
fun get(imageCache: ImageCache): ImageLoader =
ImageLoader {
components {
register(context, http)
add(MokoResourceFetcher.Factory())
@@ -60,7 +60,6 @@ class ImageLoaderProvider
bitmapMemoryCacheConfig { configure(context) }
}
}
}
inner class MangaCoverMapper : Mapper<Url> {
override fun map(

View File

@@ -103,6 +103,7 @@ fun ActionMenu(
is ActionGroup -> {
{ openGroup = item }
}
is ActionItem -> item.doAction
},
enabled = item.enabled,
@@ -158,6 +159,7 @@ fun ActionMenu(
onClick = {
when (item) {
is ActionGroup -> openGroup = item
is ActionItem -> {
openGroup = null
item()
@@ -200,9 +202,11 @@ private fun separateIntoIconAndOverflow(
OverflowMode.NEVER_OVERFLOW -> {
iconActions.add(item)
}
OverflowMode.ALWAYS_OVERFLOW -> {
overflowActions.add(item)
}
OverflowMode.IF_NECESSARY -> {
if (iconsAvailableBeforeOverflow > 0) {
iconActions.add(item)
@@ -211,6 +215,7 @@ private fun separateIntoIconAndOverflow(
overflowActions.add(item)
}
}
OverflowMode.NOT_SHOWN -> {
// skip
}

View File

@@ -208,10 +208,18 @@ private fun ColorPresetItem(
private fun getColorShades(color: Color): ImmutableList<Color> {
val f = color.toLong()
return listOf(
shadeColor(f, 0.9), shadeColor(f, 0.7), shadeColor(f, 0.5),
shadeColor(f, 0.333), shadeColor(f, 0.166), shadeColor(f, -0.125),
shadeColor(f, -0.25), shadeColor(f, -0.375), shadeColor(f, -0.5),
shadeColor(f, -0.675), shadeColor(f, -0.7), shadeColor(f, -0.775),
shadeColor(f, 0.9),
shadeColor(f, 0.7),
shadeColor(f, 0.5),
shadeColor(f, 0.333),
shadeColor(f, 0.166),
shadeColor(f, -0.125),
shadeColor(f, -0.25),
shadeColor(f, -0.375),
shadeColor(f, -0.5),
shadeColor(f, -0.675),
shadeColor(f, -0.7),
shadeColor(f, -0.775),
).toImmutableList()
}

View File

@@ -14,9 +14,7 @@ import kotlinx.coroutines.internal.synchronized
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> SavedStateHandle.getStateFlow(initialValue: () -> T): SavedStateHandleDelegate<T> {
return SavedStateHandleDelegate(this, initialValue)
}
fun <T> SavedStateHandle.getStateFlow(initialValue: () -> T): SavedStateHandleDelegate<T> = SavedStateHandleDelegate(this, initialValue)
@OptIn(InternalCoroutinesApi::class)
class SavedStateHandleDelegate<T>(
@@ -30,8 +28,8 @@ class SavedStateHandleDelegate<T>(
override fun getValue(
thisRef: ViewModel,
property: KProperty<*>,
): SavedStateHandleStateFlow<T> {
return item ?: synchronized(synchronizedObject) {
): SavedStateHandleStateFlow<T> =
item ?: synchronized(synchronizedObject) {
if (item == null) {
savedStateHandle.getSavedStateFlow(property.name, initialValue)
.also { item = it }
@@ -39,7 +37,6 @@ class SavedStateHandleDelegate<T>(
item!!
}
}
}
}
class SavedStateHandleStateFlow<T>(

View File

@@ -107,10 +107,9 @@ class AppThemeViewModel
fun getTheme(
id: Int,
isLight: Boolean,
): Theme {
return themes.find { it.id == id && it.colors.isLight == isLight }
): Theme =
themes.find { it.id == id && it.colors.isLight == isLight }
?: themes.first { it.colors.isLight == isLight }
}
return when (themeMode) {
ThemeMode.System -> if (!isSystemInDarkTheme()) {
@@ -118,7 +117,9 @@ class AppThemeViewModel
} else {
getTheme(darkTheme, false)
}
ThemeMode.Light -> getTheme(lightTheme, true)
ThemeMode.Dark -> getTheme(darkTheme, false)
}
}

View File

@@ -148,6 +148,7 @@ fun ExtensionsScreenContent(
modifier = Modifier.animateItemPlacement()
.padding(16.dp, 16.dp, 16.dp, 4.dp),
)
is ExtensionUI.ExtensionItem -> Column {
ExtensionItem(
Modifier.animateItemPlacement(),

View File

@@ -111,6 +111,7 @@ private fun LibraryMap.setManga(
val flow = getManga(id)
when (val state = flow.value) {
is CategoryState.Loaded -> state.unfilteredItems.value = manga
else -> {
val unfilteredItems = MutableStateFlow(manga)
flow.value = CategoryState.Loaded(getItemsFlow(unfilteredItems), unfilteredItems)
@@ -160,15 +161,17 @@ class LibraryScreenViewModel
FilterState.EXCLUDED -> manga.downloadCount == null || manga.downloadCount == 0
FilterState.INCLUDED -> manga.downloadCount != null && (manga.downloadCount ?: 0) > 0
FilterState.IGNORED -> true
} && when (unread) {
FilterState.EXCLUDED -> manga.unreadCount == null || manga.unreadCount == 0
FilterState.INCLUDED -> manga.unreadCount != null && (manga.unreadCount ?: 0) > 0
FilterState.IGNORED -> true
} && when (completed) {
FilterState.EXCLUDED -> manga.status != MangaStatus.COMPLETED
FilterState.INCLUDED -> manga.status == MangaStatus.COMPLETED
FilterState.IGNORED -> true
}
} &&
when (unread) {
FilterState.EXCLUDED -> manga.unreadCount == null || manga.unreadCount == 0
FilterState.INCLUDED -> manga.unreadCount != null && (manga.unreadCount ?: 0) > 0
FilterState.IGNORED -> true
} &&
when (completed) {
FilterState.EXCLUDED -> manga.status != MangaStatus.COMPLETED
FilterState.INCLUDED -> manga.status == MangaStatus.COMPLETED
FilterState.IGNORED -> true
}
}
}
@@ -238,17 +241,22 @@ class LibraryScreenViewModel
collator.compare(a.title.toLowerCase(locale), b.title.toLowerCase(locale))
}
}
Sort.UNREAD -> {
{ a, b ->
when {
// Ensure unread content comes first
(a.unreadCount ?: 0) == (b.unreadCount ?: 0) -> 0
a.unreadCount == null || a.unreadCount == 0 -> if (ascending) 1 else -1
b.unreadCount == null || b.unreadCount == 0 -> if (ascending) -1 else 1
else -> (a.unreadCount ?: 0).compareTo(b.unreadCount ?: 0)
}
}
}
Sort.DATE_ADDED -> {
{ a, b ->
a.inLibraryAt.compareTo(b.inLibraryAt)

View File

@@ -40,7 +40,9 @@ fun LibraryPager(
HorizontalPager(state = pagerState) {
when (val library = getLibraryForPage(categories[it].id).value) {
CategoryState.Loading -> LoadingScreen()
is CategoryState.Failed -> ErrorScreen(library.e.message)
is CategoryState.Loaded -> LibraryLoadedPage(
library = library,
displayMode = displayMode,
@@ -83,6 +85,7 @@ private fun LibraryLoadedPage(
showLanguage = showLanguage,
showLocal = showLocal,
)
DisplayMode.ComfortableGrid -> LibraryMangaComfortableGrid(
library = items,
gridColumns = gridColumns,
@@ -94,6 +97,7 @@ private fun LibraryLoadedPage(
showLanguage = showLanguage,
showLocal = showLocal,
)
DisplayMode.CoverOnlyGrid -> LibraryMangaCoverOnlyGrid(
library = items,
gridColumns = gridColumns,
@@ -105,6 +109,7 @@ private fun LibraryLoadedPage(
showLanguage = showLanguage,
showLocal = showLocal,
)
DisplayMode.List -> LibraryMangaList(
library = items,
onClickManga = onClickManga,
@@ -114,6 +119,7 @@ private fun LibraryLoadedPage(
showLanguage = showLanguage,
showLocal = showLocal,
)
else -> Box {}
}
}

View File

@@ -220,9 +220,11 @@ fun WideLibraryScreenContent(
is LibraryState.Failed -> {
ErrorScreen(libraryState.e.message)
}
LibraryState.Loading -> {
LoadingScreen(true)
}
is LibraryState.Loaded -> {
LibraryPager(
pagerState = pagerState,
@@ -296,6 +298,7 @@ fun ThinLibraryScreenContent(
confirmValueChange = {
when (it) {
ModalBottomSheetValue.Hidden -> setShowingSheet(false)
ModalBottomSheetValue.Expanded,
ModalBottomSheetValue.HalfExpanded,
-> setShowingSheet(true)
@@ -359,9 +362,11 @@ fun ThinLibraryScreenContent(
LibraryState.Loading -> {
LoadingScreen(true)
}
is LibraryState.Failed -> {
ErrorScreen(libraryState.e.message)
}
is LibraryState.Loaded -> {
LibraryPager(
pagerState = pagerState,

View File

@@ -265,6 +265,7 @@ private fun LinkDisplay() {
contentDescription = name,
modifier = modifier,
)
is LinkIcon.Icon -> Icon(
imageVector = it.icon.icon,
contentDescription = name,
@@ -288,6 +289,7 @@ private fun LinkDisplay() {
contentDescription = name,
modifier = Modifier.fillMaxSize(),
)
is LinkIcon.Icon -> Icon(
imageVector = it.icon.icon,
contentDescription = name,

View File

@@ -39,6 +39,7 @@ fun DownloadsExtraInfo() {
val list by vm.downloadQueue.collectAsState()
val text = when (serviceStatus) {
WebsocketService.Status.STARTING -> stringResource(MR.strings.downloads_loading)
WebsocketService.Status.RUNNING -> {
if (list.isNotEmpty()) {
val remainingDownloads = stringResource(MR.strings.downloads_remaining, list.size)
@@ -51,6 +52,7 @@ fun DownloadsExtraInfo() {
null
}
}
WebsocketService.Status.STOPPED -> null
}
if (!text.isNullOrBlank()) {

View File

@@ -55,6 +55,7 @@ fun LibraryUpdatesExtraInfo() {
val text = when (serviceStatus) {
WebsocketService.Status.STARTING -> stringResource(MR.strings.downloads_loading)
WebsocketService.Status.RUNNING -> {
if (updateStatus.running) {
stringResource(MR.strings.notification_updating, current, total)
@@ -62,6 +63,7 @@ fun LibraryUpdatesExtraInfo() {
null
}
}
WebsocketService.Status.STOPPED -> null
}
if (!text.isNullOrBlank()) {

View File

@@ -615,6 +615,7 @@ fun ChapterSeparator(
previousChapter == null && nextChapter != null -> {
Text(stringResource(MR.strings.no_previous_chapter))
}
previousChapter != null && nextChapter != null -> {
val prevChapter by previousChapter.stateObserver.collectAsState()
when (prevChapter) {
@@ -624,6 +625,7 @@ fun ChapterSeparator(
}
CircularProgressIndicator()
}
else -> Unit
}
Text(stringResource(MR.strings.previous_chapter, previousChapter.chapter.name))
@@ -637,9 +639,11 @@ fun ChapterSeparator(
}
CircularProgressIndicator()
}
else -> Unit
}
}
previousChapter != null && nextChapter == null -> {
Text(stringResource(MR.strings.no_next_chapter))
}

View File

@@ -208,20 +208,26 @@ class ReaderMenuViewModel
setReaderSettingsMenuOpen(!readerSettingsMenuOpen.value)
null
}
Navigation.NEXT -> MoveTo.Next
Navigation.PREV -> MoveTo.Previous
Navigation.RIGHT -> when (readerModeSettings.direction.value) {
Direction.Left -> MoveTo.Previous
else -> MoveTo.Next
}
Navigation.LEFT -> when (readerModeSettings.direction.value) {
Direction.Left -> MoveTo.Next
else -> MoveTo.Previous
}
Navigation.DOWN -> when (readerModeSettings.direction.value) {
Direction.Up -> MoveTo.Previous
else -> MoveTo.Next
}
Navigation.UP -> when (readerModeSettings.direction.value) {
Direction.Up -> MoveTo.Next
else -> MoveTo.Previous

View File

@@ -154,8 +154,8 @@ class TachideskPageLoader(
}
}
private suspend fun getImageFromCache(page: ReaderPage): ReaderPage.ImageDecodeState {
return chapterCache.openSnapshot(page.cacheKey)?.use {
private suspend fun getImageFromCache(page: ReaderPage): ReaderPage.ImageDecodeState =
chapterCache.openSnapshot(page.cacheKey)?.use {
it.source().use { source ->
val decoder = bitmapDecoderFactory.create(
ImageResult.OfSource(
@@ -183,7 +183,6 @@ class TachideskPageLoader(
}
}
} ?: ReaderPage.ImageDecodeState.FailedToGetSnapShot
}
/**
* Preloads the given [amount] of pages after the [currentPage] with a lower priority.

View File

@@ -86,6 +86,7 @@ fun ContinuousReader(
)
Unit
}
is PageMove.Page -> {
val pageNumber = pages.indexOf(pageMove.page)
if (pageNumber > -1) {
@@ -155,6 +156,7 @@ fun ContinuousReader(
reverseLayout = direction == Direction.Up,
)
}
false -> {
LazyRow(
state = state,
@@ -217,6 +219,7 @@ private fun LazyListScope.items(
retry = retry,
)
}
is ReaderPageSeparator -> ChapterSeparator(
previousChapter = image.previousChapter,
nextChapter = image.nextChapter,

View File

@@ -63,6 +63,7 @@ fun PagerReader(
state.animateScrollToPage(page)
}
}
is PageMove.Page -> {
val pageNumber = pages.indexOf(pageMove.page)
if (pageNumber > -1) {
@@ -158,6 +159,7 @@ fun HandlePager(
contentScale = pageContentScale,
)
}
is ReaderPageSeparator -> ChapterSeparator(
previousChapter = image.previousChapter,
nextChapter = image.nextChapter,

View File

@@ -434,11 +434,13 @@ private fun PreferenceFile(
modifier = modifier,
tint = Color.Red,
)
Status.Success -> Icon(
Icons.Rounded.Check,
contentDescription = null,
modifier = modifier,
)
else -> Unit
}
}

View File

@@ -210,6 +210,7 @@ fun SettingsServerScreenContent(
}
when (proxyValue) {
Proxy.NO_PROXY -> Unit
Proxy.HTTP_PROXY -> {
item {
EditTextPreference(
@@ -226,6 +227,7 @@ fun SettingsServerScreenContent(
)
}
}
Proxy.SOCKS_PROXY -> {
item {
EditTextPreference(

View File

@@ -119,6 +119,7 @@ class SourceScreenViewModel(
)
}
}
isLatest.value -> {
{ page ->
getLatestManga.await(
@@ -128,6 +129,7 @@ class SourceScreenViewModel(
)
}
}
else -> {
{ page ->
getPopularManga.await(

View File

@@ -285,6 +285,7 @@ private fun SourceThinScreenContent(
confirmValueChange = {
when (it) {
ModalBottomSheetValue.Hidden -> setShowingFilters(false)
ModalBottomSheetValue.Expanded,
ModalBottomSheetValue.HalfExpanded,
-> setShowingFilters(true)
@@ -492,6 +493,7 @@ private fun MangaTable(
hasNextPage = hasNextPage,
onLoadNextPage = onLoadNextPage,
)
DisplayMode.ComfortableGrid -> SourceMangaComfortableGrid(
mangas = mangas,
gridColumns = gridColumns,
@@ -500,12 +502,14 @@ private fun MangaTable(
hasNextPage = hasNextPage,
onLoadNextPage = onLoadNextPage,
)
DisplayMode.List -> SourceMangaList(
mangas = mangas,
onClickManga = onMangaClick,
hasNextPage = hasNextPage,
onLoadNextPage = onLoadNextPage,
)
else -> Box {}
}
}

View File

@@ -155,11 +155,13 @@ fun SourcesSideMenu(
contentDescription = stringResource(MR.strings.sources_home),
modifier = modifier,
)
SourceNavigatorScreen.SearchScreen -> Icon(
imageVector = Icons.Rounded.Search,
contentDescription = stringResource(MR.strings.location_global_search),
modifier = modifier,
)
is SourceNavigatorScreen.SourceScreen -> Box(Modifier.align(Alignment.Center)) {
ImageLoaderImage(
data = screen.source,

View File

@@ -196,12 +196,14 @@ fun GlobalSearchItem(
) {
ErrorScreen(search.e)
}
Search.Searching -> Box(
Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 16.dp),
contentAlignment = Alignment.Center,
) {
CircularProgressIndicator()
}
is Search.Success -> Box(
Modifier
.fillMaxWidth()

View File

@@ -185,6 +185,7 @@ fun WideSourcesMenu(
sourceUI.header,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
)
is SourceUI.SourceItem -> WideSourceItem(
sourceUI,
onSourceClicked = onAddSource,
@@ -285,6 +286,7 @@ fun ThinSourcesMenu(
sourceUI.header,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
)
is SourceUI.SourceItem -> ThinSourceItem(
sourceUI,
onSourceClicked = onAddSource,

View File

@@ -87,12 +87,15 @@ fun SourceSettingsScreenContent(settings: ImmutableList<SourceSettingsView<*, *>
is CheckBox, is Switch -> {
TwoStatePreference(it as TwoState, it is CheckBox)
}
is List -> {
ListPreference(it)
}
is EditText -> {
EditTextPreference(it)
}
is MultiSelect -> {
MultiSelectPreference(it)
}

View File

@@ -184,6 +184,7 @@ fun UpdatesScreenContent(
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
fontWeight = FontWeight.Medium,
)
is UpdatesUI.Item -> {
val manga = item.chapterDownloadItem.manga!!
val chapter = item.chapterDownloadItem.chapter

View File

@@ -21,11 +21,17 @@ actual fun stringFormat(
@Suppress("MagicNumber")
return when (args.size) {
0 -> NSString.stringWithFormat(objcFormat)
1 -> NSString.stringWithFormat(objcFormat, args[0])
2 -> NSString.stringWithFormat(objcFormat, args[0], args[1])
3 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2])
4 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3])
5 -> NSString.stringWithFormat(objcFormat, args[0], args[1], args[2], args[3], args[4])
6 -> NSString.stringWithFormat(
objcFormat,
args[0],
@@ -35,6 +41,7 @@ actual fun stringFormat(
args[4],
args[5],
)
7 -> NSString.stringWithFormat(
objcFormat,
args[0],
@@ -45,6 +52,7 @@ actual fun stringFormat(
args[5],
args[6],
)
8 -> NSString.stringWithFormat(
objcFormat,
args[0],
@@ -56,6 +64,7 @@ actual fun stringFormat(
args[6],
args[7],
)
9 -> NSString.stringWithFormat(
objcFormat,
args[0],
@@ -68,6 +77,7 @@ actual fun stringFormat(
args[7],
args[8],
)
else -> throw IllegalArgumentException("can't handle more then 9 arguments now")
}
}