mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 01:35:10 +01:00
Fixed recently read bug set it to 50 years back
because I'm too tired to figured out the sql query Also reworded the restore complete text
This commit is contained in:
parent
1e30d249ee
commit
f297b74682
@ -434,7 +434,7 @@ class BackupRestoreService : Service() {
|
||||
* @param context the application context.
|
||||
* @return true if the service is running, false otherwise.
|
||||
*/
|
||||
private fun isRunning(context: Context): Boolean =
|
||||
fun isRunning(context: Context): Boolean =
|
||||
context.isServiceRunning(BackupRestoreService::class.java)
|
||||
|
||||
/**
|
||||
|
@ -19,8 +19,9 @@ interface HistoryQueries : DbProvider {
|
||||
fun insertHistory(history: History) = db.put().`object`(history).prepare()
|
||||
|
||||
/**
|
||||
* Returns history of recent manga containing last read chapter
|
||||
* Returns history of recent manga containing last read chapter in 25s
|
||||
* @param date recent date range
|
||||
* @offset offset the db by
|
||||
*/
|
||||
fun getRecentManga(date: Date, offset: Int = 0) = db.get()
|
||||
.listOfObjects(MangaChapterHistory::class.java)
|
||||
@ -32,6 +33,21 @@ interface HistoryQueries : DbProvider {
|
||||
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
|
||||
.prepare()
|
||||
|
||||
/**
|
||||
* Returns history of recent manga containing last read chapter in 25s
|
||||
* @param date recent date range
|
||||
* @offset offset the db by
|
||||
*/
|
||||
fun getRecentMangaLimit(date: Date, limit: Int = 0) = db.get()
|
||||
.listOfObjects(MangaChapterHistory::class.java)
|
||||
.withQuery(RawQuery.builder()
|
||||
.query(getRecentMangasLimitQuery(limit))
|
||||
.args(date.time)
|
||||
.observesTables(HistoryTable.TABLE)
|
||||
.build())
|
||||
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
|
||||
.prepare()
|
||||
|
||||
fun getHistoryByMangaId(mangaId: Long) = db.get()
|
||||
.listOfObjects(History::class.java)
|
||||
.withQuery(RawQuery.builder()
|
||||
|
@ -65,6 +65,30 @@ fun getRecentMangasQuery(offset: Int = 0) = """
|
||||
LIMIT 25 OFFSET $offset
|
||||
"""
|
||||
|
||||
/**
|
||||
* Query to get the recently read chapters of manga from the library up to a date.
|
||||
* The max_last_read table contains the most recent chapters grouped by manga
|
||||
* The select statement returns all information of chapters that have the same id as the chapter in max_last_read
|
||||
* and are read after the given time period
|
||||
*/
|
||||
fun getRecentMangasLimitQuery(limit: Int = 25) = """
|
||||
SELECT ${Manga.TABLE}.${Manga.COL_URL} as mangaUrl, ${Manga.TABLE}.*, ${Chapter.TABLE}.*, ${History.TABLE}.*
|
||||
FROM ${Manga.TABLE}
|
||||
JOIN ${Chapter.TABLE}
|
||||
ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
|
||||
JOIN ${History.TABLE}
|
||||
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
||||
JOIN (
|
||||
SELECT ${Chapter.TABLE}.${Chapter.COL_MANGA_ID},${Chapter.TABLE}.${Chapter.COL_ID} as ${History.COL_CHAPTER_ID}, MAX(${History.TABLE}.${History.COL_LAST_READ}) as ${History.COL_LAST_READ}
|
||||
FROM ${Chapter.TABLE} JOIN ${History.TABLE}
|
||||
ON ${Chapter.TABLE}.${Chapter.COL_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
||||
GROUP BY ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}) AS max_last_read
|
||||
ON ${Chapter.TABLE}.${Chapter.COL_MANGA_ID} = max_last_read.${Chapter.COL_MANGA_ID}
|
||||
WHERE ${History.TABLE}.${History.COL_LAST_READ} > ? AND max_last_read.${History.COL_CHAPTER_ID} = ${History.TABLE}.${History.COL_CHAPTER_ID}
|
||||
ORDER BY max_last_read.${History.COL_LAST_READ} DESC
|
||||
LIMIT $limit
|
||||
"""
|
||||
|
||||
fun getHistoryByMangaId() = """
|
||||
SELECT ${History.TABLE}.*
|
||||
FROM ${History.TABLE}
|
||||
|
@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreService
|
||||
import eu.kanade.tachiyomi.data.database.models.History
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
@ -79,10 +80,11 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
*
|
||||
* @param mangaHistory list of manga history
|
||||
*/
|
||||
fun onNextManga(mangaHistory: List<RecentlyReadItem>) {
|
||||
if (adapter?.itemCount ?: 0 == 0)
|
||||
fun onNextManga(mangaHistory: List<RecentlyReadItem>, cleanBatch: Boolean = false) {
|
||||
if (adapter?.itemCount ?: 0 == 0 || cleanBatch)
|
||||
resetProgressItem()
|
||||
adapter?.onLoadMoreComplete(mangaHistory)
|
||||
if (cleanBatch) adapter?.updateDataSet(mangaHistory)
|
||||
else adapter?.onLoadMoreComplete(mangaHistory)
|
||||
}
|
||||
|
||||
fun onAddPageError(error: Throwable) {
|
||||
@ -108,13 +110,17 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
}
|
||||
|
||||
override fun onLoadMore(lastPosition: Int, currentPage: Int) {
|
||||
val view = view ?: return
|
||||
if (BackupRestoreService.isRunning(view.context.applicationContext)) {
|
||||
onAddPageError(Throwable())
|
||||
return
|
||||
}
|
||||
val adapter = adapter ?: return
|
||||
presenter.requestNext(adapter.itemCount)
|
||||
}
|
||||
|
||||
override fun noMoreLoad(newItemsSize: Int) { }
|
||||
|
||||
|
||||
override fun onResumeClick(position: Int) {
|
||||
val activity = activity ?: return
|
||||
val (manga, chapter, _) = (adapter?.getItem(position) as? RecentlyReadItem)?.mch ?: return
|
||||
@ -142,9 +148,29 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
||||
if (all) {
|
||||
// Reset last read of chapter to 0L
|
||||
presenter.removeAllFromHistory(manga.id!!)
|
||||
/*val safeAdapter = adapter ?: return
|
||||
val items = (0 until safeAdapter.itemCount).filter {
|
||||
val item = safeAdapter.getItem(it)
|
||||
if (item is RecentlyReadItem)
|
||||
item.mch.manga.id == manga.id
|
||||
|
||||
else
|
||||
false
|
||||
}
|
||||
adapter?.removeItems(items)*/
|
||||
} else {
|
||||
// Remove all chapters belonging to manga from library
|
||||
presenter.removeFromHistory(history)
|
||||
/*val safeAdapter = adapter ?: return
|
||||
val item = (0 until safeAdapter.itemCount).find {
|
||||
val item = safeAdapter.getItem(it)
|
||||
if (item is RecentlyReadItem)
|
||||
item.mch.history == history
|
||||
|
||||
else
|
||||
false
|
||||
} ?: return
|
||||
adapter?.removeItem(item)*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,19 +26,18 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
||||
* Used to connect to database
|
||||
*/
|
||||
val db: DatabaseHelper by injectLazy()
|
||||
var lastCount = 25
|
||||
|
||||
override fun onCreate(savedState: Bundle?) {
|
||||
super.onCreate(savedState)
|
||||
|
||||
//pageSubscription?.let { remove(it) }
|
||||
// Used to get a list of recently read manga
|
||||
getRecentMangaObservable()
|
||||
.subscribeLatestCache({ view, mangas ->
|
||||
view.onNextManga(mangas)
|
||||
}, RecentlyReadController::onAddPageError)
|
||||
updateList()
|
||||
}
|
||||
|
||||
fun requestNext(offset: Int) {
|
||||
lastCount = offset
|
||||
getRecentMangaObservable((offset))
|
||||
.subscribeLatestCache({ view, mangas ->
|
||||
view.onNextManga(mangas)
|
||||
@ -53,21 +52,44 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
||||
// Set date for recent manga
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time = Date()
|
||||
cal.add(Calendar.YEAR, -1)
|
||||
cal.add(Calendar.YEAR, -50)
|
||||
|
||||
return db.getRecentManga(cal.time, offset).asRxObservable()
|
||||
.map { recents -> recents.map(::RecentlyReadItem) }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent manga observable
|
||||
* @return list of history
|
||||
*/
|
||||
private fun getRecentMangaLimitObservable(offset: Int = 0): Observable<List<RecentlyReadItem>> {
|
||||
// Set date for recent manga
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time = Date()
|
||||
cal.add(Calendar.YEAR, -50)
|
||||
|
||||
return db.getRecentMangaLimit(cal.time, lastCount).asRxObservable()
|
||||
.map { recents -> recents.map(::RecentlyReadItem) }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset last read of chapter to 0L
|
||||
* @param history history belonging to chapter
|
||||
*/
|
||||
fun removeFromHistory(history: History) {
|
||||
history.last_read = 0L
|
||||
db.updateHistoryLastRead(history).asRxObservable()
|
||||
.subscribe()
|
||||
db.updateHistoryLastRead(history).executeAsBlocking()
|
||||
updateList()
|
||||
}
|
||||
|
||||
|
||||
fun updateList() {
|
||||
getRecentMangaLimitObservable(lastCount).take(1)
|
||||
.subscribeLatestCache({ view, mangas ->
|
||||
view.onNextManga(mangas, true)
|
||||
}, RecentlyReadController::onAddPageError)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,12 +97,10 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
||||
* @param mangaId id of manga
|
||||
*/
|
||||
fun removeAllFromHistory(mangaId: Long) {
|
||||
db.getHistoryByMangaId(mangaId).asRxSingle()
|
||||
.map { list ->
|
||||
list.forEach { it.last_read = 0L }
|
||||
db.updateHistoryLastRead(list).executeAsBlocking()
|
||||
}
|
||||
.subscribe()
|
||||
val history = db.getHistoryByMangaId(mangaId).executeAsBlocking()
|
||||
history.forEach { it.last_read = 0L }
|
||||
db.updateHistoryLastRead(history).executeAsBlocking()
|
||||
updateList()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,7 @@
|
||||
<string name="restore_completed">Restore completed</string>
|
||||
<string name="restore_error">Restore error</string>
|
||||
<string name="error_opening_log">Could not open log</string>
|
||||
<string name="restore_completed_content">Restored %1$s. %2$s errors found</string>
|
||||
<string name="restore_completed_content">%1$s Restored. %2$s errors found</string>
|
||||
<string name="restore_completed_content_2">%1$d skipped</string>
|
||||
<string name="backup_restore_content">Restore uses the network to fetch data, carrier costs may apply.\n\nMake sure you have installed all necessary extensions and are logged in to sources and tracking services before restoring.</string>
|
||||
<string name="file_saved">File saved at %1$s</string>
|
||||
|
Loading…
Reference in New Issue
Block a user