Index: chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkItemsAdapter.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkItemsAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkItemsAdapter.java |
index 40b83b2efb3186b2d232ecbc663a9ef55e59ed2d..d0e93f751881858186c414ef09272f1e788caf29 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkItemsAdapter.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/enhancedbookmarks/EnhancedBookmarkItemsAdapter.java |
@@ -15,7 +15,11 @@ import org.chromium.base.annotations.SuppressFBWarnings; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.BookmarksBridge.BookmarkItem; |
import org.chromium.chrome.browser.BookmarksBridge.BookmarkModelObserver; |
+import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkManager.UIState; |
import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkPromoHeader.PromoHeaderShowingChangeListener; |
+import org.chromium.chrome.browser.offline_pages.OfflinePageBridge; |
+import org.chromium.chrome.browser.offline_pages.OfflinePageFreeUpSpaceCallback; |
+import org.chromium.chrome.browser.offline_pages.OfflinePageStorageSpaceHeader; |
import org.chromium.components.bookmarks.BookmarkId; |
import java.util.ArrayList; |
@@ -31,13 +35,16 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
private static final int FOLDER_VIEW = 1; |
private static final int DIVIDER_VIEW = 2; |
private static final int BOOKMARK_VIEW = 3; |
+ private static final int OFFLINE_PAGES_STORAGE_VIEW = 4; |
private EnhancedBookmarkDelegate mDelegate; |
private Context mContext; |
private EnhancedBookmarkPromoHeader mPromoHeaderManager; |
+ private OfflinePageStorageSpaceHeader mOfflineStorageHeader; |
private List<List<? extends Object>> mSections; |
private List<Object> mPromoHeaderSection = new ArrayList<>(); |
+ private List<Object> mOfflineStorageSection = new ArrayList<>(); |
private List<Object> mFolderDividerSection = new ArrayList<>(); |
private List<BookmarkId> mFolderSection = new ArrayList<>(); |
private List<Object> mBookmarkDividerSection = new ArrayList<>(); |
@@ -74,6 +81,7 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
mSections = new ArrayList<>(); |
mSections.add(mPromoHeaderSection); |
+ mSections.add(mOfflineStorageSection); |
mSections.add(mFolderDividerSection); |
mSections.add(mFolderSection); |
mSections.add(mBookmarkDividerSection); |
@@ -131,6 +139,7 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
mBookmarkSection.clear(); |
mBookmarkSection.addAll(bookmarks); |
+ updateHeader(); |
updateDividerSections(); |
// TODO(kkimlabs): Animation is disabled due to a performance issue on bookmark undo. |
@@ -141,11 +150,14 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
private void updateDividerSections() { |
mFolderDividerSection.clear(); |
mBookmarkDividerSection.clear(); |
- if (!mPromoHeaderSection.isEmpty() && !mFolderSection.isEmpty()) { |
+ |
+ boolean isHeaderPresent = |
+ !mPromoHeaderSection.isEmpty() || !mOfflineStorageSection.isEmpty(); |
+ |
+ if (isHeaderPresent && !mFolderSection.isEmpty()) { |
mFolderDividerSection.add(null); |
} |
- if ((!mPromoHeaderSection.isEmpty() || !mFolderSection.isEmpty()) |
- && !mBookmarkSection.isEmpty()) { |
+ if ((isHeaderPresent || !mFolderSection.isEmpty()) && !mBookmarkSection.isEmpty()) { |
mBookmarkDividerSection.add(null); |
} |
} |
@@ -174,6 +186,8 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
if (section == mPromoHeaderSection) { |
return PROMO_HEADER_VIEW; |
+ } else if (section == mOfflineStorageSection) { |
+ return OFFLINE_PAGES_STORAGE_VIEW; |
} else if (section == mFolderDividerSection |
|| section == mBookmarkDividerSection) { |
return DIVIDER_VIEW; |
@@ -192,6 +206,8 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
switch (viewType) { |
case PROMO_HEADER_VIEW: |
return mPromoHeaderManager.createHolder(parent); |
+ case OFFLINE_PAGES_STORAGE_VIEW: |
+ return mOfflineStorageHeader.createHolder(parent); |
case DIVIDER_VIEW: |
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate( |
R.layout.eb_divider, parent, false)) {}; |
@@ -217,6 +233,7 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
BookmarkId id = getItem(position); |
switch (getItemViewType(position)) { |
case PROMO_HEADER_VIEW: |
+ case OFFLINE_PAGES_STORAGE_VIEW: |
case DIVIDER_VIEW: |
break; |
case FOLDER_VIEW: |
@@ -234,9 +251,12 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
@Override |
public void onPromoHeaderShowingChanged(boolean isShowing) { |
- mPromoHeaderSection.clear(); |
- if (isShowing) mPromoHeaderSection.add(null); |
+ if (mDelegate.getCurrentState() != UIState.STATE_ALL_BOOKMARKS |
+ && mDelegate.getCurrentState() != UIState.STATE_FOLDER) { |
+ return; |
+ } |
+ updateHeader(); |
updateDividerSections(); |
notifyDataSetChanged(); |
} |
@@ -249,9 +269,21 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
mDelegate.addUIObserver(this); |
mDelegate.getModel().addObserver(mBookmarkModelObserver); |
mPromoHeaderManager = new EnhancedBookmarkPromoHeader(mContext, this); |
- if (mPromoHeaderManager.shouldShow()) mPromoHeaderSection.add(null); |
- |
- updateDividerSections(); |
+ OfflinePageBridge offlinePageBridge = mDelegate.getModel().getOfflinePageBridge(); |
+ if (offlinePageBridge != null) { |
+ mOfflineStorageHeader = new OfflinePageStorageSpaceHeader( |
+ mContext, offlinePageBridge, new OfflinePageFreeUpSpaceCallback() { |
+ @Override |
+ public void onFreeUpSpaceDone() { |
+ refreshOfflinePagesFilterView(); |
+ } |
+ |
+ @Override |
+ public void onFreeUpSpaceCancelled() { |
+ // No need to refresh, as result outcome should be the same here. |
+ } |
+ }); |
+ } |
} |
@Override |
@@ -286,4 +318,29 @@ class EnhancedBookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.Vie |
super(view); |
} |
} |
+ |
+ private void updateHeader() { |
+ int currentUIState = mDelegate.getCurrentState(); |
+ if (currentUIState == UIState.STATE_LOADING) return; |
+ |
+ mPromoHeaderSection.clear(); |
+ mOfflineStorageSection.clear(); |
+ if (currentUIState == UIState.STATE_FILTER) { |
+ if (mOfflineStorageHeader != null && mOfflineStorageHeader.shouldShow()) { |
+ mOfflineStorageSection.add(null); |
+ } |
+ } else { |
+ assert currentUIState == UIState.STATE_ALL_BOOKMARKS |
+ || currentUIState == UIState.STATE_FOLDER : "Unexpected UI state"; |
+ if (mPromoHeaderManager.shouldShow()) { |
+ mPromoHeaderSection.add(null); |
+ } |
+ } |
+ } |
+ |
+ private void refreshOfflinePagesFilterView() { |
+ if (mDelegate.getCurrentState() != UIState.STATE_FILTER) return; |
+ setBookmarks(null, |
+ mDelegate.getModel().getBookmarkIDsByFilter(EnhancedBookmarkFilter.OFFLINE_PAGES)); |
+ } |
} |