Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
TargetAttributes = {
1A42C2881C0E3882000F2137 = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = 32F2T8EJ6G;
DevelopmentTeam = C3VKVFB3SA;
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
SystemCapabilities = {
Expand Down Expand Up @@ -1008,7 +1008,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
DEVELOPMENT_TEAM = C3VKVFB3SA;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.Example;
Expand All @@ -1025,7 +1025,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
DEVELOPMENT_TEAM = C3VKVFB3SA;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.Example;
Expand Down
95 changes: 95 additions & 0 deletions Source/FolioReaderBookmarkList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// FolioReaderBookmarkList.swift
// FolioReaderKit
//
// Created by Omar Albeik on 26.03.2018.
//

import UIKit

class FolioReaderBookmarkList: UITableViewController {

fileprivate var bookmarks = [Bookmark]()
fileprivate var readerConfig: FolioReaderConfig
fileprivate var folioReader: FolioReader

init(folioReader: FolioReader, readerConfig: FolioReaderConfig) {
self.readerConfig = readerConfig
self.folioReader = folioReader

super.init(style: UITableViewStyle.plain)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init with coder not supported")
}

override func viewDidLoad() {
super.viewDidLoad()

self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: kReuseCellIdentifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove all unnecessary self?

self.tableView.separatorInset = UIEdgeInsets.zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove UIEdgeInsets?
tableView.separatorInset = .zero

self.tableView.backgroundColor = self.folioReader.isNight(self.readerConfig.nightModeMenuBackground, self.readerConfig.menuBackgroundColor)
self.tableView.separatorColor = self.folioReader.isNight(self.readerConfig.nightModeSeparatorColor, self.readerConfig.menuSeparatorColor)

guard let bookId = (self.folioReader.readerContainer?.book.name as NSString?)?.deletingPathExtension else {
self.bookmarks = []
return
}

self.bookmarks = Bookmark.allByBookId(withConfiguration: self.readerConfig, bookId: bookId)
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could remove this method

return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return bookmarks.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: kReuseCellIdentifier, for: indexPath)
cell.backgroundColor = UIColor.clear
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove UIColor?
cell.backgroundColor = .clear


let bookmark = bookmarks[(indexPath as NSIndexPath).row]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why (indexPath as NSIndexPath)?


// Format date
let dateFormatter = DateFormatter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you turn it into a lazy var?

private lazy var dateFormatter: DateFormatter = {
   let dateFormatter = DateFormatter()
   dateFormatter.dateFormat = self.readerConfig.localizedHighlightsDateFormat
   return dateFormatter
}()

dateFormatter.dateFormat = self.readerConfig.localizedHighlightsDateFormat
let dateString = dateFormatter.string(from: bookmark.date)

cell.textLabel?.text = "Page \(bookmark.page)"
cell.detailTextLabel?.text = dateString

return cell
}

// MARK: - Table view delegate

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let bookmark = bookmarks[safe: (indexPath as NSIndexPath).row] else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is (indexPath as NSIndexPath) really necessary?

return
}

self.folioReader.readerCenter?.changePageWith(page: bookmark.page, andFragment: bookmark.bookmarkId)
self.dismiss()
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let bookmark = bookmarks[(indexPath as NSIndexPath).row]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again..

bookmark.remove(withConfiguration: self.readerConfig) // Remove from Database
bookmarks.remove(at: (indexPath as NSIndexPath).row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}

// MARK: - Handle rotation transition

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
tableView.reloadData()
}
}
Loading