Download task controller

This commit is contained in:
Chris Li 2017-01-26 13:40:42 -05:00
parent f1fccd37fb
commit 8864dbbf44
6 changed files with 101 additions and 47 deletions

View File

@ -54,8 +54,8 @@ class LibraryBooksController: CoreDataCollectionBaseController, UICollectionView
} }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
configureItemWidth(collectionViewWidth: collectionView.frame.width) configureItemWidth(collectionViewWidth: size.width)
collectionView.collectionViewLayout.invalidateLayout() collectionView?.collectionViewLayout.invalidateLayout()
} }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

View File

@ -10,9 +10,12 @@ import UIKit
import CoreData import CoreData
class LibraryDownloadController: CoreDataTableBaseController, UITableViewDelegate, UITableViewDataSource { class LibraryDownloadController: CoreDataTableBaseController, UITableViewDelegate, UITableViewDataSource {
let progressFormatter = Progress()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
progressFormatter.kind = .file
} }
@IBAction func dismissButtonTapped(_ sender: UIBarButtonItem) { @IBAction func dismissButtonTapped(_ sender: UIBarButtonItem) {
@ -35,10 +38,18 @@ class LibraryDownloadController: CoreDataTableBaseController, UITableViewDelegat
} }
override func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) { override func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
guard let cell = cell as? DownloadTaskCell else {return}
let downloadTask = fetchedResultController.object(at: indexPath) let downloadTask = fetchedResultController.object(at: indexPath)
let book = downloadTask.book guard let book = downloadTask.book else {return}
cell.textLabel?.text = book?.title
cell.detailTextLabel?.text = "\(downloadTask.totalBytesWritten)" progressFormatter.completedUnitCount = downloadTask.totalBytesWritten
progressFormatter.totalUnitCount = book.fileSize
if let data = book.favIcon {cell.thumbImageView.image = UIImage(data: data)}
cell.titleLabel.text = book.title
cell.subtitleLabel.text = progressFormatter.localizedAdditionalDescription
cell.progressView.setProgress(Float(downloadTask.totalBytesWritten) / Float(book.fileSize), animated: true)
} }
// MARK: - NSFetchedResultsController // MARK: - NSFetchedResultsController

View File

