You can now filter the item list when clicking on a feed drawer item

This commit is contained in:
Shinokuni 2019-04-04 15:13:14 +02:00
parent 1ba3f4f745
commit 37f3a33600
4 changed files with 55 additions and 14 deletions

View File

@ -61,4 +61,6 @@ dependencies {
implementation 'com.mikepenz:fastadapter:3.2.9'
implementation 'com.mikepenz:fastadapter-commons:3.2.9'
implementation "com.mikepenz:materialdrawer:6.0.9"
implementation 'org.apache.commons:commons-collections4:4.3'
}

View File

@ -6,10 +6,6 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
@ -18,7 +14,6 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
@ -30,10 +25,12 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
import com.bumptech.glide.util.ViewPreloadSizeProvider;
import com.github.clans.fab.FloatingActionMenu;
import com.mikepenz.materialdrawer.AccountHeader;
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.ExpandableBadgeDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.readrops.app.database.entities.Feed;
@ -45,10 +42,11 @@ import com.readrops.app.R;
import com.readrops.app.database.pojo.ItemWithFeed;
import com.readrops.app.database.entities.Item;
import com.readrops.app.utils.GlideApp;
import com.readrops.app.utils.ParsingResult;
import org.apache.commons.collections4.Predicate;
import org.joda.time.LocalDateTime;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
@ -75,7 +73,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
private Drawer drawer;
private FloatingActionMenu actionMenu;
private List<ItemWithFeed> newItems;
private List<ItemWithFeed> allItems;
private TreeMap<LocalDateTime, Item> itemsMap;
private MainViewModel viewModel;
@ -100,13 +98,13 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
itemsMap = new TreeMap<>(LocalDateTime::compareTo);
newItems = new ArrayList<>();
allItems = new ArrayList<>();
viewModel.getItemsWithFeed().observe(this, (itemWithFeeds -> {
newItems = itemWithFeeds;
allItems = itemWithFeeds;
if (!refreshLayout.isRefreshing())
adapter.submitList(newItems);
adapter.submitList(allItems);
}));
refreshLayout = findViewById(R.id.swipe_refresh_layout);
@ -123,6 +121,10 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
.withActivity(this)
.withToolbar(toolbar)
.withShowDrawerOnFirstLaunch(true)
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
handleDrawerClick(drawerItem);
return true;
})
.build();
drawerManager = new DrawerManager(drawer);
@ -130,6 +132,32 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
updateDrawerFeeds();
}
private void handleDrawerClick(IDrawerItem drawerItem) {
drawer.closeDrawer();
if (drawerItem instanceof PrimaryDrawerItem) {
int id = (int)drawerItem.getIdentifier();
switch (id) {
case DrawerManager.ARTICLES_ITEM_ID:
adapter.submitList(allItems);
break;
case DrawerManager.READ_LATER_ID:
break;
}
} else if (drawerItem instanceof SecondaryDrawerItem) {
filterItems((int)drawerItem.getIdentifier());
}
}
private void filterItems(int id) {
List<ItemWithFeed> filteredItems = new ArrayList<>(allItems);
CollectionUtils.filter(filteredItems, object -> object.getFeedId() == id);
adapter.submitList(filteredItems);
}
private void updateDrawerFeeds() {
viewModel.getFoldersWithFeeds()
.subscribeOn(Schedulers.io())
@ -317,7 +345,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
syncProgressLayout.setVisibility(View.GONE);
refreshLayout.setRefreshing(false);
adapter.submitList(newItems);
adapter.submitList(allItems);
}
});
}

View File

@ -20,7 +20,7 @@ public interface ItemDao {
@Query("Select * from Item Order By pub_date DESC")
LiveData<List<Item>> getAll();
@Query("Select Item.id, title, clean_description, image_link, pub_date, Feed.name, text_color, background_color, icon_url, read_time, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Folder.id = Feed.folder_id Order By Item.id DESC")
@Query("Select Item.id, title, clean_description, image_link, pub_date, Feed.name, text_color, background_color, icon_url, read_time, Feed.id as feedId, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Folder.id = Feed.folder_id Order By Item.id DESC")
LiveData<List<ItemWithFeed>> getAllItemWithFeeds();
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
@ -32,6 +32,6 @@ public interface ItemDao {
@Insert
void insertAll(List<Item> items);
@Query("Select title, Item.description, content, link, pub_date, image_link, author, text_color, background_color, read_time, Feed.name, siteUrl, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Item.id = :id And Folder.id = Feed.folder_id")
@Query("Select title, Item.description, content, link, pub_date, image_link, author, text_color, background_color, read_time, Feed.name, Feed.id as feedId, siteUrl, Folder.id as folder_id, Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Item.id = :id And Folder.id = Feed.folder_id")
LiveData<ItemWithFeed> getItemById(int id);
}

View File

@ -15,6 +15,9 @@ public class ItemWithFeed {
@ColumnInfo(name = "name")
private String feedName;
@ColumnInfo(name = "feedId")
private int feedId;
@ColumnInfo(name = "text_color")
private @ColorInt int color;
@ -46,6 +49,14 @@ public class ItemWithFeed {
this.feedName = feedName;
}
public int getFeedId() {
return feedId;
}
public void setFeedId(int feedId) {
this.feedId = feedId;
}
public @ColorInt int getColor() {
return color;
}