Run default Android Studio formatter on code

This commit is contained in:
arkon
2020-02-17 17:23:37 -05:00
parent a1fadce7c6
commit 3ecc883944
109 changed files with 640 additions and 585 deletions

View File

@@ -129,17 +129,17 @@ class LocalSource(private val context: Context) : CatalogueSource {
.filter { it.extension.equals("json") }
.firstOrNull()
?.apply {
val json = Gson().fromJson(Scanner(this).useDelimiter("\\Z").next(), JsonObject::class.java)
manga.title = json["title"]?.asString ?: manga.title
manga.author = json["author"]?.asString ?: manga.author
manga.artist = json["artist"]?.asString ?: manga.artist
manga.description = json["description"]?.asString ?: manga.description
manga.genre = json["genre"]?.asJsonArray
?.map { it.asString }
?.joinToString(", ")
?: manga.genre
manga.status = json["status"]?.asInt ?: manga.status
}
val json = Gson().fromJson(Scanner(this).useDelimiter("\\Z").next(), JsonObject::class.java)
manga.title = json["title"]?.asString ?: manga.title
manga.author = json["author"]?.asString ?: manga.author
manga.artist = json["artist"]?.asString ?: manga.artist
manga.description = json["description"]?.asString ?: manga.description
manga.genre = json["genre"]?.asJsonArray
?.map { it.asString }
?.joinToString(", ")
?: manga.genre
manga.status = json["status"]?.asInt ?: manga.status
}
return Observable.just(manga)
}
@@ -210,34 +210,34 @@ class LocalSource(private val context: Context) : CatalogueSource {
return when (format) {
is Format.Directory -> {
val entry = format.file.listFiles()
.sortedWith(Comparator<File> { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) })
.find { !it.isDirectory && ImageUtil.isImage(it.name) { FileInputStream(it) } }
.sortedWith(Comparator<File> { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) })
.find { !it.isDirectory && ImageUtil.isImage(it.name) { FileInputStream(it) } }
entry?.let { updateCover(context, manga, it.inputStream())}
entry?.let { updateCover(context, manga, it.inputStream()) }
}
is Format.Zip -> {
ZipFile(format.file).use { zip ->
val entry = zip.entries().toList()
.sortedWith(Comparator<ZipEntry> { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) })
.find { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } }
.sortedWith(Comparator<ZipEntry> { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) })
.find { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } }
entry?.let { updateCover(context, manga, zip.getInputStream(it) )}
entry?.let { updateCover(context, manga, zip.getInputStream(it)) }
}
}
is Format.Rar -> {
Archive(format.file).use { archive ->
val entry = archive.fileHeaders
.sortedWith(Comparator<FileHeader> { f1, f2 -> f1.fileNameString.compareToCaseInsensitiveNaturalOrder(f2.fileNameString) })
.find { !it.isDirectory && ImageUtil.isImage(it.fileNameString) { archive.getInputStream(it) } }
.sortedWith(Comparator<FileHeader> { f1, f2 -> f1.fileNameString.compareToCaseInsensitiveNaturalOrder(f2.fileNameString) })
.find { !it.isDirectory && ImageUtil.isImage(it.fileNameString) { archive.getInputStream(it) } }
entry?.let { updateCover(context, manga, archive.getInputStream(it) )}
entry?.let { updateCover(context, manga, archive.getInputStream(it)) }
}
}
is Format.Epub -> {
EpubFile(format.file).use { epub ->
val entry = epub.getImagesFromPages()
.firstOrNull()
?.let { epub.getEntry(it) }
.firstOrNull()
?.let { epub.getEntry(it) }
entry?.let { updateCover(context, manga, epub.getInputStream(it)) }
}
@@ -252,7 +252,7 @@ class LocalSource(private val context: Context) : CatalogueSource {
sealed class Format {
data class Directory(val file: File) : Format()
data class Zip(val file: File) : Format()
data class Rar(val file: File): Format()
data class Rar(val file: File) : Format()
data class Epub(val file: File) : Format()
}

View File

@@ -17,7 +17,8 @@ sealed class Filter<T>(val name: String, var state: T) {
const val STATE_EXCLUDE = 2
}
}
abstract class Group<V>(name: String, state: List<V>): Filter<List<V>>(name, state)
abstract class Group<V>(name: String, state: List<V>) : Filter<List<V>>(name, state)
abstract class Sort(name: String, val values: Array<String>, state: Selection? = null)
: Filter<Sort.Selection?>(name, state) {
@@ -37,4 +38,4 @@ sealed class Filter<T>(val name: String, var state: T) {
return result
}
}
}

