Skip to content

Commit

Permalink
- Avoid showing download progress indicator when viewing files that a…
Browse files Browse the repository at this point in the history
…re already downloaded (issue (46) in #237)

- Fix bug in PDFViewerViewController where CoreGraphics would throw an error when using pdfView with zero size (before properly laying it out)
  • Loading branch information
felix-schwarz committed Apr 25, 2019
1 parent b4676e1 commit 14dbecb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ownCloud.xcodeproj/xcshareddata/xcschemes/ownCloud.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "CG_NUMERICS_SHOW_BACKTRACE"
value = "1"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "oc:app.show-beta-warning"
value = "false"
Expand Down
9 changes: 8 additions & 1 deletion ownCloud/Tools/DispatchQueueTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

import Foundation

func OnMainThread(async: Bool = true, after: TimeInterval? = nil, _ block: @escaping () -> Void) {
func OnMainThread(async: Bool = true, after: TimeInterval? = nil, inline: Bool = false, _ block: @escaping () -> Void) {
if inline {
if Thread.isMainThread {
block()
return
}
}

if let after = after {
DispatchQueue.main.asyncAfter(deadline: .now() + after, execute: block)
} else {
Expand Down
12 changes: 9 additions & 3 deletions ownCloud/Viewer/DisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DisplayViewController: UIViewController, OCQueryDelegate {

var source: URL? {
didSet {
OnMainThread {
OnMainThread(inline: true) {
self.iconImageView.isHidden = true
self.hideItemMetadataUIElements()
self.renderSpecificView()
Expand All @@ -72,7 +72,7 @@ class DisplayViewController: UIViewController, OCQueryDelegate {

private var state: DisplayViewState = .hasNetworkConnection {
didSet {
OnMainThread {
OnMainThread(inline: true) {
switch self.state {
case .downloading(let progress):
self.downloadProgress = progress
Expand Down Expand Up @@ -427,7 +427,13 @@ class DisplayViewController: UIViewController, OCQueryDelegate {
self.stopQuery()
self.startQuery()

self.downloadItem(sender: nil)
if core?.localCopy(of: item) == nil {
self.downloadItem(sender: nil)
} else {
if let core = core, let file = item.file(with: core) {
self.source = file.url
}
}

if let parent = parent {
parent.navigationItem.title = item.name
Expand Down
2 changes: 2 additions & 0 deletions ownCloud/Viewer/PDFViewerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class PDFViewerViewController: DisplayViewController, DisplayExtension {

setupConstraints()

self.view.layoutIfNeeded()

pdfView.document = document

pdfView.scaleFactor = pdfView.scaleFactorForSizeToFit
Expand Down

0 comments on commit 14dbecb

Please sign in to comment.