mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Naming convention improved
This commit is contained in:
parent
775d9439f3
commit
b81e4b5c97
@ -22,21 +22,21 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.PageHistoryRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class PageHistoryRoomDao {
|
abstract class WebViewHistoryRoomDao {
|
||||||
@Insert
|
@Insert
|
||||||
abstract fun insertPageHistoryItem(pageHistoryRoomEntity: PageHistoryRoomEntity)
|
abstract fun insertWebViewPageHistoryItem(webViewHistoryEntity: WebViewHistoryEntity)
|
||||||
|
|
||||||
@Query("SELECT * FROM PageHistoryRoomEntity ORDER BY isForward ASC,timestamp ASC")
|
@Query("SELECT * FROM WebViewHistoryEntity ORDER BY isForward ASC,timestamp ASC")
|
||||||
abstract fun getAllPageHistory(): Flowable<List<PageHistoryRoomEntity>>
|
abstract fun getAllWebViewPagesHistory(): Flowable<List<WebViewHistoryEntity>>
|
||||||
|
|
||||||
@Query("Delete from PageHistoryRoomEntity")
|
@Query("Delete from WebViewHistoryEntity")
|
||||||
abstract fun clearPageHistory()
|
abstract fun clearWebViewPagesHistory()
|
||||||
|
|
||||||
fun clearPageHistoryWithPrimaryKey() {
|
fun clearPageHistoryWithPrimaryKey() {
|
||||||
clearPageHistory()
|
clearWebViewPagesHistory()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("DELETE FROM sqlite_sequence WHERE name='PageHistoryRoomEntity'")
|
@Query("DELETE FROM sqlite_sequence WHERE name='PageHistoryRoomEntity'")
|
@ -20,10 +20,10 @@ package org.kiwix.kiwixmobile.core.dao.entities
|
|||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.PageHistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class PageHistoryRoomEntity(
|
data class WebViewHistoryEntity(
|
||||||
@PrimaryKey(autoGenerate = true) var id: Long = 0L,
|
@PrimaryKey(autoGenerate = true) var id: Long = 0L,
|
||||||
val zimId: String,
|
val zimId: String,
|
||||||
val title: String,
|
val title: String,
|
||||||
@ -31,12 +31,12 @@ data class PageHistoryRoomEntity(
|
|||||||
val isForward: Boolean = false,
|
val isForward: Boolean = false,
|
||||||
val timeStamp: Long
|
val timeStamp: Long
|
||||||
) {
|
) {
|
||||||
constructor(pageHistoryItem: PageHistoryItem) : this(
|
constructor(webViewHistoryItem: WebViewHistoryItem) : this(
|
||||||
pageHistoryItem.databaseId,
|
webViewHistoryItem.databaseId,
|
||||||
pageHistoryItem.zimId,
|
webViewHistoryItem.zimId,
|
||||||
pageHistoryItem.title,
|
webViewHistoryItem.title,
|
||||||
pageHistoryItem.pageUrl,
|
webViewHistoryItem.pageUrl,
|
||||||
pageHistoryItem.isForward,
|
webViewHistoryItem.isForward,
|
||||||
pageHistoryItem.timeStamp
|
webViewHistoryItem.timeStamp
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -20,11 +20,11 @@ package org.kiwix.kiwixmobile.core.data
|
|||||||
import io.reactivex.Completable
|
import io.reactivex.Completable
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.PageHistoryRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity
|
||||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.PageHistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||||
import org.kiwix.kiwixmobile.core.zim_manager.Language
|
import org.kiwix.kiwixmobile.core.zim_manager.Language
|
||||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
|
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem
|
||||||
@ -56,7 +56,7 @@ interface DataSource {
|
|||||||
fun deleteNote(noteTitle: String): Completable
|
fun deleteNote(noteTitle: String): Completable
|
||||||
fun deleteNotes(noteList: List<NoteListItem>): Completable
|
fun deleteNotes(noteList: List<NoteListItem>): Completable
|
||||||
|
|
||||||
fun insertPageHistoryItem(pageHistory: PageHistoryItem): Completable
|
fun insertWebViewHistoryItem(pageHistory: WebViewHistoryItem): Completable
|
||||||
fun getAllPageHistory(): Single<List<PageHistoryRoomEntity>>
|
fun getAllWebViewPagesHistory(): Single<List<WebViewHistoryEntity>>
|
||||||
fun clearPageHistory(): Completable
|
fun clearWebViewPagesHistory(): Completable
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao
|
|||||||
import org.kiwix.kiwixmobile.core.dao.HistoryRoomDao
|
import org.kiwix.kiwixmobile.core.dao.HistoryRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.HistoryRoomDaoCoverts
|
import org.kiwix.kiwixmobile.core.dao.HistoryRoomDaoCoverts
|
||||||
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.PageHistoryRoomDao
|
|
||||||
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
||||||
|
import org.kiwix.kiwixmobile.core.dao.WebViewHistoryRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.DownloadRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.DownloadRoomEntity
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.HistoryRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.HistoryRoomEntity
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.NotesRoomEntity
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.PageHistoryRoomEntity
|
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.RecentSearchRoomEntity
|
||||||
|
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.ZimSourceRoomConverter
|
import org.kiwix.kiwixmobile.core.dao.entities.ZimSourceRoomConverter
|
||||||
|
|
||||||
@Suppress("UnnecessaryAbstractClass")
|
@Suppress("UnnecessaryAbstractClass")
|
||||||
@ -45,7 +45,7 @@ import org.kiwix.kiwixmobile.core.dao.entities.ZimSourceRoomConverter
|
|||||||
HistoryRoomEntity::class,
|
HistoryRoomEntity::class,
|
||||||
NotesRoomEntity::class,
|
NotesRoomEntity::class,
|
||||||
DownloadRoomEntity::class,
|
DownloadRoomEntity::class,
|
||||||
PageHistoryRoomEntity::class
|
WebViewHistoryEntity::class
|
||||||
],
|
],
|
||||||
version = 8,
|
version = 8,
|
||||||
exportSchema = false
|
exportSchema = false
|
||||||
@ -56,7 +56,7 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
|
|||||||
abstract fun historyRoomDao(): HistoryRoomDao
|
abstract fun historyRoomDao(): HistoryRoomDao
|
||||||
abstract fun notesRoomDao(): NotesRoomDao
|
abstract fun notesRoomDao(): NotesRoomDao
|
||||||
abstract fun downloadRoomDao(): DownloadRoomDao
|
abstract fun downloadRoomDao(): DownloadRoomDao
|
||||||
abstract fun pageHistoryRoomDao(): PageHistoryRoomDao
|
abstract fun pageHistoryRoomDao(): WebViewHistoryRoomDao
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var db: KiwixRoomDatabase? = null
|
private var db: KiwixRoomDatabase? = null
|
||||||
@ -279,14 +279,15 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
|
|||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
private val MIGRATION_7_8 = object : Migration(7, 8) {
|
private val MIGRATION_7_8 = object : Migration(7, 8) {
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
database.execSQL("DROP TABLE PageHistoryRoomEntity")
|
||||||
database.execSQL(
|
database.execSQL(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS `PageHistoryRoomEntity` (
|
CREATE TABLE IF NOT EXISTS `WebViewHistoryEntity` (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
`zimId` TEXT NOT NULL,
|
`zimId` TEXT NOT NULL,
|
||||||
`title` TEXT NOT NULL,
|
`title` TEXT NOT NULL,
|
||||||
`pageUrl` TEXT NOT NULL,
|
`pageUrl` TEXT NOT NULL,
|
||||||
`isForward` INTEGER NOT NULL DEFAULT 0
|
`isForward` INTEGER NOT NULL DEFAULT 0,
|
||||||
`timeStamp` INTEGER NOT NULL
|
`timeStamp` INTEGER NOT NULL
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
@ -28,16 +28,16 @@ import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks
|
|||||||
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
import org.kiwix.kiwixmobile.core.dao.NewBookDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
|
import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.PageHistoryRoomDao
|
import org.kiwix.kiwixmobile.core.dao.WebViewHistoryRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.PageHistoryRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity
|
||||||
import org.kiwix.kiwixmobile.core.di.qualifiers.IO
|
import org.kiwix.kiwixmobile.core.di.qualifiers.IO
|
||||||
import org.kiwix.kiwixmobile.core.di.qualifiers.MainThread
|
import org.kiwix.kiwixmobile.core.di.qualifiers.MainThread
|
||||||
import org.kiwix.kiwixmobile.core.extensions.HeaderizableList
|
import org.kiwix.kiwixmobile.core.extensions.HeaderizableList
|
||||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.PageHistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||||
import org.kiwix.kiwixmobile.core.zim_manager.Language
|
import org.kiwix.kiwixmobile.core.zim_manager.Language
|
||||||
@ -58,7 +58,7 @@ class Repository @Inject internal constructor(
|
|||||||
private val bookDao: NewBookDao,
|
private val bookDao: NewBookDao,
|
||||||
private val libkiwixBookmarks: LibkiwixBookmarks,
|
private val libkiwixBookmarks: LibkiwixBookmarks,
|
||||||
private val historyRoomDao: HistoryRoomDao,
|
private val historyRoomDao: HistoryRoomDao,
|
||||||
private val pageHistoryRoomDao: PageHistoryRoomDao,
|
private val webViewHistoryRoomDao: WebViewHistoryRoomDao,
|
||||||
private val notesRoomDao: NotesRoomDao,
|
private val notesRoomDao: NotesRoomDao,
|
||||||
private val languageDao: NewLanguagesDao,
|
private val languageDao: NewLanguagesDao,
|
||||||
private val recentSearchRoomDao: RecentSearchRoomDao,
|
private val recentSearchRoomDao: RecentSearchRoomDao,
|
||||||
@ -148,22 +148,22 @@ class Repository @Inject internal constructor(
|
|||||||
Completable.fromAction { notesRoomDao.deleteNotes(noteList) }
|
Completable.fromAction { notesRoomDao.deleteNotes(noteList) }
|
||||||
.subscribeOn(ioThread)
|
.subscribeOn(ioThread)
|
||||||
|
|
||||||
override fun insertPageHistoryItem(pageHistory: PageHistoryItem): Completable =
|
override fun insertWebViewHistoryItem(pageHistory: WebViewHistoryItem): Completable =
|
||||||
Completable.fromAction {
|
Completable.fromAction {
|
||||||
pageHistoryRoomDao.insertPageHistoryItem(
|
webViewHistoryRoomDao.insertWebViewPageHistoryItem(
|
||||||
PageHistoryRoomEntity(pageHistory)
|
WebViewHistoryEntity(pageHistory)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.subscribeOn(ioThread)
|
.subscribeOn(ioThread)
|
||||||
|
|
||||||
override fun getAllPageHistory() =
|
override fun getAllWebViewPagesHistory() =
|
||||||
pageHistoryRoomDao.getAllPageHistory()
|
webViewHistoryRoomDao.getAllWebViewPagesHistory()
|
||||||
.first(emptyList())
|
.first(emptyList())
|
||||||
.subscribeOn(ioThread)
|
.subscribeOn(ioThread)
|
||||||
.observeOn(mainThread)
|
.observeOn(mainThread)
|
||||||
|
|
||||||
override fun clearPageHistory(): Completable =
|
override fun clearWebViewPagesHistory(): Completable =
|
||||||
Completable.fromAction(pageHistoryRoomDao::clearPageHistoryWithPrimaryKey)
|
Completable.fromAction(webViewHistoryRoomDao::clearPageHistoryWithPrimaryKey)
|
||||||
.subscribeOn(ioThread)
|
.subscribeOn(ioThread)
|
||||||
|
|
||||||
override fun deleteNote(noteTitle: String): Completable =
|
override fun deleteNote(noteTitle: String): Completable =
|
||||||
|
@ -37,7 +37,7 @@ import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
|
|||||||
import org.kiwix.kiwixmobile.core.dao.NewNoteDao
|
import org.kiwix.kiwixmobile.core.dao.NewNoteDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchDao
|
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
import org.kiwix.kiwixmobile.core.dao.NotesRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.PageHistoryRoomDao
|
import org.kiwix.kiwixmobile.core.dao.WebViewHistoryRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
import org.kiwix.kiwixmobile.core.dao.RecentSearchRoomDao
|
||||||
import org.kiwix.kiwixmobile.core.data.DataModule
|
import org.kiwix.kiwixmobile.core.data.DataModule
|
||||||
import org.kiwix.kiwixmobile.core.data.DataSource
|
import org.kiwix.kiwixmobile.core.data.DataSource
|
||||||
@ -106,7 +106,7 @@ interface CoreComponent {
|
|||||||
fun libkiwixBookmarks(): LibkiwixBookmarks
|
fun libkiwixBookmarks(): LibkiwixBookmarks
|
||||||
fun recentSearchRoomDao(): RecentSearchRoomDao
|
fun recentSearchRoomDao(): RecentSearchRoomDao
|
||||||
fun historyRoomDao(): HistoryRoomDao
|
fun historyRoomDao(): HistoryRoomDao
|
||||||
fun pageHistoryRoomDao(): PageHistoryRoomDao
|
fun pageHistoryRoomDao(): WebViewHistoryRoomDao
|
||||||
fun noteRoomDao(): NotesRoomDao
|
fun noteRoomDao(): NotesRoomDao
|
||||||
fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator
|
fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator
|
||||||
fun context(): Context
|
fun context(): Context
|
||||||
|
@ -136,7 +136,7 @@ import org.kiwix.kiwixmobile.core.page.history.NavigationHistoryDialog
|
|||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.DataCallback
|
import org.kiwix.kiwixmobile.core.page.history.adapter.DataCallback
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.NavigationHistoryListItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.NavigationHistoryListItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.PageHistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudCallbacks
|
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudCallbacks
|
||||||
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService
|
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService
|
||||||
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService.Companion.ACTION_PAUSE_OR_RESUME_TTS
|
import org.kiwix.kiwixmobile.core.read_aloud.ReadAloudService.Companion.ACTION_PAUSE_OR_RESUME_TTS
|
||||||
@ -991,7 +991,7 @@ abstract class CoreReaderFragment :
|
|||||||
|
|
||||||
override fun clearHistory() {
|
override fun clearHistory() {
|
||||||
getCurrentWebView()?.clearHistory()
|
getCurrentWebView()?.clearHistory()
|
||||||
repositoryActions?.clearPageHistory()
|
repositoryActions?.clearWebViewPagesHistory()
|
||||||
updateBottomToolbarArrowsAlpha()
|
updateBottomToolbarArrowsAlpha()
|
||||||
toast(R.string.navigation_history_cleared)
|
toast(R.string.navigation_history_cleared)
|
||||||
}
|
}
|
||||||
@ -1975,23 +1975,19 @@ abstract class CoreReaderFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("MagicNumber")
|
@Suppress("MagicNumber")
|
||||||
private fun loadWebViewHistory(pageHistory: List<PageHistoryItem>) {
|
private fun loadWebViewHistory(pageHistory: List<WebViewHistoryItem>) {
|
||||||
val backStack = pageHistory.filter { !it.isForward }
|
val backStack = pageHistory.filter { !it.isForward }
|
||||||
val forwardStack = pageHistory.filter(PageHistoryItem::isForward)
|
val forwardStack = pageHistory.filter(WebViewHistoryItem::isForward)
|
||||||
val currentWebView = getCurrentWebView() ?: return
|
val currentWebView = getCurrentWebView() ?: return
|
||||||
val currentPageUrl = currentWebView.copyBackForwardList().currentItem?.url
|
val currentPageUrl = currentWebView.copyBackForwardList().currentItem?.url
|
||||||
|
val currentZimId = zimReaderContainer?.zimFileReader?.id
|
||||||
|
|
||||||
// If backStack and forwardStack are empty, return
|
// If backStack and forwardStack are empty, return
|
||||||
if (backStack.isEmpty() && forwardStack.isEmpty()) {
|
if (backStack.isEmpty() && forwardStack.isEmpty() || currentZimId != pageHistory[0].zimId) {
|
||||||
|
repositoryActions?.clearWebViewPagesHistory()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug info: Toast to check the size of back and forward stack
|
|
||||||
activity.toast(
|
|
||||||
"${pageHistory.size} items loaded. Back stack size: ${backStack.size}",
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
)
|
|
||||||
|
|
||||||
if (backStack.isNotEmpty()) {
|
if (backStack.isNotEmpty()) {
|
||||||
// Step 1: Load the first item immediately (0th index)
|
// Step 1: Load the first item immediately (0th index)
|
||||||
currentWebView.loadUrl(backStack[0].pageUrl)
|
currentWebView.loadUrl(backStack[0].pageUrl)
|
||||||
@ -2037,7 +2033,7 @@ abstract class CoreReaderFragment :
|
|||||||
) // Initial delay to allow the first page to load
|
) // Initial delay to allow the first page to load
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDataFetched(pageHistory: List<PageHistoryItem>) {
|
override fun onDataFetched(pageHistory: List<WebViewHistoryItem>) {
|
||||||
loadWebViewHistory(pageHistory)
|
loadWebViewHistory(pageHistory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2047,7 +2043,7 @@ abstract class CoreReaderFragment :
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
repositoryActions?.loadPageHistory(this)
|
repositoryActions?.loadWebViewPagesHistory(this)
|
||||||
updateBottomToolbarVisibility()
|
updateBottomToolbarVisibility()
|
||||||
updateNightMode()
|
updateNightMode()
|
||||||
if (tts == null) {
|
if (tts == null) {
|
||||||
@ -2448,43 +2444,39 @@ abstract class CoreReaderFragment :
|
|||||||
if (currentIndex != null) {
|
if (currentIndex != null) {
|
||||||
// Save BackStack
|
// Save BackStack
|
||||||
webBackForwardList.let { historyList ->
|
webBackForwardList.let { historyList ->
|
||||||
(0 until historyList.currentIndex)
|
for (index in 0 until historyList.currentIndex) {
|
||||||
.asSequence()
|
val historyItem = historyList.getItemAtIndex(index)
|
||||||
.forEach {
|
val pageHistory = WebViewHistoryItem(
|
||||||
val historyItem = webBackForwardList.getItemAtIndex(it)
|
zimId = zimId,
|
||||||
val pageHistory = PageHistoryItem(
|
title = historyItem.title,
|
||||||
zimId = zimId,
|
pageUrl = historyItem.url,
|
||||||
title = historyItem.title,
|
isForward = false,
|
||||||
pageUrl = historyItem.url,
|
timeStamp = index.toLong()
|
||||||
isForward = false,
|
)
|
||||||
timeStamp = it.toLong()
|
repositoryActions?.saveWebViewPageHistory(pageHistory)
|
||||||
)
|
}
|
||||||
repositoryActions?.savePageHistory(pageHistory)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save ForwardStack
|
// Save ForwardStack
|
||||||
webBackForwardList.let { historyList ->
|
webBackForwardList.let { historyList ->
|
||||||
(historyList.currentIndex + 1 until webBackForwardList.size)
|
for (index in (historyList.currentIndex + 1) until historyList.size) {
|
||||||
.asSequence()
|
val historyItem = historyList.getItemAtIndex(index)
|
||||||
.forEach {
|
val pageHistory = WebViewHistoryItem(
|
||||||
val historyItem = webBackForwardList.getItemAtIndex(it)
|
zimId = zimId,
|
||||||
val pageHistory = PageHistoryItem(
|
title = historyItem.title,
|
||||||
zimId = zimId,
|
pageUrl = historyItem.url,
|
||||||
title = historyItem.title,
|
isForward = true,
|
||||||
pageUrl = historyItem.url,
|
timeStamp = index.toLong()
|
||||||
isForward = true,
|
)
|
||||||
timeStamp = it.toLong()
|
repositoryActions?.saveWebViewPageHistory(pageHistory)
|
||||||
)
|
}
|
||||||
repositoryActions?.savePageHistory(pageHistory)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
repositoryActions?.clearPageHistory()
|
repositoryActions?.clearWebViewPagesHistory()
|
||||||
saveWebBackForwardListToRoom()
|
saveWebBackForwardListToRoom()
|
||||||
saveTabStates()
|
saveTabStates()
|
||||||
Log.d(
|
Log.d(
|
||||||
|
@ -23,7 +23,7 @@ import org.kiwix.kiwixmobile.core.di.ActivityScope
|
|||||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.DataCallback
|
import org.kiwix.kiwixmobile.core.page.history.adapter.DataCallback
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.history.adapter.PageHistoryItem
|
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||||
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||||
import org.kiwix.kiwixmobile.core.utils.files.Log
|
import org.kiwix.kiwixmobile.core.utils.files.Log
|
||||||
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk
|
||||||
@ -73,20 +73,20 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
|
|||||||
.subscribe({}, { e -> Log.e(TAG, "Unable to save book", e) })
|
.subscribe({}, { e -> Log.e(TAG, "Unable to save book", e) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun savePageHistory(pageHistory: PageHistoryItem) {
|
fun saveWebViewPageHistory(pageHistory: WebViewHistoryItem) {
|
||||||
savePageHistoryDisposable = dataSource.insertPageHistoryItem(pageHistory)
|
savePageHistoryDisposable = dataSource.insertWebViewHistoryItem(pageHistory)
|
||||||
.subscribe({}, { e -> Log.e(TAG, "Unable to save page history", e) })
|
.subscribe({}, { e -> Log.e(TAG, "Unable to save page history", e) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearPageHistory() {
|
fun clearWebViewPagesHistory() {
|
||||||
clearPageHistoryDisposable = dataSource.clearPageHistory()
|
clearPageHistoryDisposable = dataSource.clearWebViewPagesHistory()
|
||||||
.subscribe({}, { e -> Log.e(TAG, "Unable to clear page history", e) })
|
.subscribe({}, { e -> Log.e(TAG, "Unable to clear page history", e) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadPageHistory(callBack: DataCallback) {
|
fun loadWebViewPagesHistory(callBack: DataCallback) {
|
||||||
getPageHistoryDisposable = dataSource.getAllPageHistory()
|
getPageHistoryDisposable = dataSource.getAllWebViewPagesHistory()
|
||||||
.map { roomEntities ->
|
.map { roomEntities ->
|
||||||
roomEntities.map(::PageHistoryItem)
|
roomEntities.map(::WebViewHistoryItem)
|
||||||
}
|
}
|
||||||
.subscribe(callBack::onDataFetched) { e -> Log.e(TAG, "Unable to load page history", e) }
|
.subscribe(callBack::onDataFetched) { e -> Log.e(TAG, "Unable to load page history", e) }
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.core.page.history.adapter
|
package org.kiwix.kiwixmobile.core.page.history.adapter
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.core.dao.entities.PageHistoryRoomEntity
|
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity
|
||||||
|
|
||||||
data class PageHistoryItem(
|
data class WebViewHistoryItem(
|
||||||
val databaseId: Long = 0L,
|
val databaseId: Long = 0L,
|
||||||
val zimId: String,
|
val zimId: String,
|
||||||
val title: String,
|
val title: String,
|
||||||
@ -43,17 +43,17 @@ data class PageHistoryItem(
|
|||||||
timeStamp
|
timeStamp
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor(pageHistoryRoomEntity: PageHistoryRoomEntity) : this(
|
constructor(webViewHistoryEntity: WebViewHistoryEntity) : this(
|
||||||
pageHistoryRoomEntity.id,
|
webViewHistoryEntity.id,
|
||||||
pageHistoryRoomEntity.zimId,
|
webViewHistoryEntity.zimId,
|
||||||
pageHistoryRoomEntity.title,
|
webViewHistoryEntity.title,
|
||||||
pageHistoryRoomEntity.pageUrl,
|
webViewHistoryEntity.pageUrl,
|
||||||
pageHistoryRoomEntity.isForward,
|
webViewHistoryEntity.isForward,
|
||||||
pageHistoryRoomEntity.timeStamp
|
webViewHistoryEntity.timeStamp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DataCallback {
|
interface DataCallback {
|
||||||
fun onDataFetched(pageHistory: List<PageHistoryItem>)
|
fun onDataFetched(pageHistory: List<WebViewHistoryItem>)
|
||||||
fun onError(error: Throwable)
|
fun onError(error: Throwable)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user