mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Linting fixes
This commit is contained in:
@@ -39,8 +39,9 @@ object ChapterRecognition {
|
||||
|
||||
fun parseChapterNumber(chapter: SChapter, manga: SManga) {
|
||||
// If chapter number is known return.
|
||||
if (chapter.chapter_number == -2f || chapter.chapter_number > -1f)
|
||||
if (chapter.chapter_number == -2f || chapter.chapter_number > -1f) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get chapter title with lower case
|
||||
var name = chapter.name.toLowerCase()
|
||||
@@ -59,8 +60,9 @@ object ChapterRecognition {
|
||||
}
|
||||
|
||||
// Check base case ch.xx
|
||||
if (updateChapter(basic.find(name), chapter))
|
||||
if (updateChapter(basic.find(name), chapter)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check one number occurrence.
|
||||
val occurrences: MutableList<MatchResult> = arrayListOf()
|
||||
@@ -69,20 +71,23 @@ object ChapterRecognition {
|
||||
}
|
||||
|
||||
if (occurrences.size == 1) {
|
||||
if (updateChapter(occurrences[0], chapter))
|
||||
if (updateChapter(occurrences[0], chapter)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Remove manga title from chapter title.
|
||||
val nameWithoutManga = name.replace(manga.title.toLowerCase(), "").trim()
|
||||
|
||||
// Check if first value is number after title remove.
|
||||
if (updateChapter(withoutManga.find(nameWithoutManga), chapter))
|
||||
if (updateChapter(withoutManga.find(nameWithoutManga), chapter)) {
|
||||
return
|
||||
}
|
||||
|
||||
// Take the first number encountered.
|
||||
if (updateChapter(occurrence.find(nameWithoutManga), chapter))
|
||||
if (updateChapter(occurrence.find(nameWithoutManga), chapter)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,18 +115,22 @@ object ChapterRecognition {
|
||||
* @return decimal/alpha float value
|
||||
*/
|
||||
private fun checkForDecimal(decimal: String?, alpha: String?): Float {
|
||||
if (!decimal.isNullOrEmpty())
|
||||
if (!decimal.isNullOrEmpty()) {
|
||||
return decimal.toFloat()
|
||||
}
|
||||
|
||||
if (!alpha.isNullOrEmpty()) {
|
||||
if (alpha.contains("extra"))
|
||||
if (alpha.contains("extra")) {
|
||||
return .99f
|
||||
}
|
||||
|
||||
if (alpha.contains("omake"))
|
||||
if (alpha.contains("omake")) {
|
||||
return .98f
|
||||
}
|
||||
|
||||
if (alpha.contains("special"))
|
||||
if (alpha.contains("special")) {
|
||||
return .97f
|
||||
}
|
||||
|
||||
return if (alpha[0] == '.') {
|
||||
// Take value after (.)
|
||||
|
||||
@@ -24,7 +24,6 @@ fun syncChaptersWithSource(
|
||||
manga: Manga,
|
||||
source: Source
|
||||
): Pair<List<Chapter>, List<Chapter>> {
|
||||
|
||||
if (rawSourceChapters.isEmpty()) {
|
||||
throw Exception("No chapters found")
|
||||
}
|
||||
@@ -142,6 +141,6 @@ fun syncChaptersWithSource(
|
||||
// checks if the chapter in db needs updated
|
||||
private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: SChapter): Boolean {
|
||||
return dbChapter.scanlator != sourceChapter.scanlator || dbChapter.name != sourceChapter.name ||
|
||||
dbChapter.date_upload != sourceChapter.date_upload ||
|
||||
dbChapter.chapter_number != sourceChapter.chapter_number
|
||||
dbChapter.date_upload != sourceChapter.date_upload ||
|
||||
dbChapter.chapter_number != sourceChapter.chapter_number
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
fun launchUI(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
GlobalScope.launch(Dispatchers.Main, CoroutineStart.DEFAULT, block)
|
||||
GlobalScope.launch(Dispatchers.Main, CoroutineStart.DEFAULT, block)
|
||||
|
||||
fun launchIO(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT, block)
|
||||
GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT, block)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun launchNow(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED, block)
|
||||
GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED, block)
|
||||
|
||||
@@ -36,8 +36,9 @@ fun Long.toDateKey(): Date {
|
||||
* @return Calendar instance at supplied epoch time. Null if epoch was 0.
|
||||
*/
|
||||
fun Long.toCalendar(): Calendar? {
|
||||
if (this == 0L)
|
||||
if (this == 0L) {
|
||||
return null
|
||||
}
|
||||
val cal = Calendar.getInstance()
|
||||
cal.timeInMillis = this
|
||||
return cal
|
||||
|
||||
@@ -4,8 +4,10 @@ import java.security.MessageDigest
|
||||
|
||||
object Hash {
|
||||
|
||||
private val chars = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f')
|
||||
private val chars = charArrayOf(
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f'
|
||||
)
|
||||
|
||||
private val MD5 get() = MessageDigest.getInstance("MD5")
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ import kotlin.math.floor
|
||||
* If [replacement] is longer than [count] an exception will be thrown when `length > count`.
|
||||
*/
|
||||
fun String.chop(count: Int, replacement: String = "..."): String {
|
||||
return if (length > count)
|
||||
return if (length > count) {
|
||||
take(count - replacement.length) + replacement
|
||||
else
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,8 +19,9 @@ fun String.chop(count: Int, replacement: String = "..."): String {
|
||||
* If [replacement] is longer than [count] an exception will be thrown when `length > count`.
|
||||
*/
|
||||
fun String.truncateCenter(count: Int, replacement: String = "..."): String {
|
||||
if (length <= count)
|
||||
if (length <= count) {
|
||||
return this
|
||||
}
|
||||
|
||||
val pieceLength: Int = floor((count - replacement.length).div(2.0)).toInt()
|
||||
|
||||
|
||||
@@ -34,16 +34,16 @@ object DiskUtil {
|
||||
fun getExternalStorages(context: Context): Collection<File> {
|
||||
val directories = mutableSetOf<File>()
|
||||
directories += ContextCompat.getExternalFilesDirs(context, null)
|
||||
.filterNotNull()
|
||||
.mapNotNull {
|
||||
val file = File(it.absolutePath.substringBefore("/Android/"))
|
||||
val state = EnvironmentCompat.getStorageState(file)
|
||||
if (state == Environment.MEDIA_MOUNTED || state == Environment.MEDIA_MOUNTED_READ_ONLY) {
|
||||
file
|
||||
} else {
|
||||
null
|
||||
}
|
||||
.filterNotNull()
|
||||
.mapNotNull {
|
||||
val file = File(it.absolutePath.substringBefore("/Android/"))
|
||||
val state = EnvironmentCompat.getStorageState(file)
|
||||
if (state == Environment.MEDIA_MOUNTED || state == Environment.MEDIA_MOUNTED_READ_ONLY) {
|
||||
file
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
return directories
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ class EpubFile(file: File) : Closeable {
|
||||
*/
|
||||
private fun getPagesFromDocument(document: Document): List<String> {
|
||||
val pages = document.select("manifest > item")
|
||||
.filter { "application/xhtml+xml" == it.attr("media-type") }
|
||||
.associateBy { it.attr("id") }
|
||||
.filter { "application/xhtml+xml" == it.attr("media-type") }
|
||||
.associateBy { it.attr("id") }
|
||||
|
||||
val spine = document.select("spine > itemref").map { it.attr("idref") }
|
||||
return spine.mapNotNull { pages[it] }.map { it.attr("href") }
|
||||
|
||||
@@ -13,7 +13,9 @@ import java.io.File
|
||||
* @param context context of application
|
||||
*/
|
||||
fun File.getUriCompat(context: Context): Uri {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", this)
|
||||
else Uri.fromFile(this)
|
||||
} else {
|
||||
Uri.fromFile(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT) {
|
||||
*/
|
||||
fun Context.notificationBuilder(channelId: String, block: (NotificationCompat.Builder.() -> Unit)? = null): NotificationCompat.Builder {
|
||||
val builder = NotificationCompat.Builder(this, channelId)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
|
||||
if (block != null) {
|
||||
builder.block()
|
||||
}
|
||||
@@ -78,10 +78,10 @@ fun Context.notification(channelId: String, block: (NotificationCompat.Builder.(
|
||||
*/
|
||||
fun Context.getFilePicker(currentDir: String): Intent {
|
||||
return Intent(this, CustomLayoutPickerActivity::class.java)
|
||||
.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
|
||||
.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
|
||||
.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
|
||||
.putExtra(FilePickerActivity.EXTRA_START_PATH, currentDir)
|
||||
.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)
|
||||
.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true)
|
||||
.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR)
|
||||
.putExtra(FilePickerActivity.EXTRA_START_PATH, currentDir)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +178,7 @@ fun Context.isServiceRunning(serviceClass: Class<*>): Boolean {
|
||||
val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
@Suppress("DEPRECATION")
|
||||
return manager.getRunningServices(Integer.MAX_VALUE)
|
||||
.any { className == it.service.className }
|
||||
.any { className == it.service.className }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,8 +188,8 @@ fun Context.openInBrowser(url: String) {
|
||||
try {
|
||||
val parsedUrl = Uri.parse(url)
|
||||
val intent = CustomTabsIntent.Builder()
|
||||
.setToolbarColor(getResourceColor(R.attr.colorPrimary))
|
||||
.build()
|
||||
.setToolbarColor(getResourceColor(R.attr.colorPrimary))
|
||||
.build()
|
||||
intent.launchUrl(this, parsedUrl)
|
||||
} catch (e: Exception) {
|
||||
toast(e.message)
|
||||
|
||||
@@ -29,8 +29,9 @@ object ImageUtil {
|
||||
stream.read(bytes, 0, bytes.size)
|
||||
}
|
||||
|
||||
if (length == -1)
|
||||
if (length == -1) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (bytes.compareWith(charByteArrayOf(0xFF, 0xD8, 0xFF))) {
|
||||
return ImageType.JPG
|
||||
|
||||
@@ -60,8 +60,10 @@ abstract class WebViewClientCompat : WebViewClient() {
|
||||
request: WebResourceRequest,
|
||||
error: WebResourceError
|
||||
) {
|
||||
onReceivedErrorCompat(view, error.errorCode, error.description?.toString(),
|
||||
request.url.toString(), request.isForMainFrame)
|
||||
onReceivedErrorCompat(
|
||||
view, error.errorCode, error.description?.toString(),
|
||||
request.url.toString(), request.isForMainFrame
|
||||
)
|
||||
}
|
||||
|
||||
final override fun onReceivedError(
|
||||
@@ -79,7 +81,11 @@ abstract class WebViewClientCompat : WebViewClient() {
|
||||
request: WebResourceRequest,
|
||||
error: WebResourceResponse
|
||||
) {
|
||||
onReceivedErrorCompat(view, error.statusCode, error.reasonPhrase, request.url
|
||||
.toString(), request.isForMainFrame)
|
||||
onReceivedErrorCompat(
|
||||
view, error.statusCode, error.reasonPhrase,
|
||||
request.url
|
||||
.toString(),
|
||||
request.isForMainFrame
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ fun ImageView.roundTextIcon(text: String) {
|
||||
val letter = text.take(1).toUpperCase()
|
||||
val size = min(this.width, this.height)
|
||||
|
||||
setImageDrawable(TextDrawable(
|
||||
setImageDrawable(
|
||||
TextDrawable(
|
||||
shape = TextDrawable.DRAWABLE_SHAPE_OVAL,
|
||||
desiredWidth = size,
|
||||
desiredHeight = size,
|
||||
@@ -103,7 +104,8 @@ fun ImageView.roundTextIcon(text: String) {
|
||||
textColor = Color.WHITE,
|
||||
text = letter,
|
||||
color = ColorGenerator.MATERIAL.getColor(letter)
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,10 +116,11 @@ fun ImageView.roundTextIcon(text: String) {
|
||||
fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView) {
|
||||
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
if (dy <= 0)
|
||||
if (dy <= 0) {
|
||||
extend()
|
||||
else
|
||||
} else {
|
||||
shrink()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ import android.view.Window
|
||||
|
||||
fun Window.showBar() {
|
||||
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
decorView.systemUiVisibility = uiFlags
|
||||
}
|
||||
|
||||
fun Window.hideBar() {
|
||||
val uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN or
|
||||
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
decorView.systemUiVisibility = uiFlags
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user