Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Add bookmarks #328

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -376,7 +376,7 @@
TargetAttributes = {
1A42C2881C0E3882000F2137 = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = 32F2T8EJ6G;
DevelopmentTeam = C3VKVFB3SA;
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
SystemCapabilities = {
Expand Down Expand Up @@ -944,7 +944,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 @@ -961,7 +961,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
92 changes: 92 additions & 0 deletions Source/FolioReaderBookmarkList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// FolioReaderBookmarkList.swift
// FolioReaderKit
//
// Created by Omar Albeik on 26.03.2018.
// Copyright (c) 2015 Folio Reader. All rights reserved.
//

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()

tableView.register(UITableViewCell.self, forCellReuseIdentifier: kReuseCellIdentifier)
tableView.separatorInset = UIEdgeInsets.zero
tableView.backgroundColor = folioReader.isNight(readerConfig.nightModeMenuBackground, readerConfig.menuBackgroundColor)
tableView.separatorColor = folioReader.isNight(readerConfig.nightModeSeparatorColor, readerConfig.menuSeparatorColor)

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

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

// MARK: - Table view data source

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 = .clear

let bookmark = bookmarks[indexPath.row]

// Format date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = 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.row] else {
return
}

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

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let bookmark = bookmarks[indexPath.row]
bookmark.remove(withConfiguration: readerConfig) // Remove from Database
bookmarks.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}

// MARK: - Handle rotation transition

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