diff --git a/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt b/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt index 5975c6cf..cf6c24eb 100644 --- a/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt +++ b/app/src/main/java/com/readrops/app/notifications/sync/SyncResultAnalyser.kt @@ -80,7 +80,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map { - - @Query("Select * from Account") - LiveData> selectAllAsync(); - - @Query("Select * From Account Where id = :accountId") - LiveData selectAsync(int accountId); - - @Query("Select * from Account") - List selectAll(); - - @Query("Select * From Account Where id = :accountId") - Account select(int accountId); - - @Query("Update Account set last_modified = :lastModified Where id = :accountId") - void updateLastModified(int accountId, long lastModified); - - @Query("Update Account set current_account = 0 Where id Not In (:accountId)") - void deselectOldCurrentAccount(int accountId); - - @Query("Update Account set current_account = 1 Where id = :accountId") - void setCurrentAccount(int accountId); - - @Query("Select count(*) From Account") - Single getAccountCount(); - - @Query("Update Account set writeToken = :writeToken Where id = :accountId") - void updateWriteToken(int accountId, String writeToken); - - @Query("Update Account set notifications_enabled = :enabled Where id = :accountId") - Completable updateNotificationState(int accountId, boolean enabled); -} diff --git a/db/src/main/java/com/readrops/db/dao/AccountDao.kt b/db/src/main/java/com/readrops/db/dao/AccountDao.kt new file mode 100644 index 00000000..e13f5662 --- /dev/null +++ b/db/src/main/java/com/readrops/db/dao/AccountDao.kt @@ -0,0 +1,42 @@ +package com.readrops.db.dao + +import androidx.lifecycle.LiveData +import androidx.room.Dao +import androidx.room.Query +import com.readrops.db.entities.account.Account +import io.reactivex.Completable +import io.reactivex.Single + +@Dao +interface AccountDao : BaseDao { + + @Query("Select * from Account") + fun selectAllAsync(): LiveData> + + @Query("Select * From Account Where id = :accountId") + fun selectAsync(accountId: Int): LiveData + + @Query("Select * from Account") + fun selectAll(): List + + @Query("Select * From Account Where id = :accountId") + fun select(accountId: Int): Account + + @Query("Update Account set last_modified = :lastModified Where id = :accountId") + fun updateLastModified(accountId: Int, lastModified: Long) + + @Query("Update Account set current_account = 0 Where id Not In (:accountId)") + fun deselectOldCurrentAccount(accountId: Int) + + @Query("Update Account set current_account = 1 Where id = :accountId") + fun setCurrentAccount(accountId: Int) + + @get:Query("Select count(*) From Account") + val accountCount: Single + + @Query("Update Account set writeToken = :writeToken Where id = :accountId") + fun updateWriteToken(accountId: Int, writeToken: String) + + @Query("Update Account set notifications_enabled = :enabled Where id = :accountId") + fun updateNotificationState(accountId: Int, enabled: Boolean): Completable +} \ No newline at end of file diff --git a/db/src/main/java/com/readrops/db/dao/ItemDao.java b/db/src/main/java/com/readrops/db/dao/ItemDao.java deleted file mode 100644 index 30f368c0..00000000 --- a/db/src/main/java/com/readrops/db/dao/ItemDao.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.readrops.db.dao; - - -import androidx.lifecycle.LiveData; -import androidx.paging.DataSource; -import androidx.room.Dao; -import androidx.room.Query; -import androidx.room.RawQuery; -import androidx.sqlite.db.SupportSQLiteQuery; - -import com.readrops.db.entities.Feed; -import com.readrops.db.entities.Folder; -import com.readrops.db.entities.Item; -import com.readrops.db.entities.ItemState; -import com.readrops.db.pojo.ItemWithFeed; -import com.readrops.db.pojo.StarItem; - -import java.util.List; - -import io.reactivex.Completable; - -@Dao -public interface ItemDao extends BaseDao { - - @RawQuery(observedEntities = {Item.class, Folder.class, Feed.class, ItemState.class}) - DataSource.Factory selectAll(SupportSQLiteQuery query); - - @Query("Select * From Item Where id = :itemId") - Item select(int itemId); - - @Query("Select case When :guid In (Select guid From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end") - boolean itemExists(String guid, int accountId); - - @Query("Select case When :remoteId In (Select remoteId from Item) And :feedId In (Select feed_id From Item) Then 1 else 0 end") - boolean remoteItemExists(String remoteId, int feedId); - - @Query("Select * From Item Where remoteId = :remoteId And feed_id = :feedId") - Item selectByRemoteId(String remoteId, int feedId); - - @Query("Update Item Set read = :read Where id = :itemId") - Completable setReadState(int itemId, boolean read); - - @Query("Update Item set starred = :starred Where id = :itemId") - Completable setStarState(int itemId, boolean starred); - - @Query("Update Item set read = :readState Where feed_id In (Select id From Feed Where account_id = :accountId)") - Completable setAllItemsReadState(int readState, int accountId); - - @Query("Update Item set read = :readState Where feed_id = :feedId") - Completable setAllFeedItemsReadState(int feedId, int readState); - - @Query("Update Item set read_it_later = :readLater Where id = :itemId") - Completable setReadItLater(boolean readLater, int itemId); - - @Query("Select count(*) From Item Where feed_id = :feedId And read = 0") - int getUnreadCount(int feedId); - - @RawQuery(observedEntities = {Item.class, ItemState.class}) - LiveData getItemById(SupportSQLiteQuery query); - - @Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId In (:remoteIds) And account_id = :accountId") - List getStarChanges(List remoteIds, int accountId); - - @Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId") - void setReadAndStarState(String remoteId, boolean read, boolean starred); -} diff --git a/db/src/main/java/com/readrops/db/dao/ItemDao.kt b/db/src/main/java/com/readrops/db/dao/ItemDao.kt new file mode 100644 index 00000000..5cd7ce0d --- /dev/null +++ b/db/src/main/java/com/readrops/db/dao/ItemDao.kt @@ -0,0 +1,61 @@ +package com.readrops.db.dao + +import androidx.lifecycle.LiveData +import androidx.paging.DataSource +import androidx.room.Dao +import androidx.room.Query +import androidx.room.RawQuery +import androidx.sqlite.db.SupportSQLiteQuery +import com.readrops.db.entities.Feed +import com.readrops.db.entities.Folder +import com.readrops.db.entities.Item +import com.readrops.db.entities.ItemState +import com.readrops.db.pojo.ItemWithFeed +import com.readrops.db.pojo.StarItem +import io.reactivex.Completable + +@Dao +interface ItemDao : BaseDao { + + @RawQuery(observedEntities = [Item::class, Folder::class, Feed::class, ItemState::class]) + fun selectAll(query: SupportSQLiteQuery): DataSource.Factory + + @Query("Select * From Item Where id = :itemId") + fun select(itemId: Int): Item + + @Query("Select case When :guid In (Select guid From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end") + fun itemExists(guid: String, accountId: Int): Boolean + + @Query("Select case When :remoteId In (Select remoteId from Item) And :feedId In (Select feed_id From Item) Then 1 else 0 end") + fun remoteItemExists(remoteId: String, feedId: Int): Boolean + + @Query("Select * From Item Where remoteId = :remoteId And feed_id = :feedId") + fun selectByRemoteId(remoteId: String, feedId: Int): Item + + @Query("Update Item Set read = :read Where id = :itemId") + fun setReadState(itemId: Int, read: Boolean): Completable + + @Query("Update Item set starred = :starred Where id = :itemId") + fun setStarState(itemId: Int, starred: Boolean): Completable + + @Query("Update Item set read = :readState Where feed_id In (Select id From Feed Where account_id = :accountId)") + fun setAllItemsReadState(readState: Int, accountId: Int): Completable + + @Query("Update Item set read = :readState Where feed_id = :feedId") + fun setAllFeedItemsReadState(feedId: Int, readState: Int): Completable + + @Query("Update Item set read_it_later = :readLater Where id = :itemId") + fun setReadItLater(readLater: Boolean, itemId: Int): Completable + + @Query("Select count(*) From Item Where feed_id = :feedId And read = 0") + fun getUnreadCount(feedId: Int): Int + + @RawQuery(observedEntities = [Item::class, ItemState::class]) + fun getItemById(query: SupportSQLiteQuery): LiveData + + @Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId In (:remoteIds) And account_id = :accountId") + fun getStarChanges(remoteIds: List, accountId: Int): List + + @Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId") + fun setReadAndStarState(remoteId: String, read: Boolean, starred: Boolean) +} \ No newline at end of file