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

View File

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

View File

@ -315,4 +315,8 @@ public class DrawerManager {
public void setDrawerSelection(long identifier) { public void setDrawerSelection(long identifier) {
drawer.setSelection(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.IMAGE_URL;
import static com.readrops.app.utils.ReadropsKeys.ITEM_ID; import static com.readrops.app.utils.ReadropsKeys.ITEM_ID;
import static com.readrops.app.utils.ReadropsKeys.SETTINGS; 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; import static com.readrops.app.utils.ReadropsKeys.SYNCING;
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, 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(ITEM_ID, itemWithFeed.getItem().getId());
intent.putExtra(IMAGE_URL, itemWithFeed.getItem().getImageLink()); intent.putExtra(IMAGE_URL, itemWithFeed.getItem().getImageLink());
intent.putExtra(STARRED_ITEM, drawerManager.getCurrentSelection() == DrawerManager.STARS_ID &&
viewModel.getCurrentAccount().getConfig().useStarredItems());
startActivityForResult(intent, ITEM_REQUEST); startActivityForResult(intent, ITEM_REQUEST);
itemWithFeed.getItem().setRead(true); itemWithFeed.getItem().setRead(true);

View File

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

View File

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

View File

@ -1,14 +1,16 @@
package com.readrops.db.dao package com.readrops.db.dao
import androidx.lifecycle.LiveData
import androidx.paging.DataSource import androidx.paging.DataSource
import androidx.room.Dao import androidx.room.Dao
import androidx.room.Query import androidx.room.Query
import androidx.room.RawQuery import androidx.room.RawQuery
import androidx.room.RoomWarnings
import androidx.sqlite.db.SupportSQLiteQuery import androidx.sqlite.db.SupportSQLiteQuery
import com.readrops.db.entities.Feed import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder import com.readrops.db.entities.Folder
import com.readrops.db.entities.Item
import com.readrops.db.entities.StarredItem import com.readrops.db.entities.StarredItem
import com.readrops.db.entities.UnreadItemsIds
import com.readrops.db.pojo.ItemWithFeed import com.readrops.db.pojo.ItemWithFeed
@Dao @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)") @Query("Delete From StarredItem Where feed_id In (Select feed_id From Feed Where account_id = :accountId)")
fun deleteStarredItems(accountId: Int) fun deleteStarredItems(accountId: Int)
@RawQuery(observedEntities = [StarredItem::class, Folder::class, Feed::class]) @RawQuery(observedEntities = [StarredItem::class, Folder::class, Feed::class, UnreadItemsIds::class])
fun selectAll(query: SupportSQLiteQuery?): DataSource.Factory<Int?, ItemWithFeed?>? 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; this.notificationsEnabled = notificationsEnabled;
} }
public AccountConfig getConfig() {
return accountType.getAccountConfig();
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -9,7 +9,7 @@ public class AccountConfig {
.setUseStarredItems(false) .setUseStarredItems(false)
.build(); .build();
public static final AccountConfig NEXTNEWS = new AccountConfigBuilder() public static final AccountConfig NEXTCLOUD_NEWS = new AccountConfigBuilder()
.setFeedUrlEditable(false) .setFeedUrlEditable(false)
.setFolderCreation(true) .setFolderCreation(true)
.setNoFolderCase(false) .setNoFolderCase(false)
@ -23,13 +23,17 @@ public class AccountConfig {
.setUseStarredItems(true) .setUseStarredItems(true)
.build(); .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() { public boolean isFeedUrlEditable() {
return feedUrlEditable; return feedUrlEditable;
@ -43,7 +47,7 @@ public class AccountConfig {
return noFolderCase; return noFolderCase;
} }
public boolean isUseStarredItems() { public boolean useStarredItems() {
return useStarredItems; return useStarredItems;
} }

View File

@ -11,7 +11,7 @@ import com.readrops.db.R;
public enum AccountType implements Parcelable { public enum AccountType implements Parcelable {
LOCAL(R.mipmap.ic_launcher, R.string.local_account, AccountConfig.LOCAL), 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), FEEDLY(R.drawable.ic_feedly, R.string.feedly, null),
FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss, AccountConfig.FRESHRSS); FRESHRSS(R.drawable.ic_freshrss, R.string.freshrss, AccountConfig.FRESHRSS);