Optimize imports, disallow wildcard imports because of klint, run linter
This commit is contained in:
@@ -16,20 +16,22 @@ class GalleryAdder {
|
||||
|
||||
private val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
fun addGallery(url: String,
|
||||
fav: Boolean = false,
|
||||
forceSource: UrlImportableSource? = null,
|
||||
throttleFunc: () -> Unit = {}): GalleryAddEvent {
|
||||
fun addGallery(
|
||||
url: String,
|
||||
fav: Boolean = false,
|
||||
forceSource: UrlImportableSource? = null,
|
||||
throttleFunc: () -> Unit = {}
|
||||
): GalleryAddEvent {
|
||||
XLog.d("Importing gallery (url: %s, fav: %s, forceSource: %s)...", url, fav, forceSource)
|
||||
try {
|
||||
val uri = Uri.parse(url)
|
||||
|
||||
// Find matching source
|
||||
val source = if(forceSource != null) {
|
||||
val source = if (forceSource != null) {
|
||||
try {
|
||||
if (forceSource.matchesUri(uri)) forceSource
|
||||
else return GalleryAddEvent.Fail.UnknownType(url)
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
XLog.e("Source URI match check error!", e)
|
||||
return GalleryAddEvent.Fail.UnknownType(url)
|
||||
}
|
||||
@@ -39,7 +41,7 @@ class GalleryAdder {
|
||||
.find {
|
||||
try {
|
||||
it.matchesUri(uri)
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
XLog.e("Source URI match check error!", e)
|
||||
false
|
||||
}
|
||||
@@ -49,7 +51,7 @@ class GalleryAdder {
|
||||
// Map URL to manga URL
|
||||
val realUrl = try {
|
||||
source.mapUrlToMangaUrl(uri)
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
XLog.e("Source URI map-to-manga error!", e)
|
||||
null
|
||||
} ?: return GalleryAddEvent.Fail.UnknownType(url)
|
||||
@@ -57,12 +59,12 @@ class GalleryAdder {
|
||||
// Clean URL
|
||||
val cleanedUrl = try {
|
||||
source.cleanMangaUrl(realUrl)
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
XLog.e("Source URI clean error!", e)
|
||||
null
|
||||
} ?: return GalleryAddEvent.Fail.UnknownType(url)
|
||||
|
||||
//Use manga in DB if possible, otherwise, make a new manga
|
||||
// Use manga in DB if possible, otherwise, make a new manga
|
||||
val manga = db.getManga(cleanedUrl, source.id).executeAsBlocking()
|
||||
?: Manga.create(source.id).apply {
|
||||
this.url = cleanedUrl
|
||||
@@ -71,7 +73,7 @@ class GalleryAdder {
|
||||
|
||||
// Insert created manga if not in DB before fetching details
|
||||
// This allows us to keep the metadata when fetching details
|
||||
if(manga.id == null) {
|
||||
if (manga.id == null) {
|
||||
db.insertManga(manga).executeAsBlocking().insertedId()?.let {
|
||||
manga.id = it
|
||||
}
|
||||
@@ -86,9 +88,9 @@ class GalleryAdder {
|
||||
|
||||
db.insertManga(manga).executeAsBlocking()
|
||||
|
||||
//Fetch and copy chapters
|
||||
// Fetch and copy chapters
|
||||
try {
|
||||
val chapterListObs = if(source is EHentai) {
|
||||
val chapterListObs = if (source is EHentai) {
|
||||
source.fetchChapterList(manga, throttleFunc)
|
||||
} else {
|
||||
source.fetchChapterList(manga)
|
||||
@@ -102,10 +104,10 @@ class GalleryAdder {
|
||||
}
|
||||
|
||||
return GalleryAddEvent.Success(url, manga)
|
||||
} catch(e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
XLog.w("Could not add gallery (url: $url)!", e)
|
||||
|
||||
if(e is EHentai.GalleryNotFoundException) {
|
||||
if (e is EHentai.GalleryNotFoundException) {
|
||||
return GalleryAddEvent.Fail.NotFound(url)
|
||||
}
|
||||
|
||||
@@ -120,21 +122,25 @@ sealed class GalleryAddEvent {
|
||||
abstract val galleryUrl: String
|
||||
open val galleryTitle: String? = null
|
||||
|
||||
class Success(override val galleryUrl: String,
|
||||
val manga: Manga): GalleryAddEvent() {
|
||||
class Success(
|
||||
override val galleryUrl: String,
|
||||
val manga: Manga
|
||||
) : GalleryAddEvent() {
|
||||
override val galleryTitle = manga.title
|
||||
override val logMessage = "Added gallery: $galleryTitle"
|
||||
}
|
||||
|
||||
sealed class Fail: GalleryAddEvent() {
|
||||
class UnknownType(override val galleryUrl: String): Fail() {
|
||||
sealed class Fail : GalleryAddEvent() {
|
||||
class UnknownType(override val galleryUrl: String) : Fail() {
|
||||
override val logMessage = "Unknown gallery type for gallery: $galleryUrl"
|
||||
}
|
||||
|
||||
open class Error(override val galleryUrl: String,
|
||||
override val logMessage: String): Fail()
|
||||
open class Error(
|
||||
override val galleryUrl: String,
|
||||
override val logMessage: String
|
||||
) : Fail()
|
||||
|
||||
class NotFound(galleryUrl: String):
|
||||
class NotFound(galleryUrl: String) :
|
||||
Error(galleryUrl, "Gallery does not exist: $galleryUrl")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user