View File

@@ -14,15 +14,20 @@ open class Page(
val number: Int
get() = index + 1
@Transient @Volatile var status: Int = 0
@Transient
@Volatile
var status: Int = 0
set(value) {
field = value
statusSubject?.onNext(value)
}
@Transient @Volatile var progress: Int = 0
@Transient
@Volatile
var progress: Int = 0
@Transient private var statusSubject: Subject<Int, Int>? = null
@Transient
private var statusSubject: Subject<Int, Int>? = null
override fun update(bytesRead: Long, contentLength: Long, done: Boolean) {
progress = if (contentLength > 0) {

View File

@@ -10,6 +10,6 @@ class SChapterImpl : SChapter {
override var chapter_number: Float = -1f
override var scanlator: String? = null
override var scanlator: String? = null
}
}

View File

@@ -69,7 +69,7 @@ abstract class HttpSource : CatalogueSource {
/**
* Headers builder for requests. Implementations can override this method for custom headers.
*/
open protected fun headersBuilder() = Headers.Builder().apply {
protected open fun headersBuilder() = Headers.Builder().apply {
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
}
@@ -97,14 +97,14 @@ abstract class HttpSource : CatalogueSource {
*
* @param page the page number to retrieve.
*/
abstract protected fun popularMangaRequest(page: Int): Request
protected abstract fun popularMangaRequest(page: Int): Request
/**
* Parses the response from the site and returns a [MangasPage] object.
*
* @param response the response from the site.
*/
abstract protected fun popularMangaParse(response: Response): MangasPage
protected abstract fun popularMangaParse(response: Response): MangasPage
/**
* Returns an observable containing a page with a list of manga. Normally it's not needed to
@@ -129,14 +129,14 @@ abstract class HttpSource : CatalogueSource {
* @param query the search query.
* @param filters the list of filters to apply.
*/
abstract protected fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request
protected abstract fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request
/**
* Parses the response from the site and returns a [MangasPage] object.
*
* @param response the response from the site.
*/
abstract protected fun searchMangaParse(response: Response): MangasPage
protected abstract fun searchMangaParse(response: Response): MangasPage
/**
* Returns an observable containing a page with a list of latest manga updates.
@@ -156,14 +156,14 @@ abstract class HttpSource : CatalogueSource {
*
* @param page the page number to retrieve.
*/
abstract protected fun latestUpdatesRequest(page: Int): Request
protected abstract fun latestUpdatesRequest(page: Int): Request
/**
* Parses the response from the site and returns a [MangasPage] object.
*
* @param response the response from the site.
*/
abstract protected fun latestUpdatesParse(response: Response): MangasPage
protected abstract fun latestUpdatesParse(response: Response): MangasPage
/**
* Returns an observable with the updated details for a manga. Normally it's not needed to
@@ -194,7 +194,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param response the response from the site.
*/
abstract protected fun mangaDetailsParse(response: Response): SManga
protected abstract fun mangaDetailsParse(response: Response): SManga
/**
* Returns an observable with the updated chapter list for a manga. Normally it's not needed to
@@ -220,7 +220,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param manga the manga to look for chapters.
*/
open protected fun chapterListRequest(manga: SManga): Request {
protected open fun chapterListRequest(manga: SManga): Request {
return GET(baseUrl + manga.url, headers)
}
@@ -229,7 +229,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param response the response from the site.
*/
abstract protected fun chapterListParse(response: Response): List<SChapter>
protected abstract fun chapterListParse(response: Response): List<SChapter>
/**
* Returns an observable with the page list for a chapter.
@@ -250,7 +250,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param chapter the chapter whose page list has to be fetched.
*/
open protected fun pageListRequest(chapter: SChapter): Request {
protected open fun pageListRequest(chapter: SChapter): Request {
return GET(baseUrl + chapter.url, headers)
}
@@ -259,7 +259,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param response the response from the site.
*/
abstract protected fun pageListParse(response: Response): List<Page>
protected abstract fun pageListParse(response: Response): List<Page>
/**
* Returns an observable with the page containing the source url of the image. If there's any
@@ -279,7 +279,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param page the chapter whose page list has to be fetched
*/
open protected fun imageUrlRequest(page: Page): Request {
protected open fun imageUrlRequest(page: Page): Request {
return GET(page.url, headers)
}
@@ -288,7 +288,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param response the response from the site.
*/
abstract protected fun imageUrlParse(response: Response): String
protected abstract fun imageUrlParse(response: Response): String
/**
* Returns an observable with the response of the source image.
@@ -306,7 +306,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param page the chapter whose page list has to be fetched
*/
open protected fun imageRequest(page: Page): Request {
protected open fun imageRequest(page: Page): Request {
return GET(page.imageUrl!!, headers)
}

View File

@@ -6,10 +6,10 @@ import rx.Observable
fun HttpSource.getImageUrl(page: Page): Observable<Page> {
page.status = Page.LOAD_PAGE
return fetchImageUrl(page)
.doOnError { page.status = Page.ERROR }
.onErrorReturn { null }
.doOnNext { page.imageUrl = it }
.map { page }
.doOnError { page.status = Page.ERROR }
.onErrorReturn { null }
.doOnNext { page.imageUrl = it }
.map { page }
}
fun HttpSource.fetchAllImageUrlsFromPageList(pages: List<Page>): Observable<Page> {

View File

@@ -36,7 +36,7 @@ abstract class ParsedHttpSource : HttpSource() {
/**
* Returns the Jsoup selector that returns a list of [Element] corresponding to each manga.
*/
abstract protected fun popularMangaSelector(): String
protected abstract fun popularMangaSelector(): String
/**
* Returns a manga from the given [element]. Most sites only show the title and the url, it's
@@ -44,13 +44,13 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param element an element obtained from [popularMangaSelector].
*/
abstract protected fun popularMangaFromElement(element: Element): SManga
protected abstract fun popularMangaFromElement(element: Element): SManga
/**
* Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if
* there's no next page.
*/
abstract protected fun popularMangaNextPageSelector(): String?
protected abstract fun popularMangaNextPageSelector(): String?
/**
* Parses the response from the site and returns a [MangasPage] object.
@@ -74,7 +74,7 @@ abstract class ParsedHttpSource : HttpSource() {
/**
* Returns the Jsoup selector that returns a list of [Element] corresponding to each manga.
*/
abstract protected fun searchMangaSelector(): String
protected abstract fun searchMangaSelector(): String
/**
* Returns a manga from the given [element]. Most sites only show the title and the url, it's
@@ -82,13 +82,13 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param element an element obtained from [searchMangaSelector].
*/
abstract protected fun searchMangaFromElement(element: Element): SManga
protected abstract fun searchMangaFromElement(element: Element): SManga
/**
* Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if
* there's no next page.
*/
abstract protected fun searchMangaNextPageSelector(): String?
protected abstract fun searchMangaNextPageSelector(): String?
/**
* Parses the response from the site and returns a [MangasPage] object.
@@ -112,7 +112,7 @@ abstract class ParsedHttpSource : HttpSource() {
/**
* Returns the Jsoup selector that returns a list of [Element] corresponding to each manga.
*/
abstract protected fun latestUpdatesSelector(): String
protected abstract fun latestUpdatesSelector(): String
/**
* Returns a manga from the given [element]. Most sites only show the title and the url, it's
@@ -120,13 +120,13 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param element an element obtained from [latestUpdatesSelector].
*/
abstract protected fun latestUpdatesFromElement(element: Element): SManga
protected abstract fun latestUpdatesFromElement(element: Element): SManga
/**
* Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if
* there's no next page.
*/
abstract protected fun latestUpdatesNextPageSelector(): String?
protected abstract fun latestUpdatesNextPageSelector(): String?
/**
* Parses the response from the site and returns the details of a manga.
@@ -142,7 +142,7 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param document the parsed document.
*/
abstract protected fun mangaDetailsParse(document: Document): SManga
protected abstract fun mangaDetailsParse(document: Document): SManga
/**
* Parses the response from the site and returns a list of chapters.
@@ -157,14 +157,14 @@ abstract class ParsedHttpSource : HttpSource() {
/**
* Returns the Jsoup selector that returns a list of [Element] corresponding to each chapter.
*/
abstract protected fun chapterListSelector(): String
protected abstract fun chapterListSelector(): String
/**
* Returns a chapter from the given element.
*
* @param element an element obtained from [chapterListSelector].
*/
abstract protected fun chapterFromElement(element: Element): SChapter
protected abstract fun chapterFromElement(element: Element): SChapter
/**
* Parses the response from the site and returns the page list.
@@ -180,7 +180,7 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param document the parsed document.
*/
abstract protected fun pageListParse(document: Document): List<Page>
protected abstract fun pageListParse(document: Document): List<Page>
/**
* Parse the response from the site and returns the absolute url to the source image.
@@ -196,5 +196,5 @@ abstract class ParsedHttpSource : HttpSource() {
*
* @param document the parsed document.
*/
abstract protected fun imageUrlParse(document: Document): String
protected abstract fun imageUrlParse(document: Document): String
}