Skip to content

Commit

Permalink
Fixed downloading unsupported mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
mneuwert committed Nov 10, 2019
1 parent 9492130 commit d84b433
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 49 deletions.
5 changes: 2 additions & 3 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
4C464BF42187AF1500D30602 /* PDFSearchTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C464BEC2187AF1500D30602 /* PDFSearchTableViewCell.swift */; };
4C464BF52187AF1500D30602 /* PDFThumbnailsCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C464BED2187AF1500D30602 /* PDFThumbnailsCollectionViewController.swift */; };
4C464BF62187AF1500D30602 /* PDFTocItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C464BEE2187AF1500D30602 /* PDFTocItem.swift */; };
4C63F0E5231A91230088E8CA /* UIImageView+Thumbnails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C63F0E4231A91230088E8CA /* UIImageView+Thumbnails.swift */; };
4C51727D22DE04BD001BC97F /* ScheduledTaskExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C51727522DE04BD001BC97F /* ScheduledTaskExtension.swift */; };
4C51727E22DE04BD001BC97F /* BackgroundFetchUpdateTaskAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C51727622DE04BD001BC97F /* BackgroundFetchUpdateTaskAction.swift */; };
4C51727F22DE04BD001BC97F /* ScheduledTaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C51727722DE04BD001BC97F /* ScheduledTaskManager.swift */; };
4C63F0E5231A91230088E8CA /* UIImageView+Thumbnails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C63F0E4231A91230088E8CA /* UIImageView+Thumbnails.swift */; };
4C6B78102226B83300C5F3DB /* PhotoAlbumTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */; };
4C6B78122226B86300C5F3DB /* PhotoAlbumTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */; };
4C7295D8228C384E00FA4E68 /* LogFilesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7295D7228C384E00FA4E68 /* LogFilesViewController.swift */; };
Expand Down Expand Up @@ -672,10 +672,10 @@
4C464BEC2187AF1500D30602 /* PDFSearchTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFSearchTableViewCell.swift; sourceTree = "<group>"; };
4C464BED2187AF1500D30602 /* PDFThumbnailsCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFThumbnailsCollectionViewController.swift; sourceTree = "<group>"; };
4C464BEE2187AF1500D30602 /* PDFTocItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFTocItem.swift; sourceTree = "<group>"; };
4C63F0E4231A91230088E8CA /* UIImageView+Thumbnails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Thumbnails.swift"; sourceTree = "<group>"; };
4C51727522DE04BD001BC97F /* ScheduledTaskExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledTaskExtension.swift; sourceTree = "<group>"; };
4C51727622DE04BD001BC97F /* BackgroundFetchUpdateTaskAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackgroundFetchUpdateTaskAction.swift; sourceTree = "<group>"; };
4C51727722DE04BD001BC97F /* ScheduledTaskManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScheduledTaskManager.swift; sourceTree = "<group>"; };
4C63F0E4231A91230088E8CA /* UIImageView+Thumbnails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Thumbnails.swift"; sourceTree = "<group>"; };
4C6B780F2226B83300C5F3DB /* PhotoAlbumTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewController.swift; sourceTree = "<group>"; };
4C6B78112226B86300C5F3DB /* PhotoAlbumTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTableViewCell.swift; sourceTree = "<group>"; };
4C7295D7228C384E00FA4E68 /* LogFilesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogFilesViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1207,7 +1207,6 @@
children = (
3913214A22956D5700EF88F4 /* LibraryTableViewController.swift */,
DC29F09222976B9200F77349 /* LibrarySharesTableViewController.swift */,
DC29F09322976B9200F77349 /* LibraryFilesTableViewController.swift */,
DC33939E22E0A1A300DD3DA4 /* Item Policies */,
);
path = Library;
Expand Down
112 changes: 66 additions & 46 deletions ownCloud/Client/Viewer/DisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum DisplayViewState {
case noNetworkConnection
case downloading(progress: Progress)
case errorDownloading(error: Error?)
case downloadFinished
case canceledDownload
case notSupportedMimeType
}
Expand Down Expand Up @@ -80,15 +81,17 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
var source: URL? {
didSet {
OnMainThread(inline: true) {
self.iconImageView?.isHidden = true
self.hideItemMetadataUIElements()
self.renderSpecificView(completion: { (success) in
if !success {
self.iconImageView?.isHidden = false
self.infoLabel?.text = "File couldn't be opened".localized
self.infoLabel?.isHidden = false
}
})
if self.shallShowPreview == true {
self.iconImageView?.isHidden = true
self.hideItemMetadataUIElements()
self.renderSpecificView(completion: { (success) in
if !success {
self.iconImageView?.isHidden = false
self.infoLabel?.text = "File couldn't be opened".localized
self.infoLabel?.isHidden = false
}
})
}
}
}
}
Expand All @@ -97,24 +100,27 @@ class DisplayViewController: UIViewController, OCQueryDelegate {

var shallDisplayMoreButtonInToolbar = true

var shallShowPreview = true

private var state: DisplayViewState = .hasNetworkConnection {
didSet {
OnMainThread(inline: true) {
switch self.state {
case .downloading(let progress):
self.downloadProgress = progress

default:
self.downloadProgress = nil
}
self.render()
switch self.state {
case .downloading(let progress):
self.downloadProgress = progress
case .notSupportedMimeType:
shallShowPreview = false
default:
self.downloadProgress = nil
}
self.render()
}
}

public var downloadProgress : Progress? {
didSet {
progressView?.observedProgress = downloadProgress
OnMainThread(inline: true) {
self.progressView?.observedProgress = self.downloadProgress
}
}
}

Expand Down Expand Up @@ -289,6 +295,8 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
}
return
}
self?.state = .downloadFinished

