| Index: ios/chrome/browser/ui/reading_list/reading_list_mediator.mm
|
| diff --git a/ios/chrome/browser/ui/reading_list/reading_list_mediator.mm b/ios/chrome/browser/ui/reading_list/reading_list_mediator.mm
|
| index 815673078d6fcf1c4e19c3bebb716ff43f2dabec..6738d8df34530c9f560b41ac428d7b51d52ce1fb 100644
|
| --- a/ios/chrome/browser/ui/reading_list/reading_list_mediator.mm
|
| +++ b/ios/chrome/browser/ui/reading_list/reading_list_mediator.mm
|
| @@ -4,15 +4,27 @@
|
|
|
| #import "ios/chrome/browser/ui/reading_list/reading_list_mediator.h"
|
|
|
| +#include <algorithm>
|
| +
|
| #include "base/metrics/histogram_macros.h"
|
| +#include "base/strings/sys_string_conversions.h"
|
| #include "components/reading_list/core/reading_list_model.h"
|
| #import "components/reading_list/ios/reading_list_model_bridge_observer.h"
|
| +#include "components/url_formatter/url_formatter.h"
|
| +#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h"
|
| #import "ios/chrome/browser/ui/reading_list/reading_list_data_sink.h"
|
| +#import "ios/chrome/browser/ui/reading_list/reading_list_utils.h"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| +namespace {
|
| +bool EntrySorter(const ReadingListEntry* rhs, const ReadingListEntry* lhs) {
|
| + return rhs->UpdateTime() > lhs->UpdateTime();
|
| +}
|
| +} // namespace
|
| +
|
| @interface ReadingListMediator ()<ReadingListModelBridgeObserver> {
|
| std::unique_ptr<ReadingListModelBridge> _modelBridge;
|
| }
|
| @@ -51,10 +63,6 @@
|
| self.model->SetReadStatus(URL, read);
|
| }
|
|
|
| -- (const std::vector<GURL>)keys {
|
| - return self.model->Keys();
|
| -}
|
| -
|
| - (const ReadingListEntry*)entryWithURL:(const GURL&)URL {
|
| return self.model->GetEntryByURL(URL);
|
| }
|
| @@ -63,6 +71,36 @@
|
| self.model->RemoveEntryByURL(URL);
|
| }
|
|
|
| +- (void)fillReadItems:(NSMutableArray<ReadingListCollectionViewItem*>*)readArray
|
| + unreadItems:
|
| + (NSMutableArray<ReadingListCollectionViewItem*>*)unreadArray {
|
| + std::vector<const ReadingListEntry*> readEntries;
|
| + std::vector<const ReadingListEntry*> unreadEntries;
|
| +
|
| + for (const auto& url : self.model->Keys()) {
|
| + const ReadingListEntry* entry = self.model->GetEntryByURL(url);
|
| + DCHECK(entry);
|
| + if (entry->IsRead()) {
|
| + readEntries.push_back(entry);
|
| + } else {
|
| + unreadEntries.push_back(entry);
|
| + }
|
| + }
|
| +
|
| + std::sort(readEntries.begin(), readEntries.end(), EntrySorter);
|
| + std::sort(unreadEntries.begin(), unreadEntries.end(), EntrySorter);
|
| +
|
| + for (const ReadingListEntry* entry : readEntries) {
|
| + [readArray addObject:[self cellItemForReadingListEntry:entry]];
|
| + }
|
| +
|
| + for (const ReadingListEntry* entry : unreadEntries) {
|
| + [unreadArray addObject:[self cellItemForReadingListEntry:entry]];
|
| + }
|
| +
|
| + DCHECK(self.model->Keys().size() == [readArray count] + [unreadArray count]);
|
| +}
|
| +
|
| - (std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>)
|
| beginBatchUpdates {
|
| return self.model->BeginBatchUpdates();
|
| @@ -110,4 +148,38 @@
|
| [self.dataSink readingListModelCompletedBatchUpdates];
|
| }
|
|
|
| +#pragma mark - Private
|
| +
|
| +// Creates a ReadingListCollectionViewItem from a ReadingListEntry |entry|.
|
| +- (ReadingListCollectionViewItem*)cellItemForReadingListEntry:
|
| + (const ReadingListEntry*)entry {
|
| + const GURL& url = entry->URL();
|
| + ReadingListCollectionViewItem* item = [[ReadingListCollectionViewItem alloc]
|
| + initWithType:0
|
| + url:url
|
| + distillationState:reading_list::UIStatusFromModelStatus(
|
| + entry->DistilledState())];
|
| +
|
| + item.faviconPageURL =
|
| + entry->DistilledURL().is_valid() ? entry->DistilledURL() : url;
|
| +
|
| + BOOL has_distillation_details =
|
| + entry->DistilledState() == ReadingListEntry::PROCESSED &&
|
| + entry->DistillationSize() != 0 && entry->DistillationTime() != 0;
|
| + NSString* title = base::SysUTF8ToNSString(entry->Title());
|
| + if ([title length]) {
|
| + item.title = title;
|
| + } else {
|
| + item.title =
|
| + base::SysUTF16ToNSString(url_formatter::FormatUrl(url.GetOrigin()));
|
| + }
|
| + item.subtitle =
|
| + base::SysUTF16ToNSString(url_formatter::FormatUrl(url.GetOrigin()));
|
| + item.distillationDate =
|
| + has_distillation_details ? entry->DistillationTime() : 0;
|
| + item.distillationSize =
|
| + has_distillation_details ? entry->DistillationSize() : 0;
|
| + return item;
|
| +}
|
| +
|
| @end
|
|
|