-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in J2K newest changes into Neko (#511)
- Loading branch information
Showing
587 changed files
with
21,906 additions
and
12,016 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
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
95 changes: 95 additions & 0 deletions
95
app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.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,95 @@ | ||
package eu.kanade.tachiyomi.data.backup | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import eu.kanade.tachiyomi.data.database.DatabaseHelper | ||
import eu.kanade.tachiyomi.data.database.models.Chapter | ||
import eu.kanade.tachiyomi.data.database.models.Manga | ||
import eu.kanade.tachiyomi.data.library.CustomMangaManager | ||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper | ||
import eu.kanade.tachiyomi.data.track.TrackManager | ||
import eu.kanade.tachiyomi.source.Source | ||
import eu.kanade.tachiyomi.source.SourceManager | ||
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource | ||
import uy.kohesive.injekt.injectLazy | ||
|
||
abstract class AbstractBackupManager(protected val context: Context) { | ||
|
||
internal val databaseHelper: DatabaseHelper by injectLazy() | ||
internal val sourceManager: SourceManager by injectLazy() | ||
internal val trackManager: TrackManager by injectLazy() | ||
protected val preferences: PreferencesHelper by injectLazy() | ||
protected val customMangaManager: CustomMangaManager by injectLazy() | ||
|
||
abstract fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String? | ||
|
||
/** | ||
* Returns manga | ||
* | ||
* @return [Manga], null if not found | ||
*/ | ||
internal fun getMangaFromDatabase(manga: Manga): Manga? = | ||
databaseHelper.getManga(manga.url, manga.source).executeAsBlocking() | ||
|
||
/** | ||
* Fetches chapter information. | ||
* | ||
* @param source source of manga | ||
* @param manga manga that needs updating | ||
* @param chapters list of chapters in the backup | ||
* @return Updated manga chapters. | ||
*/ | ||
internal suspend fun restoreChapters(source: Source, manga: Manga, chapters: List<Chapter>): Pair<List<Chapter>, List<Chapter>> { | ||
val fetchedChapters = source.fetchChapterList(manga) | ||
val syncedChapters = syncChaptersWithSource(databaseHelper, fetchedChapters, manga) | ||
if (syncedChapters.first.isNotEmpty()) { | ||
chapters.forEach { it.manga_id = manga.id } | ||
updateChapters(chapters) | ||
} | ||
return syncedChapters | ||
} | ||
|
||
/** | ||
* Returns list containing manga from library | ||
* | ||
* @return [Manga] from library | ||
*/ | ||
protected fun getFavoriteManga(): List<Manga> = | ||
databaseHelper.getFavoriteMangas().executeAsBlocking() | ||
|
||
/** | ||
* Inserts manga and returns id | ||
* | ||
* @return id of [Manga], null if not found | ||
*/ | ||
internal fun insertManga(manga: Manga): Long? = | ||
databaseHelper.insertManga(manga).executeAsBlocking().insertedId() | ||
|
||
/** | ||
* Inserts list of chapters | ||
*/ | ||
protected fun insertChapters(chapters: List<Chapter>) { | ||
databaseHelper.insertChapters(chapters).executeAsBlocking() | ||
} | ||
|
||
/** | ||
* Updates a list of chapters | ||
*/ | ||
protected fun updateChapters(chapters: List<Chapter>) { | ||
databaseHelper.updateChaptersBackup(chapters).executeAsBlocking() | ||
} | ||
|
||
/** | ||
* Updates a list of chapters with known database ids | ||
*/ | ||
protected fun updateKnownChapters(chapters: List<Chapter>) { | ||
databaseHelper.updateKnownChaptersBackup(chapters).executeAsBlocking() | ||
} | ||
|
||
/** | ||
* Return number of backups. | ||
* | ||
* @return number of backups selected by user | ||
*/ | ||
protected fun numberOfBackups(): Int = preferences.numberOfBackups().get() | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestoreValidator.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,16 @@ | ||
package eu.kanade.tachiyomi.data.backup | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import eu.kanade.tachiyomi.data.track.TrackManager | ||
import eu.kanade.tachiyomi.source.SourceManager | ||
import uy.kohesive.injekt.injectLazy | ||
|
||
abstract class AbstractBackupRestoreValidator { | ||
protected val sourceManager: SourceManager by injectLazy() | ||
protected val trackManager: TrackManager by injectLazy() | ||
|
||
abstract fun validate(context: Context, uri: Uri): Results | ||
|
||
data class Results(val missingSources: List<String>, val missingTrackers: List<String>) | ||
} |
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
Oops, something went wrong.