forked from jobobby04/TachiyomiSY
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
1,390 additions
and
413 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github: inorichi | ||
ko_fi: inorichi |
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaTitlePutResolver.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,32 @@ | ||
package eu.kanade.tachiyomi.data.database.resolvers | ||
|
||
import android.content.ContentValues | ||
import com.pushtorefresh.storio.sqlite.StorIOSQLite | ||
import com.pushtorefresh.storio.sqlite.operations.put.PutResolver | ||
import com.pushtorefresh.storio.sqlite.operations.put.PutResult | ||
import com.pushtorefresh.storio.sqlite.queries.UpdateQuery | ||
import eu.kanade.tachiyomi.data.database.inTransactionReturn | ||
import eu.kanade.tachiyomi.data.database.models.Manga | ||
import eu.kanade.tachiyomi.data.database.tables.MangaTable | ||
|
||
class MangaTitlePutResolver : PutResolver<Manga>() { | ||
|
||
override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { | ||
val updateQuery = mapToUpdateQuery(manga) | ||
val contentValues = mapToContentValues(manga) | ||
|
||
val numberOfRowsUpdated = db.lowLevel().update(updateQuery, contentValues) | ||
PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) | ||
} | ||
|
||
fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() | ||
.table(MangaTable.TABLE) | ||
.where("${MangaTable.COL_ID} = ?") | ||
.whereArgs(manga.id) | ||
.build() | ||
|
||
fun mapToContentValues(manga: Manga) = ContentValues(1).apply { | ||
put(MangaTable.COL_TITLE, manga.title) | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateRanker.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,43 @@ | ||
package eu.kanade.tachiyomi.data.library | ||
|
||
import eu.kanade.tachiyomi.data.database.models.Manga | ||
|
||
/** | ||
* This class will provide various functions to Rank mangas to efficiently schedule mangas to update. | ||
*/ | ||
object LibraryUpdateRanker { | ||
|
||
val rankingScheme = listOf( | ||
(this::lexicographicRanking)(), | ||
(this::latestFirstRanking)()) | ||
|
||
/** | ||
* Provides a total ordering over all the Mangas. | ||
* | ||
* Assumption: An active [Manga] mActive is expected to have been last updated after an | ||
* inactive [Manga] mInactive. | ||
* | ||
* Using this insight, function returns a Comparator for which mActive appears before mInactive. | ||
* @return a Comparator that ranks manga based on relevance. | ||
*/ | ||
fun latestFirstRanking(): Comparator<Manga> { | ||
return Comparator { mangaFirst: Manga, | ||
mangaSecond: Manga -> | ||
compareValues(mangaSecond.last_update, mangaFirst.last_update) | ||
} | ||
} | ||
|
||
/** | ||
* Provides a total ordering over all the Mangas. | ||
* | ||
* Order the manga lexicographically. | ||
* @return a Comparator that ranks manga lexicographically based on the title. | ||
*/ | ||
fun lexicographicRanking(): Comparator<Manga> { | ||
return Comparator { mangaFirst: Manga, | ||
mangaSecond: Manga -> | ||
compareValues(mangaFirst.title, mangaSecond.title) | ||
} | ||
} | ||
|
||
} |
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
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Avatar.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,7 @@ | ||
package eu.kanade.tachiyomi.data.track.bangumi | ||
|
||
data class Avatar( | ||
val large: String? = "", | ||
val medium: String? = "", | ||
val small: String? = "" | ||
) |
144 changes: 144 additions & 0 deletions
144
app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.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,144 @@ | ||
package eu.kanade.tachiyomi.data.track.bangumi | ||
|
||
import android.content.Context | ||
import android.graphics.Color | ||
import com.google.gson.Gson | ||
import eu.kanade.tachiyomi.R | ||
import eu.kanade.tachiyomi.data.database.models.Track | ||
import eu.kanade.tachiyomi.data.track.TrackService | ||
import eu.kanade.tachiyomi.data.track.model.TrackSearch | ||
import rx.Completable | ||
import rx.Observable | ||
import uy.kohesive.injekt.injectLazy | ||
|
||
class Bangumi(private val context: Context, id: Int) : TrackService(id) { | ||
|
||
override fun getScoreList(): List<String> { | ||
return IntRange(0, 10).map(Int::toString) | ||
} | ||
|
||
override fun displayScore(track: Track): String { | ||
return track.score.toInt().toString() | ||
} | ||
|
||
override fun add(track: Track): Observable<Track> { | ||
return api.addLibManga(track) | ||
} | ||
|
||
override fun update(track: Track): Observable<Track> { | ||
if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { | ||
track.status = COMPLETED | ||
} | ||
return api.updateLibManga(track) | ||
} | ||
|
||
override fun bind(track: Track): Observable<Track> { | ||
return api.statusLibManga(track) | ||
.flatMap { | ||
api.findLibManga(track).flatMap { remoteTrack -> | ||
if (remoteTrack != null && it != null) { | ||
track.copyPersonalFrom(remoteTrack) | ||
track.library_id = remoteTrack.library_id | ||
track.status = remoteTrack.status | ||
track.last_chapter_read = remoteTrack.last_chapter_read | ||
update(track) | ||
} else { | ||
// Set default fields if it's not found in the list | ||
track.score = DEFAULT_SCORE.toFloat() | ||
track.status = DEFAULT_STATUS | ||
add(track) | ||
update(track) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun search(query: String): Observable<List<TrackSearch>> { | ||
return api.search(query) | ||
} | ||
|
||
override fun refresh(track: Track): Observable<Track> { | ||
return api.statusLibManga(track) | ||
.flatMap { | ||
track.copyPersonalFrom(it!!) | ||
api.findLibManga(track) | ||
.map { remoteTrack -> | ||
if (remoteTrack != null) { | ||
track.total_chapters = remoteTrack.total_chapters | ||
track.status = remoteTrack.status | ||
} | ||
track | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val READING = 3 | ||
const val COMPLETED = 2 | ||
const val ON_HOLD = 4 | ||
const val DROPPED = 5 | ||
const val PLANNING = 1 | ||
|
||
const val DEFAULT_STATUS = READING | ||
const val DEFAULT_SCORE = 0 | ||
} | ||
|
||
override val name = "Bangumi" | ||
|
||
private val gson: Gson by injectLazy() | ||
|
||
private val interceptor by lazy { BangumiInterceptor(this, gson) } | ||
|
||
private val api by lazy { BangumiApi(client, interceptor) } | ||
|
||
override fun getLogo() = R.drawable.bangumi | ||
|
||
override fun getLogoColor() = Color.rgb(0xF0, 0x91, 0x99) | ||
|
||
override fun getStatusList(): List<Int> { | ||
return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLANNING) | ||
} | ||
|
||
override fun getStatus(status: Int): String = with(context) { | ||
when (status) { | ||
READING -> getString(R.string.reading) | ||
COMPLETED -> getString(R.string.completed) | ||
ON_HOLD -> getString(R.string.on_hold) | ||
DROPPED -> getString(R.string.dropped) | ||
PLANNING -> getString(R.string.plan_to_read) | ||
else -> "" | ||
} | ||
} | ||
|
||
override fun login(username: String, password: String) = login(password) | ||
|
||
fun login(code: String): Completable { | ||
return api.accessToken(code).map { oauth: OAuth? -> | ||
interceptor.newAuth(oauth) | ||
if (oauth != null) { | ||
saveCredentials(oauth.user_id.toString(), oauth.access_token) | ||
} | ||
}.doOnError { | ||
logout() | ||
}.toCompletable() | ||
} | ||
|
||
fun saveToken(oauth: OAuth?) { | ||
val json = gson.toJson(oauth) | ||
preferences.trackToken(this).set(json) | ||
} | ||
|
||
fun restoreToken(): OAuth? { | ||
return try { | ||
gson.fromJson(preferences.trackToken(this).get(), OAuth::class.java) | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
|
||
override fun logout() { | ||
super.logout() | ||
preferences.trackToken(this).set(null) | ||
interceptor.newAuth(null) | ||
} | ||
} |
Oops, something went wrong.