mirror of https://github.com/readrops/Readrops.git
Replace standard navigation drawer by mike penz material drawer
This commit is contained in:
parent
75a65730f7
commit
252c661858
|
@ -60,4 +60,5 @@ dependencies {
|
||||||
// fastadapter requires androidx after 3.2.9
|
// fastadapter requires androidx after 3.2.9
|
||||||
implementation 'com.mikepenz:fastadapter:3.2.9'
|
implementation 'com.mikepenz:fastadapter:3.2.9'
|
||||||
implementation 'com.mikepenz:fastadapter-commons:3.2.9'
|
implementation 'com.mikepenz:fastadapter-commons:3.2.9'
|
||||||
|
implementation "com.mikepenz:materialdrawer:6.0.9"
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,14 @@ import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
|
import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader;
|
||||||
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
import com.bumptech.glide.util.ViewPreloadSizeProvider;
|
||||||
import com.github.clans.fab.FloatingActionMenu;
|
import com.github.clans.fab.FloatingActionMenu;
|
||||||
|
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.SecondaryDrawerItem;
|
||||||
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||||
import com.readrops.app.database.entities.Feed;
|
import com.readrops.app.database.entities.Feed;
|
||||||
|
import com.readrops.app.database.entities.Folder;
|
||||||
import com.readrops.app.views.MainItemListAdapter;
|
import com.readrops.app.views.MainItemListAdapter;
|
||||||
import com.readrops.app.viewmodels.MainViewModel;
|
import com.readrops.app.viewmodels.MainViewModel;
|
||||||
import com.readrops.app.R;
|
import com.readrops.app.R;
|
||||||
|
@ -43,6 +50,7 @@ import com.readrops.app.utils.ParsingResult;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
@ -50,19 +58,20 @@ import io.reactivex.Observer;
|
||||||
import io.reactivex.SingleObserver;
|
import io.reactivex.SingleObserver;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.observers.DisposableSingleObserver;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
|
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
|
||||||
|
|
||||||
public static final String TAG = MainActivity.class.getSimpleName();
|
public static final String TAG = MainActivity.class.getSimpleName();
|
||||||
public static final int ADD_FEED_REQUEST = 1;
|
public static final int ADD_FEED_REQUEST = 1;
|
||||||
|
public static final int MANAGE_FEEDS_REQUEST = 2;
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private MainItemListAdapter adapter;
|
private MainItemListAdapter adapter;
|
||||||
private SwipeRefreshLayout refreshLayout;
|
private SwipeRefreshLayout refreshLayout;
|
||||||
|
|
||||||
private NavigationView navigationView;
|
private Drawer drawer;
|
||||||
private DrawerLayout drawerLayout;
|
|
||||||
private FloatingActionMenu actionMenu;
|
private FloatingActionMenu actionMenu;
|
||||||
|
|
||||||
private List<ItemWithFeed> newItems;
|
private List<ItemWithFeed> newItems;
|
||||||
|
@ -85,28 +94,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar_main);
|
Toolbar toolbar = findViewById(R.id.toolbar_main);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_nav_drawer, R.string.close_nav_drawer);
|
|
||||||
drawerLayout.addDrawerListener(toggle);
|
|
||||||
toggle.syncState();
|
|
||||||
|
|
||||||
actionMenu = findViewById(R.id.fab_menu);
|
actionMenu = findViewById(R.id.fab_menu);
|
||||||
|
|
||||||
navigationView = findViewById(R.id.nav_view);
|
|
||||||
navigationView.setNavigationItemSelectedListener((menuItem) -> {
|
|
||||||
menuItem.setChecked(true);
|
|
||||||
drawerLayout.closeDrawers();
|
|
||||||
|
|
||||||
switch (menuItem.getItemId()) {
|
|
||||||
case R.id.to_read:
|
|
||||||
break;
|
|
||||||
case R.id.non_read_articles:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
|
viewModel = ViewModelProviders.of(this).get(MainViewModel.class);
|
||||||
|
|
||||||
itemsMap = new TreeMap<>(LocalDateTime::compareTo);
|
itemsMap = new TreeMap<>(LocalDateTime::compareTo);
|
||||||
|
@ -127,25 +115,80 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
syncProgressBar = findViewById(R.id.sync_progress_bar);
|
syncProgressBar = findViewById(R.id.sync_progress_bar);
|
||||||
|
|
||||||
feedCount = 0;
|
feedCount = 0;
|
||||||
|
|
||||||
initRecyclerView();
|
initRecyclerView();
|
||||||
|
|
||||||
|
drawer = new DrawerBuilder()
|
||||||
|
.withActivity(this)
|
||||||
|
.withToolbar(toolbar)
|
||||||
|
.withShowDrawerOnFirstLaunch(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
updateDrawerFeeds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDrawerFeeds() {
|
||||||
|
viewModel.getFoldersWithFeeds()
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new DisposableSingleObserver<HashMap<Folder, List<Feed>>>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(HashMap<Folder, List<Feed>> folderListHashMap) {
|
||||||
|
populateDrawer(folderListHashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public void onError(Throwable e) {
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
}
|
||||||
drawerLayout.openDrawer(GravityCompat.START);
|
});
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
private void populateDrawer(HashMap<Folder, List<Feed>> folderListHashMap) {
|
||||||
|
drawer.removeAllItems();
|
||||||
|
List<SecondaryDrawerItem> feedsWithoutFolder = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Folder folder : folderListHashMap.keySet()) {
|
||||||
|
if (folder.getId() != 1) {
|
||||||
|
ExpandableBadgeDrawerItem badgeDrawerItem = new ExpandableBadgeDrawerItem()
|
||||||
|
.withName(folder.getName())
|
||||||
|
.withIdentifier(folder.getId())
|
||||||
|
.withIcon(getDrawable(R.drawable.ic_folder_grey));
|
||||||
|
|
||||||
|
List<IDrawerItem> secondaryDrawerItems = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Feed feed : folderListHashMap.get(folder)) {
|
||||||
|
SecondaryDrawerItem secondaryDrawerItem = new SecondaryDrawerItem()
|
||||||
|
.withName(feed.getName())
|
||||||
|
.withIdentifier(feed.getId());
|
||||||
|
|
||||||
|
secondaryDrawerItems.add(secondaryDrawerItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondaryDrawerItems.size() > 0) {
|
||||||
|
badgeDrawerItem.withSubItems(secondaryDrawerItems);
|
||||||
|
drawer.addItem(badgeDrawerItem);
|
||||||
|
}
|
||||||
|
} else { // no folder case
|
||||||
|
for (Feed feed : folderListHashMap.get(folder)) {
|
||||||
|
SecondaryDrawerItem primaryDrawerItem = new SecondaryDrawerItem()
|
||||||
|
.withName(feed.getName())
|
||||||
|
.withIdentifier(feed.getId());
|
||||||
|
|
||||||
|
feedsWithoutFolder.add(primaryDrawerItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// work-around as MaterialDrawer doesn't accept an item list
|
||||||
|
for (SecondaryDrawerItem primaryDrawerItem : feedsWithoutFolder) {
|
||||||
|
drawer.addItem(primaryDrawerItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (drawerLayout.isDrawerOpen(GravityCompat.START))
|
if (drawer.isDrawerOpen())
|
||||||
drawerLayout.closeDrawers();
|
drawer.closeDrawer();
|
||||||
else
|
else
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
@ -242,7 +285,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayAddFeedDialog(View view) {
|
public void openAddFeedActivity(View view) {
|
||||||
actionMenu.close(true);
|
actionMenu.close(true);
|
||||||
|
|
||||||
Intent intent = new Intent(this, AddFeedActivity.class);
|
Intent intent = new Intent(this, AddFeedActivity.class);
|
||||||
|
@ -253,12 +296,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
actionMenu.close(true);
|
actionMenu.close(true);
|
||||||
|
|
||||||
Intent intent = new Intent(this, ManageFeedsActivity.class);
|
Intent intent = new Intent(this, ManageFeedsActivity.class);
|
||||||
startActivity(intent);
|
startActivityForResult(intent, MANAGE_FEEDS_REQUEST);
|
||||||
}
|
|
||||||
|
|
||||||
public void insertNewFeed(ParsingResult result) {
|
|
||||||
refreshLayout.setRefreshing(true);
|
|
||||||
viewModel.addFeed(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -271,6 +309,8 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
||||||
feedNb = feeds.size();
|
feedNb = feeds.size();
|
||||||
sync(feeds);
|
sync(feeds);
|
||||||
}
|
}
|
||||||
|
} else if (requestCode == MANAGE_FEEDS_REQUEST) {
|
||||||
|
updateDrawerFeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
|
@ -36,6 +36,9 @@ public interface FeedDao {
|
||||||
@Query("Select * from Feed Where url = :feedUrl")
|
@Query("Select * from Feed Where url = :feedUrl")
|
||||||
Feed getFeedByUrl(String feedUrl);
|
Feed getFeedByUrl(String feedUrl);
|
||||||
|
|
||||||
|
@Query("Select * from Feed Where folder_id = :folderId")
|
||||||
|
List<Feed> getFeedsByFolder(int folderId);
|
||||||
|
|
||||||
@Query("Update Feed set etag = :etag, last_modified = :lastModified Where id = :feedId")
|
@Query("Update Feed set etag = :etag, last_modified = :lastModified Where id = :feedId")
|
||||||
void updateHeaders(String etag, String lastModified, int feedId);
|
void updateHeaders(String etag, String lastModified, int feedId);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@ public interface FolderDao {
|
||||||
@Query("Select * from Folder Order By name ASC")
|
@Query("Select * from Folder Order By name ASC")
|
||||||
LiveData<List<Folder>> getAllFolders();
|
LiveData<List<Folder>> getAllFolders();
|
||||||
|
|
||||||
|
@Query("Select * from Folder Order By name ASC")
|
||||||
|
List<Folder> getFolders();
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
long insert(Folder folder);
|
long insert(Folder folder);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.readrops.app.repositories;
|
||||||
import android.accounts.NetworkErrorException;
|
import android.accounts.NetworkErrorException;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.arch.lifecycle.LiveData;
|
import android.arch.lifecycle.LiveData;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.readrops.app.database.entities.Folder;
|
import com.readrops.app.database.entities.Folder;
|
||||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||||
|
@ -53,7 +54,7 @@ public class LocalFeedRepository extends ARepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Observable<Feed> sync(List<Feed> feeds) {
|
public Observable<Feed> sync(@Nullable List<Feed> feeds) {
|
||||||
return Observable.create(emitter -> {
|
return Observable.create(emitter -> {
|
||||||
List<Feed> feedList;
|
List<Feed> feedList;
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,14 @@ import android.arch.lifecycle.AndroidViewModel;
|
||||||
import android.arch.lifecycle.LiveData;
|
import android.arch.lifecycle.LiveData;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.readrops.app.database.Database;
|
||||||
import com.readrops.app.database.entities.Feed;
|
import com.readrops.app.database.entities.Feed;
|
||||||
|
import com.readrops.app.database.entities.Folder;
|
||||||
import com.readrops.app.database.pojo.ItemWithFeed;
|
import com.readrops.app.database.pojo.ItemWithFeed;
|
||||||
import com.readrops.app.repositories.LocalFeedRepository;
|
import com.readrops.app.repositories.LocalFeedRepository;
|
||||||
import com.readrops.app.utils.ParsingResult;
|
import com.readrops.app.utils.ParsingResult;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
@ -19,13 +22,14 @@ public class MainViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private LiveData<List<ItemWithFeed>> itemsWithFeed;
|
private LiveData<List<ItemWithFeed>> itemsWithFeed;
|
||||||
private LocalFeedRepository repository;
|
private LocalFeedRepository repository;
|
||||||
|
private Database db;
|
||||||
|
|
||||||
public MainViewModel(@NonNull Application application) {
|
public MainViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
||||||
repository = new LocalFeedRepository(application);
|
repository = new LocalFeedRepository(application);
|
||||||
|
|
||||||
itemsWithFeed = repository.getItemsWithFeed();
|
itemsWithFeed = repository.getItemsWithFeed();
|
||||||
|
db = Database.getInstance(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<ItemWithFeed>> getItemsWithFeed() {
|
public LiveData<List<ItemWithFeed>> getItemsWithFeed() {
|
||||||
|
@ -43,4 +47,18 @@ public class MainViewModel extends AndroidViewModel {
|
||||||
public Single<Integer> getFeedCount() {
|
public Single<Integer> getFeedCount() {
|
||||||
return repository.getFeedCount();
|
return repository.getFeedCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Single<HashMap<Folder, List<Feed>>> getFoldersWithFeeds() {
|
||||||
|
return Single.create(emitter -> {
|
||||||
|
List<Folder> folders = db.folderDao().getFolders();
|
||||||
|
HashMap<Folder, List<Feed>> foldersWithFeeds = new HashMap<>();
|
||||||
|
|
||||||
|
for (Folder folder : folders) {
|
||||||
|
List<Feed> feeds = db.feedDao().getFeedsByFolder(folder.getId());
|
||||||
|
foldersWithFeeds.put(folder, feeds);
|
||||||
|
}
|
||||||
|
|
||||||
|
emitter.onSuccess(foldersWithFeeds);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/drawer_layout"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".activities.MainActivity">
|
tools:context=".activities.MainActivity">
|
||||||
|
@ -13,11 +12,6 @@
|
||||||
android:animateLayoutChanges="true"
|
android:animateLayoutChanges="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.design.widget.AppBarLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
|
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar_main"
|
android:id="@+id/toolbar_main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -25,7 +19,6 @@
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/sync_progress_layout"
|
android:id="@+id/sync_progress_layout"
|
||||||
|
@ -102,7 +95,7 @@
|
||||||
android:id="@+id/add_feed_fab"
|
android:id="@+id/add_feed_fab"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:onClick="displayAddFeedDialog"
|
android:onClick="openAddFeedActivity"
|
||||||
android:src="@drawable/ic_insert_link_white"
|
android:src="@drawable/ic_insert_link_white"
|
||||||
app:fab_colorNormal="@color/colorPrimary"
|
app:fab_colorNormal="@color/colorPrimary"
|
||||||
app:fab_label="@string/add_feed_item"
|
app:fab_label="@string/add_feed_item"
|
||||||
|
@ -122,14 +115,4 @@
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
||||||
<android.support.design.widget.NavigationView
|
|
||||||
android:id="@+id/nav_view"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_gravity="start"
|
|
||||||
android:fitsSystemWindows="true"
|
|
||||||
app:headerLayout="@layout/nav_header"
|
|
||||||
app:menu="@menu/drawer_view" />
|
|
||||||
|
|
||||||
</android.support.v4.widget.DrawerLayout>
|
|
Loading…
Reference in New Issue