self?.item = latestItem
self?.source = file?.url

Expand Down Expand Up @@ -316,33 +324,44 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
}

private func render() {
switch state {
case .hasNetworkConnection:
hideProgressIndicators()

case .noNetworkConnection:
self.progressView?.isHidden = true
self.cancelButton?.isHidden = true
self.infoLabel?.isHidden = false
self.showPreviewButton?.isHidden = true

case .errorDownloading, .canceledDownload:
if core?.connectionStatus == .online {
hideProgressIndicators()
}

case .downloading(_):
self.progressView?.isHidden = false
self.cancelButton?.isHidden = false
self.infoLabel?.isHidden = true
self.showPreviewButton?.isHidden = true
OnMainThread(inline: true) {
switch self.state {
case .hasNetworkConnection:
self.hideProgressIndicators()

case .noNetworkConnection:
self.progressView?.isHidden = true
self.cancelButton?.isHidden = true
self.infoLabel?.isHidden = false
self.showPreviewButton?.isHidden = true

case .errorDownloading, .canceledDownload:
if self.core?.connectionStatus == .online {
self.hideProgressIndicators()
}

case .notSupportedMimeType:
self.progressView?.isHidden = true
self.cancelButton?.isHidden = true
self.infoLabel?.isHidden = true
self.showPreviewButton?.isHidden = true
case .downloading(_):
self.progressView?.isHidden = false
self.cancelButton?.isHidden = false
self.infoLabel?.isHidden = true
self.showPreviewButton?.isHidden = true

case .notSupportedMimeType:
self.progressView?.isHidden = true
self.cancelButton?.isHidden = true
self.infoLabel?.isHidden = true

if let item = self.item {
if self.core?.localCopy(of:item) == nil {
self.showPreviewButton?.isHidden = false
self.showPreviewButton?.setTitle("Download".localized, for: .normal)
}
}

case .downloadFinished:
self.cancelButton?.isHidden = true
self.progressView?.isHidden = true
}
}
}

Expand Down Expand Up @@ -427,12 +446,13 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
return
}

self.item = item
metadataInfoLabel?.text = item.sizeLocalized + " - " + item.lastModifiedLocalized

switch state {
case .notSupportedMimeType: break

default:
self.item = item
metadataInfoLabel?.text = item.sizeLocalized + " - " + item.lastModifiedLocalized

Log.log("Presenting item (DisplayViewController.present): \(item.description)")

Expand Down

0 comments on commit d84b433

Please sign in to comment.