Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jun 13, 2022
2 parents 5f434c0 + fd5da2d commit 068d0c7
Show file tree
Hide file tree
Showing 243 changed files with 4,412 additions and 2,432 deletions.
5 changes: 3 additions & 2 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pull_request_rules:
- name: Automatically merge translations
conditions:
- "author=weblate"
- "author = weblate"
- "-conflict"
- "current-day-of-week=Sat"
- "current-day-of-week = Sat"
- "created-at < 1 day ago"
actions:
merge:
method: squash
5 changes: 0 additions & 5 deletions .github/runner-files/ci-gradle.properties

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/build_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ jobs:
java-version: 11
distribution: adopt

- name: Copy CI gradle.properties
run: |
mkdir -p ~/.gradle
cp .github/runner-files/ci-gradle.properties ~/.gradle/gradle.properties
- name: Build app and run unit tests
uses: gradle/gradle-command-action@v2
with:
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ jobs:
java-version: 11
distribution: adopt

- name: Copy CI gradle.properties
run: |
mkdir -p ~/.gradle
cp .github/runner-files/ci-gradle.properties ~/.gradle/gradle.properties
- name: Build app and run unit tests
uses: gradle/gradle-command-action@v2
with:
Expand Down
43 changes: 40 additions & 3 deletions app/src/main/java/eu/kanade/data/anime/AnimeRepositoryImpl.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,60 @@
package eu.kanade.data.anime

import eu.kanade.data.AnimeDatabaseHandler
import eu.kanade.data.listOfStringsAdapter
import eu.kanade.data.toLong
import eu.kanade.domain.anime.model.Anime
import eu.kanade.domain.anime.model.AnimeUpdate
import eu.kanade.domain.anime.repository.AnimeRepository
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.flow.Flow
import logcat.LogPriority

