Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkRecyclerView.java

Issue 1688033002: Rename EnhancedBookmarks to Bookmarks, part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.enhancedbookmarks; 5 package org.chromium.chrome.browser.bookmarks;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Rect; 8 import android.graphics.Rect;
9 import android.support.v7.widget.LinearLayoutManager; 9 import android.support.v7.widget.LinearLayoutManager;
10 import android.support.v7.widget.RecyclerView; 10 import android.support.v7.widget.RecyclerView;
11 import android.util.AttributeSet; 11 import android.util.AttributeSet;
12 import android.view.View; 12 import android.view.View;
13 import android.widget.Checkable; 13 import android.widget.Checkable;
14 14
15 import org.chromium.base.VisibleForTesting; 15 import org.chromium.base.VisibleForTesting;
16 import org.chromium.components.bookmarks.BookmarkId; 16 import org.chromium.components.bookmarks.BookmarkId;
17 17
18 import java.util.List; 18 import java.util.List;
19 19
20 /** 20 /**
21 * Container for all bookmark items shown in enhanced bookmark manager. 21 * Container for all bookmark items shown in enhanced bookmark manager.
22 */ 22 */
23 public class EnhancedBookmarkRecyclerView extends RecyclerView implements 23 public class BookmarkRecyclerView extends RecyclerView implements
24 EnhancedBookmarkUIObserver { 24 BookmarkUIObserver {
25 25
26 private EnhancedBookmarkDelegate mDelegate; 26 private BookmarkDelegate mDelegate;
27 private View mEmptyView; 27 private View mEmptyView;
28 28
29 /** 29 /**
30 * Provides a way to override the default spacing between 2 items in Recycle rView. 30 * Provides a way to override the default spacing between 2 items in Recycle rView.
31 */ 31 */
32 private static class VerticalSpaceItemDecoration extends RecyclerView.ItemDe coration { 32 private static class VerticalSpaceItemDecoration extends RecyclerView.ItemDe coration {
33 private final int mSpacing; 33 private final int mSpacing;
34 34
35 public VerticalSpaceItemDecoration(int spacing) { 35 public VerticalSpaceItemDecoration(int spacing) {
36 this.mSpacing = spacing; 36 this.mSpacing = spacing;
37 } 37 }
38 38
39 @Override 39 @Override
40 public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 40 public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
41 RecyclerView.State state) { 41 RecyclerView.State state) {
42 outRect.bottom = mSpacing; 42 outRect.bottom = mSpacing;
43 } 43 }
44 } 44 }
45 45
46 /** 46 /**
47 * Constructs a new instance of enhanced bookmark recycler view. 47 * Constructs a new instance of enhanced bookmark recycler view.
48 */ 48 */
49 public EnhancedBookmarkRecyclerView(Context context, AttributeSet attrs) { 49 public BookmarkRecyclerView(Context context, AttributeSet attrs) {
50 super(context, attrs); 50 super(context, attrs);
51 51
52 setLayoutManager(new LinearLayoutManager(context)); 52 setLayoutManager(new LinearLayoutManager(context));
53 setHasFixedSize(true); 53 setHasFixedSize(true);
54 } 54 }
55 55
56 /** 56 /**
57 * Sets the view to be shown if there are no items in adapter. 57 * Sets the view to be shown if there are no items in adapter.
58 */ 58 */
59 void setEmptyView(View emptyView) { 59 void setEmptyView(View emptyView) {
(...skipping 22 matching lines...) Expand all
82 public void onItemRangeRemoved(int positionStart, int itemCount) { 82 public void onItemRangeRemoved(int positionStart, int itemCount) {
83 super.onItemRangeRemoved(positionStart, itemCount); 83 super.onItemRangeRemoved(positionStart, itemCount);
84 updateEmptyViewVisibility(adapter); 84 updateEmptyViewVisibility(adapter);
85 } 85 }
86 }); 86 });
87 updateEmptyViewVisibility(adapter); 87 updateEmptyViewVisibility(adapter);
88 } 88 }
89 89
90 @VisibleForTesting 90 @VisibleForTesting
91 @Override 91 @Override
92 public EnhancedBookmarkItemsAdapter getAdapter() { 92 public BookmarkItemsAdapter getAdapter() {
93 return (EnhancedBookmarkItemsAdapter) super.getAdapter(); 93 return (BookmarkItemsAdapter) super.getAdapter();
94 } 94 }
95 95
96 /** 96 /**
97 * Unlike ListView or GridView, RecyclerView does not provide default empty 97 * Unlike ListView or GridView, RecyclerView does not provide default empty
98 * view implementation. We need to check it ourselves. 98 * view implementation. We need to check it ourselves.
99 */ 99 */
100 private void updateEmptyViewVisibility(Adapter adapter) { 100 private void updateEmptyViewVisibility(Adapter adapter) {
101 mEmptyView.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : Vi ew.GONE); 101 mEmptyView.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : Vi ew.GONE);
102 } 102 }
103 103
104 // EnhancedBookmarkUIObserver implementations 104 // BookmarkUIObserver implementations
105 105
106 @Override 106 @Override
107 public void onEnhancedBookmarkDelegateInitialized(EnhancedBookmarkDelegate d elegate) { 107 public void onBookmarkDelegateInitialized(BookmarkDelegate delegate) {
108 mDelegate = delegate; 108 mDelegate = delegate;
109 mDelegate.addUIObserver(this); 109 mDelegate.addUIObserver(this);
110 110
111 EnhancedBookmarkItemsAdapter adapter = new EnhancedBookmarkItemsAdapter( getContext()); 111 BookmarkItemsAdapter adapter = new BookmarkItemsAdapter(getContext());
112 adapter.onEnhancedBookmarkDelegateInitialized(mDelegate); 112 adapter.onBookmarkDelegateInitialized(mDelegate);
113 setAdapter(adapter); 113 setAdapter(adapter);
114 } 114 }
115 115
116 @Override 116 @Override
117 public void onDestroy() { 117 public void onDestroy() {
118 mDelegate.removeUIObserver(this); 118 mDelegate.removeUIObserver(this);
119 } 119 }
120 120
121 @Override 121 @Override
122 public void onAllBookmarksStateSet() { 122 public void onAllBookmarksStateSet() {
123 scrollToPosition(0); 123 scrollToPosition(0);
124 } 124 }
125 125
126 @Override 126 @Override
127 public void onFolderStateSet(BookmarkId folder) { 127 public void onFolderStateSet(BookmarkId folder) {
128 scrollToPosition(0); 128 scrollToPosition(0);
129 } 129 }
130 130
131 @Override 131 @Override
132 public void onFilterStateSet(EnhancedBookmarkFilter filter) { 132 public void onFilterStateSet(BookmarkFilter filter) {
133 assert filter == EnhancedBookmarkFilter.OFFLINE_PAGES; 133 assert filter == BookmarkFilter.OFFLINE_PAGES;
134 scrollToPosition(0); 134 scrollToPosition(0);
135 } 135 }
136 136
137 @Override 137 @Override
138 public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) { 138 public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) {
139 if (!mDelegate.isSelectionEnabled()) { 139 if (!mDelegate.isSelectionEnabled()) {
140 for (int i = 0; i < getLayoutManager().getChildCount(); ++i) { 140 for (int i = 0; i < getLayoutManager().getChildCount(); ++i) {
141 View child = getLayoutManager().getChildAt(i); 141 View child = getLayoutManager().getChildAt(i);
142 if (child instanceof Checkable) ((Checkable) child).setChecked(f alse); 142 if (child instanceof Checkable) ((Checkable) child).setChecked(f alse);
143 } 143 }
144 } 144 }
145 } 145 }
146 146
147 @VisibleForTesting 147 @VisibleForTesting
148 public EnhancedBookmarkDelegate getDelegateForTesting() { 148 public BookmarkDelegate getDelegateForTesting() {
149 return mDelegate; 149 return mDelegate;
150 } 150 }
151 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698