From c0443cd506998d3366bc2c4c44b7b53c8d8ea50d Mon Sep 17 00:00:00 2001 From: Chris Li Date: Tue, 17 Jan 2017 13:11:53 -0500 Subject: [PATCH] bookmark Collection view --- .../Dots.imageset/Contents.json | 21 ++++++++ .../Assets.xcassets/Dots.imageset/more-2.png | Bin 0 -> 479 bytes .../BookmarkCollectionController.swift | 12 ++++- Kiwix-iOS/Controller/Main/MainDelegates.swift | 1 + Kiwix-iOS/Storyboard/Bookmark.storyboard | 48 ++++++++++++------ Kiwix-iOS/View/Cells.swift | 6 +++ 6 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 Kiwix-iOS/Assets.xcassets/Dots.imageset/Contents.json create mode 100644 Kiwix-iOS/Assets.xcassets/Dots.imageset/more-2.png diff --git a/Kiwix-iOS/Assets.xcassets/Dots.imageset/Contents.json b/Kiwix-iOS/Assets.xcassets/Dots.imageset/Contents.json new file mode 100644 index 00000000..1dd8ef56 --- /dev/null +++ b/Kiwix-iOS/Assets.xcassets/Dots.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "more-2.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Kiwix-iOS/Assets.xcassets/Dots.imageset/more-2.png b/Kiwix-iOS/Assets.xcassets/Dots.imageset/more-2.png new file mode 100644 index 0000000000000000000000000000000000000000..106baee98e31710d659a8aaa383c7e084d550507 GIT binary patch literal 479 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!n2Vh}LpV4%Za?&Y0OWEOctjR6 zFfi^0VMePrj~@XAB}-f*N`mv#O3D+9QW?t2%k?tzvWt@w3sUv+i_&MmvylQSN(=A_ zasB`Qzj4}shpboDWv`vHKRM*SwaR{Pm-osh@3l?-E8E=HHaV~Dv)|h0ytK=E0~EB) zd2I(4w9R>ClMCd&vCVr8lme1K#kRRXEpNaK2p3B3nKeHYXrp3DkY6wZD-W-*jJ&F` zjlF|waC}-uaeZ6Qr0J_RZ{Kg~mcv@^ z*^@7Lzvh0iy<_W!Yn$iFf4b#YmdKI;Vst09-!LGynhq literal 0 HcmV?d00001 diff --git a/Kiwix-iOS/Controller/Bookmark/BookmarkCollectionController.swift b/Kiwix-iOS/Controller/Bookmark/BookmarkCollectionController.swift index b815c180..0fc2da89 100644 --- a/Kiwix-iOS/Controller/Bookmark/BookmarkCollectionController.swift +++ b/Kiwix-iOS/Controller/Bookmark/BookmarkCollectionController.swift @@ -32,6 +32,13 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource } } + let dateFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .medium + formatter.timeStyle = .short + return formatter + }() + @IBAction func dismiss(_ sender: UIBarButtonItem) { dismiss(animated: true, completion: nil) } @@ -80,6 +87,8 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource if let data = article.thumbImageData { cell.thumbImageView.image = UIImage(data: data) } + cell.bookTitleLabel.text = article.book?.title + if let date = article.bookmarkDate {cell.bookmarkDetailLabel.text = dateFormatter.string(from: date)} return cell } @@ -104,8 +113,7 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource let managedObjectContext = AppDelegate.persistentContainer.viewContext lazy var fetchedResultController: NSFetchedResultsController
= { let fetchRequest = Article.fetchRequest() - let titleDescriptor = NSSortDescriptor(key: "title", ascending: true) - fetchRequest.sortDescriptors = [titleDescriptor] + fetchRequest.sortDescriptors = [NSSortDescriptor(key: "bookmarkDate", ascending: false)] var predicates = [NSPredicate]() predicates.append(NSPredicate(format: "isBookmarked = true")) if let book = self.book { predicates.append(NSPredicate(format: "book == %@", book)) } diff --git a/Kiwix-iOS/Controller/Main/MainDelegates.swift b/Kiwix-iOS/Controller/Main/MainDelegates.swift index 7b1a3b43..b09ed670 100644 --- a/Kiwix-iOS/Controller/Main/MainDelegates.swift +++ b/Kiwix-iOS/Controller/Main/MainDelegates.swift @@ -203,6 +203,7 @@ extension MainController: ButtonDelegates { guard let url = webView.request?.url, let article = Article.fetch(url: url, context: context) else {return} article.isBookmarked = !article.isBookmarked + if article.isBookmarked {article.bookmarkDate = Date()} if context.hasChanges {try? context.save()} diff --git a/Kiwix-iOS/Storyboard/Bookmark.storyboard b/Kiwix-iOS/Storyboard/Bookmark.storyboard index 22b59c9c..3f927e08 100644 --- a/Kiwix-iOS/Storyboard/Bookmark.storyboard +++ b/Kiwix-iOS/Storyboard/Bookmark.storyboard @@ -48,60 +48,75 @@ -