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.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import tachiyomi.domain.track.model.Track as DomainTrack
|
||||
import tachiyomi.i18n.MR
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import tachiyomi.domain.track.model.Track as DomainTrack
|
||||
|
||||
class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
||||
|
||||
|
@ -51,7 +51,7 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
|||
ON_HOLD,
|
||||
DROPPED,
|
||||
PLAN_TO_READ,
|
||||
REREADING
|
||||
REREADING,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ class Hikka(id: Long) : BaseTracker(id, "Hikka"), DeletableTracker {
|
|||
try {
|
||||
val oauth = api.accessToken(code)
|
||||
interceptor.setAuth(oauth)
|
||||
val user = api.getCurrentUser()
|
||||
val user = api.getCurrentUser()
|
||||
saveCredentials(user.reference, oauth.accessToken)
|
||||
} catch (e: Throwable) {
|
||||
logout()
|
||||
|
|
|
@ -79,19 +79,25 @@ class HikkaApi(
|
|||
put("only_translated", false)
|
||||
put("magazines", buildJsonArray { })
|
||||
put("genres", buildJsonArray { })
|
||||
put("score", buildJsonArray {
|
||||
add(0)
|
||||
add(10)
|
||||
})
|
||||
put(
|
||||
"score",
|
||||
buildJsonArray {
|
||||
add(0)
|
||||
add(10)
|
||||
},
|
||||
)
|
||||
put("query", query)
|
||||
put("sort", buildJsonArray {
|
||||
add("score:asc")
|
||||
add("scored_by:asc")
|
||||
})
|
||||
put(
|
||||
"sort",
|
||||
buildJsonArray {
|
||||
add("score:asc")
|
||||
add("scored_by:asc")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
with(json) {
|
||||
authClient.newCall(POST(url.toString(), body=payload.toString().toRequestBody(jsonMime)))
|
||||
authClient.newCall(POST(url.toString(), body = payload.toString().toRequestBody(jsonMime)))
|
||||
.awaitSuccess()
|
||||
.parseAs<HKMangaPagination>()
|
||||
.list
|
||||
|
@ -103,7 +109,7 @@ class HikkaApi(
|
|||
private suspend fun getRead(track: Track): HKRead? {
|
||||
return withIOContext {
|
||||
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) {
|
||||
val response = authClient.newCall(GET(url.toString())).execute()
|
||||
if (response.code == 404) {
|
||||
|
@ -120,7 +126,7 @@ class HikkaApi(
|
|||
return withIOContext {
|
||||
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()
|
||||
|
||||
with(json) {
|
||||
|
@ -136,7 +142,7 @@ class HikkaApi(
|
|||
return withIOContext {
|
||||
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()
|
||||
|
||||
authClient.newCall(DELETE(url.toString()))
|
||||
|
@ -148,7 +154,7 @@ class HikkaApi(
|
|||
return withIOContext {
|
||||
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()
|
||||
|
||||
var rereads = getRead(track)?.rereads ?: 0
|
||||
|
@ -166,7 +172,7 @@ class HikkaApi(
|
|||
}
|
||||
|
||||
with(json) {
|
||||
authClient.newCall(PUT(url.toString(), body=payload.toString().toRequestBody(jsonMime)))
|
||||
authClient.newCall(PUT(url.toString(), body = payload.toString().toRequestBody(jsonMime)))
|
||||
.awaitSuccess()
|
||||
.parseAs<HKRead>()
|
||||
.toTrack(trackId)
|
||||
|
|
|
@ -9,5 +9,5 @@ data class HKAuthTokenInfo(
|
|||
val client: HKClient,
|
||||
val scope: List<String>,
|
||||
val expiration: Long,
|
||||
val used: Long
|
||||
val used: Long,
|
||||
)
|
||||
|
|
|
@ -10,5 +10,5 @@ data class HKClient(
|
|||
val verified: Boolean,
|
||||
val user: HKUser,
|
||||
val created: Long,
|
||||
val updated: Long
|
||||
val updated: Long,
|
||||
)
|
||||
|
|
|
@ -21,7 +21,7 @@ data class HKManga(
|
|||
val year: Int,
|
||||
@SerialName("scored_by") val scoredBy: Int,
|
||||
val score: Double,
|
||||
val slug: String
|
||||
val slug: String,
|
||||
) {
|
||||
fun toTrack(trackId: Long): TrackSearch {
|
||||
return TrackSearch.create(trackId).apply {
|
||||
|
|
|
@ -5,5 +5,5 @@ import kotlinx.serialization.Serializable
|
|||
@Serializable
|
||||
data class HKMangaPagination(
|
||||
val pagination: HKPagination,
|
||||
val list: List<HKManga>
|
||||
val list: List<HKManga>,
|
||||
)
|
||||
|
|
|
@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
|
|||
data class HKPagination(
|
||||
val total: Int,
|
||||
val pages: Int,
|
||||
val page: Int
|
||||
val page: Int,
|
||||
)
|
||||
|
|
|
@ -17,7 +17,7 @@ data class HKRead(
|
|||
val volumes: Int,
|
||||
val rereads: Int,
|
||||
val score: Int,
|
||||
val content: HKManga
|
||||
val content: HKManga,
|
||||
) {
|
||||
fun toTrack(trackId: Long): TrackSearch {
|
||||
return TrackSearch.create(trackId).apply {
|
||||
|
|
|
@ -12,5 +12,5 @@ data class HKUser(
|
|||
val cover: String,
|
||||
val active: Boolean,
|
||||
val avatar: String,
|
||||
val role: String
|
||||
val role: String,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue