mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
ref: optimized imports and refactor code
This commit is contained in:
parent
a8f4e63d54
commit
f480d4cb38
9 changed files with 30 additions and 24 deletions
|
@ -12,9 +12,9 @@ import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import tachiyomi.domain.track.model.Track as DomainTrack
|
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import tachiyomi.domain.track.model.Track as DomainTrack
|
||||||
|
|
||||||
class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
||||||
ON_HOLD,
|
ON_HOLD,
|
||||||
DROPPED,
|
DROPPED,
|
||||||
PLAN_TO_READ,
|
PLAN_TO_READ,
|
||||||
REREADING
|
REREADING,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
||||||
try {
|
try {
|
||||||
val oauth = api.accessToken(code)
|
val oauth = api.accessToken(code)
|
||||||
interceptor.setAuth(oauth)
|
interceptor.setAuth(oauth)
|
||||||
val user = api.getCurrentUser()
|
val user = api.getCurrentUser()
|
||||||
saveCredentials(user.reference, oauth.accessToken)
|
saveCredentials(user.reference, oauth.accessToken)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logout()
|
logout()
|
||||||
|
|
|
@ -79,19 +79,25 @@ class HikkaApi(
|
||||||
put("only_translated", false)
|
put("only_translated", false)
|
||||||
put("magazines", buildJsonArray { })
|
put("magazines", buildJsonArray { })
|
||||||
put("genres", buildJsonArray { })
|
put("genres", buildJsonArray { })
|
||||||
put("score", buildJsonArray {
|
put(
|
||||||
add(0)
|
"score",
|
||||||
add(10)
|
buildJsonArray {
|
||||||
})
|
add(0)
|
||||||
|
add(10)
|
||||||
|
},
|
||||||
|
)
|
||||||
put("query", query)
|
put("query", query)
|
||||||
put("sort", buildJsonArray {
|
put(
|
||||||
add("score:asc")
|
"sort",
|
||||||
add("scored_by:asc")
|
buildJsonArray {
|
||||||
})
|
add("score:asc")
|
||||||
|
add("scored_by:asc")
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
with(json) {
|
with(json) {
|
||||||
authClient.newCall(POST(url.toString(), body=payload.toString().toRequestBody(jsonMime)))
|
authClient.newCall(POST(url.toString(), body = payload.toString().toRequestBody(jsonMime)))
|
||||||
.awaitSuccess()
|
.awaitSuccess()
|
||||||
.parseAs<HKMangaPagination>()
|
.parseAs<HKMangaPagination>()
|
||||||
.list
|
.list
|
||||||
|
@ -103,7 +109,7 @@ class HikkaApi(
|
||||||
private suspend fun getRead(track: Track): HKRead? {
|
private suspend fun getRead(track: Track): HKRead? {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val slug = track.tracking_url.split("/")[4]
|
val slug = track.tracking_url.split("/")[4]
|
||||||
val url = "$BASE_API_URL/read/manga/${slug}".toUri().buildUpon().build()
|
val url = "$BASE_API_URL/read/manga/$slug".toUri().buildUpon().build()
|
||||||
with(json) {
|
with(json) {
|
||||||
val response = authClient.newCall(GET(url.toString())).execute()
|
val response = authClient.newCall(GET(url.toString())).execute()
|
||||||
if (response.code == 404) {
|
if (response.code == 404) {
|
||||||
|
@ -120,7 +126,7 @@ class HikkaApi(
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val slug = track.tracking_url.split("/")[4]
|
val slug = track.tracking_url.split("/")[4]
|
||||||
|
|
||||||
val url = "$BASE_API_URL/manga/${slug}".toUri().buildUpon()
|
val url = "$BASE_API_URL/manga/$slug".toUri().buildUpon()
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
with(json) {
|
with(json) {
|
||||||
|
@ -136,7 +142,7 @@ class HikkaApi(
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val slug = track.remoteUrl.split("/")[4]
|
val slug = track.remoteUrl.split("/")[4]
|
||||||
|
|
||||||
val url = "$BASE_API_URL/read/manga/${slug}".toUri().buildUpon()
|
val url = "$BASE_API_URL/read/manga/$slug".toUri().buildUpon()
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
authClient.newCall(DELETE(url.toString()))
|
authClient.newCall(DELETE(url.toString()))
|
||||||
|
@ -148,7 +154,7 @@ class HikkaApi(
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val slug = track.tracking_url.split("/")[4]
|
val slug = track.tracking_url.split("/")[4]
|
||||||
|
|
||||||
val url = "$BASE_API_URL/read/manga/${slug}".toUri().buildUpon()
|
val url = "$BASE_API_URL/read/manga/$slug".toUri().buildUpon()
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
var rereads = getRead(track)?.rereads ?: 0
|
var rereads = getRead(track)?.rereads ?: 0
|
||||||
|
@ -166,7 +172,7 @@ class HikkaApi(
|
||||||
}
|
}
|
||||||
|
|
||||||
with(json) {
|
with(json) {
|
||||||
authClient.newCall(PUT(url.toString(), body=payload.toString().toRequestBody(jsonMime)))
|
authClient.newCall(PUT(url.toString(), body = payload.toString().toRequestBody(jsonMime)))
|
||||||
.awaitSuccess()
|
.awaitSuccess()
|
||||||
.parseAs<HKRead>()
|
.parseAs<HKRead>()
|
||||||
.toTrack(trackId)
|
.toTrack(trackId)
|
||||||
|
|
|
@ -9,5 +9,5 @@ data class HKAuthTokenInfo(
|
||||||
val client: HKClient,
|
val client: HKClient,
|
||||||
val scope: List<String>,
|
val scope: List<String>,
|
||||||
val expiration: Long,
|
val expiration: Long,
|
||||||
val used: Long
|
val used: Long,
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,5 +10,5 @@ data class HKClient(
|
||||||
val verified: Boolean,
|
val verified: Boolean,
|
||||||
val user: HKUser,
|
val user: HKUser,
|
||||||
val created: Long,
|
val created: Long,
|
||||||
val updated: Long
|
val updated: Long,
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,7 +21,7 @@ data class HKManga(
|
||||||
val year: Int,
|
val year: Int,
|
||||||
@SerialName("scored_by") val scoredBy: Int,
|
@SerialName("scored_by") val scoredBy: Int,
|
||||||
val score: Double,
|
val score: Double,
|
||||||
val slug: String
|
val slug: String,
|
||||||
) {
|
) {
|
||||||
fun toTrack(trackId: Long): TrackSearch {
|
fun toTrack(trackId: Long): TrackSearch {
|
||||||
return TrackSearch.create(trackId).apply {
|
return TrackSearch.create(trackId).apply {
|
||||||
|
|
|
@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable
|
||||||
@Serializable
|
@Serializable
|
||||||
data class HKMangaPagination(
|
data class HKMangaPagination(
|
||||||
val pagination: HKPagination,
|
val pagination: HKPagination,
|
||||||
val list: List<HKManga>
|
val list: List<HKManga>,
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
|
||||||
data class HKPagination(
|
data class HKPagination(
|
||||||
val total: Int,
|
val total: Int,
|
||||||
val pages: Int,
|
val pages: Int,
|
||||||
val page: Int
|
val page: Int,
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,7 +17,7 @@ data class HKRead(
|
||||||
val volumes: Int,
|
val volumes: Int,
|
||||||
val rereads: Int,
|
val rereads: Int,
|
||||||
val score: Int,
|
val score: Int,
|
||||||
val content: HKManga
|
val content: HKManga,
|
||||||
) {
|
) {
|
||||||
fun toTrack(trackId: Long): TrackSearch {
|
fun toTrack(trackId: Long): TrackSearch {
|
||||||
return TrackSearch.create(trackId).apply {
|
return TrackSearch.create(trackId).apply {
|
||||||
|
|
|
@ -12,5 +12,5 @@ data class HKUser(
|
||||||
val cover: String,
|
val cover: String,
|
||||||
val active: Boolean,
|
val active: Boolean,
|
||||||
val avatar: String,
|
val avatar: String,
|
||||||
val role: String
|
val role: String,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue