-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Hikka Tracker Integration #1386
Open
Lorg0n
wants to merge
32
commits into
mihonapp:main
Choose a base branch
from
Lorg0n:Add-Hikka-Tracker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8ac5fd4
feat: add Hikka logo to resources
Lorg0n a357b5e
feat: add core Hikka tracker classes and DTOs for API requests
Lorg0n 9444cee
feat: update AndroidManifest for auth support, modify auth-related cl…
Lorg0n b018928
feat: improve Hikka authorization
Lorg0n 328dd96
feat: improve Hikka authorization
Lorg0n 3d939ca
feat: more optimization Hikka authorization
Lorg0n 3c8a60f
ref: added more specificity and removed unnecessary code in Hikka Api
Lorg0n 16581de
fix: corrected function names and added reread logic
Lorg0n 41e6d08
fix: slightly optimised the function of string to number conversion a…
Lorg0n 94532a2
fix: recode the rereading logic in HikkaApi
Lorg0n f27c321
fix: fixed a bug where the server returned a 404 error due to receivi…
Lorg0n 30a13be
ref: optimized imports and reduced the length of lines
Lorg0n f45c0a8
ref: optimized imports and refactor code
Lorg0n fe8f40f
feat: changed authorization principle, removed dependence on third-pa…
Lorg0n 0fde5e7
fix: remove unused import
Lorg0n 8ec826c
fix: fixed a bug in DTO that caused a data parsing error
Lorg0n eaf385a
fix: fixed a bug in DTO that caused a data parsing error in manga search
Lorg0n 3445509
fix: update the API link by replacing the deprecated one
Lorg0n 586fd38
feat: changed the buffer time to check the token for expiry
Lorg0n fcc8c76
ref: deleted unnecessary fields in the HKUser
Lorg0n a2f269d
ref: deleted deleted unnecessary imports
Lorg0n 2047d48
feat: change logic of binding track from Hikka source
Lorg0n 9ed5741
ref: deleted unnecessary comment
Lorg0n 2f7509e
style: nothing change
Lorg0n 04b3593
ref: simplify methods using expression bodies
Lorg0n ec9fa64
fix: changed the sorting in the search to from higher score to lower …
Lorg0n f10813a
ref: move annotations above properties and optimize string formatting…
Lorg0n 5d5d640
fix: auth issue caused by null value
Lorg0n 6612764
style: add support of Hikka.io to README.md
Lorg0n de772ea
Merge branch 'main' into Add-Hikka-Tracker
Lorg0n b347453
fix: resolved the Hikka title bug in SettingsTrackingScreen.kt
Lorg0n 3030ac0
chore: apply spotless formatting
Lorg0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
app/src/main/java/eu/kanade/tachiyomi/data/track/hikka/Hikka.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package eu.kanade.tachiyomi.data.track.hikka | ||
|
||
import android.graphics.Color | ||
import dev.icerock.moko.resources.StringResource | ||
import eu.kanade.tachiyomi.R | ||
import eu.kanade.tachiyomi.data.database.models.Track | ||
import eu.kanade.tachiyomi.data.track.BaseTracker | ||
import eu.kanade.tachiyomi.data.track.DeletableTracker | ||
import eu.kanade.tachiyomi.data.track.hikka.dto.HKOAuth | ||
import eu.kanade.tachiyomi.data.track.model.TrackSearch | ||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.toImmutableList | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
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 { | ||
|
||
companion object { | ||
const val READING = 0L | ||
const val COMPLETED = 1L | ||
const val ON_HOLD = 2L | ||
const val DROPPED = 3L | ||
const val PLAN_TO_READ = 4L | ||
const val REREADING = 5L | ||
|
||
private val SCORE_LIST = IntRange(0, 10) | ||
.map(Int::toString) | ||
.toImmutableList() | ||
} | ||
Lorg0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private val json: Json by injectLazy() | ||
|
||
private val interceptor by lazy { HikkaInterceptor(this) } | ||
private val api by lazy { HikkaApi(id, client, interceptor) } | ||
|
||
override fun getLogoColor(): Int { | ||
return Color.rgb(0, 0, 0) | ||
} | ||
|
||
override fun getLogo(): Int { | ||
return R.drawable.ic_tracker_hikka | ||
} | ||
Lorg0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override fun getStatusList(): List<Long> { | ||
return listOf( | ||
READING, | ||
COMPLETED, | ||
ON_HOLD, | ||
DROPPED, | ||
PLAN_TO_READ, | ||
REREADING, | ||
) | ||
} | ||
|
||
override fun getStatus(status: Long): StringResource? = when (status) { | ||
READING -> MR.strings.reading | ||
PLAN_TO_READ -> MR.strings.plan_to_read | ||
COMPLETED -> MR.strings.completed | ||
ON_HOLD -> MR.strings.on_hold | ||
DROPPED -> MR.strings.dropped | ||
REREADING -> MR.strings.repeating | ||
else -> null | ||
} | ||
|
||
override fun getReadingStatus(): Long { | ||
return READING | ||
} | ||
Lorg0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override fun getRereadingStatus(): Long { | ||
return REREADING | ||
} | ||
|
||
override fun getCompletionStatus(): Long { | ||
return COMPLETED | ||
} | ||
|
||
override fun getScoreList(): ImmutableList<String> { | ||
return SCORE_LIST | ||
} | ||
|
||
override fun displayScore(track: DomainTrack): String { | ||
return track.score.toInt().toString() | ||
} | ||
|
||
override suspend fun update( | ||
track: Track, | ||
didReadChapter: Boolean, | ||
): Track { | ||
if (track.status != COMPLETED) { | ||
if (didReadChapter) { | ||
if (track.last_chapter_read.toLong() == track.total_chapters && track.total_chapters > 0) { | ||
track.status = COMPLETED | ||
} else if (track.status != REREADING) { | ||
track.status = READING | ||
} | ||
} | ||
} | ||
return api.updateUserManga(track) | ||
} | ||
|
||
override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { | ||
val readContent = api.getRead(track) | ||
val remoteTrack = api.getManga(track) | ||
|
||
track.copyPersonalFrom(remoteTrack) | ||
track.library_id = remoteTrack.library_id | ||
|
||
if (track.status != COMPLETED) { | ||
val isRereading = track.status == REREADING | ||
track.status = if (!isRereading && hasReadChapters) READING else track.status | ||
} | ||
|
||
return if (readContent != null) { | ||
track.score = readContent.score.toDouble() | ||
track.last_chapter_read = readContent.chapters.toDouble() | ||
track.score = readContent.score.toDouble() | ||
update(track) | ||
} else { | ||
track.score = 0.0 | ||
update(track) | ||
} | ||
} | ||
|
||
override suspend fun search(query: String): List<TrackSearch> { | ||
return api.searchManga(query) | ||
} | ||
|
||
override suspend fun refresh(track: Track): Track { | ||
val remoteTrack = api.updateUserManga(track) | ||
track.copyPersonalFrom(remoteTrack) | ||
track.total_chapters = remoteTrack.total_chapters | ||
return track | ||
} | ||
|
||
override suspend fun login(username: String, password: String) = login(password) | ||
|
||
suspend fun login(reference: String) { | ||
try { | ||
val oauth = api.accessToken(reference) | ||
interceptor.setAuth(oauth) | ||
val user = api.getCurrentUser() | ||
saveCredentials(user.reference, oauth.accessToken) | ||
} catch (e: Throwable) { | ||
logout() | ||
} | ||
} | ||
|
||
override suspend fun delete(track: DomainTrack) { | ||
api.deleteUserManga(track) | ||
} | ||
|
||
override fun logout() { | ||
super.logout() | ||
trackPreferences.trackToken(this).delete() | ||
interceptor.setAuth(null) | ||
} | ||
|
||
fun saveOAuth(oAuth: HKOAuth?) { | ||
trackPreferences.trackToken(this).set(json.encodeToString(oAuth)) | ||
} | ||
|
||
fun loadOAuth(): HKOAuth? { | ||
return try { | ||
json.decodeFromString<HKOAuth>(trackPreferences.trackToken(this).get()) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't compile. Remove the
title
line and it should be good.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in case you're worried, it still shows Hikka in the Tracking screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks, the problem appeared because I wrote back when all trackers had a title. Fixed it now