@ -157,7 +157,7 @@
</barButtonItem> </barButtonItem>
</navigationItem> </navigationItem>
<connections> <connections>
<outlet property="collectionView" destination="UY0-46-c3y" id="lFH-jM-jh7"/> <outlet property="collectionView" destination="UY0-46-c3y" id="ki9-ID-J18"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="BWN-YP-64P" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="BWN-YP-64P" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -311,52 +311,74 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="VO0-cd-Axb"> <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="60" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="prU-fs-X0V">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="prU-fs-X0V"> <prototypes>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="56" id="3r6-eO-Iy1" customClass="DownloadTaskCell" customModule="Kiwix" customModuleProvider="target">
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <rect key="frame" x="0.0" y="28" width="375" height="56"/>
<prototypes> <autoresizingMask key="autoresizingMask"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" textLabel="0az-To-29T" detailTextLabel="P8A-Na-1yb" style="IBUITableViewCellStyleValue1" id="3r6-eO-Iy1"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="3r6-eO-Iy1" id="nVN-8L-w1D">
<rect key="frame" x="0.0" y="28" width="375" height="44"/> <rect key="frame" x="0.0" y="0.0" width="375" height="55.5"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="3r6-eO-Iy1" id="nVN-8L-w1D"> <subviews>
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="GhC-S8-4Ak">
<autoresizingMask key="autoresizingMask"/> <rect key="frame" x="8" y="6" width="44" height="44"/>
<subviews> <constraints>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="0az-To-29T"> <constraint firstAttribute="height" constant="44" id="pvZ-WG-KsC"/>
<rect key="frame" x="15" y="12" width="33.5" height="20.5"/> <constraint firstAttribute="width" constant="44" id="sD0-cc-kIz"/>
<autoresizingMask key="autoresizingMask"/> </constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/> </imageView>
<nil key="textColor"/> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zkf-Od-qYs">
<nil key="highlightedColor"/> <rect key="frame" x="60" y="8" width="307" height="21"/>
</label> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="P8A-Na-1yb"> <nil key="textColor"/>
<rect key="frame" x="316" y="12" width="44" height="20.5"/> <nil key="highlightedColor"/>
<autoresizingMask key="autoresizingMask"/> </label>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="bDK-ON-vzl">
<nil key="textColor"/> <rect key="frame" x="60" y="31" width="307" height="2"/>
<nil key="highlightedColor"/> </progressView>
</label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kV6-Lt-E6s">
</subviews> <rect key="frame" x="60" y="35" width="307" height="15"/>
</tableViewCellContentView> <fontDescription key="fontDescription" type="system" pointSize="12"/>
</tableViewCell> <nil key="textColor"/>
</prototypes> <nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="GhC-S8-4Ak" firstAttribute="centerY" secondItem="nVN-8L-w1D" secondAttribute="centerY" id="1HQ-Ka-V5B"/>
<constraint firstItem="kV6-Lt-E6s" firstAttribute="top" secondItem="bDK-ON-vzl" secondAttribute="bottom" constant="2" id="BCZ-fO-oVq"/>
<constraint firstAttribute="leadingMargin" secondItem="GhC-S8-4Ak" secondAttribute="leading" id="KJW-gj-p94"/>
<constraint firstItem="kV6-Lt-E6s" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="MH1-8I-9h5"/>
<constraint firstItem="bDK-ON-vzl" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="Nq4-pU-ACR"/>
<constraint firstAttribute="trailingMargin" secondItem="Zkf-Od-qYs" secondAttribute="trailing" id="Pef-Qp-ZN1"/>
<constraint firstAttribute="topMargin" secondItem="Zkf-Od-qYs" secondAttribute="top" id="dBr-yy-eSZ"/>
<constraint firstAttribute="trailingMargin" secondItem="bDK-ON-vzl" secondAttribute="trailing" id="giD-gR-Qou"/>
<constraint firstAttribute="trailingMargin" secondItem="kV6-Lt-E6s" secondAttribute="trailing" id="lFV-oP-iqa"/>
<constraint firstItem="Zkf-Od-qYs" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="pm3-kg-EYD"/>
<constraint firstItem="bDK-ON-vzl" firstAttribute="top" secondItem="Zkf-Od-qYs" secondAttribute="bottom" constant="2" id="rV9-Mq-ksX"/>
</constraints>
</tableViewCellContentView>
<connections> <connections>
<outlet property="dataSource" destination="n7s-WF-MFQ" id="rNc-cd-1e8"/> <outlet property="progressView" destination="bDK-ON-vzl" id="K0z-pr-4pw"/>
<outlet property="delegate" destination="n7s-WF-MFQ" id="Q8f-t7-tCe"/> <outlet property="subtitleLabel" destination="kV6-Lt-E6s" id="LPp-11-o1V"/>
<outlet property="thumbImageView" destination="GhC-S8-4Ak" id="5Yy-Zz-Ona"/>
<outlet property="titleLabel" destination="Zkf-Od-qYs" id="NYe-GC-sBA"/>
</connections> </connections>
</tableView> </tableViewCell>
</subviews> </prototypes>
</stackView> <connections>
<outlet property="dataSource" destination="n7s-WF-MFQ" id="rNc-cd-1e8"/>
<outlet property="delegate" destination="n7s-WF-MFQ" id="Q8f-t7-tCe"/>
</connections>
</tableView>
</subviews> </subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints> <constraints>
<constraint firstItem="VO0-cd-Axb" firstAttribute="top" secondItem="MOG-eQ-eA6" secondAttribute="top" id="DDC-YV-D2a"/> <constraint firstItem="prU-fs-X0V" firstAttribute="top" secondItem="MOG-eQ-eA6" secondAttribute="top" id="BM7-3Z-ME9"/>
<constraint firstAttribute="trailing" secondItem="VO0-cd-Axb" secondAttribute="trailing" id="LZE-Nv-V5P"/> <constraint firstItem="1HO-0f-jcI" firstAttribute="top" secondItem="prU-fs-X0V" secondAttribute="bottom" id="I9g-RI-2Eg"/>
<constraint firstItem="1HO-0f-jcI" firstAttribute="top" secondItem="VO0-cd-Axb" secondAttribute="bottom" id="pSr-O1-OGq"/> <constraint firstAttribute="trailing" secondItem="prU-fs-X0V" secondAttribute="trailing" id="fba-Df-RTs"/>
<constraint firstItem="VO0-cd-Axb" firstAttribute="leading" secondItem="MOG-eQ-eA6" secondAttribute="leading" id="w9u-si-WcW"/> <constraint firstItem="prU-fs-X0V" firstAttribute="leading" secondItem="MOG-eQ-eA6" secondAttribute="leading" id="s9z-jW-Sud"/>
</constraints> </constraints>
</view> </view>
<navigationItem key="navigationItem" id="nXq-yo-F6Y"> <navigationItem key="navigationItem" id="nXq-yo-F6Y">
@ -372,7 +394,7 @@
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Rra-HQ-Ajz" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="Rra-HQ-Ajz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="-174" y="-658"/> <point key="canvasLocation" x="-175.19999999999999" y="-658.02098950524737"/>
</scene> </scene>
</scenes> </scenes>
<resources> <resources>

View File

