Commit f6e2201b authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Introduces ListModel and ListItem.

These serve as common model classes that can back either
UICollectionView or UITableView.  CollectionViewModel is updated to be a
subclass of ListModel with added restrictions on permitted item types
but no functional changes.  CollectionViewController and its subclasses
are largely unchanged.

BUG=805136

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ibcfbab5bae62c5c8a37f764508294421d3d1c307
Reviewed-on: https://chromium-review.googlesource.com/916365
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536708}
parent d0345bb1
......@@ -12,6 +12,7 @@ source_set("collection_view") {
]
deps = [
"//base",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/material_components",
]
public_deps = [
......@@ -43,7 +44,6 @@ source_set("unit_tests") {
testonly = true
sources = [
"collection_view_controller_unittest.mm",
"collection_view_model_unittest.mm",
]
deps = [
":collection_view",
......
......@@ -14,7 +14,6 @@ source_set("cells") {
"collection_view_detail_item.mm",
"collection_view_footer_item.h",
"collection_view_footer_item.mm",
"collection_view_item+collection_view_controller.h",
"collection_view_item.h",
"collection_view_item.mm",
"collection_view_switch_item.h",
......@@ -29,6 +28,7 @@ source_set("cells") {
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/util",
"//ios/chrome/common",
......@@ -68,6 +68,7 @@ source_set("unit_tests") {
deps = [
":cells",
":test_support",
"//ios/chrome/browser/ui/list_model",
"//ios/third_party/material_components_ios",
"//testing/gtest",
]
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_COLLECTION_VIEW_ITEM_COLLECTION_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_COLLECTION_VIEW_ITEM_COLLECTION_VIEW_CONTROLLER_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
// CollectionViewItem can be created with a default item type but it needs to
// have a valid item type to be inserted in the model. Only the
// CollectionViewController managing the item is allowed to set the item type.
@interface CollectionViewItem (CollectionViewController)
@property(nonatomic, readwrite, assign) NSInteger type;
@end
#endif // IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_COLLECTION_VIEW_ITEM_COLLECTION_VIEW_CONTROLLER_H_
......@@ -7,18 +7,12 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/list_model/list_item.h"
@class MDCCollectionViewCell;
// CollectionViewItem holds the model data for a given collection view item.
@interface CollectionViewItem : NSObject<UIAccessibilityIdentification>
// A client-defined value. It should be unique among items of a given collection
// view model.
@property(nonatomic, readonly, assign) NSInteger type;
// The cell class to use in conjunction with this item. Must be a subclass of
// MDCCollectionViewCell. The default is MDCCollectionViewCell.
@property(nonatomic, assign) Class cellClass;
@interface CollectionViewItem : ListItem
- (instancetype)initWithType:(NSInteger)type NS_DESIGNATED_INITIALIZER;
......
......@@ -5,7 +5,6 @@
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "base/logging.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -14,27 +13,13 @@
@implementation CollectionViewItem
@synthesize type = _type;
@synthesize cellClass = _cellClass;
@synthesize accessibilityIdentifier = _accessibilityIdentifier;
- (instancetype)initWithType:(NSInteger)type {
if ((self = [super init])) {
_type = type;
_cellClass = [MDCCollectionViewCell class];
if ((self = [super initWithType:type])) {
self.cellClass = [MDCCollectionViewCell class];
}
return self;
}
- (instancetype)init {
return [self initWithType:0];
}
- (void)setCellClass:(Class)cellClass {
DCHECK([cellClass isSubclassOfClass:[MDCCollectionViewCell class]]);
_cellClass = cellClass;
}
- (void)configureCell:(MDCCollectionViewCell*)cell {
DCHECK([cell class] == self.cellClass);
cell.accessibilityTraits = self.accessibilityTraits;
......@@ -42,11 +27,3 @@
}
@end
@implementation CollectionViewItem (CollectionViewController)
- (void)setType:(NSInteger)type {
_type = type;
}
@end
......@@ -4,7 +4,6 @@
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
......@@ -18,21 +17,6 @@ namespace {
using CollectionViewItemTest = PlatformTest;
TEST_F(CollectionViewItemTest, Accessors) {
CollectionViewItem* five = [[CollectionViewItem alloc] initWithType:5];
CollectionViewItem* twelve = [[CollectionViewItem alloc] initWithType:12];
EXPECT_EQ(5, [five type]);
EXPECT_EQ(12, [twelve type]);
// Test setting the type property used in CollectionViewController.
[five setType:55];
EXPECT_EQ(55, [five type]);
[twelve setType:1212];
EXPECT_EQ(1212, [twelve type]);
}
TEST_F(CollectionViewItemTest, ConfigureCellPortsAccessibilityProperties) {
CollectionViewItem* item = [[CollectionViewItem alloc] initWithType:0];
item.accessibilityIdentifier = @"test_identifier";
......
......@@ -7,184 +7,12 @@
#import <UIKit/UIKit.h>
@class CollectionViewItem;
// Use these as the starting value for section identifier and item type enums.
// These are provided to help not mix between indexPath's section/item and the
// model section identifier / item type.
//
// For example:
// typedef NS_ENUM(NSInteger, SectionIdentifier) {
// SectionIdentifierFoo = kSectionIdentifierEnumZero,
// SectionIdentifierBar,
// };
//
// typedef NS_ENUM(NSInteger, ItemType) {
// ItemTypeBaz = kItemTypeEnumZero,
// ItemTypeQux,
// };
//
// These values are chosen to try to prevent overlapping.
const NSInteger kSectionIdentifierEnumZero = 10;
const NSInteger kItemTypeEnumZero = 100;
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/list_model/list_model.h"
// CollectionViewModel acts as a model class for collection view controllers.
// It provides methods to map from collection view index paths (aka collection
// view section and collection view item) to model coordinates. These are
// useful when the contents of a collection view are dynamic (for example, based
// on experimental flags), so that there is not a static mapping between index
// paths and section items.
// Model coordinates have 3 dimensions: section identifier, item type and index
// in item type.
// Disclaimer: CollectionViewModel doesn't support a batch update logic. All
// changes are immediately processed (contrary to the reload/delete/add order of
// UICollectionView's |performBatchUpdates:completion:|).
// The __covariant modifier allows an instance of CollectionViewModel<A> to be
// assigned to an instance of CollectionViewModel<B> iff A:B (see unit test for
// an example).
@interface CollectionViewModel<__covariant ObjectType : CollectionViewItem*>
: NSObject
#pragma mark Modification methods
// Adds a new section tagged with the given identifier. This method must not be
// called multiple times with the same identifier.
- (void)addSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Inserts a new section tagged with the given identifier at the given index.
// This method must not be called multiple times with the same identifier.
- (void)insertSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Adds an item to the section with the given identifier. Adding several times
// the same item is undefined behavior.
- (void)addItem:(ObjectType)item
toSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Inserts an item to the section with the given identifier at the given index.
// |index| must not be greater than the count of elements in the section.
- (void)insertItem:(ObjectType)item
inSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Removes the item for |itemType| from the section for |sectionIdentifier|.
// If there are multiple entries with the same item type, this will remove the
// first occurrence, but to selectively delete an item for a given index, use
// -removeItemWithType:fromSectionWithIdentifier:atIndex:.
- (void)removeItemWithType:(NSInteger)itemType
fromSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Removes the item for |itemType| from the section for |sectionIdentifier| at
// |index|.
- (void)removeItemWithType:(NSInteger)itemType
fromSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Removes the section for |sectionIdentifier|. If there are still items left in
// the section, they are removed.
- (void)removeSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Sets the header item for the section with the given |sectionIdentifier|.
- (void)setHeader:(CollectionViewItem*)header
forSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Sets the footer item for the section with the given |sectionIdentifier|.
- (void)setFooter:(CollectionViewItem*)footer
forSectionWithIdentifier:(NSInteger)sectionIdentifier;
#pragma mark Query model coordinates from index paths
// Returns the section identifier for the given section.
- (NSInteger)sectionIdentifierForSection:(NSInteger)section;
// Returns the item type for the given index path.
- (NSInteger)itemTypeForIndexPath:(NSIndexPath*)indexPath;
// Returns the index in item type for the given index path.
// It corresponds to the index of the item at index path, among all the items if
// the same type in the given section.
// For example, let [A, B, B, B] a section, where A and B are item identifiers.
// -indexInItemTypeForIndexPath:{0, 0} would return 0.
// -indexInItemTypeForIndexPath:{0, 1} would return 0.
// -indexInItemTypeForIndexPath:{0, 3} would return 2.
- (NSUInteger)indexInItemTypeForIndexPath:(NSIndexPath*)indexPath;
#pragma mark Query items from index paths
// Returns whether there is an item at the given index path.
- (BOOL)hasItemAtIndexPath:(NSIndexPath*)indexPath;
// Returns the item at the given index path.
- (ObjectType)itemAtIndexPath:(NSIndexPath*)indexPath;
// Returns the header for the given |section|.
- (CollectionViewItem*)headerForSection:(NSInteger)section;
// Returns the footer for the given |section|.
- (CollectionViewItem*)footerForSection:(NSInteger)section;
// Returns an array of items in the section with the given identifier.
- (NSArray<ObjectType>*)itemsInSectionWithIdentifier:
(NSInteger)sectionIdentifier;
// Returns the header for the section with the given |sectionIdentifier|.
- (CollectionViewItem*)headerForSectionWithIdentifier:
(NSInteger)sectionIdentifier;
// Returns the footer for the section with the given |sectionIdentifier|.
- (CollectionViewItem*)footerForSectionWithIdentifier:
(NSInteger)sectionIdentifier;
#pragma mark Query index paths from model coordinates
// Returns whether there is a section at the given section identifier.
- (BOOL)hasSectionForSectionIdentifier:(NSInteger)sectionIdentifier;
// Returns the index path's section for the given section identifier.
- (NSInteger)sectionForSectionIdentifier:(NSInteger)sectionIdentifier;
// Returns whether there is an item of type |itemType| at the given
// |sectionIdentifier|.
- (BOOL)hasItemForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier;
// Returns the index path for |itemType| in the section for |sectionIdentifier|.
// If there are multiple entries with the same item type, use
// -indexPathForItemType:sectionIdentifier:atIndex:.
- (NSIndexPath*)indexPathForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier;
// Returns whether there is an item of type |itemType| at the given
// |sectionIdentifier| and |index|.
- (BOOL)hasItemForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Returns the index path for |itemType| in the section for |sectionIdentifier|
// at |index|.
- (NSIndexPath*)indexPathForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
#pragma mark Query index paths from items
// Returns whether |item| exists in section for |sectionIdentifier|.
- (BOOL)hasItem:(ObjectType)item
inSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Returns whether |item| exists.
- (BOOL)hasItem:(ObjectType)item;
// Returns the index path corresponding to the given |item|.
- (NSIndexPath*)indexPathForItem:(ObjectType)item;
#pragma mark UICollectionView data sourcing
// Returns the number of collection view sections.
- (NSInteger)numberOfSections;
// Returns the number of collection view items in the given section.
- (NSInteger)numberOfItemsInSection:(NSInteger)section;
: ListModel<ObjectType, CollectionViewItem*>
@end
......
......@@ -122,6 +122,7 @@ source_set("content_suggestions_ui") {
"//ios/chrome/browser/ui/content_suggestions/cells:cells_ui",
"//ios/chrome/browser/ui/content_suggestions/identifier",
"//ios/chrome/browser/ui/favicon:favicon_ui",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/ntp",
"//ios/chrome/browser/ui/ntp:ntp_header",
"//ios/chrome/browser/ui/overscroll_actions",
......
......@@ -9,7 +9,6 @@
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
......@@ -26,6 +25,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller_audience.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestions_section_information.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("list_model") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"list_item+Controller.h",
"list_item.h",
"list_item.mm",
"list_model.h",
"list_model.mm",
]
deps = [
"//base",
]
}
source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"list_item_unittest.mm",
"list_model_unittest.mm",
]
deps = [
":list_model",
"//base",
"//ios/chrome/test:test_support",
"//ios/chrome/test/base",
"//testing/gtest",
]
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_CONTROLLER_H_
// ListItem can be created with a default item type but it needs to
// have a valid item type to be inserted in the model. Only the
// UIViewControllers managing the item are allowed to set the item type.
@interface ListItem (Controller)
// Redeclared as readwrite.
@property(nonatomic, readwrite, assign) NSInteger type;
@end
#endif // IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_H_
#define IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_H_
#import <UIKit/UIKit.h>
// ListItem holds the model data for a given list item. This is intended to be
// an abstract base class; callers should use one of the {collectionview,
// tableview}-specific subclasses.
@interface ListItem : NSObject<UIAccessibilityIdentification>
// A client-defined value. It should be unique among items of a given list
// model.
@property(nonatomic, readonly, assign) NSInteger type;
// The cell class to use in conjunction with this item.
@property(nonatomic, assign) Class cellClass;
- (instancetype)initWithType:(NSInteger)type NS_DESIGNATED_INITIALIZER;
@end
#endif // IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_ITEM_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/list_model/list_item.h"
#import "base/logging.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ListItem
@synthesize type = _type;
@synthesize cellClass = _cellClass;
@synthesize accessibilityIdentifier = _accessibilityIdentifier;
- (instancetype)initWithType:(NSInteger)type {
if ((self = [super init])) {
_type = type;
}
return self;
}
- (instancetype)init {
return [self initWithType:0];
}
- (void)setCellClass:(Class)cellClass {
_cellClass = cellClass;
}
@end
@implementation ListItem (Controller)
- (void)setType:(NSInteger)type {
_type = type;
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/list_model/list_item.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
using ListItemTest = PlatformTest;
TEST_F(ListItemTest, Accessors) {
ListItem* five = [[ListItem alloc] initWithType:5];
ListItem* twelve = [[ListItem alloc] initWithType:12];
EXPECT_EQ(5, [five type]);
EXPECT_EQ(12, [twelve type]);
// Test setting the type property.
[five setType:55];
EXPECT_EQ(55, [five type]);
[twelve setType:1212];
EXPECT_EQ(1212, [twelve type]);
}
} // namespace
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_MODEL_H_
#define IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_MODEL_H_
#import <UIKit/UIKit.h>
@class ListItem;
// Use these as the starting value for section identifier and item type enums.
// These are provided to help not mix between indexPath's section/item and the
// model section identifier / item type.
//
// For example:
// typedef NS_ENUM(NSInteger, SectionIdentifier) {
// SectionIdentifierFoo = kSectionIdentifierEnumZero,
// SectionIdentifierBar,
// };
//
// typedef NS_ENUM(NSInteger, ItemType) {
// ItemTypeBaz = kItemTypeEnumZero,
// ItemTypeQux,
// };
//
// These values are chosen to try to prevent overlapping.
const NSInteger kSectionIdentifierEnumZero = 10;
const NSInteger kItemTypeEnumZero = 100;
// ListModel acts as a model class for collectionview and tableview controllers.
// It provides methods to map from index paths (aka section and item) to model
// coordinates. These are useful when the contents of a list are dynamic (for
// example, based on experimental flags), so that there is not a static mapping
// between index paths and section items. Model coordinates have 3 dimensions:
// section identifier, item type and index in item type.
//
// Disclaimer: ListModel doesn't support a batch update logic. All changes are
// immediately processed (contrary to the reload/delete/add order of
// |performBatchUpdates:completion:|). The __covariant modifier allows an
// instance of ListModel<A,B> to be assigned to an instance of ListModel<X,Y>
// iff A:X and B:Y (see unit test for an example).
@interface ListModel<__covariant ObjectType : ListItem*,
__covariant SupplementalType : ListItem*> : NSObject
#pragma mark Modification methods
// Adds a new section tagged with the given identifier. This method must not be
// called multiple times with the same identifier.
- (void)addSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Inserts a new section tagged with the given identifier at the given
// index. This method must not be called multiple times with the same
// identifier.
- (void)insertSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Adds an item to the section with the given identifier. Adding several
// times the same item is undefined behavior.
- (void)addItem:(ObjectType)item
toSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Inserts an item to the section with the given identifier at the given
// index. |index| must not be greater than the count of elements in the
// section.
- (void)insertItem:(ObjectType)item
inSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Removes the item for |itemType| from the section for |sectionIdentifier|.
// If there are multiple entries with the same item type, this will remove
// the first occurrence, but to selectively delete an item for a given
// index, use -removeItemWithType:fromSectionWithIdentifier:atIndex:.
- (void)removeItemWithType:(NSInteger)itemType
fromSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Removes the item for |itemType| from the section for |sectionIdentifier|
// at |index|.
- (void)removeItemWithType:(NSInteger)itemType
fromSectionWithIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Removes the section for |sectionIdentifier|. If there are still items
// left in the section, they are removed.
- (void)removeSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Sets the header item for the section with the given |sectionIdentifier|.
- (void)setHeader:(SupplementalType)header
forSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Sets the footer item for the section with the given |sectionIdentifier|.
- (void)setFooter:(SupplementalType)footer
forSectionWithIdentifier:(NSInteger)sectionIdentifier;
#pragma mark Query model coordinates from index paths
// Returns the section identifier for the given section.
- (NSInteger)sectionIdentifierForSection:(NSInteger)section;
// Returns the item type for the given index path.
- (NSInteger)itemTypeForIndexPath:(NSIndexPath*)indexPath;
// Returns the index in item type for the given index path.
// It corresponds to the index of the item at index path, among all the
// items if the same type in the given section. For example, let [A, B, B,
// B] a section, where A and B are item identifiers.
// -indexInItemTypeForIndexPath:{0, 0} would return 0.
// -indexInItemTypeForIndexPath:{0, 1} would return 0.
// -indexInItemTypeForIndexPath:{0, 3} would return 2.
- (NSUInteger)indexInItemTypeForIndexPath:(NSIndexPath*)indexPath;
#pragma mark Query items from index paths
// Returns whether there is an item at the given index path.
- (BOOL)hasItemAtIndexPath:(NSIndexPath*)indexPath;
// Returns the item at the given index path.
- (ObjectType)itemAtIndexPath:(NSIndexPath*)indexPath;
// Returns the header for the given |section|.
- (SupplementalType)headerForSection:(NSInteger)section;
// Returns the footer for the given |section|.
- (SupplementalType)footerForSection:(NSInteger)section;
// Returns an array of items in the section with the given identifier.
- (NSArray<ObjectType>*)itemsInSectionWithIdentifier:
(NSInteger)sectionIdentifier;
// Returns the header for the section with the given |sectionIdentifier|.
- (SupplementalType)headerForSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Returns the footer for the section with the given |sectionIdentifier|.
- (SupplementalType)footerForSectionWithIdentifier:(NSInteger)sectionIdentifier;
#pragma mark Query index paths from model coordinates
// Returns whether there is a section at the given section identifier.
- (BOOL)hasSectionForSectionIdentifier:(NSInteger)sectionIdentifier;
// Returns the index path's section for the given section identifier.
- (NSInteger)sectionForSectionIdentifier:(NSInteger)sectionIdentifier;
// Returns whether there is an item of type |itemType| at the given
// |sectionIdentifier|.
- (BOOL)hasItemForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier;
// Returns the index path for |itemType| in the section for
// |sectionIdentifier|. If there are multiple entries with the same item
// type, use -indexPathForItemType:sectionIdentifier:atIndex:.
- (NSIndexPath*)indexPathForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier;
// Returns whether there is an item of type |itemType| at the given
// |sectionIdentifier| and |index|.
- (BOOL)hasItemForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
// Returns the index path for |itemType| in the section for
// |sectionIdentifier| at |index|.
- (NSIndexPath*)indexPathForItemType:(NSInteger)itemType
sectionIdentifier:(NSInteger)sectionIdentifier
atIndex:(NSUInteger)index;
#pragma mark Query index paths from items
// Returns whether |item| exists in section for |sectionIdentifier|.
- (BOOL)hasItem:(ObjectType)item
inSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Returns whether |item| exists.
- (BOOL)hasItem:(ObjectType)item;
// Returns the index path corresponding to the given |item|.
- (NSIndexPath*)indexPathForItem:(ObjectType)item;
#pragma mark Data sourcing
// Returns the number of sections.
- (NSInteger)numberOfSections;
// Returns the number of items in the given section.
- (NSInteger)numberOfItemsInSection:(NSInteger)section;
@end
#endif // IOS_CHROME_BROWSER_UI_LIST_MODEL_LIST_MODEL_H_
This diff is collapsed.
......@@ -144,6 +144,7 @@ source_set("payments_ui") {
"//ios/chrome/browser/ui/collection_view",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/icons",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/material_components",
"//ios/chrome/browser/ui/payments/cells",
"//ios/third_party/material_components_ios",
......
......@@ -7,11 +7,11 @@
#include "base/mac/foundation_util.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/icons/chrome_icon.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/payments/cells/price_item.h"
#import "ios/chrome/browser/ui/payments/payment_items_display_view_controller_actions.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
......
......@@ -12,9 +12,9 @@
#import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/payments/cells/payments_selector_edit_item.h"
#import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
#import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller_actions.h"
......
......@@ -8,11 +8,11 @@
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/autofill/cells/status_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/icons/chrome_icon.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/payments/cells/payments_is_selectable.h"
#import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
#import "ios/chrome/browser/ui/payments/payment_request_selector_view_controller_actions.h"
......
......@@ -11,10 +11,10 @@
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/payments/cells/page_info_item.h"
#import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
#import "ios/chrome/browser/ui/payments/cells/price_item.h"
......
......@@ -96,6 +96,7 @@ source_set("reading_list_ui") {
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/favicon:favicon_ui",
"//ios/chrome/browser/ui/keyboard",
"//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/util",
"//ios/chrome/common",
"//ios/third_party/material_components_ios",
......
......@@ -10,9 +10,9 @@
#include "base/metrics/user_metrics_action.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collection_view_controller.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/list_model/list_item+Controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item_accessibility_delegate.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_data_sink.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_data_source.h"
......
......@@ -199,6 +199,7 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/ui/icons:unit_tests",
"//ios/chrome/browser/ui/infobars:unit_tests",
"//ios/chrome/browser/ui/keyboard:unit_tests",
"//ios/chrome/browser/ui/list_model:unit_tests",
"//ios/chrome/browser/ui/location_bar:unit_tests",
"//ios/chrome/browser/ui/main:unit_tests",
"//ios/chrome/browser/ui/main_content:unit_tests",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment