Skip to content

Commit

Permalink
Lint (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 authored Oct 22, 2022
1 parent 3bef07e commit a3c366c
Show file tree
Hide file tree
Showing 54 changed files with 159 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
}

private fun internalMove(row: Int) {
if (cursor < 0) cursor = 0
else if (cursor > resultSetLength + 1) cursor = resultSetLength + 1
else cursor = row
if (cursor < 0) {
cursor = 0
} else if (cursor > resultSetLength + 1) {
cursor = resultSetLength + 1
} else {
cursor = row
}
}

private fun obj(column: Int): Any? {
Expand Down Expand Up @@ -293,10 +297,11 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
}

override fun <T : Any?> unwrap(iface: Class<T>?): T {
if (thisIsWrapperFor(iface))
if (thisIsWrapperFor(iface)) {
return this as T
else
} else {
return parent.unwrap(iface)
}
}

override fun next(): Boolean {
Expand Down Expand Up @@ -531,10 +536,15 @@ class ScrollableResultSet(val parent: ResultSet) : ResultSet by parent {
}

private fun castToLong(obj: Any?): Long {
if (obj == null) return 0
else if (obj is Long) return obj
else if (obj is Number) return obj.toLong()
else throw IllegalStateException("Object is not a long!")
if (obj == null) {
return 0
} else if (obj is Long) {
return obj
} else if (obj is Number) {
return obj.toLong()
} else {
throw IllegalStateException("Object is not a long!")
}
}

override fun getLong(columnIndex: Int): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ class PackageController {

fun findPackage(packageName: String): InstalledPackage? {
val file = File(androidFiles.packagesDir, packageName)
return if (file.exists())
return if (file.exists()) {
InstalledPackage(file)
else
} else {
null
}
}

fun findJarFromApk(apkFile: File): File? {
Expand Down
1 change: 0 additions & 1 deletion server/src/main/kotlin/eu/kanade/tachiyomi/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import uy.kohesive.injekt.api.get
class AppModule(val app: Application) : InjektModule {

override fun InjektRegistrar.registerInjectables() {

addSingleton(app)

// addSingletonFactory { PreferencesHelper(app) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import java.util.concurrent.TimeUnit
fun OkHttpClient.Builder.rateLimit(
permits: Int,
period: Long = 1,
unit: TimeUnit = TimeUnit.SECONDS,
unit: TimeUnit = TimeUnit.SECONDS
) = addInterceptor(RateLimitInterceptor(permits, period, unit))

private class RateLimitInterceptor(
private val permits: Int,
period: Long,
unit: TimeUnit,
unit: TimeUnit
) : Interceptor {

private val requestQueue = ArrayList<Long>(permits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ fun OkHttpClient.Builder.rateLimitHost(
httpUrl: HttpUrl,
permits: Int,
period: Long = 1,
unit: TimeUnit = TimeUnit.SECONDS,
unit: TimeUnit = TimeUnit.SECONDS
) = addInterceptor(SpecificHostRateLimitInterceptor(httpUrl, permits, period, unit))

class SpecificHostRateLimitInterceptor(
httpUrl: HttpUrl,
private val permits: Int,
period: Long,
unit: TimeUnit,
unit: TimeUnit
) : Interceptor {

private val requestQueue = ArrayList<Long>(permits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ class LocalSource : CatalogueSource {

fun getFormat(chapter: SChapter): Format {
val chapFile = File(applicationDirs.localMangaRoot, chapter.url)
if (chapFile.exists())
if (chapFile.exists()) {
return getFormat(chapFile)
}

throw Exception("Chapter not found")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class AboutDataClass(
val buildType: String,
val buildTime: Long,
val github: String,
val discord: String,
val discord: String
)

object About {
Expand All @@ -28,7 +28,7 @@ object About {
BuildConfig.BUILD_TYPE,
BuildConfig.BUILD_TIME,
BuildConfig.GITHUB,
BuildConfig.DISCORD,
BuildConfig.DISCORD
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ object AppUpdate {
UpdateDataClass(
"Stable",
stableJson["tag_name"]!!.jsonPrimitive.content,
stableJson["html_url"]!!.jsonPrimitive.content,
stableJson["html_url"]!!.jsonPrimitive.content
),
UpdateDataClass(
"Preview",
previewJson["tag_name"]!!.jsonPrimitive.content,
previewJson["html_url"]!!.jsonPrimitive.content,
),
previewJson["html_url"]!!.jsonPrimitive.content
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object BackupController {
includeCategories = true,
includeChapters = true,
includeTracking = true,
includeHistory = true,
includeHistory = true
)
)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ object BackupController {
includeCategories = true,
includeChapters = true,
includeTracking = true,
includeHistory = true,
includeHistory = true
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ object Category {
normalizeCategories()

newCategoryId
} else -1
} else {
-1
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ object CategoryManga {
dataClass
}

if (categoryId == DEFAULT_CATEGORY_ID)
if (categoryId == DEFAULT_CATEGORY_ID) {
return transaction {
MangaTable
.slice(selectedColumns)
.select { (MangaTable.inLibrary eq true) and (MangaTable.defaultCategory eq true) }
.map(transform)
}
}

return transaction {
CategoryMangaTable.innerJoin(MangaTable)
Expand Down
12 changes: 7 additions & 5 deletions server/src/main/kotlin/suwayomi/tachidesk/manga/impl/Manga.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ import java.io.InputStream

object Manga {
private fun truncate(text: String?, maxLength: Int): String? {
return if (text?.length ?: 0 > maxLength)
return if (text?.length ?: 0 > maxLength) {
text?.take(maxLength - 3) + "..."
else
} else {
text
}
}

suspend fun getManga(mangaId: Int, onlineFetch: Boolean = false): MangaDataClass {
Expand All @@ -68,12 +69,12 @@ object Manga {

transaction {
MangaTable.update({ MangaTable.id eq mangaId }) {

if (sManga.title != mangaEntry[MangaTable.title]) {
val canUpdateTitle = updateMangaDownloadDir(mangaId, sManga.title)

if (canUpdateTitle)
if (canUpdateTitle) {
it[MangaTable.title] = sManga.title
}
}
it[MangaTable.initialized] = true

Expand All @@ -82,8 +83,9 @@ object Manga {
it[MangaTable.description] = truncate(sManga.description, 4096)
it[MangaTable.genre] = sManga.genre
it[MangaTable.status] = sManga.status
if (sManga.thumbnail_url != null && sManga.thumbnail_url.orEmpty().isNotEmpty())
if (sManga.thumbnail_url != null && sManga.thumbnail_url.orEmpty().isNotEmpty()) {
it[MangaTable.thumbnail_url] = sManga.thumbnail_url
}

it[MangaTable.realUrl] = runCatching {
(source as? HttpSource)?.mangaDetailsRequest(sManga)?.url?.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object Search {

data class FilterObject(
val type: String,
val filter: Filter<*>,
val filter: Filter<*>
)

fun setFilter(sourceId: Long, changes: List<FilterChange>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object Source {
catalogueSource.supportsLatest,
catalogueSource is ConfigurableSource,
it[SourceTable.isNsfw],
catalogueSource.toString(),
catalogueSource.toString()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ data class BackupFlags(
val includeCategories: Boolean,
val includeChapters: Boolean,
val includeTracking: Boolean,
val includeHistory: Boolean,
val includeHistory: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object ProtoBackupExport : ProtoBackupBase() {
MangaStatus.valueOf(mangaRow[MangaTable.status]).value,
mangaRow[MangaTable.thumbnail_url],
TimeUnit.SECONDS.toMillis(mangaRow[MangaTable.inLibraryAt]),
0, // not supported in Tachidesk
0 // not supported in Tachidesk
)

val mangaId = mangaRow[MangaTable.id].value
Expand All @@ -94,7 +94,7 @@ object ProtoBackupExport : ProtoBackupBase() {
TimeUnit.SECONDS.toMillis(it.fetchedAt),
it.uploadDate,
it.chapterNumber,
chapters.size - it.index,
chapters.size - it.index
)
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ object ProtoBackupExport : ProtoBackupBase() {
BackupCategory(
it.name,
it.order,
0, // not supported in Tachidesk
0 // not supported in Tachidesk
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class Backup(
@ProtoNumber(2) var backupCategories: List<BackupCategory> = emptyList(),
// Bump by 100 to specify this is a 0.x value
@ProtoNumber(100) var brokenBackupSources: List<BrokenBackupSource> = emptyList(),
@ProtoNumber(101) var backupSources: List<BackupSource> = emptyList(),
@ProtoNumber(101) var backupSources: List<BackupSource> = emptyList()
) {
fun getSourceMap(): Map<Long, String> {
return (brokenBackupSources.map { BackupSource(it.name, it.sourceId) } + backupSources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BackupCategory(
@ProtoNumber(2) var order: Int = 0,
// @ProtoNumber(3) val updateInterval: Int = 0, 1.x value not used in 0.x
// Bump by 100 to specify this is a 0.x value
@ProtoNumber(100) var flags: Int = 0,
@ProtoNumber(100) var flags: Int = 0
) {
fun getCategoryImpl(): CategoryImpl {
return CategoryImpl().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class BackupChapter(
@ProtoNumber(8) var dateUpload: Long = 0,
// chapterNumber is called number is 1.x
@ProtoNumber(9) var chapterNumber: Float = 0F,
@ProtoNumber(10) var sourceOrder: Int = 0,
@ProtoNumber(10) var sourceOrder: Int = 0
) {
fun toChapterImpl(): ChapterImpl {
return ChapterImpl().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class BackupManga(
@ProtoNumber(101) var chapterFlags: Int = 0,
@ProtoNumber(102) var brokenHistory: List<BrokenBackupHistory> = emptyList(),
@ProtoNumber(103) var viewer_flags: Int? = null,
@ProtoNumber(104) var history: List<BackupHistory> = emptyList(),
@ProtoNumber(104) var history: List<BackupHistory> = emptyList()
) {
fun getMangaImpl(): MangaImpl {
return MangaImpl().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class BackupTracking(
// startedReadingDate is called startReadTime in 1.x
@ProtoNumber(10) var startedReadingDate: Long = 0,
// finishedReadingDate is called endReadTime in 1.x
@ProtoNumber(11) var finishedReadingDate: Long = 0,
@ProtoNumber(11) var finishedReadingDate: Long = 0
) {
fun getTrackingImpl(): TrackImpl {
return TrackImpl().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private class ChapterForDownload(
private val mangaId: Int
) {
suspend fun asDownloadReady(): ChapterDataClass {

if (isNotCompletelyDownloaded()) {
markAsNotDownloaded()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object DownloadManager {
|Supported commands are:
| - STATUS
| sends the current download status
|""".trimMargin()
|
""".trimMargin()
)
}
}
Expand All @@ -65,7 +66,11 @@ object DownloadManager {
return DownloadStatus(
if (downloader == null ||
downloadQueue.none { it.state == Downloading }
) "Stopped" else "Started",
) {
"Stopped"
} else {
"Started"
},
downloadQueue
)
}
Expand Down Expand Up @@ -96,8 +101,10 @@ object DownloadManager {
}

fun start() {
if (downloader != null && !downloader?.isAlive!!) // doesn't exist or is dead
if (downloader != null && !downloader?.isAlive!!) {
// doesn't exist or is dead
downloader = null
}

if (downloader == null) {
downloader = Downloader(downloadQueue) { notifyAllClients() }
Expand Down Expand Up @@ -127,5 +134,5 @@ object DownloadManager {
enum class DownloaderState(val state: Int) {
Stopped(0),
Running(1),
Paused(2),
Paused(2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class DownloadChapter(
var manga: MangaDataClass,
var state: DownloadState = Queued,
var progress: Float = 0f,
var tries: Int = 0,
var tries: Int = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ enum class DownloadState(val state: Int) {
Queued(0),
Downloading(1),
Finished(2),
Error(3),
Error(3)
}
Loading

0 comments on commit a3c366c

Please sign in to comment.