-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3996 from Saifuddin53/Issue#398
Saving and Restoring the Web View Navigation History Across Sessions
- Loading branch information
Showing
18 changed files
with
654 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
core/src/main/java/org/kiwix/kiwixmobile/core/dao/WebViewHistoryRoomDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Kiwix Android | ||
* Copyright (c) 2024 Kiwix <android.kiwix.org> | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package org.kiwix.kiwixmobile.core.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import io.reactivex.Flowable | ||
import org.kiwix.kiwixmobile.core.dao.entities.WebViewHistoryEntity | ||
|
||
@Dao | ||
abstract class WebViewHistoryRoomDao { | ||
|
||
fun insertWebViewPageHistoryItem(webViewHistoryEntity: WebViewHistoryEntity) { | ||
insertWebViewPageHistoryItems(listOf(webViewHistoryEntity)) | ||
} | ||
|
||
@Insert | ||
abstract fun insertWebViewPageHistoryItems(webViewHistoryEntityList: List<WebViewHistoryEntity>) | ||
|
||
@Query("SELECT * FROM WebViewHistoryEntity ORDER BY webViewIndex ASC") | ||
abstract fun getAllWebViewPagesHistory(): Flowable<List<WebViewHistoryEntity>> | ||
|
||
@Query("Delete from WebViewHistoryEntity") | ||
abstract fun clearWebViewPagesHistory() | ||
|
||
fun clearPageHistoryWithPrimaryKey() { | ||
clearWebViewPagesHistory() | ||
} | ||
|
||
@Query("DELETE FROM sqlite_sequence WHERE name='PageHistoryRoomEntity'") | ||
abstract fun resetPrimaryKey() | ||
} |
68 changes: 68 additions & 0 deletions
68
core/src/main/java/org/kiwix/kiwixmobile/core/dao/entities/WebViewHistoryEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Kiwix Android | ||
* Copyright (c) 2024 Kiwix <android.kiwix.org> | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package org.kiwix.kiwixmobile.core.dao.entities | ||
|
||
import android.os.Bundle | ||
import android.os.Parcel | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import androidx.room.TypeConverter | ||
import androidx.room.TypeConverters | ||
import org.kiwix.kiwixmobile.core.page.history.adapter.WebViewHistoryItem | ||
|
||
@Entity | ||
data class WebViewHistoryEntity( | ||
@PrimaryKey(autoGenerate = true) var id: Long = 0L, | ||
val zimId: String, | ||
val webViewIndex: Int, | ||
val webViewCurrentPosition: Int, | ||
@TypeConverters(BundleRoomConverter::class) | ||
val webViewBackForwardListBundle: Bundle? | ||
) { | ||
constructor(webViewHistoryItem: WebViewHistoryItem) : this( | ||
webViewHistoryItem.databaseId, | ||
webViewHistoryItem.zimId, | ||
webViewHistoryItem.webViewIndex, | ||
webViewHistoryItem.webViewCurrentPosition, | ||
webViewHistoryItem.webViewBackForwardListBundle, | ||
) | ||
} | ||
|
||
class BundleRoomConverter { | ||
@TypeConverter | ||
fun convertToDatabaseValue(bundle: Bundle?): ByteArray? { | ||
if (bundle == null) return null | ||
val parcel = Parcel.obtain() | ||
parcel.writeBundle(bundle) | ||
val bytes = parcel.marshall() | ||
parcel.recycle() | ||
return bytes | ||
} | ||
|
||
@TypeConverter | ||
fun convertToEntityProperty(byteArray: ByteArray?): Bundle? { | ||
if (byteArray == null) return null | ||
val parcel = Parcel.obtain() | ||
parcel.unmarshall(byteArray, 0, byteArray.size) | ||
parcel.setDataPosition(0) | ||
val bundle = parcel.readBundle(Bundle::class.java.classLoader) | ||
parcel.recycle() | ||
return bundle | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.