Linting Fixes AZ
This commit is contained in:
@@ -14,16 +14,16 @@ import java.util.Date
|
||||
|
||||
inline fun <reified E : RealmModel> RealmQuery<out E>.beginLog(
|
||||
clazz: Class<out E>? =
|
||||
E::class.java
|
||||
E::class.java
|
||||
): LoggingRealmQuery<out E> =
|
||||
LoggingRealmQuery.fromQuery(this, clazz)
|
||||
|
||||
class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
companion object {
|
||||
fun <E : RealmModel> fromQuery(q: RealmQuery<out E>, clazz: Class<out E>?) =
|
||||
LoggingRealmQuery(q).apply {
|
||||
log += "SELECT * FROM ${clazz?.name ?: "???"} WHERE"
|
||||
}
|
||||
LoggingRealmQuery(q).apply {
|
||||
log += "SELECT * FROM ${clazz?.name ?: "???"} WHERE"
|
||||
}
|
||||
}
|
||||
|
||||
private val log = mutableListOf<String>()
|
||||
@@ -47,9 +47,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendEqualTo(fieldName: String, value: String, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" == \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" == \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun equalTo(fieldName: String, value: String): RealmQuery<E> {
|
||||
@@ -108,11 +112,18 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
fun appendIn(fieldName: String, values: Array<out Any?>, casing: Case? = null) {
|
||||
log += sec("[${values.joinToString(separator = ", ", transform = {
|
||||
"\"$it\""
|
||||
})}] IN \"$fieldName\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"[${values.joinToString(
|
||||
separator = ", ",
|
||||
transform = {
|
||||
"\"$it\""
|
||||
}
|
||||
)}] IN \"$fieldName\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun `in`(fieldName: String, values: Array<String>): RealmQuery<E> {
|
||||
@@ -166,9 +177,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendNotEqualTo(fieldName: String, value: Any?, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" != \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" != \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun notEqualTo(fieldName: String, value: String): RealmQuery<E> {
|
||||
@@ -372,9 +387,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendContains(fieldName: String, value: Any?, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" CONTAINS \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" CONTAINS \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun contains(fieldName: String, value: String): RealmQuery<E> {
|
||||
@@ -388,9 +407,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendBeginsWith(fieldName: String, value: Any?, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" BEGINS WITH \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" BEGINS WITH \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun beginsWith(fieldName: String, value: String): RealmQuery<E> {
|
||||
@@ -404,9 +427,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendEndsWith(fieldName: String, value: Any?, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" ENDS WITH \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" ENDS WITH \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun endsWith(fieldName: String, value: String): RealmQuery<E> {
|
||||
@@ -420,9 +447,13 @@ class LoggingRealmQuery<E : RealmModel>(val query: RealmQuery<E>) {
|
||||
}
|
||||
|
||||
private fun appendLike(fieldName: String, value: Any?, casing: Case? = null) {
|
||||
log += sec("\"$fieldName\" LIKE \"$value\"" + (casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""))
|
||||
log += sec(
|
||||
"\"$fieldName\" LIKE \"$value\"" + (
|
||||
casing?.let {
|
||||
" CASE ${casing.name}"
|
||||
} ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun like(fieldName: String, value: String): RealmQuery<E> {
|
||||
|
||||
@@ -209,10 +209,14 @@ class NakedTrie<T> : MutableMap<String, T> {
|
||||
override val entries: Set<Map.Entry<String, T>>
|
||||
get() {
|
||||
val out = mutableSetOf<Map.Entry<String, T>>()
|
||||
node.walk("", { k, v ->
|
||||
out.add(AbstractMap.SimpleImmutableEntry(k, v))
|
||||
true
|
||||
}, leavesOnly)
|
||||
node.walk(
|
||||
"",
|
||||
{ k, v ->
|
||||
out.add(AbstractMap.SimpleImmutableEntry(k, v))
|
||||
true
|
||||
},
|
||||
leavesOnly
|
||||
)
|
||||
return out
|
||||
}
|
||||
/**
|
||||
@@ -221,10 +225,14 @@ class NakedTrie<T> : MutableMap<String, T> {
|
||||
override val keys: Set<String>
|
||||
get() {
|
||||
val out = mutableSetOf<String>()
|
||||
node.walk("", { k, _ ->
|
||||
out.add(k)
|
||||
true
|
||||
}, leavesOnly)
|
||||
node.walk(
|
||||
"",
|
||||
{ k, _ ->
|
||||
out.add(k)
|
||||
true
|
||||
},
|
||||
leavesOnly
|
||||
)
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -243,10 +251,14 @@ class NakedTrie<T> : MutableMap<String, T> {
|
||||
override val values: Collection<T>
|
||||
get() {
|
||||
val out = mutableSetOf<T>()
|
||||
node.walk("", { _, v ->
|
||||
out.add(v)
|
||||
true
|
||||
}, leavesOnly)
|
||||
node.walk(
|
||||
"",
|
||||
{ _, v ->
|
||||
out.add(v)
|
||||
true
|
||||
},
|
||||
leavesOnly
|
||||
)
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -264,10 +276,14 @@ class NakedTrie<T> : MutableMap<String, T> {
|
||||
* Returns `true` if the map maps one or more keys to the specified [value].
|
||||
*/
|
||||
override fun containsValue(value: T): Boolean {
|
||||
node.walk("", { _, v ->
|
||||
if (v == value) return true
|
||||
true
|
||||
}, leavesOnly)
|
||||
node.walk(
|
||||
"",
|
||||
{ _, v ->
|
||||
if (v == value) return true
|
||||
true
|
||||
},
|
||||
leavesOnly
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -315,32 +331,38 @@ class NakedTrie<T> : MutableMap<String, T> {
|
||||
* Returns a [MutableSet] of all key/value pairs in this map.
|
||||
*/
|
||||
override val entries: MutableSet<MutableMap.MutableEntry<String, T>>
|
||||
get() = FakeMutableSet.fromSet(mutableSetOf<MutableMap.MutableEntry<String, T>>().apply {
|
||||
walk { k, v ->
|
||||
this += FakeMutableEntry.fromPair(k, v)
|
||||
true
|
||||
get() = FakeMutableSet.fromSet(
|
||||
mutableSetOf<MutableMap.MutableEntry<String, T>>().apply {
|
||||
walk { k, v ->
|
||||
this += FakeMutableEntry.fromPair(k, v)
|
||||
true
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns a [MutableSet] of all keys in this map.
|
||||
*/
|
||||
override val keys: MutableSet<String>
|
||||
get() = FakeMutableSet.fromSet(mutableSetOf<String>().apply {
|
||||
walk { k, _ ->
|
||||
this += k
|
||||
true
|
||||
get() = FakeMutableSet.fromSet(
|
||||
mutableSetOf<String>().apply {
|
||||
walk { k, _ ->
|
||||
this += k
|
||||
true
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Returns a [MutableCollection] of all values in this map. Note that this collection may contain duplicate values.
|
||||
*/
|
||||
override val values: MutableCollection<T>
|
||||
get() = FakeMutableCollection.fromCollection(mutableListOf<T>().apply {
|
||||
walk { _, v ->
|
||||
this += v
|
||||
true
|
||||
get() = FakeMutableCollection.fromCollection(
|
||||
mutableListOf<T>().apply {
|
||||
walk { _, v ->
|
||||
this += v
|
||||
true
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import org.jsoup.nodes.Document
|
||||
fun Response.interceptAsHtml(block: (Document) -> Unit): Response {
|
||||
val body = body
|
||||
if (body?.contentType()?.type == "text" &&
|
||||
body.contentType()?.subtype == "html") {
|
||||
body.contentType()?.subtype == "html"
|
||||
) {
|
||||
val bodyString = body.string()
|
||||
val rebuiltResponse = newBuilder()
|
||||
.body(ResponseBody.create(body.contentType(), bodyString))
|
||||
.build()
|
||||
.body(ResponseBody.create(body.contentType(), bodyString))
|
||||
.build()
|
||||
try {
|
||||
// Search for captcha
|
||||
val parsed = asJsoup(html = bodyString)
|
||||
|
||||
@@ -53,4 +53,4 @@ fun <T : RealmModel> Realm.createUUIDObj(clazz: Class<T>) =
|
||||
createObject(clazz, UUID.randomUUID().toString())!!
|
||||
|
||||
inline fun <reified T : RealmModel> Realm.createUUIDObj() =
|
||||
createUUIDObj(T::class.java)
|
||||
createUUIDObj(T::class.java)
|
||||
|
||||
@@ -37,14 +37,18 @@ suspend fun <T> Single<T>.await(subscribeOn: Scheduler? = null): T {
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
val self = if (subscribeOn != null) subscribeOn(subscribeOn) else this
|
||||
lateinit var sub: Subscription
|
||||
sub = self.subscribe({
|
||||
continuation.resume(it) {
|
||||
sub.unsubscribe()
|
||||
sub = self.subscribe(
|
||||
{
|
||||
continuation.resume(it) {
|
||||
sub.unsubscribe()
|
||||
}
|
||||
},
|
||||
{
|
||||
if (!continuation.isCancelled) {
|
||||
continuation.resumeWithException(it)
|
||||
}
|
||||
}
|
||||
}, {
|
||||
if (!continuation.isCancelled)
|
||||
continuation.resumeWithException(it)
|
||||
})
|
||||
)
|
||||
|
||||
continuation.invokeOnCancellation {
|
||||
sub.unsubscribe()
|
||||
@@ -59,14 +63,18 @@ suspend fun Completable.awaitSuspending(subscribeOn: Scheduler? = null) {
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
val self = if (subscribeOn != null) subscribeOn(subscribeOn) else this
|
||||
lateinit var sub: Subscription
|
||||
sub = self.subscribe({
|
||||
continuation.resume(Unit) {
|
||||
sub.unsubscribe()
|
||||
sub = self.subscribe(
|
||||
{
|
||||
continuation.resume(Unit) {
|
||||
sub.unsubscribe()
|
||||
}
|
||||
},
|
||||
{
|
||||
if (!continuation.isCancelled) {
|
||||
continuation.resumeWithException(it)
|
||||
}
|
||||
}
|
||||
}, {
|
||||
if (!continuation.isCancelled)
|
||||
continuation.resumeWithException(it)
|
||||
})
|
||||
)
|
||||
|
||||
continuation.invokeOnCancellation {
|
||||
sub.unsubscribe()
|
||||
|
||||
@@ -14,15 +14,21 @@ private val galleryAdder by lazy {
|
||||
* A version of fetchSearchManga that supports URL importing
|
||||
*/
|
||||
fun UrlImportableSource.urlImportFetchSearchManga(query: String, fail: () -> Observable<MangasPage>) =
|
||||
when {
|
||||
query.startsWith("http://") || query.startsWith("https://") -> {
|
||||
Observable.fromCallable {
|
||||
val res = galleryAdder.addGallery(query, false, this)
|
||||
MangasPage((if (res is GalleryAddEvent.Success)
|
||||
listOf(res.manga)
|
||||
else
|
||||
emptyList()), false)
|
||||
}
|
||||
when {
|
||||
query.startsWith("http://") || query.startsWith("https://") -> {
|
||||
Observable.fromCallable {
|
||||
val res = galleryAdder.addGallery(query, false, this)
|
||||
MangasPage(
|
||||
(
|
||||
if (res is GalleryAddEvent.Success) {
|
||||
listOf(res.manga)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
),
|
||||
false
|
||||
)
|
||||
}
|
||||
else -> fail()
|
||||
}
|
||||
else -> fail()
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ class SparseArrayCollection<E>(val sparseArray: SparseArray<E>, var reverse: Boo
|
||||
var idx = index++
|
||||
if (reverse) idx = sparseArray.size() - 1 - idx
|
||||
return AbstractMap.SimpleImmutableEntry(
|
||||
sparseArray.keyAt(idx),
|
||||
sparseArray.valueAt(idx)
|
||||
sparseArray.keyAt(idx),
|
||||
sparseArray.valueAt(idx)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user