From da3241bea0d86dadb0dc0c69b2220a56bd20af3e Mon Sep 17 00:00:00 2001 From: MohitMali Date: Tue, 29 Aug 2023 11:33:11 +0530 Subject: [PATCH] Created LibkiwixBooks to store and retrieve bookmarks --- .../kiwixmobile/core/dao/LibkiwixBookmarks.kt | 38 +++++++++++++++++++ .../kiwix/kiwixmobile/core/data/Repository.kt | 3 +- .../core/di/components/CoreComponent.kt | 2 + .../kiwixmobile/core/di/modules/JNIModule.kt | 5 +++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt new file mode 100644 index 000000000..cc4a684a5 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/dao/LibkiwixBookmarks.kt @@ -0,0 +1,38 @@ +/* + * Kiwix Android + * Copyright (c) 2023 Kiwix + * 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 . + * + */ + +package org.kiwix.kiwixmobile.core.dao + +import io.objectbox.kotlin.query +import io.reactivex.Flowable +import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity_ +import org.kiwix.kiwixmobile.core.page.adapter.Page +import org.kiwix.libkiwix.Manager +import javax.inject.Inject + +class LibkiwixBookmarks @Inject constructor(val manager: Manager) : PageDao { + fun bookmarks(): Flowable> = box.asFlowable( + box.query { + order(BookmarkEntity_.bookmarkTitle) + } + ).map { it.map(org.kiwix.kiwixmobile.core.page.bookmark.adapter::BookmarkItem) } + override fun pages(): Flowable> = bookmarks() + + override fun deletePages(pagesToDelete: List) { + } +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt index 2aaf489cb..6a93709e8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/data/Repository.kt @@ -23,6 +23,7 @@ import io.reactivex.Flowable import io.reactivex.Scheduler import io.reactivex.Single import org.kiwix.kiwixmobile.core.dao.HistoryDao +import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookmarksDao import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao @@ -53,7 +54,7 @@ class Repository @Inject internal constructor( @param:IO private val io: Scheduler, @param:MainThread private val mainThread: Scheduler, private val bookDao: NewBookDao, - private val bookmarksDao: NewBookmarksDao, + private val libkiwixBookmarks: LibkiwixBookmarks, private val historyDao: HistoryDao, private val notesDao: NewNoteDao, private val languageDao: NewLanguagesDao, diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt index a7077be32..8b550a9ca 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/components/CoreComponent.kt @@ -29,6 +29,7 @@ import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.StorageObserver import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.dao.HistoryDao +import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.dao.NewBookmarksDao import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao @@ -95,6 +96,7 @@ interface CoreComponent { fun connectivityManager(): ConnectivityManager fun wifiManager(): WifiManager fun objectBoxToLibkiwixMigrator(): ObjectBoxToLibkiwixMigrator + fun libkiwixBookmarks(): LibkiwixBookmarks fun context(): Context fun downloader(): Downloader fun notificationManager(): NotificationManager diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/JNIModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/JNIModule.kt index ba1001d12..4bc313db1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/JNIModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/JNIModule.kt @@ -20,11 +20,16 @@ package org.kiwix.kiwixmobile.core.di.modules import android.content.Context import dagger.Module import dagger.Provides +import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks import org.kiwix.libkiwix.JNIKiwix +import org.kiwix.libkiwix.Manager import javax.inject.Singleton @Module class JNIModule { @Provides @Singleton fun providesJNIKiwix(context: Context): JNIKiwix = JNIKiwix(context) + + @Provides @Singleton + fun providesLibkiwixBookmarks(manager: Manager): LibkiwixBookmarks = LibkiwixBookmarks(manager) }