 Chromium Code Reviews
 Chromium Code Reviews Issue 2703463002:
  [List UI Unification] Basic list unification for phones  (Closed)
    
  
    Issue 2703463002:
  [List UI Unification] Basic list unification for phones  (Closed) 
  | OLD | NEW | 
|---|---|
| 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.bookmarks; | 5 package org.chromium.chrome.browser.bookmarks; | 
| 6 | 6 | 
| 7 import android.content.Context; | 7 import android.content.Context; | 
| 8 import android.support.v7.widget.RecyclerView; | 8 import android.support.v7.widget.RecyclerView; | 
| 9 import android.support.v7.widget.RecyclerView.ViewHolder; | 9 import android.support.v7.widget.RecyclerView.ViewHolder; | 
| 10 import android.view.LayoutInflater; | 10 import android.view.LayoutInflater; | 
| 11 import android.view.View; | 11 import android.view.View; | 
| 12 import android.view.ViewGroup; | 12 import android.view.ViewGroup; | 
| 13 | 13 | 
| 14 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; | 
| 15 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; | 
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; | 
| 17 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; | 17 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem; | 
| 18 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkModelObserve r; | 18 import org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkModelObserve r; | 
| 19 import org.chromium.chrome.browser.bookmarks.BookmarkPromoHeader.PromoHeaderShow ingChangeListener; | 19 import org.chromium.chrome.browser.bookmarks.BookmarkPromoHeader.PromoHeaderShow ingChangeListener; | 
| 20 import org.chromium.components.bookmarks.BookmarkId; | 20 import org.chromium.components.bookmarks.BookmarkId; | 
| 21 import org.chromium.ui.base.DeviceFormFactor; | |
| 21 | 22 | 
| 22 import java.util.ArrayList; | 23 import java.util.ArrayList; | 
| 23 import java.util.List; | 24 import java.util.List; | 
| 24 | 25 | 
| 25 /** | 26 /** | 
| 26 * BaseAdapter for {@link RecyclerView}. It manages bookmarks to list there. | 27 * BaseAdapter for {@link RecyclerView}. It manages bookmarks to list there. | 
| 27 */ | 28 */ | 
| 28 class BookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements | 29 class BookmarkItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements | 
| 29 BookmarkUIObserver, PromoHeaderShowingChangeListener { | 30 BookmarkUIObserver, PromoHeaderShowingChangeListener { | 
| 30 private static final int PROMO_HEADER_VIEW = 0; | 31 private static final int PROMO_HEADER_VIEW = 0; | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 assert mDelegate != null; | 71 assert mDelegate != null; | 
| 71 mDelegate.notifyStateChange(BookmarkItemsAdapter.this); | 72 mDelegate.notifyStateChange(BookmarkItemsAdapter.this); | 
| 72 } | 73 } | 
| 73 }; | 74 }; | 
| 74 | 75 | 
| 75 BookmarkItemsAdapter(Context context) { | 76 BookmarkItemsAdapter(Context context) { | 
| 76 mContext = context; | 77 mContext = context; | 
| 77 | 78 | 
| 78 mSections = new ArrayList<>(); | 79 mSections = new ArrayList<>(); | 
| 79 mSections.add(mPromoHeaderSection); | 80 mSections.add(mPromoHeaderSection); | 
| 80 mSections.add(mFolderDividerSection); | 81 | 
| 82 if (DeviceFormFactor.isLargeTablet(context)) { | |
| 
gone
2017/02/17 01:45:02
You should probably just have a function that abst
 
Theresa
2017/02/17 17:34:28
A function that abstracts whether dividers should
 | |
| 83 mSections.add(mFolderDividerSection); | |
| 84 } | |
| 85 | |
| 81 mSections.add(mFolderSection); | 86 mSections.add(mFolderSection); | 
| 82 mSections.add(mBookmarkDividerSection); | 87 | 
| 88 if (DeviceFormFactor.isLargeTablet(context)) { | |
| 89 mSections.add(mBookmarkDividerSection); | |
| 90 } | |
| 91 | |
| 83 mSections.add(mBookmarkSection); | 92 mSections.add(mBookmarkSection); | 
| 84 } | 93 } | 
| 85 | 94 | 
| 86 BookmarkId getItem(int position) { | 95 BookmarkId getItem(int position) { | 
| 87 return (BookmarkId) getSection(position).get(toSectionPosition(position) ); | 96 return (BookmarkId) getSection(position).get(toSectionPosition(position) ); | 
| 88 } | 97 } | 
| 89 | 98 | 
| 90 private int toSectionPosition(int globalPosition) { | 99 private int toSectionPosition(int globalPosition) { | 
| 91 int sectionPosition = globalPosition; | 100 int sectionPosition = globalPosition; | 
| 92 for (List<?> section : mSections) { | 101 for (List<?> section : mSections) { | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 145 | 
| 137 updateHeader(); | 146 updateHeader(); | 
| 138 updateDividerSections(); | 147 updateDividerSections(); | 
| 139 | 148 | 
| 140 // TODO(kkimlabs): Animation is disabled due to a performance issue on b ookmark undo. | 149 // TODO(kkimlabs): Animation is disabled due to a performance issue on b ookmark undo. | 
| 141 // http://crbug.com/484174 | 150 // http://crbug.com/484174 | 
| 142 notifyDataSetChanged(); | 151 notifyDataSetChanged(); | 
| 143 } | 152 } | 
| 144 | 153 | 
| 145 private void updateDividerSections() { | 154 private void updateDividerSections() { | 
| 155 if (!DeviceFormFactor.isLargeTablet(mContext)) return; | |
| 156 | |
| 146 mFolderDividerSection.clear(); | 157 mFolderDividerSection.clear(); | 
| 147 mBookmarkDividerSection.clear(); | 158 mBookmarkDividerSection.clear(); | 
| 148 | 159 | 
| 149 boolean isHeaderPresent = !mPromoHeaderSection.isEmpty(); | 160 boolean isHeaderPresent = !mPromoHeaderSection.isEmpty(); | 
| 150 | 161 | 
| 151 if (isHeaderPresent && !mFolderSection.isEmpty()) { | 162 if (isHeaderPresent && !mFolderSection.isEmpty()) { | 
| 152 mFolderDividerSection.add(null); | 163 mFolderDividerSection.add(null); | 
| 153 } | 164 } | 
| 154 if ((isHeaderPresent || !mFolderSection.isEmpty()) && !mBookmarkSection. isEmpty()) { | 165 if ((isHeaderPresent || !mFolderSection.isEmpty()) && !mBookmarkSection. isEmpty()) { | 
| 155 mBookmarkDividerSection.add(null); | 166 mBookmarkDividerSection.add(null); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 @Override | 234 @Override | 
| 224 public void onBindViewHolder(ViewHolder holder, int position) { | 235 public void onBindViewHolder(ViewHolder holder, int position) { | 
| 225 BookmarkId id = getItem(position); | 236 BookmarkId id = getItem(position); | 
| 226 | 237 | 
| 227 switch (getItemViewType(position)) { | 238 switch (getItemViewType(position)) { | 
| 228 case PROMO_HEADER_VIEW: | 239 case PROMO_HEADER_VIEW: | 
| 229 case DIVIDER_VIEW: | 240 case DIVIDER_VIEW: | 
| 230 break; | 241 break; | 
| 231 case FOLDER_VIEW: | 242 case FOLDER_VIEW: | 
| 232 ((BookmarkRow) holder.itemView).setBookmarkId(id); | 243 ((BookmarkRow) holder.itemView).setBookmarkId(id); | 
| 244 ((BookmarkRow) holder.itemView) | |
| 245 .setBackgroundResourceForGroupPosition(id.equals(mFolder Section.get(0)), | |
| 246 id.equals(mFolderSection.get(mFolderSection.size () - 1))); | |
| 233 break; | 247 break; | 
| 234 case BOOKMARK_VIEW: | 248 case BOOKMARK_VIEW: | 
| 235 ((BookmarkRow) holder.itemView).setBookmarkId(id); | 249 ((BookmarkRow) holder.itemView).setBookmarkId(id); | 
| 250 ((BookmarkRow) holder.itemView) | |
| 251 .setBackgroundResourceForGroupPosition(id.equals(mBookma rkSection.get(0)), | |
| 252 id.equals(mBookmarkSection.get(mBookmarkSection. size() - 1))); | |
| 236 break; | 253 break; | 
| 237 default: | 254 default: | 
| 238 assert false : "View type not supported!"; | 255 assert false : "View type not supported!"; | 
| 239 } | 256 } | 
| 240 } | 257 } | 
| 241 | 258 | 
| 242 // PromoHeaderShowingChangeListener implementation. | 259 // PromoHeaderShowingChangeListener implementation. | 
| 243 | 260 | 
| 244 @Override | 261 @Override | 
| 245 public void onPromoHeaderShowingChanged(boolean isShowing) { | 262 public void onPromoHeaderShowingChanged(boolean isShowing) { | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 if (mPromoHeaderManager.shouldShow()) { | 316 if (mPromoHeaderManager.shouldShow()) { | 
| 300 mPromoHeaderSection.add(null); | 317 mPromoHeaderSection.add(null); | 
| 301 } | 318 } | 
| 302 } | 319 } | 
| 303 | 320 | 
| 304 @VisibleForTesting | 321 @VisibleForTesting | 
| 305 public BookmarkDelegate getDelegateForTesting() { | 322 public BookmarkDelegate getDelegateForTesting() { | 
| 306 return mDelegate; | 323 return mDelegate; | 
| 307 } | 324 } | 
| 308 } | 325 } | 
| OLD | NEW |