mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-04 03:06:41 -04:00
Naming conventions improved and some reviewed changes
This commit is contained in:
parent
4cdd449564
commit
5390c98d83
@ -56,7 +56,7 @@ abstract class KiwixRoomDatabase : RoomDatabase() {
|
||||
abstract fun historyRoomDao(): HistoryRoomDao
|
||||
abstract fun notesRoomDao(): NotesRoomDao
|
||||
abstract fun downloadRoomDao(): DownloadRoomDao
|
||||
abstract fun pageHistoryRoomDao(): WebViewHistoryRoomDao
|
||||
abstract fun webViewHistoryRoomDao(): WebViewHistoryRoomDao
|
||||
|
||||
companion object {
|
||||
private var db: KiwixRoomDatabase? = null
|
||||
|
@ -106,7 +106,7 @@ interface CoreComponent {
|
||||
fun libkiwixBookmarks(): LibkiwixBookmarks
|
||||
fun recentSearchRoomDao(): RecentSearchRoomDao
|
||||
fun historyRoomDao(): HistoryRoomDao
|
||||
fun pageHistoryRoomDao(): WebViewHistoryRoomDao
|
||||
fun webViewHistoryRoomDao(): WebViewHistoryRoomDao
|
||||
fun noteRoomDao(): NotesRoomDao
|
||||
fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator
|
||||
fun context(): Context
|
||||
|
@ -88,7 +88,7 @@ open class DatabaseModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePageHistoryRoomDao(db: KiwixRoomDatabase) = db.pageHistoryRoomDao()
|
||||
fun provideWebViewHistoryRoomDao(db: KiwixRoomDatabase) = db.webViewHistoryRoomDao()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
@ -133,7 +133,7 @@ import org.kiwix.kiwixmobile.core.navigateToAppSettings
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.NavigationHistoryClickListener
|
||||
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.WebViewHistoryCallback
|
||||
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.WebViewHistoryItem
|
||||
@ -195,7 +195,7 @@ abstract class CoreReaderFragment :
|
||||
ReadAloudCallbacks,
|
||||
NavigationHistoryClickListener,
|
||||
ShowDonationDialogCallback,
|
||||
DataCallback {
|
||||
WebViewHistoryCallback {
|
||||
protected val webViewList: MutableList<KiwixWebView> = ArrayList()
|
||||
private val webUrlsProcessor = BehaviorProcessor.create<String>()
|
||||
private var fragmentReaderBinding: FragmentReaderBinding? = null
|
||||
@ -991,7 +991,7 @@ abstract class CoreReaderFragment :
|
||||
|
||||
override fun clearHistory() {
|
||||
getCurrentWebView()?.clearHistory()
|
||||
repositoryActions?.clearWebViewPagesHistory()
|
||||
repositoryActions?.clearWebViewPageHistory()
|
||||
updateBottomToolbarArrowsAlpha()
|
||||
toast(R.string.navigation_history_cleared)
|
||||
}
|
||||
@ -1984,7 +1984,7 @@ abstract class CoreReaderFragment :
|
||||
|
||||
// If backStack and forwardStack are empty, return
|
||||
if (backStack.isEmpty() && forwardStack.isEmpty() || currentZimId != pageHistory[0].zimId) {
|
||||
repositoryActions?.clearWebViewPagesHistory()
|
||||
repositoryActions?.clearWebViewPageHistory()
|
||||
return
|
||||
}
|
||||
|
||||
@ -2038,7 +2038,7 @@ abstract class CoreReaderFragment :
|
||||
}
|
||||
|
||||
override fun onError(error: Throwable) {
|
||||
activity.toast(R.string.could_not_restore_tabs, Toast.LENGTH_LONG)
|
||||
activity.toast(R.string.could_not_restore_web_view_history, Toast.LENGTH_LONG)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@ -2436,6 +2436,26 @@ abstract class CoreReaderFragment :
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
private fun saveWebViewHistoryItems(
|
||||
startIndex: Int,
|
||||
endIndex: Int,
|
||||
zimId: String,
|
||||
isForward: Boolean,
|
||||
historyList: WebBackForwardList
|
||||
) {
|
||||
for (index in startIndex until endIndex) {
|
||||
val historyItem = historyList.getItemAtIndex(index)
|
||||
val pageHistory = WebViewHistoryItem(
|
||||
zimId = zimId,
|
||||
title = historyItem.title,
|
||||
pageUrl = historyItem.url,
|
||||
isForward = isForward,
|
||||
timeStamp = index.toLong()
|
||||
)
|
||||
repositoryActions?.saveWebViewPageHistory(pageHistory)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveWebBackForwardListToRoom() {
|
||||
val webBackForwardList = getCurrentWebView()?.copyBackForwardList()
|
||||
val currentIndex = webBackForwardList?.currentIndex
|
||||
@ -2443,40 +2463,28 @@ abstract class CoreReaderFragment :
|
||||
|
||||
if (currentIndex != null) {
|
||||
// Save BackStack
|
||||
webBackForwardList.let { historyList ->
|
||||
for (index in 0 until historyList.currentIndex) {
|
||||
val historyItem = historyList.getItemAtIndex(index)
|
||||
val pageHistory = WebViewHistoryItem(
|
||||
zimId = zimId,
|
||||
title = historyItem.title,
|
||||
pageUrl = historyItem.url,
|
||||
isForward = false,
|
||||
timeStamp = index.toLong()
|
||||
)
|
||||
repositoryActions?.saveWebViewPageHistory(pageHistory)
|
||||
}
|
||||
}
|
||||
saveWebViewHistoryItems(
|
||||
0,
|
||||
webBackForwardList.currentIndex,
|
||||
zimId,
|
||||
false,
|
||||
webBackForwardList
|
||||
)
|
||||
|
||||
// Save ForwardStack
|
||||
webBackForwardList.let { historyList ->
|
||||
for (index in historyList.currentIndex + 1 until historyList.size) {
|
||||
val historyItem = historyList.getItemAtIndex(index)
|
||||
val pageHistory = WebViewHistoryItem(
|
||||
zimId = zimId,
|
||||
title = historyItem.title,
|
||||
pageUrl = historyItem.url,
|
||||
isForward = true,
|
||||
timeStamp = index.toLong()
|
||||
)
|
||||
repositoryActions?.saveWebViewPageHistory(pageHistory)
|
||||
}
|
||||
}
|
||||
saveWebViewHistoryItems(
|
||||
currentIndex + 1,
|
||||
webBackForwardList.size,
|
||||
zimId,
|
||||
true,
|
||||
webBackForwardList
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
repositoryActions?.clearWebViewPagesHistory()
|
||||
repositoryActions?.clearWebViewPageHistory()
|
||||
saveWebBackForwardListToRoom()
|
||||
saveTabStates()
|
||||
Log.d(
|
||||
|
@ -21,7 +21,7 @@ import io.reactivex.disposables.Disposable
|
||||
import org.kiwix.kiwixmobile.core.data.DataSource
|
||||
import org.kiwix.kiwixmobile.core.di.ActivityScope
|
||||
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.WebViewHistoryCallback
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
|
||||
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
|
||||
@ -38,9 +38,9 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
|
||||
private var saveNoteDisposable: Disposable? = null
|
||||
private var saveBookDisposable: Disposable? = null
|
||||
private var deleteNoteDisposable: Disposable? = null
|
||||
private var savePageHistoryDisposable: Disposable? = null
|
||||
private var clearPageHistoryDisposable: Disposable? = null
|
||||
private var getPageHistoryDisposable: Disposable? = null
|
||||
private var saveWebViewHistoryDisposable: Disposable? = null
|
||||
private var clearWebViewHistoryDisposable: Disposable? = null
|
||||
private var getWebViewHistoryDisposable: Disposable? = null
|
||||
|
||||
fun saveHistory(history: HistoryItem) {
|
||||
saveHistoryDisposable = dataSource.saveHistory(history)
|
||||
@ -74,17 +74,17 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
|
||||
}
|
||||
|
||||
fun saveWebViewPageHistory(pageHistory: WebViewHistoryItem) {
|
||||
savePageHistoryDisposable = dataSource.insertWebViewHistoryItem(pageHistory)
|
||||
saveWebViewHistoryDisposable = dataSource.insertWebViewHistoryItem(pageHistory)
|
||||
.subscribe({}, { e -> Log.e(TAG, "Unable to save page history", e) })
|
||||
}
|
||||
|
||||
fun clearWebViewPagesHistory() {
|
||||
clearPageHistoryDisposable = dataSource.clearWebViewPagesHistory()
|
||||
fun clearWebViewPageHistory() {
|
||||
clearWebViewHistoryDisposable = dataSource.clearWebViewPagesHistory()
|
||||
.subscribe({}, { e -> Log.e(TAG, "Unable to clear page history", e) })
|
||||
}
|
||||
|
||||
fun loadWebViewPagesHistory(callBack: DataCallback) {
|
||||
getPageHistoryDisposable = dataSource.getAllWebViewPagesHistory()
|
||||
fun loadWebViewPagesHistory(callBack: WebViewHistoryCallback) {
|
||||
getWebViewHistoryDisposable = dataSource.getAllWebViewPagesHistory()
|
||||
.map { roomEntities ->
|
||||
roomEntities.map(::WebViewHistoryItem)
|
||||
}
|
||||
@ -97,8 +97,8 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
|
||||
saveNoteDisposable?.dispose()
|
||||
deleteNoteDisposable?.dispose()
|
||||
saveBookDisposable?.dispose()
|
||||
savePageHistoryDisposable?.dispose()
|
||||
clearPageHistoryDisposable?.dispose()
|
||||
getPageHistoryDisposable?.dispose()
|
||||
saveWebViewHistoryDisposable?.dispose()
|
||||
clearWebViewHistoryDisposable?.dispose()
|
||||
getWebViewHistoryDisposable?.dispose()
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ data class WebViewHistoryItem(
|
||||
)
|
||||
}
|
||||
|
||||
interface DataCallback {
|
||||
interface WebViewHistoryCallback {
|
||||
fun onDataFetched(pageHistory: List<WebViewHistoryItem>)
|
||||
fun onError(error: Throwable)
|
||||
}
|
||||
|
@ -233,6 +233,7 @@
|
||||
<string name="close_all_tabs">Close all tabs</string>
|
||||
<string name="close_tab">Close tab</string>
|
||||
<string name="could_not_restore_tabs">Could not restore tabs.</string>
|
||||
<string name="could_not_restore_web_view_history">Could not restore web view history</string>
|
||||
<string name="pending_state">Pending</string>
|
||||
<string name="running_state">In Progress</string>
|
||||
<string name="complete">Complete</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user