Fix starred items selection queries

This commit is contained in:
Shinokuni 2021-04-18 19:44:14 +02:00
parent 66844cfaf8
commit 1852a0bd9a
10 changed files with 50 additions and 20 deletions

View File

@ -52,6 +52,7 @@ import io.reactivex.schedulers.Schedulers;
import static com.readrops.app.utils.ReadropsKeys.ACTION_BAR_COLOR;
import static com.readrops.app.utils.ReadropsKeys.IMAGE_URL;
import static com.readrops.app.utils.ReadropsKeys.ITEM_ID;
import static com.readrops.app.utils.ReadropsKeys.STARRED_ITEM;
import static com.readrops.app.utils.ReadropsKeys.WEB_URL;
public class ItemActivity extends AppCompatActivity {
@ -81,6 +82,7 @@ public class ItemActivity extends AppCompatActivity {
Intent intent = getIntent();
int itemId = intent.getIntExtra(ITEM_ID, 0);
String imageUrl = intent.getStringExtra(IMAGE_URL);
boolean starredItem = intent.getBooleanExtra(STARRED_ITEM, false);
setSupportActionBar(binding.collapsingLayoutToolbar);
@ -117,7 +119,7 @@ public class ItemActivity extends AppCompatActivity {
}));
viewModel = ViewModelCompat.getViewModel(this, ItemViewModel.class);
viewModel.getItemById(itemId).observe(this, itemWithFeed1 -> {
viewModel.getItemById(itemId, starredItem).observe(this, itemWithFeed1 -> {
if (!uiBinded) {
bindUI(itemWithFeed1);
uiBinded = true;

View File

@ -31,8 +31,12 @@ public class ItemViewModel extends ViewModel {
this.database = database;
}
public LiveData<ItemWithFeed> getItemById(int id) {
return database.itemDao().getItemById(id);
public LiveData<ItemWithFeed> getItemById(int id, boolean starredItem) {
if (starredItem) {
return database.starredItemDao().getStarredItemById(id);
} else {
return database.itemDao().getItemById(id);
}
}
public Completable setStarState(Item item) {

View File

@ -315,4 +315,8 @@ public class DrawerManager {
public void setDrawerSelection(long identifier) {
drawer.setSelection(identifier);
}
public long getCurrentSelection() {
return drawer.getCurrentSelection();
}
}

View File

@ -73,6 +73,7 @@ import static com.readrops.app.utils.ReadropsKeys.FROM_MAIN_ACTIVITY;
import static com.readrops.app.utils.ReadropsKeys.IMAGE_URL;
import static com.readrops.app.utils.ReadropsKeys.ITEM_ID;
import static com.readrops.app.utils.ReadropsKeys.SETTINGS;
import static com.readrops.app.utils.ReadropsKeys.STARRED_ITEM;
import static com.readrops.app.utils.ReadropsKeys.SYNCING;
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener,
@ -317,6 +318,8 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
intent.putExtra(ITEM_ID, itemWithFeed.getItem().getId());
intent.putExtra(IMAGE_URL, itemWithFeed.getItem().getImageLink());
intent.putExtra(STARRED_ITEM, drawerManager.getCurrentSelection() == DrawerManager.STARS_ID &&
viewModel.getCurrentAccount().getConfig().useStarredItems());
startActivityForResult(intent, ITEM_REQUEST);
itemWithFeed.getItem().setRead(true);

View File

@ -4,9 +4,9 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.ViewModel;
import androidx.paging.DataSource;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import androidx.sqlite.db.SupportSQLiteQuery;
import com.readrops.app.repositories.ARepository;
import com.readrops.app.utils.SharedPreferencesManager;
@ -69,16 +69,15 @@ public class MainViewModel extends ViewModel {
itemsWithFeed.removeSource(lastFetch);
}
SupportSQLiteQuery query;
DataSource.Factory<Integer, ItemWithFeed> items;
if (queryFilters.getFilterType() == FilterType.STARS_FILTER && currentAccount.getAccountType().getAccountConfig().isUseStarredItems()) {
query = ItemsQueryBuilder.buildStarredItemsQuery(queryFilters);
if (queryFilters.getFilterType() == FilterType.STARS_FILTER && currentAccount.getAccountType().getAccountConfig().useStarredItems()) {
items = database.starredItemDao().selectAll(ItemsQueryBuilder.buildStarredItemsQuery(queryFilters));
} else {
query = ItemsQueryBuilder.buildItemsQuery(queryFilters);
items = database.itemDao().selectAll(ItemsQueryBuilder.buildItemsQuery(queryFilters));
}
lastFetch = new LivePagedListBuilder<>(new RoomFactoryWrapper<>(database.itemDao()
.selectAll(query)),
lastFetch = new LivePagedListBuilder<>(new RoomFactoryWrapper<>(items),
new PagedList.Config.Builder()
.setPageSize(100)
.setPrefetchDistance(150)

View File

@ -20,4 +20,6 @@ object ReadropsKeys {
const val ACTION_BAR_COLOR = "ACTION_BAR_COLOR_KEY"
const val FEEDS = "FEEDS"
const val STARRED_ITEM = "STARRED_ITEM"
}

View File

@ -1,14 +1,16 @@
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.room.RoomWarnings
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.StarredItem
import com.readrops.db.entities.UnreadItemsIds
import com.readrops.db.pojo.ItemWithFeed
@Dao
@ -17,7 +19,13 @@ interface StarredItemDao : BaseDao<StarredItem> {
@Query("Delete From StarredItem Where feed_id In (Select feed_id From Feed Where account_id = :accountId)")
fun deleteStarredItems(accountId: Int)
@RawQuery(observedEntities = [StarredItem::class, Folder::class, Feed::class])
fun selectAll(query: SupportSQLiteQuery?): DataSource.Factory<Int?, ItemWithFeed?>?
@RawQuery(observedEntities = [StarredItem::class, Folder::class, Feed::class, UnreadItemsIds::class])
fun selectAll(query: SupportSQLiteQuery?): DataSource.Factory<Int, ItemWithFeed>
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("Select StarredItem.id, title, StarredItem.description, content, link, pub_date, image_link, author, read, text_color, " +
"background_color, read_time, starred, Feed.name, Feed.id as feedId, siteUrl, Folder.id as folder_id, " +
"Folder.name as folder_name from StarredItem Inner Join Feed On StarredItem.feed_id = Feed.id Left Join Folder on Folder.id = Feed.folder_id Where StarredItem.id = :id")
fun getStarredItemById(id: Int): LiveData<ItemWithFeed>
}

View File

@ -185,6 +185,10 @@ public class Account implements Parcelable {
this.notificationsEnabled = notificationsEnabled;
}
public AccountConfig getConfig() {
return accountType.getAccountConfig();
}
@Override
public int describeContents() {
return 0;

View File

@ -9,7 +9,7 @@ public class AccountConfig {
.setUseStarredItems(false)
.build();
public static final AccountConfig NEXTNEWS = new AccountConfigBuilder()
public static final AccountConfig NEXTCLOUD_NEWS = new AccountConfigBuilder()
.setFeedUrlEditable(false)
.setFolderCreation(true)
.setNoFolderCase(false)
@ -23,13 +23,17 @@ public class AccountConfig {
.setUseStarredItems(true)
.build();
private boolean feedUrlEditable;
private final boolean feedUrlEditable;
private boolean folderCreation;
private final boolean folderCreation;
private boolean noFolderCase;
private final boolean noFolderCase;
private boolean useStarredItems;
/*
This parameter lets know if the account separates items and starred items
by using the StarredItem table
*/
private final boolean useStarredItems;
public boolean isFeedUrlEditable() {
return feedUrlEditable;
@ -43,7 +47,7 @@ public class AccountConfig {
return noFolderCase;
}
public boolean isUseStarredItems() {
public boolean useStarredItems() {
return useStarredItems;
}

View File

@ -11,7 +11,7 @@ import com.readrops.db.R;
public enum AccountType implements Parcelable {
LOCAL(R.mipmap.ic_launcher, R.string.local_account, AccountConfig.LOCAL),
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news, AccountConfig.NEXTNEWS),
NEXTCLOUD_NEWS(R.drawable.ic_nextcloud_news, R.string.nextcloud_news, AccountConfig.NEXTCLOUD_NEWS),
FEEDLY(R.drawable.ic_feedly, R.string.feedly, null),
FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss, AccountConfig.FRESHRSS);