mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-26 21:39:37 -04:00
bookmark editing
This commit is contained in:
parent
0601ae6e36
commit
b652259783
@ -11,20 +11,9 @@ import CoreData
|
||||
|
||||
class BookmarkCollectionController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, NSFetchedResultsControllerDelegate {
|
||||
|
||||
@IBOutlet weak var collectionView: UICollectionView!
|
||||
private(set) var itemWidth: CGFloat = 0.0
|
||||
private(set) var shouldReloadCollectionView = false
|
||||
@IBOutlet weak var collectionView: UICollectionView!
|
||||
@IBAction func removaAll(_ sender: UIBarButtonItem) {
|
||||
let context = AppDelegate.persistentContainer.viewContext
|
||||
context.perform {
|
||||
let fetchRequest = Article.fetchRequest() as! NSFetchRequest<Article>
|
||||
let articles = try? context.fetch(fetchRequest)
|
||||
articles?.forEach({ (article) in
|
||||
context.delete(article)
|
||||
})
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
|
||||
var book: Book? {
|
||||
didSet {
|
||||
@ -39,8 +28,13 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource
|
||||
return formatter
|
||||
}()
|
||||
|
||||
@IBAction func dismiss(_ sender: UIBarButtonItem) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||
super.setEditing(editing, animated: animated)
|
||||
if editing {
|
||||
navigationItem.rightBarButtonItems? = [doneButton, deleteButton]
|
||||
} else {
|
||||
navigationItem.rightBarButtonItems = [editButton]
|
||||
}
|
||||
}
|
||||
|
||||
func configureItemWidth(collectionViewWidth: CGFloat) {
|
||||
@ -48,10 +42,42 @@ class BookmarkCollectionController: UIViewController, UICollectionViewDataSource
|
||||
self.itemWidth = floor((collectionViewWidth - (itemsPerRow + 1) * 10) / itemsPerRow)
|
||||
}
|
||||
|
||||
// MARK: - UI Control
|
||||
|
||||
let editButton = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(editButtonTapped(sender:)))
|
||||
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonTapped(sender:)))
|
||||
let deleteButton = UIBarButtonItem(barButtonSystemItem: .trash, target: self, action: #selector(deleteButtonTapped(sender:)))
|
||||
|
||||
@IBAction func dismiss(_ sender: UIBarButtonItem) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func editButtonTapped(sender: UIBarButtonItem) {
|
||||
setEditing(true, animated: true)
|
||||
}
|
||||
|
||||
func doneButtonTapped(sender: UIBarButtonItem) {
|
||||
setEditing(false, animated: true)
|
||||
}
|
||||
|
||||
func deleteButtonTapped(sender: UIBarButtonItem) {
|
||||
let context = AppDelegate.persistentContainer.viewContext
|
||||
context.perform {
|
||||
let fetchRequest = Article.fetchRequest() as! NSFetchRequest<Article>
|
||||
let articles = try? context.fetch(fetchRequest)
|
||||
articles?.forEach({ (article) in
|
||||
context.delete(article)
|
||||
})
|
||||
try? context.save()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - override
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
title = "Bookmarks"
|
||||
navigationItem.rightBarButtonItems = [editButton]
|
||||
collectionView.alwaysBounceVertical = true
|
||||
|
||||
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
|
||||
|
@ -44,6 +44,7 @@ class MainController: UIViewController {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
guard traitCollection.horizontalSizeClass != previousTraitCollection?.horizontalSizeClass ||
|
||||
traitCollection.verticalSizeClass != previousTraitCollection?.verticalSizeClass else {return}
|
||||
|
||||
// buttons
|
||||
switch traitCollection.horizontalSizeClass {
|
||||
case .compact:
|
||||
|
@ -49,7 +49,7 @@
|
||||
</constraints>
|
||||
</imageView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="justified" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsLetterSpacingToFitWidth="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="LK0-aY-C9L">
|
||||
<rect key="frame" x="8" y="31" width="191" height="17"/>
|
||||
<rect key="frame" x="8" y="30" width="191" height="17"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
@ -95,7 +95,9 @@
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="9EM-Do-qfE" secondAttribute="trailing" id="0H3-5k-m0f"/>
|
||||
<constraint firstItem="LK0-aY-C9L" firstAttribute="top" secondItem="YA4-yb-hoI" secondAttribute="bottom" constant="1" id="95I-Gx-tc1"/>
|
||||
<constraint firstItem="LK0-aY-C9L" firstAttribute="top" secondItem="YA4-yb-hoI" secondAttribute="bottom" constant="1" id="95I-Gx-tc1">
|
||||
<variation key="widthClass=compact" constant="0.0"/>
|
||||
</constraint>
|
||||
<constraint firstItem="CQi-0M-O0e" firstAttribute="top" secondItem="9EM-Do-qfE" secondAttribute="bottom" constant="6" id="9jg-Ou-dzI"/>
|
||||
<constraint firstItem="Alw-Di-WEl" firstAttribute="leading" secondItem="CQi-0M-O0e" secondAttribute="trailing" constant="8" id="Eoq-GI-7la"/>
|
||||
<constraint firstItem="Alw-Di-WEl" firstAttribute="top" secondItem="9EM-Do-qfE" secondAttribute="bottom" constant="6" id="GkX-zd-iqc"/>
|
||||
@ -143,11 +145,6 @@
|
||||
<action selector="dismiss:" destination="mMM-mS-I3F" id="PkU-Qf-DQ9"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem key="rightBarButtonItem" systemItem="trash" id="ELs-vA-7OD">
|
||||
<connections>
|
||||
<action selector="removaAll:" destination="mMM-mS-I3F" id="LC1-Lp-IK5"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</navigationItem>
|
||||
<connections>
|
||||
<outlet property="collectionView" destination="Nlm-HS-W5q" id="nxj-xO-4Py"/>
|
||||
|
@ -136,6 +136,8 @@ class BookmarkCollectionCell: UICollectionViewCell {
|
||||
@IBOutlet weak var dividerView: UIView!
|
||||
@IBOutlet weak var bookTitleLabel: UILabel!
|
||||
@IBOutlet weak var bookmarkDetailLabel: UILabel!
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user