class AnimeRepositoryImpl(
private val databaseHandler: AnimeDatabaseHandler,
private val handler: AnimeDatabaseHandler,
) : AnimeRepository {

override suspend fun getAnimeById(id: Long): Anime {
return handler.awaitOne { animesQueries.getAnimeById(id, animeMapper) }
}

override fun getFavoritesBySourceId(sourceId: Long): Flow<List<Anime>> {
return databaseHandler.subscribeToList { animesQueries.getFavoriteBySourceId(sourceId, animeMapper) }
return handler.subscribeToList { animesQueries.getFavoriteBySourceId(sourceId, animeMapper) }
}

override suspend fun resetViewerFlags(): Boolean {
return try {
databaseHandler.await { animesQueries.resetViewerFlags() }
handler.await { animesQueries.resetViewerFlags() }
true
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
false
}
}

override suspend fun update(update: AnimeUpdate): Boolean {
return try {
handler.await {
animesQueries.update(
source = update.source,
url = update.url,
artist = update.artist,
author = update.author,
description = update.description,
genre = update.genre?.let(listOfStringsAdapter::encode),
title = update.title,
status = update.status,
thumbnailUrl = update.thumbnailUrl,
favorite = update.favorite?.toLong(),
lastUpdate = update.lastUpdate,
initialized = update.initialized?.toLong(),
viewer = update.viewerFlags,
episodeFlags = update.episodeFlags,
coverLastModified = update.coverLastModified,
dateAdded = update.dateAdded,
animeId = update.id,
)
}
true
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class AnimeHistoryRepositoryImpl(
)
}

override suspend fun getNextEpisodeForAnime(animeId: Long, episodeId: Long): Episode? {
override suspend fun getLastHistory(): AnimeHistoryWithRelations? {
return handler.awaitOneOrNull {
animehistoryViewQueries.getLatestAnimeHistory(animehistoryWithRelationsMapper)
}
}

override suspend fun getNextEpisode(animeId: Long, episodeId: Long): Episode? {
val episode = handler.awaitOne { episodesQueries.getEpisodeById(episodeId, episodeMapper) }
val anime = handler.awaitOne { animesQueries.getAnimeById(animeId, animeMapper) }

Expand All @@ -41,7 +47,7 @@ class AnimeHistoryRepositoryImpl(
else -> throw NotImplementedError("Unknown sorting method")
}

val episodes = handler.awaitList { episodesQueries.getEpisodeByAnimeId(animeId, episodeMapper) }
val episodes = handler.awaitList { episodesQueries.getEpisodesByAnimeId(animeId, episodeMapper) }
.sortedWith(sortFunction)

val currEpisodeIndex = episodes.indexOfFirst { episode.id == it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.animesource.AnimeSourceManager
import eu.kanade.tachiyomi.animesource.LocalAnimeSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import eu.kanade.tachiyomi.animesource.AnimeSource as LoadedAnimeSource

class AnimeSourceRepositoryImpl(
private val sourceManager: AnimeSourceManager,
Expand All @@ -29,13 +30,23 @@ class AnimeSourceRepositoryImpl(
val sourceIdWithFavoriteCount = handler.subscribeToList { animesQueries.getAnimeSourceIdWithFavoriteCount() }
return sourceIdWithFavoriteCount.map { sourceIdsWithCount ->
sourceIdsWithCount
.filterNot { it.source == LocalAnimeSource.ID }
.map { (sourceId, count) ->
val source = sourceManager.getOrStub(sourceId).run {
animesourceMapper(this)
}
source to count
}
.filterNot { it.first.id == LocalAnimeSource.ID }
}
}

override fun getSourcesWithNonLibraryAnime(): Flow<List<Pair<LoadedAnimeSource, Long>>> {
val sourceIdWithNonLibraryAnime = handler.subscribeToList { animesQueries.getSourceIdsWithNonLibraryAnime() }
return sourceIdWithNonLibraryAnime.map { sourceId ->
sourceId.map { (sourceId, count) ->
val source = sourceManager.getOrStub(sourceId)
source to count
}
}
}
}
74 changes: 72 additions & 2 deletions app/src/main/java/eu/kanade/data/chapter/ChapterRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,47 @@ package eu.kanade.data.chapter

import eu.kanade.data.DatabaseHandler
import eu.kanade.data.toLong
import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.chapter.model.ChapterUpdate
import eu.kanade.domain.chapter.repository.ChapterRepository
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.flow.Flow
import logcat.LogPriority

class ChapterRepositoryImpl(
private val databaseHandler: DatabaseHandler,
private val handler: DatabaseHandler,
) : ChapterRepository {

override suspend fun addAll(chapters: List<Chapter>): List<Chapter> {
return try {
handler.await(inTransaction = true) {
chapters.map { chapter ->
chaptersQueries.insert(
chapter.mangaId,
chapter.url,
chapter.name,
chapter.scanlator,
chapter.read,
chapter.bookmark,
chapter.lastPageRead,
chapter.chapterNumber,
chapter.sourceOrder,
chapter.dateFetch,
chapter.dateUpload,
)
val lastInsertId = chaptersQueries.selectLastInsertedRowId().executeAsOne()
chapter.copy(id = lastInsertId)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
emptyList()
}
}

override suspend fun update(chapterUpdate: ChapterUpdate) {
try {
databaseHandler.await {
handler.await {
chaptersQueries.update(
chapterUpdate.mangaId,
chapterUpdate.url,
Expand All @@ -33,4 +62,45 @@ class ChapterRepositoryImpl(
logcat(LogPriority.ERROR, e)
}
}

override suspend fun updateAll(chapterUpdates: List<ChapterUpdate>) {
try {
handler.await(inTransaction = true) {
chapterUpdates.forEach { chapterUpdate ->
chaptersQueries.update(
chapterUpdate.mangaId,
chapterUpdate.url,
chapterUpdate.name,
chapterUpdate.scanlator,
chapterUpdate.read?.toLong(),
chapterUpdate.bookmark?.toLong(),
chapterUpdate.lastPageRead,
chapterUpdate.chapterNumber?.toDouble(),
chapterUpdate.sourceOrder,
chapterUpdate.dateFetch,
chapterUpdate.dateUpload,
chapterId = chapterUpdate.id,
)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}
}

override suspend fun removeChaptersWithIds(chapterIds: List<Long>) {
try {
handler.await { chaptersQueries.removeChaptersWithIds(chapterIds) }
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}
}

override suspend fun getChapterByMangaId(mangaId: Long): List<Chapter> {
return handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) }
}

override suspend fun getChapterByMangaIdAsFlow(mangaId: Long): Flow<List<Chapter>> {
return handler.subscribeToList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package eu.kanade.data.chapter

class NoChaptersException : Exception()
77 changes: 75 additions & 2 deletions app/src/main/java/eu/kanade/data/episode/EpisodeRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@ package eu.kanade.data.episode

import eu.kanade.data.AnimeDatabaseHandler
import eu.kanade.data.toLong
import eu.kanade.domain.episode.model.Episode
import eu.kanade.domain.episode.model.EpisodeUpdate
import eu.kanade.domain.episode.repository.EpisodeRepository
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.flow.Flow
import logcat.LogPriority

class EpisodeRepositoryImpl(
private val databaseHandler: AnimeDatabaseHandler,
private val handler: AnimeDatabaseHandler,
) : EpisodeRepository {

override suspend fun addAll(episodes: List<Episode>): List<Episode> {
return try {
handler.await(inTransaction = true) {
episodes.map { episode ->
episodesQueries.insert(
episode.animeId,
episode.url,
episode.name,
episode.scanlator,
episode.seen,
episode.bookmark,
episode.lastSecondSeen,
episode.totalSeconds,
episode.episodeNumber,
episode.sourceOrder,
episode.dateFetch,
episode.dateUpload,
)
val lastInsertId = episodesQueries.selectLastInsertedRowId().executeAsOne()
episode.copy(id = lastInsertId)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
emptyList()
}
}

override suspend fun update(episodeUpdate: EpisodeUpdate) {
try {
databaseHandler.await {
handler.await {
episodesQueries.update(
episodeUpdate.animeId,
episodeUpdate.url,
Expand All @@ -22,6 +52,7 @@ class EpisodeRepositoryImpl(
episodeUpdate.seen?.toLong(),
episodeUpdate.bookmark?.toLong(),
episodeUpdate.lastSecondSeen,
episodeUpdate.totalSeconds,
episodeUpdate.episodeNumber?.toDouble(),
episodeUpdate.sourceOrder,
episodeUpdate.dateFetch,
Expand All @@ -33,4 +64,46 @@ class EpisodeRepositoryImpl(
logcat(LogPriority.ERROR, e)
}
}

override suspend fun updateAll(episodeUpdates: List<EpisodeUpdate>) {
try {
handler.await(inTransaction = true) {
episodeUpdates.forEach { episodeUpdate ->
episodesQueries.update(
episodeUpdate.animeId,
episodeUpdate.url,
episodeUpdate.name,
episodeUpdate.scanlator,
episodeUpdate.seen?.toLong(),
episodeUpdate.bookmark?.toLong(),
episodeUpdate.lastSecondSeen,
episodeUpdate.totalSeconds,
episodeUpdate.episodeNumber?.toDouble(),
episodeUpdate.sourceOrder,
episodeUpdate.dateFetch,
episodeUpdate.dateUpload,
episodeId = episodeUpdate.id,
)
}
}
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}
}

override suspend fun removeEpisodesWithIds(episodeIds: List<Long>) {
try {
handler.await { episodesQueries.removeEpisodesWithIds(episodeIds) }
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
}
}

override suspend fun getEpisodeByAnimeId(animeId: Long): List<Episode> {
return handler.awaitList { episodesQueries.getEpisodesByAnimeId(animeId, episodeMapper) }
}

override suspend fun getEpisodeByAnimeIdAsFlow(animeId: Long): Flow<List<Episode>> {
return handler.subscribeToList { episodesQueries.getEpisodesByAnimeId(animeId, episodeMapper) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package eu.kanade.data.episode

class NoEpisodesException : Exception()
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ class HistoryRepositoryImpl(
)
}

override suspend fun getNextChapterForManga(mangaId: Long, chapterId: Long): Chapter? {
override suspend fun getLastHistory(): HistoryWithRelations? {
return handler.awaitOneOrNull {
historyViewQueries.getLatestHistory(historyWithRelationsMapper)
}
}

override suspend fun getNextChapter(mangaId: Long, chapterId: Long): Chapter? {
val chapter = handler.awaitOne { chaptersQueries.getChapterById(chapterId, chapterMapper) }
val manga = handler.awaitOne { mangasQueries.getMangaById(mangaId, mangaMapper) }

Expand All @@ -41,7 +47,7 @@ class HistoryRepositoryImpl(
else -> throw NotImplementedError("Unknown sorting method")
}

val chapters = handler.awaitList { chaptersQueries.getChapterByMangaId(mangaId, chapterMapper) }
val chapters = handler.awaitList { chaptersQueries.getChaptersByMangaId(mangaId, chapterMapper) }
.sortedWith(sortFunction)

val currChapterIndex = chapters.indexOfFirst { chapter.id == it.id }
Expand Down
Loading

0 comments on commit 068d0c7

Please sign in to comment.