Naming conventions improved and some reviewed changes

This commit is contained in:
Saifuddin 2024-10-18 11:02:41 +05:30 committed by MohitMaliFtechiz
parent 4cdd449564
commit 5390c98d83
7 changed files with 57 additions and 48 deletions

View File

@ -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(): WebViewHistoryRoomDao abstract fun webViewHistoryRoomDao(): WebViewHistoryRoomDao
companion object { companion object {
private var db: KiwixRoomDatabase? = null private var db: KiwixRoomDatabase? = null

View File

@ -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(): WebViewHistoryRoomDao fun webViewHistoryRoomDao(): WebViewHistoryRoomDao
fun noteRoomDao(): NotesRoomDao fun noteRoomDao(): NotesRoomDao
fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator fun objectBoxToRoomMigrator(): ObjectBoxToRoomMigrator
fun context(): Context fun context(): Context

View File

@ -88,7 +88,7 @@ open class DatabaseModule {
@Provides @Provides
@Singleton @Singleton
fun providePageHistoryRoomDao(db: KiwixRoomDatabase) = db.pageHistoryRoomDao() fun provideWebViewHistoryRoomDao(db: KiwixRoomDatabase) = db.webViewHistoryRoomDao()
@Singleton @Singleton
@Provides @Provides

View File

@ -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.bookmark.adapter.LibkiwixBookmarkItem
import org.kiwix.kiwixmobile.core.page.history.NavigationHistoryClickListener import org.kiwix.kiwixmobile.core.page.history.NavigationHistoryClickListener
import org.kiwix.kiwixmobile.core.page.history.NavigationHistoryDialog 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.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.WebViewHistoryItem import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem
@ -195,7 +195,7 @@ abstract class CoreReaderFragment :
ReadAloudCallbacks, ReadAloudCallbacks,
NavigationHistoryClickListener, NavigationHistoryClickListener,
ShowDonationDialogCallback, ShowDonationDialogCallback,
DataCallback { WebViewHistoryCallback {
protected val webViewList: MutableList<KiwixWebView> = ArrayList() protected val webViewList: MutableList<KiwixWebView> = ArrayList()
private val webUrlsProcessor = BehaviorProcessor.create<String>() private val webUrlsProcessor = BehaviorProcessor.create<String>()
private var fragmentReaderBinding: FragmentReaderBinding? = null private var fragmentReaderBinding: FragmentReaderBinding? = null
@ -991,7 +991,7 @@ abstract class CoreReaderFragment :
override fun clearHistory() { override fun clearHistory() {
getCurrentWebView()?.clearHistory() getCurrentWebView()?.clearHistory()
repositoryActions?.clearWebViewPagesHistory() repositoryActions?.clearWebViewPageHistory()
updateBottomToolbarArrowsAlpha() updateBottomToolbarArrowsAlpha()
toast(R.string.navigation_history_cleared) toast(R.string.navigation_history_cleared)
} }
@ -1984,7 +1984,7 @@ abstract class CoreReaderFragment :
// If backStack and forwardStack are empty, return // If backStack and forwardStack are empty, return
if (backStack.isEmpty() && forwardStack.isEmpty() || currentZimId != pageHistory[0].zimId) { if (backStack.isEmpty() && forwardStack.isEmpty() || currentZimId != pageHistory[0].zimId) {
repositoryActions?.clearWebViewPagesHistory() repositoryActions?.clearWebViewPageHistory()
return return
} }
@ -2038,7 +2038,7 @@ abstract class CoreReaderFragment :
} }
override fun onError(error: Throwable) { 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() { override fun onResume() {
@ -2436,6 +2436,26 @@ abstract class CoreReaderFragment :
editor.apply() 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() { private fun saveWebBackForwardListToRoom() {
val webBackForwardList = getCurrentWebView()?.copyBackForwardList() val webBackForwardList = getCurrentWebView()?.copyBackForwardList()
val currentIndex = webBackForwardList?.currentIndex val currentIndex = webBackForwardList?.currentIndex
@ -2443,40 +2463,28 @@ abstract class CoreReaderFragment :
if (currentIndex != null) { if (currentIndex != null) {
// Save BackStack // Save BackStack
webBackForwardList.let { historyList -> saveWebViewHistoryItems(
for (index in 0 until historyList.currentIndex) { 0,
val historyItem = historyList.getItemAtIndex(index) webBackForwardList.currentIndex,
val pageHistory = WebViewHistoryItem( zimId,
zimId = zimId, false,
title = historyItem.title, webBackForwardList
pageUrl = historyItem.url,
isForward = false,
timeStamp = index.toLong()
) )
repositoryActions?.saveWebViewPageHistory(pageHistory)
}
}
// Save ForwardStack // Save ForwardStack
webBackForwardList.let { historyList -> saveWebViewHistoryItems(
for (index in historyList.currentIndex + 1 until historyList.size) { currentIndex + 1,
val historyItem = historyList.getItemAtIndex(index) webBackForwardList.size,
val pageHistory = WebViewHistoryItem( zimId,
zimId = zimId, true,
title = historyItem.title, webBackForwardList
pageUrl = historyItem.url,
isForward = true,
timeStamp = index.toLong()
) )
repositoryActions?.saveWebViewPageHistory(pageHistory)
}
}
} }
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
repositoryActions?.clearWebViewPagesHistory() repositoryActions?.clearWebViewPageHistory()
saveWebBackForwardListToRoom() saveWebBackForwardListToRoom()
saveTabStates() saveTabStates()
Log.d( Log.d(

View File

@ -21,7 +21,7 @@ import io.reactivex.disposables.Disposable
import org.kiwix.kiwixmobile.core.data.DataSource import org.kiwix.kiwixmobile.core.data.DataSource
import org.kiwix.kiwixmobile.core.di.ActivityScope 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.WebViewHistoryCallback
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.WebViewHistoryItem 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
@ -38,9 +38,9 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
private var saveNoteDisposable: Disposable? = null private var saveNoteDisposable: Disposable? = null
private var saveBookDisposable: Disposable? = null private var saveBookDisposable: Disposable? = null
private var deleteNoteDisposable: Disposable? = null private var deleteNoteDisposable: Disposable? = null
private var savePageHistoryDisposable: Disposable? = null private var saveWebViewHistoryDisposable: Disposable? = null
private var clearPageHistoryDisposable: Disposable? = null private var clearWebViewHistoryDisposable: Disposable? = null
private var getPageHistoryDisposable: Disposable? = null private var getWebViewHistoryDisposable: Disposable? = null
fun saveHistory(history: HistoryItem) { fun saveHistory(history: HistoryItem) {
saveHistoryDisposable = dataSource.saveHistory(history) saveHistoryDisposable = dataSource.saveHistory(history)
@ -74,17 +74,17 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
} }
fun saveWebViewPageHistory(pageHistory: WebViewHistoryItem) { fun saveWebViewPageHistory(pageHistory: WebViewHistoryItem) {
savePageHistoryDisposable = dataSource.insertWebViewHistoryItem(pageHistory) saveWebViewHistoryDisposable = 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 clearWebViewPagesHistory() { fun clearWebViewPageHistory() {
clearPageHistoryDisposable = dataSource.clearWebViewPagesHistory() clearWebViewHistoryDisposable = 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 loadWebViewPagesHistory(callBack: DataCallback) { fun loadWebViewPagesHistory(callBack: WebViewHistoryCallback) {
getPageHistoryDisposable = dataSource.getAllWebViewPagesHistory() getWebViewHistoryDisposable = dataSource.getAllWebViewPagesHistory()
.map { roomEntities -> .map { roomEntities ->
roomEntities.map(::WebViewHistoryItem) roomEntities.map(::WebViewHistoryItem)
} }
@ -97,8 +97,8 @@ class MainRepositoryActions @Inject constructor(private val dataSource: DataSour
saveNoteDisposable?.dispose() saveNoteDisposable?.dispose()
deleteNoteDisposable?.dispose() deleteNoteDisposable?.dispose()
saveBookDisposable?.dispose() saveBookDisposable?.dispose()
savePageHistoryDisposable?.dispose() saveWebViewHistoryDisposable?.dispose()
clearPageHistoryDisposable?.dispose() clearWebViewHistoryDisposable?.dispose()
getPageHistoryDisposable?.dispose() getWebViewHistoryDisposable?.dispose()
} }
} }

View File

@ -53,7 +53,7 @@ data class WebViewHistoryItem(
) )
} }
interface DataCallback { interface WebViewHistoryCallback {
fun onDataFetched(pageHistory: List<WebViewHistoryItem>) fun onDataFetched(pageHistory: List<WebViewHistoryItem>)
fun onError(error: Throwable) fun onError(error: Throwable)
} }

View File

@ -233,6 +233,7 @@
<string name="close_all_tabs">Close all tabs</string> <string name="close_all_tabs">Close all tabs</string>
<string name="close_tab">Close tab</string> <string name="close_tab">Close tab</string>
<string name="could_not_restore_tabs">Could not restore tabs.</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="pending_state">Pending</string>
<string name="running_state">In Progress</string> <string name="running_state">In Progress</string>
<string name="complete">Complete</string> <string name="complete">Complete</string>