mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 05:49:25 -04:00
Detail Controller Center text cell
This commit is contained in:
parent
40cb59cc56
commit
1486353e96
@ -9,7 +9,7 @@
|
||||
import UIKit
|
||||
import DZNEmptyDataSet
|
||||
|
||||
class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
|
||||
@IBOutlet weak var favIconImageView: UIImageView!
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
@ -123,44 +123,7 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN
|
||||
cellTitles[1] = book.spaceState == .NotEnough ? [Strings.spaceNotEnough] : [Strings.downloadNow]
|
||||
}
|
||||
} else {
|
||||
cellTitles[1] = ["Cancel Download"]
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Delegates
|
||||
|
||||
func buttonTapped(cell: CenterButtonCell) {
|
||||
|
||||
guard let title = cell.button.titleLabel?.text,
|
||||
let book = book else {return}
|
||||
|
||||
switch title {
|
||||
case Strings.downloadNow:
|
||||
func startDownload() {
|
||||
guard let download = DownloadBookOperation(bookID: book.id) else {return}
|
||||
Network.shared.queue.addOperation(download)
|
||||
}
|
||||
|
||||
if book.spaceState == .Caution {
|
||||
let cancel = UIAlertAction(title: Strings.cancel, style: .Cancel, handler: nil)
|
||||
let download = UIAlertAction(title: Strings.SpaceAlert.downloadAnyway, style: .Destructive, handler: { (alert) in
|
||||
startDownload()
|
||||
})
|
||||
let alertController = UIAlertController(title: Strings.SpaceAlert.spaceAlert, message: Strings.SpaceAlert.message, preferredStyle: .Alert)
|
||||
[download, cancel].forEach({ alertController.addAction($0) })
|
||||
presentViewController(alertController, animated: true, completion: nil)
|
||||
} else {
|
||||
startDownload()
|
||||
}
|
||||
case Strings.copyURL:
|
||||
guard let url = book.url else {return}
|
||||
UIPasteboard.generalPasteboard().string = url.absoluteString
|
||||
let action = UIAlertAction(title: LocalizedStrings.Common.ok, style: .Cancel, handler: nil)
|
||||
let alertController = UIAlertController(title: Strings.CopyURLAlert.succeed, message: nil, preferredStyle: .Alert)
|
||||
alertController.addAction(action)
|
||||
presentViewController(alertController, animated: true, completion: nil)
|
||||
default:
|
||||
return
|
||||
cellTitles[1] = [Strings.cancel]
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,18 +140,19 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN
|
||||
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
||||
let title = cellTitles[indexPath.section][indexPath.row]
|
||||
switch title {
|
||||
case Strings.downloadNow, Strings.spaceNotEnough, Strings.remove:
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("CenterButtonCell", forIndexPath: indexPath) as! CenterButtonCell
|
||||
cell.button.setTitle(title, forState: .Normal)
|
||||
cell.delegate = self
|
||||
case Strings.downloadNow, Strings.spaceNotEnough, Strings.cancel, Strings.remove:
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath)
|
||||
cell.textLabel?.text = title
|
||||
|
||||
switch title {
|
||||
case Strings.downloadNow:
|
||||
if book?.spaceState == .Caution {cell.textLabel?.textColor = UIColor.orangeColor()}
|
||||
case Strings.spaceNotEnough:
|
||||
cell.button.tintColor = UIColor.grayColor()
|
||||
case Strings.remove:
|
||||
cell.button.tintColor = UIColor.redColor()
|
||||
cell.textLabel?.textColor = UIColor.grayColor()
|
||||
case Strings.cancel, Strings.remove:
|
||||
cell.textLabel?.textColor = UIColor.redColor()
|
||||
default:
|
||||
if book?.spaceState == .Caution { cell.button.tintColor = UIColor.orangeColor() }
|
||||
break
|
||||
}
|
||||
return cell
|
||||
case Strings.pid:
|
||||
@ -196,9 +160,8 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN
|
||||
cell.textLabel?.text = book?.pid
|
||||
return cell
|
||||
case Strings.copyURL:
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("CenterButtonCell", forIndexPath: indexPath) as! CenterButtonCell
|
||||
cell.button.setTitle(title, forState: .Normal)
|
||||
cell.delegate = self
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("CenterTextCell", forIndexPath: indexPath)
|
||||
cell.textLabel?.text = title
|
||||
return cell
|
||||
default:
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier("RightDetailCell", forIndexPath: indexPath)
|
||||
@ -231,10 +194,48 @@ class BookDetailController: UITableViewController, CenterButtonCellDelegate, DZN
|
||||
return sectionFooters[section]
|
||||
}
|
||||
|
||||
// MARK: - Table view delegate
|
||||
|
||||
override func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
|
||||
guard let view = view as? UITableViewHeaderFooterView where section == 0 else {return}
|
||||
view.textLabel?.textAlignment = .Center
|
||||
}
|
||||
|
||||
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||
guard let cell = tableView.cellForRowAtIndexPath(indexPath),
|
||||
let title = cell.textLabel?.text,
|
||||
let book = book else {return}
|
||||
switch title {
|
||||
case Strings.downloadNow:
|
||||
func startDownload() {
|
||||
guard let download = DownloadBookOperation(bookID: book.id) else {return}
|
||||
Network.shared.queue.addOperation(download)
|
||||
}
|
||||
|
||||
if book.spaceState == .Caution {
|
||||
let cancel = UIAlertAction(title: Strings.cancel, style: .Cancel, handler: nil)
|
||||
let download = UIAlertAction(title: Strings.SpaceAlert.downloadAnyway, style: .Destructive, handler: { (alert) in
|
||||
startDownload()
|
||||
})
|
||||
let alertController = UIAlertController(title: Strings.SpaceAlert.spaceAlert, message: Strings.SpaceAlert.message, preferredStyle: .Alert)
|
||||
[download, cancel].forEach({ alertController.addAction($0) })
|
||||
presentViewController(alertController, animated: true, completion: nil)
|
||||
} else {
|
||||
startDownload()
|
||||
}
|
||||
|
||||
case Strings.copyURL:
|
||||
guard let url = book.url else {return}
|
||||
UIPasteboard.generalPasteboard().string = url.absoluteString
|
||||
let action = UIAlertAction(title: LocalizedStrings.Common.ok, style: .Cancel, handler: nil)
|
||||
let alertController = UIAlertController(title: Strings.CopyURLAlert.succeed, message: nil, preferredStyle: .Alert)
|
||||
alertController.addAction(action)
|
||||
presentViewController(alertController, animated: true, completion: nil)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension LocalizedStrings {
|
||||
|
@ -193,7 +193,6 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
|
||||
}
|
||||
actions.insert(pause, atIndex: 0)
|
||||
case .Paused:
|
||||
|
||||
if let book = downloadTask.book,
|
||||
let resumeData = Preference.resumeData[book.id] {
|
||||
let resume = UITableViewRowAction(style: .Normal, title: "Resume") { (action, indexPath) in
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.434</string>
|
||||
<string>1.8.454</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A319" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="niz-KF-P8W">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A322" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="niz-KF-P8W">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
|
||||
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
|
||||
@ -260,30 +260,22 @@
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CenterButtonCell" id="B0D-Hu-sVM" customClass="CenterButtonCell" customModule="Kiwix" customModuleProvider="target">
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CenterTextCell" textLabel="v12-N8-GHE" style="IBUITableViewCellStyleDefault" id="B0D-Hu-sVM">
|
||||
<rect key="frame" x="0.0" y="273" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="B0D-Hu-sVM" id="Fhf-jb-Urf">
|
||||
<frame key="frameInset" width="375" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TLs-eg-B0R">
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="v12-N8-GHE">
|
||||
<frame key="frameInset" minX="15" width="345" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
|
||||
<state key="normal" title="Button"/>
|
||||
<connections>
|
||||
<action selector="buttonTapped:" destination="B0D-Hu-sVM" eventType="touchUpInside" id="VcU-sI-csn"/>
|
||||
</connections>
|
||||
</button>
|
||||
<color key="textColor" red="0.0" green="0.4793452024" blue="0.99908632040000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottomMargin" secondItem="TLs-eg-B0R" secondAttribute="bottom" id="0Am-c4-o6J"/>
|
||||
<constraint firstItem="TLs-eg-B0R" firstAttribute="centerX" secondItem="Fhf-jb-Urf" secondAttribute="centerX" id="jDi-3Z-ZSt"/>
|
||||
<constraint firstItem="TLs-eg-B0R" firstAttribute="top" secondItem="Fhf-jb-Urf" secondAttribute="topMargin" id="pp5-Yz-bo4"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="button" destination="TLs-eg-B0R" id="EPX-7c-BLO"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="TextSwitchCell" id="c4v-9p-eEF" customClass="TextSwitchCell" customModule="Kiwix" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="317" width="375" height="44"/>
|
||||
@ -366,10 +358,10 @@
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="82" id="ekT-ed-PU9" customClass="DownloadBookCell" customModule="Kiwix" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="92" width="600" height="82"/>
|
||||
<rect key="frame" x="0.0" y="92" width="375" height="82"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ekT-ed-PU9" id="oM4-Hy-Mkf">
|
||||
<frame key="frameInset" width="600" height="81"/>
|
||||
<frame key="frameInset" width="375" height="81"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" minimumFontSize="8" adjustsLetterSpacingToFitWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hji-3G-yaJ">
|
||||
|
@ -123,16 +123,3 @@ class TextSwitchCell: UITableViewCell {
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
@IBOutlet weak var switchControl: UISwitch!
|
||||
}
|
||||
|
||||
class CenterButtonCell: UITableViewCell {
|
||||
weak var delegate: CenterButtonCellDelegate?
|
||||
@IBOutlet weak var button: UIButton!
|
||||
|
||||
@IBAction func buttonTapped(sender: UIButton) {
|
||||
delegate?.buttonTapped(self)
|
||||
}
|
||||
}
|
||||
|
||||
protocol CenterButtonCellDelegate: class {
|
||||
func buttonTapped(cell: CenterButtonCell)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.437</string>
|
||||
<string>1.8.457</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -19,21 +19,5 @@
|
||||
landmarkType = "5">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Kiwix-iOS/Controller/Library/BookDetailController.swift"
|
||||
timestampString = "495576550.917968"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "119"
|
||||
endingLineNumber = "119"
|
||||
landmarkName = "configureActionSection(book:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
@ -31,6 +31,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
|
||||
|
||||
let downloadTask = DownloadTask.addOrUpdate(book, context: context)
|
||||
downloadTask?.state = .Queued
|
||||
book.isLocal = nil
|
||||
|
||||
progress.completedUnitCount = book.downloadTask?.totalBytesWritten ?? 0
|
||||
progress.totalUnitCount = book.fileSize
|
||||
|
Loading…
x
Reference in New Issue
Block a user