mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
Minor code cleanup
This commit is contained in:
@@ -92,7 +92,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
|
||||
db.inTransaction {
|
||||
val deletedChapterNumbers = TreeSet<Float>()
|
||||
val deletedReadChapterNumbers = TreeSet<Float>()
|
||||
if (!toDelete.isEmpty()) {
|
||||
if (toDelete.isNotEmpty()) {
|
||||
for (c in toDelete) {
|
||||
if (c.read) {
|
||||
deletedReadChapterNumbers.add(c.chapter_number)
|
||||
@@ -102,7 +102,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
|
||||
db.deleteChapters(toDelete).executeAsBlocking()
|
||||
}
|
||||
|
||||
if (!toAdd.isEmpty()) {
|
||||
if (toAdd.isNotEmpty()) {
|
||||
// Set the date fetch for new items in reverse order to allow another sorting method.
|
||||
// Sources MUST return the chapters from most to less recent, which is common.
|
||||
var now = Date().time
|
||||
@@ -121,7 +121,7 @@ fun syncChaptersWithSource(db: DatabaseHelper,
|
||||
db.insertChapters(toAdd).executeAsBlocking()
|
||||
}
|
||||
|
||||
if (!toChange.isEmpty()) {
|
||||
if (toChange.isNotEmpty()) {
|
||||
db.insertChapters(toChange).executeAsBlocking()
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ fun syncChaptersWithSource(db: DatabaseHelper,
|
||||
manga.last_update = Date().time
|
||||
db.updateLastUpdated(manga).executeAsBlocking()
|
||||
}
|
||||
return Pair(toAdd.subtract(readded).toList(), toDelete.subtract(readded).toList())
|
||||
|
||||
return Pair(toAdd.subtract(readded).toList(), toDelete.subtract(readded).toList())
|
||||
}
|
||||
|
||||
//checks if the chapter in db needs updated
|
||||
@@ -141,4 +141,4 @@ private fun shouldUpdateDbChapter(dbChapter: Chapter, sourceChapter: SChapter):
|
||||
return dbChapter.scanlator != sourceChapter.scanlator || dbChapter.name != sourceChapter.name ||
|
||||
dbChapter.date_upload != sourceChapter.date_upload ||
|
||||
dbChapter.chapter_number != sourceChapter.chapter_number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ object ImageUtil {
|
||||
}
|
||||
|
||||
private fun ByteArray.compareWith(magic: ByteArray): Boolean {
|
||||
for (i in 0 until magic.size) {
|
||||
for (i in magic.indices) {
|
||||
if (this[i] != magic[i]) return false
|
||||
}
|
||||
return true
|
||||
@@ -58,7 +58,7 @@ object ImageUtil {
|
||||
|
||||
private fun charByteArrayOf(vararg bytes: Int): ByteArray {
|
||||
return ByteArray(bytes.size).apply {
|
||||
for (i in 0 until bytes.size) {
|
||||
for (i in bytes.indices) {
|
||||
set(i, bytes[i].toByte())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import android.view.ContextThemeWrapper
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.*
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Utility class to change the application's language in runtime.
|
||||
@@ -90,7 +90,7 @@ object LocaleHelper {
|
||||
* Updates the app's language to an activity.
|
||||
*/
|
||||
fun updateConfiguration(wrapper: ContextThemeWrapper) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && appLocale != null) {
|
||||
if (appLocale != null) {
|
||||
val config = Configuration(preferences.context.resources.configuration)
|
||||
config.setLocale(appLocale)
|
||||
wrapper.applyOverrideConfiguration(config)
|
||||
|
||||
@@ -22,7 +22,7 @@ object SharedData {
|
||||
* @param data the object to put.
|
||||
*/
|
||||
fun <T : Any> put(data: T) {
|
||||
map.put(data.javaClass, data)
|
||||
map[data.javaClass] = data
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package eu.kanade.tachiyomi.util
|
||||
|
||||
import java.lang.Math.floor
|
||||
import kotlin.math.floor
|
||||
|
||||
/**
|
||||
* Replaces the given string to have at most [count] characters using [replacement] at its end.
|
||||
@@ -25,4 +25,4 @@ fun String.truncateCenter(count: Int, replacement: String = "..."): String{
|
||||
val pieceLength:Int = floor((count - replacement.length).div(2.0)).toInt()
|
||||
|
||||
return "${ take(pieceLength) }$replacement${ takeLast(pieceLength) }"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ package eu.kanade.tachiyomi.util
|
||||
import android.graphics.Color
|
||||
import android.graphics.Point
|
||||
import android.graphics.Typeface
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Returns coordinates of view.
|
||||
@@ -58,7 +59,7 @@ inline fun View.visibleIf(block: () -> Boolean) {
|
||||
* @param random random color
|
||||
*/
|
||||
fun View.getRound(text: String, random : Boolean = true): TextDrawable {
|
||||
val size = Math.min(this.width, this.height)
|
||||
val size = min(this.width, this.height)
|
||||
return TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.width(size)
|
||||
|
||||
Reference in New Issue
Block a user