Migrate AccountDao and ItemDao to kotlin

This commit is contained in:
Shinokuni 2021-09-01 22:58:16 +02:00
parent 07e586a989
commit 2f82efe4cb
5 changed files with 104 additions and 113 deletions

View File

@ -80,7 +80,7 @@ class SyncResultAnalyser(val context: Context, private val syncResults: Map<Acco
}
if (items.size == 1) {
val item = database.itemDao().selectByRemoteId(items.first().remoteId,
val item = database.itemDao().selectByRemoteId(items.first().remoteId!!,
items.first().feedId)
notifContent.content = item.title
notifContent.item = item

View File

@ -1,46 +0,0 @@
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 java.util.List;
import io.reactivex.Completable;
import io.reactivex.Single;
@Dao
public interface AccountDao extends BaseDao<Account> {
@Query("Select * from Account")
LiveData<List<Account>> selectAllAsync();
@Query("Select * From Account Where id = :accountId")
LiveData<Account> selectAsync(int accountId);
@Query("Select * from Account")
List<Account> 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<Integer> 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);
}

View File

@ -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<Account> {
@Query("Select * from Account")
fun selectAllAsync(): LiveData<List<Account>>
@Query("Select * From Account Where id = :accountId")
fun selectAsync(accountId: Int): LiveData<Account>
@Query("Select * from Account")
fun selectAll(): List<Account>
@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<Int>
@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
}

View File

@ -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<Item> {
@RawQuery(observedEntities = {Item.class, Folder.class, Feed.class, ItemState.class})
DataSource.Factory<Integer, ItemWithFeed> 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<ItemWithFeed> 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<StarItem> getStarChanges(List<String> remoteIds, int accountId);
@Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId")
void setReadAndStarState(String remoteId, boolean read, boolean starred);
}

View File

@ -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<Item> {
@RawQuery(observedEntities = [Item::class, Folder::class, Feed::class, ItemState::class])
fun selectAll(query: SupportSQLiteQuery): DataSource.Factory<Int?, ItemWithFeed>
@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<ItemWithFeed>
@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<String>, accountId: Int): List<StarItem>
@Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId")
fun setReadAndStarState(remoteId: String, read: Boolean, starred: Boolean)
}