@ -175,6 +175,7 @@ class LibraryCollectionHeader: UICollectionReusableView {
// MARK: - last time refactor // MARK: - last time refactor
// MARK: - Bookmark Cell // MARK: - Bookmark Cell

View File

@ -0,0 +1,16 @@
//
// LibraryCells.swift
// Kiwix
//
// Created by Chris Li on 1/26/17.
// Copyright © 2017 Chris Li. All rights reserved.
//
import UIKit
class DownloadTaskCell: UITableViewCell {
@IBOutlet weak var thumbImageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var progressView: UIProgressView!
}

View File

@ -76,6 +76,7 @@
9779C31E1D4575AE0064CC8E /* Bookmarks.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 9779C3131D4575AD0064CC8E /* Bookmarks.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 9779C31E1D4575AE0064CC8E /* Bookmarks.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 9779C3131D4575AD0064CC8E /* Bookmarks.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
977A458C1E14EA140089C596 /* Cloud.swift in Sources */ = {isa = PBXBuildFile; fileRef = 977A458B1E14EA140089C596 /* Cloud.swift */; }; 977A458C1E14EA140089C596 /* Cloud.swift in Sources */ = {isa = PBXBuildFile; fileRef = 977A458B1E14EA140089C596 /* Cloud.swift */; };
977AE7F91DD8F22400F1E581 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A102A1D022AD5007FC62C /* SearchBar.swift */; }; 977AE7F91DD8F22400F1E581 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A102A1D022AD5007FC62C /* SearchBar.swift */; };
977B121C1E3A5E8D00981890 /* LibraryCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 977B121B1E3A5E8D00981890 /* LibraryCells.swift */; };
977B954D1DD4C40400F6F62B /* ScanLocalBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */; }; 977B954D1DD4C40400F6F62B /* ScanLocalBook.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */; };
97A08C151DD263B90070D0E4 /* Book.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D681341D6F711A00E5FA99 /* Book.swift */; }; 97A08C151DD263B90070D0E4 /* Book.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D681341D6F711A00E5FA99 /* Book.swift */; };
97A127C91D777CF100FB204D /* RecentSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A127C51D777CF100FB204D /* RecentSearchController.swift */; }; 97A127C91D777CF100FB204D /* RecentSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A127C51D777CF100FB204D /* RecentSearchController.swift */; };
@ -236,6 +237,7 @@
9779C3161D4575AE0064CC8E /* TodayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewController.swift; sourceTree = "<group>"; }; 9779C3161D4575AE0064CC8E /* TodayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewController.swift; sourceTree = "<group>"; };
9779C31B1D4575AE0064CC8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9779C31B1D4575AE0064CC8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
977A458B1E14EA140089C596 /* Cloud.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cloud.swift; sourceTree = "<group>"; }; 977A458B1E14EA140089C596 /* Cloud.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cloud.swift; sourceTree = "<group>"; };
977B121B1E3A5E8D00981890 /* LibraryCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryCells.swift; sourceTree = "<group>"; };
9788419C1DA2FF2A00D22D3C /* MainInterface.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MainInterface.storyboard; sourceTree = "<group>"; }; 9788419C1DA2FF2A00D22D3C /* MainInterface.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MainInterface.storyboard; sourceTree = "<group>"; };
97A127C51D777CF100FB204D /* RecentSearchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentSearchController.swift; sourceTree = "<group>"; }; 97A127C51D777CF100FB204D /* RecentSearchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentSearchController.swift; sourceTree = "<group>"; };
97A127C61D777CF100FB204D /* SearchScopeAndHistoryController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchScopeAndHistoryController.swift; sourceTree = "<group>"; }; 97A127C61D777CF100FB204D /* SearchScopeAndHistoryController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchScopeAndHistoryController.swift; sourceTree = "<group>"; };
@ -442,6 +444,7 @@
children = ( children = (
971A10241D022AD5007FC62C /* BarButtonItems.swift */, 971A10241D022AD5007FC62C /* BarButtonItems.swift */,
971A10261D022AD5007FC62C /* Cells.swift */, 971A10261D022AD5007FC62C /* Cells.swift */,
977B121B1E3A5E8D00981890 /* LibraryCells.swift */,
971A10271D022AD5007FC62C /* Logo.swift */, 971A10271D022AD5007FC62C /* Logo.swift */,
9764CBD01D806AD800072D6A /* RefreshLibControl.swift */, 9764CBD01D806AD800072D6A /* RefreshLibControl.swift */,
971A102A1D022AD5007FC62C /* SearchBar.swift */, 971A102A1D022AD5007FC62C /* SearchBar.swift */,
@ -1087,6 +1090,7 @@
972F81571DDBFC79008D7289 /* Search.swift in Sources */, 972F81571DDBFC79008D7289 /* Search.swift in Sources */,
970E7F831DA0305000741290 /* WelcomeController.swift in Sources */, 970E7F831DA0305000741290 /* WelcomeController.swift in Sources */,
97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */, 97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */,
977B121C1E3A5E8D00981890 /* LibraryCells.swift in Sources */,
970E7F741D9DB0FC00741290 /* 1.8.xcmappingmodel in Sources */, 970E7F741D9DB0FC00741290 /* 1.8.xcmappingmodel in Sources */,
977A458C1E14EA140089C596 /* Cloud.swift in Sources */, 977A458C1E14EA140089C596 /* Cloud.swift in Sources */,
97599AA21E26D3B000BA15EF /* BookmarkBooksController.swift in Sources */, 97599AA21E26D3B000BA15EF /* BookmarkBooksController.swift in Sources */,