Skip to content

Commit

Permalink
Upstream merge
Browse files Browse the repository at this point in the history
  • Loading branch information
NerdNumber9 committed Jul 27, 2019
2 parents 9a6bb69 + 3abae1c commit 7fe742e
Show file tree
Hide file tree
Showing 96 changed files with 1,390 additions and 413 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: inorichi
ko_fi: inorichi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can find us in the `#support-eh` channel in the [Tachiyomi discord](https://
# Features

**All the features you expect from Tachiyomi:**
* Online reading from sources such as KissManga, MangaFox, [and more](https://github.com/inorichi/tachiyomi-extensions)
* Online reading from sources such as KissManga, MangaDex, [and more](https://github.com/inorichi/tachiyomi-extensions)
* Local reading of downloaded manga
* Configurable reader with multiple viewers, reading directions and other settings
* [MyAnimeList](https://myanimelist.net/), [AniList](https://anilist.co/), and [Kitsu](https://kitsu.io/explore/anime) support
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
</intent-filter>
</activity>
<activity
android:name=".ui.setting.ShikomoriLoginActivity"
android:label="Shikomori">
android:name=".ui.setting.ShikimoriLoginActivity"
android:label="Shikimori">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

Expand All @@ -89,6 +89,20 @@
android:scheme="tachiyomi" />
</intent-filter>
</activity>
<activity
android:name=".ui.setting.BangumiLoginActivity"
android:label="Bangumi">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="bangumi-auth"
android:scheme="tachiyomi" />
</intent-filter>
</activity>

<activity
android:name=".extension.util.ExtensionInstallActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ interface MangaQueries : DbProvider {
.withPutResolver(MangaViewerPutResolver())
.prepare()

fun updateMangaTitle(manga: Manga) = db.put()
.`object`(manga)
.withPutResolver(MangaTitlePutResolver())
.prepare()

fun deleteManga(manga: Manga) = db.delete().`object`(manga).prepare()

fun deleteMangas(mangas: List<Manga>) = db.delete().objects(mangas).prepare()
Expand Down
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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class MangaViewerPutResolver : PutResolver<Manga>() {
}

fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder()
.table(MangaTable.TABLE)
.where("${MangaTable.COL_ID} = ?")
.whereArgs(manga.id)
.build()
.table(MangaTable.TABLE)
.where("${MangaTable.COL_ID} = ?")
.whereArgs(manga.id)
.build()

fun mapToContentValues(manga: Manga) = ContentValues(1).apply {
put(MangaTable.COL_VIEWER, manga.viewer)
Expand Down
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)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.data.database.models.LibraryManga
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadService
import eu.kanade.tachiyomi.data.library.LibraryUpdateRanker.rankingScheme
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications
Expand Down Expand Up @@ -206,7 +207,9 @@ class LibraryUpdateService(
// Update favorite manga. Destroy service when completed or in case of an error.
subscription = Observable
.defer {
val selectedScheme = preferences.libraryUpdatePrioritization().getOrDefault()
val mangaList = getMangaToUpdate(intent, target)
.sortedWith(rankingScheme[selectedScheme])

// Update either chapter list or manga details.
when (target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ object PreferenceKeys {

const val colorFilterValue = "color_filter_value"

const val colorFilterMode = "color_filter_mode"

const val defaultViewer = "pref_default_viewer_key"

const val imageScaleType = "pref_image_scale_type_key"
Expand Down Expand Up @@ -85,6 +87,8 @@ object PreferenceKeys {

const val libraryUpdateCategories = "library_update_categories"

const val libraryUpdatePrioritization = "library_update_prioritization"

const val filterDownloaded = "pref_filter_downloaded_key"

const val filterUnread = "pref_filter_unread_key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class PreferencesHelper(val context: Context) {

fun colorFilterValue() = rxPrefs.getInteger(Keys.colorFilterValue, 0)

fun colorFilterMode() = rxPrefs.getInteger(Keys.colorFilterMode, 0)

fun defaultViewer() = prefs.getInt(Keys.defaultViewer, 1)

fun imageScaleType() = rxPrefs.getInteger(Keys.imageScaleType, 1)
Expand Down Expand Up @@ -142,6 +144,8 @@ class PreferencesHelper(val context: Context) {

fun libraryUpdateCategories() = rxPrefs.getStringSet(Keys.libraryUpdateCategories, emptySet())

fun libraryUpdatePrioritization() = rxPrefs.getInteger(Keys.libraryUpdatePrioritization, 0)

fun libraryAsList() = rxPrefs.getBoolean(Keys.libraryAsList, false)

fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false)
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import android.content.Context
import eu.kanade.tachiyomi.data.track.anilist.Anilist
import eu.kanade.tachiyomi.data.track.kitsu.Kitsu
import eu.kanade.tachiyomi.data.track.myanimelist.Myanimelist
import eu.kanade.tachiyomi.data.track.shikomori.Shikomori
import eu.kanade.tachiyomi.data.track.shikimori.Shikimori
import eu.kanade.tachiyomi.data.track.bangumi.Bangumi

class TrackManager(private val context: Context) {

companion object {
const val MYANIMELIST = 1
const val ANILIST = 2
const val KITSU = 3
const val SHIKOMORI = 4
const val SHIKIMORI = 4
const val BANGUMI = 5
}

val myAnimeList = Myanimelist(context, MYANIMELIST)
Expand All @@ -21,9 +23,11 @@ class TrackManager(private val context: Context) {

val kitsu = Kitsu(context, KITSU)

val shikomori = Shikomori(context, SHIKOMORI)
val shikimori = Shikimori(context, SHIKIMORI)

val services = listOf(myAnimeList, aniList, kitsu, shikomori)
val bangumi = Bangumi(context, BANGUMI)

val services = listOf(myAnimeList, aniList, kitsu, shikimori, bangumi)

fun getService(id: Int) = services.find { it.id == id }

Expand Down
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 app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt
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)
}
}
Loading

0 comments on commit 7fe742e

Please sign in to comment.