Add account support for other queries

This commit is contained in:
Shinokuni 2019-06-23 22:17:30 +02:00
parent d35db1dd57
commit 59a0a81672
6 changed files with 26 additions and 26 deletions

View File

@ -225,7 +225,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
@Override
public void onError(Throwable e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}

View File

@ -26,14 +26,14 @@ public interface FeedDao {
@Query("Delete From Feed Where id = :feedId")
void delete(int feedId);
@Query("Select case When :feedUrl In (Select url from Feed) Then 'true' else 'false' end")
String feedExists(String feedUrl);
@Query("Select case When :feedUrl In (Select url from Feed Where account_id = :accountId) Then 1 else 0 end")
boolean feedExists(String feedUrl, int accountId);
@Query("Select case When :remoteId In (Select remoteId from Feed) And :accountId In (Select account_id From Feed) Then 1 else 0 end")
@Query("Select case When :remoteId In (Select remoteId from Feed Where account_id = :accountId) Then 1 else 0 end")
boolean remoteFeedExists(int remoteId, int accountId);
@Query("Select count(*) from Feed")
int getFeedCount();
@Query("Select count(*) from Feed Where account_id = :accountId")
int getFeedCount(int accountId);
@Query("Select * from Feed Where url = :feedUrl")
Feed getFeedByUrl(String feedUrl);
@ -44,6 +44,9 @@ public interface FeedDao {
@Query("Select * from Feed Where folder_id = :folderId")
List<Feed> getFeedsByFolder(int folderId);
@Query("Select * from Feed Where account_id = :accountId And folder_id is null")
List<Feed> getFeedsWithoutFolder(int accountId);
@Query("Update Feed set etag = :etag, last_modified = :lastModified Where id = :feedId")
void updateHeaders(String etag, String lastModified, int feedId);

View File

@ -63,10 +63,8 @@ public abstract class ARepository {
}
public Single<Integer> getFeedCount() {
return Single.create(emitter -> {
emitter.onSuccess(database.feedDao().getFeedCount());
});
public Single<Integer> getFeedCount(int accountId) {
return Single.create(emitter -> emitter.onSuccess(database.feedDao().getFeedCount(accountId)));
}
protected void setFavIconUtils(Feed feed) throws IOException {

View File

@ -2,27 +2,26 @@ package com.readrops.app.repositories;
import android.accounts.NetworkErrorException;
import android.app.Application;
import androidx.paging.PageKeyedDataSource;
import androidx.annotation.Nullable;
import com.readrops.app.database.entities.Account;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.database.pojo.ItemWithFeed;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.database.entities.Item;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.utils.FeedInsertionResult;
import com.readrops.app.utils.Utils;
import com.readrops.app.utils.HtmlParser;
import com.readrops.app.utils.ParsingResult;
import com.readrops.readropslibrary.utils.LibUtils;
import com.readrops.readropslibrary.utils.UnknownFormatException;
import com.readrops.app.utils.Utils;
import com.readrops.readropslibrary.localfeed.AFeed;
import com.readrops.readropslibrary.localfeed.RSSQuery;
import com.readrops.readropslibrary.localfeed.RSSQueryResult;
import com.readrops.readropslibrary.localfeed.atom.ATOMFeed;
import com.readrops.readropslibrary.localfeed.json.JSONFeed;
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
import com.readrops.readropslibrary.utils.LibUtils;
import com.readrops.readropslibrary.utils.UnknownFormatException;
import org.jsoup.Jsoup;
@ -42,8 +41,6 @@ public class LocalFeedRepository extends ARepository {
private static final String TAG = LocalFeedRepository.class.getSimpleName();
private PageKeyedDataSource.Factory<Integer, ItemWithFeed> itemsWhithFeed;
public LocalFeedRepository(Application application) {
super(application);
@ -60,7 +57,7 @@ public class LocalFeedRepository extends ARepository {
List<Feed> feedList;
if (feeds == null || feeds.size() == 0)
feedList = database.feedDao().getAllFeeds();
feedList = database.feedDao().getAllFeeds(account.getId());
else
feedList = new ArrayList<>(feeds);
@ -211,7 +208,7 @@ public class LocalFeedRepository extends ARepository {
break;
}
if (Boolean.valueOf(database.feedDao().feedExists(dbFeed.getUrl())))
if (database.feedDao().feedExists(dbFeed.getUrl(), account.getId()))
return null; // feed already inserted
setFavIconUtils(dbFeed);
@ -229,7 +226,7 @@ public class LocalFeedRepository extends ARepository {
List<Item> itemsToInsert = new ArrayList<>();
for (Item dbItem : items) {
if (!Boolean.valueOf(database.itemDao().guidExist(dbItem.getGuid()))) {
if (!database.itemDao().itemExists(dbItem.getGuid(), feed.getAccountId())) {
if (dbItem.getDescription() != null) {
dbItem.setCleanDescription(Jsoup.parse(dbItem.getDescription()).text());

View File

@ -81,7 +81,7 @@ public class DrawerManager {
List<SecondaryDrawerItem> feedsWithoutFolder = new ArrayList<>();
for (Folder folder : folderListMap.keySet()) {
if (folder.getId() != 1) {
if (folder.getId() != 0) {
ExpandableBadgeDrawerItem badgeDrawerItem = new ExpandableBadgeDrawerItem()
.withName(folder.getName())
.withIdentifier(folder.getId())
@ -106,8 +106,6 @@ public class DrawerManager {
}
} else { // no folder case, items to add after the folders
for (Feed feed : folderListMap.get(folder)) {
int color = feed.getTextColor();
SecondaryDrawerItem primaryDrawerItem = createSecondaryItem(feed);
feedsWithoutFolder.add(primaryDrawerItem);

View File

@ -127,7 +127,7 @@ public class MainViewModel extends AndroidViewModel {
}
public Single<Integer> getFeedCount() {
return repository.getFeedCount();
return repository.getFeedCount(currentAccount.getId());
}
public Single<Map<Folder, List<Feed>>> getFoldersWithFeeds() {
@ -146,6 +146,10 @@ public class MainViewModel extends AndroidViewModel {
foldersWithFeeds.put(folder, feeds);
}
Folder noFolder = new Folder("no folder");
noFolder.setId(0);
foldersWithFeeds.put(noFolder, db.feedDao().getFeedsWithoutFolder(currentAccount.getId()));
emitter.onSuccess(foldersWithFeeds);
});
}