mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-04 09:45:08 +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.
|
* @param context the application context.
|
||||||
* @return true if the service is running, false otherwise.
|
* @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)
|
context.isServiceRunning(BackupRestoreService::class.java)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,8 +19,9 @@ interface HistoryQueries : DbProvider {
|
|||||||
fun insertHistory(history: History) = db.put().`object`(history).prepare()
|
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
|
* @param date recent date range
|
||||||
|
* @offset offset the db by
|
||||||
*/
|
*/
|
||||||
fun getRecentManga(date: Date, offset: Int = 0) = db.get()
|
fun getRecentManga(date: Date, offset: Int = 0) = db.get()
|
||||||
.listOfObjects(MangaChapterHistory::class.java)
|
.listOfObjects(MangaChapterHistory::class.java)
|
||||||
@ -32,6 +33,21 @@ interface HistoryQueries : DbProvider {
|
|||||||
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
|
.withGetResolver(MangaChapterHistoryGetResolver.INSTANCE)
|
||||||
.prepare()
|
.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()
|
fun getHistoryByMangaId(mangaId: Long) = db.get()
|
||||||
.listOfObjects(History::class.java)
|
.listOfObjects(History::class.java)
|
||||||
.withQuery(RawQuery.builder()
|
.withQuery(RawQuery.builder()
|
||||||
|
@ -65,6 +65,30 @@ fun getRecentMangasQuery(offset: Int = 0) = """
|
|||||||
LIMIT 25 OFFSET $offset
|
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() = """
|
fun getHistoryByMangaId() = """
|
||||||
SELECT ${History.TABLE}.*
|
SELECT ${History.TABLE}.*
|
||||||
FROM ${History.TABLE}
|
FROM ${History.TABLE}
|
||||||
|
@ -6,6 +6,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
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.History
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
@ -79,10 +80,11 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
*
|
*
|
||||||
* @param mangaHistory list of manga history
|
* @param mangaHistory list of manga history
|
||||||
*/
|
*/
|
||||||
fun onNextManga(mangaHistory: List<RecentlyReadItem>) {
|
fun onNextManga(mangaHistory: List<RecentlyReadItem>, cleanBatch: Boolean = false) {
|
||||||
if (adapter?.itemCount ?: 0 == 0)
|
if (adapter?.itemCount ?: 0 == 0 || cleanBatch)
|
||||||
resetProgressItem()
|
resetProgressItem()
|
||||||
adapter?.onLoadMoreComplete(mangaHistory)
|
if (cleanBatch) adapter?.updateDataSet(mangaHistory)
|
||||||
|
else adapter?.onLoadMoreComplete(mangaHistory)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onAddPageError(error: Throwable) {
|
fun onAddPageError(error: Throwable) {
|
||||||
@ -108,13 +110,17 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadMore(lastPosition: Int, currentPage: Int) {
|
override fun onLoadMore(lastPosition: Int, currentPage: Int) {
|
||||||
|
val view = view ?: return
|
||||||
|
if (BackupRestoreService.isRunning(view.context.applicationContext)) {
|
||||||
|
onAddPageError(Throwable())
|
||||||
|
return
|
||||||
|
}
|
||||||
val adapter = adapter ?: return
|
val adapter = adapter ?: return
|
||||||
presenter.requestNext(adapter.itemCount)
|
presenter.requestNext(adapter.itemCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun noMoreLoad(newItemsSize: Int) { }
|
override fun noMoreLoad(newItemsSize: Int) { }
|
||||||
|
|
||||||
|
|
||||||
override fun onResumeClick(position: Int) {
|
override fun onResumeClick(position: Int) {
|
||||||
val activity = activity ?: return
|
val activity = activity ?: return
|
||||||
val (manga, chapter, _) = (adapter?.getItem(position) as? RecentlyReadItem)?.mch ?: return
|
val (manga, chapter, _) = (adapter?.getItem(position) as? RecentlyReadItem)?.mch ?: return
|
||||||
@ -142,9 +148,29 @@ class RecentlyReadController : NucleusController<RecentlyReadPresenter>(),
|
|||||||
if (all) {
|
if (all) {
|
||||||
// Reset last read of chapter to 0L
|
// Reset last read of chapter to 0L
|
||||||
presenter.removeAllFromHistory(manga.id!!)
|
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 {
|
} else {
|
||||||
// Remove all chapters belonging to manga from library
|
// Remove all chapters belonging to manga from library
|
||||||
presenter.removeFromHistory(history)
|
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
|
* Used to connect to database
|
||||||
*/
|
*/
|
||||||
val db: DatabaseHelper by injectLazy()
|
val db: DatabaseHelper by injectLazy()
|
||||||
|
var lastCount = 25
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
|
|
||||||
//pageSubscription?.let { remove(it) }
|
//pageSubscription?.let { remove(it) }
|
||||||
// Used to get a list of recently read manga
|
// Used to get a list of recently read manga
|
||||||
getRecentMangaObservable()
|
updateList()
|
||||||
.subscribeLatestCache({ view, mangas ->
|
|
||||||
view.onNextManga(mangas)
|
|
||||||
}, RecentlyReadController::onAddPageError)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestNext(offset: Int) {
|
fun requestNext(offset: Int) {
|
||||||
|
lastCount = offset
|
||||||
getRecentMangaObservable((offset))
|
getRecentMangaObservable((offset))
|
||||||
.subscribeLatestCache({ view, mangas ->
|
.subscribeLatestCache({ view, mangas ->
|
||||||
view.onNextManga(mangas)
|
view.onNextManga(mangas)
|
||||||
@ -53,21 +52,44 @@ class RecentlyReadPresenter : BasePresenter<RecentlyReadController>() {
|
|||||||
// Set date for recent manga
|
// Set date for recent manga
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
cal.time = Date()
|
cal.time = Date()
|
||||||
cal.add(Calendar.YEAR, -1)
|
cal.add(Calendar.YEAR, -50)
|
||||||
|
|
||||||
return db.getRecentManga(cal.time, offset).asRxObservable()
|
return db.getRecentManga(cal.time, offset).asRxObservable()
|
||||||
.map { recents -> recents.map(::RecentlyReadItem) }
|
.map { recents -> recents.map(::RecentlyReadItem) }
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.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
|
* Reset last read of chapter to 0L
|
||||||
* @param history history belonging to chapter
|
* @param history history belonging to chapter
|
||||||
*/
|
*/
|
||||||
fun removeFromHistory(history: History) {
|
fun removeFromHistory(history: History) {
|
||||||
history.last_read = 0L
|
history.last_read = 0L
|
||||||
db.updateHistoryLastRead(history).asRxObservable()
|
db.updateHistoryLastRead(history).executeAsBlocking()
|
||||||
.subscribe()
|
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
|
* @param mangaId id of manga
|
||||||
*/
|
*/
|
||||||
fun removeAllFromHistory(mangaId: Long) {
|
fun removeAllFromHistory(mangaId: Long) {
|
||||||
db.getHistoryByMangaId(mangaId).asRxSingle()
|
val history = db.getHistoryByMangaId(mangaId).executeAsBlocking()
|
||||||
.map { list ->
|
history.forEach { it.last_read = 0L }
|
||||||
list.forEach { it.last_read = 0L }
|
db.updateHistoryLastRead(history).executeAsBlocking()
|
||||||
db.updateHistoryLastRead(list).executeAsBlocking()
|
updateList()
|
||||||
}
|
|
||||||
.subscribe()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,7 +308,7 @@
|
|||||||
<string name="restore_completed">Restore completed</string>
|
<string name="restore_completed">Restore completed</string>
|
||||||
<string name="restore_error">Restore error</string>
|
<string name="restore_error">Restore error</string>
|
||||||
<string name="error_opening_log">Could not open log</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="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="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>
|
<string name="file_saved">File saved at %1$s</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user