mirror of https://github.com/readrops/Readrops.git
Add a drawer manager
This commit is contained in:
parent
222012647f
commit
0734eaa5da
|
@ -38,6 +38,7 @@ 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.Folder;
|
||||
import com.readrops.app.utils.DrawerManager;
|
||||
import com.readrops.app.views.MainItemListAdapter;
|
||||
import com.readrops.app.viewmodels.MainViewModel;
|
||||
import com.readrops.app.R;
|
||||
|
@ -78,6 +79,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||
private TreeMap<LocalDateTime, Item> itemsMap;
|
||||
|
||||
private MainViewModel viewModel;
|
||||
private DrawerManager drawerManager;
|
||||
|
||||
private RelativeLayout syncProgressLayout;
|
||||
private TextView syncProgress;
|
||||
|
@ -123,6 +125,8 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||
.withShowDrawerOnFirstLaunch(true)
|
||||
.build();
|
||||
|
||||
drawerManager = new DrawerManager(drawer);
|
||||
|
||||
updateDrawerFeeds();
|
||||
}
|
||||
|
||||
|
@ -133,7 +137,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||
.subscribe(new DisposableSingleObserver<HashMap<Folder, List<Feed>>>() {
|
||||
@Override
|
||||
public void onSuccess(HashMap<Folder, List<Feed>> folderListHashMap) {
|
||||
populateDrawer(folderListHashMap);
|
||||
drawerManager.updateDrawer(getApplicationContext(), folderListHashMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,48 +147,6 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||
});
|
||||
}
|
||||
|
||||
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
|
||||
public void onBackPressed() {
|
||||
if (drawer.isDrawerOpen())
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package com.readrops.app.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
||||
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.R;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
import com.readrops.app.database.entities.Folder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DrawerManager {
|
||||
|
||||
public static final int ARTICLES_ITEM_ID = 1;
|
||||
public static final int READ_LATER_ID = 2;
|
||||
|
||||
private Drawer drawer;
|
||||
|
||||
public DrawerManager(Drawer drawer) {
|
||||
this.drawer = drawer;
|
||||
}
|
||||
|
||||
public void updateDrawer(Context context, Map<Folder, List<Feed>> folderListMap) {
|
||||
drawer.removeAllItems();
|
||||
addDefaultPlaces(context);
|
||||
|
||||
List<SecondaryDrawerItem> feedsWithoutFolder = new ArrayList<>();
|
||||
|
||||
for (Folder folder : folderListMap.keySet()) {
|
||||
if (folder.getId() != 1) {
|
||||
ExpandableBadgeDrawerItem badgeDrawerItem = new ExpandableBadgeDrawerItem()
|
||||
.withName(folder.getName())
|
||||
.withIdentifier(folder.getId())
|
||||
.withIcon(context.getDrawable(R.drawable.ic_folder_grey));
|
||||
|
||||
List<IDrawerItem> secondaryDrawerItems = new ArrayList<>();
|
||||
|
||||
for (Feed feed : folderListMap.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, items to add after the folders
|
||||
for (Feed feed : folderListMap.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);
|
||||
}
|
||||
}
|
||||
|
||||
private void addDefaultPlaces(Context context) {
|
||||
PrimaryDrawerItem articles = new PrimaryDrawerItem()
|
||||
.withName(context.getString(R.string.articles))
|
||||
.withIcon(context.getDrawable(R.drawable.ic_rss_feed_grey))
|
||||
.withIdentifier(ARTICLES_ITEM_ID);
|
||||
|
||||
PrimaryDrawerItem toReadLater = new PrimaryDrawerItem()
|
||||
.withName(context.getString(R.string.read_later))
|
||||
.withIcon(context.getDrawable(R.drawable.ic_read_later_grey))
|
||||
.withIdentifier(READ_LATER_ID);
|
||||
|
||||
drawer.addItem(articles);
|
||||
drawer.addItem(toReadLater);
|
||||
drawer.addItem(new DividerDrawerItem());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#727272"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z"/>
|
||||
</vector>
|
|
@ -0,0 +1,6 @@
|
|||
<vector android:height="24dp" android:tint="#727272"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M6.18,17.82m-2.18,0a2.18,2.18 0,1 1,4.36 0a2.18,2.18 0,1 1,-4.36 0"/>
|
||||
<path android:fillColor="#FF000000" android:pathData="M4,4.44v2.83c7.03,0 12.73,5.7 12.73,12.73h2.83c0,-8.59 -6.97,-15.56 -15.56,-15.56zM4,10.1v2.83c3.9,0 7.07,3.17 7.07,7.07h2.83c0,-5.47 -4.43,-9.9 -9.9,-9.9z"/>
|
||||
</vector>
|
|
@ -38,5 +38,7 @@
|
|||
<string name="feed_insertion_parse_failed">Erreur de traitement pour le flux %1$s</string>
|
||||
<string name="feed_insertion_wrong_format">Mauvais format pour le flux %1$s</string>
|
||||
<string name="feed_insertion_unknown_error">Erreur inconnue pour le flux %1$s</string>
|
||||
<string name="articles">Articles</string>
|
||||
<string name="read_later">A lire plus tard</string>
|
||||
|
||||
</resources>
|
|
@ -40,4 +40,6 @@
|
|||
<string name="feed_insertion_parse_failed">Failure when parsing feed %1$s</string>
|
||||
<string name="feed_insertion_wrong_format">Wrong format for feed %1$s</string>
|
||||
<string name="feed_insertion_unknown_error">Unknown error for feed %1$s</string>
|
||||
<string name="articles">Articles</string>
|
||||
<string name="read_later">To read later</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue