Skip to content

Commit

Permalink
[refactor] Refactor the PDF view cell
Browse files Browse the repository at this point in the history
[feat] Add support for PDF caching
[release] Bump version 1.8.5
  • Loading branch information
engali94 committed Nov 8, 2021
1 parent f1547cb commit 3228522
Show file tree
Hide file tree
Showing 21 changed files with 656 additions and 519 deletions.
Binary file added Assets/Desk360Assets.bundle/Images/gzip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/gzip@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/gzip@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/rar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/rar@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/rar@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/zip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/zip@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Desk360Assets.bundle/Images/zip@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Desk360.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Desk360"
s.version = "1.8.4"
s.version = "1.8.5"
s.summary = "Desk360 iOS SDK"
s.description = <<-DESC
Desk360 iOS SDK [WIP]
Expand Down
4 changes: 4 additions & 0 deletions Sources/Desk360+Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public extension Desk360.Config {
return image.withRenderingMode(.alwaysOriginal)
}

static func image(withName name: String) -> UIImage? {
createImage(resources: "Images/\(name)")
}

static var desk360Logo: UIImage = {
guard let path = Desk360.Config.bundle?.path(forResource: "Images/desk360Logo", ofType: "png") else { return UIImage() }
guard let image = UIImage(contentsOfFile: path) else { return UIImage() }
Expand Down
13 changes: 13 additions & 0 deletions Sources/Desk360.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public typealias TicketsHandler = ((Result<[Ticket], Error>) -> Void)
/// - Parameter properties: DESK360 configuration properties.
@objc public init(properties: Desk360Properties) {
super.init()
listenForAppLifeCycleEvents()
Desk360.properties = properties
Desk360.appVersion = Desk360.getAppVersion()
Desk360.sdkVersion = Desk360.getSdkVersion()
Expand Down Expand Up @@ -265,6 +266,18 @@ public typealias TicketsHandler = ((Result<[Ticket], Error>) -> Void)

private extension Desk360 {

func listenForAppLifeCycleEvents() {
NotificationCenter.default.addObserver(self, selector: #selector(changeNotificationStatus), name: UIApplication.willTerminateNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(changeNotificationStatus), name: UIApplication.willResignActiveNotification, object: nil)
}

@objc func changeNotificationStatus() {
if #available(iOS 11.0, *) {
PDFDocumentCache.clear()
}
}

static func getAppVersion() -> String {
guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String else {
return "0.0.0"
Expand Down
5 changes: 5 additions & 0 deletions Sources/Networking/Models/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public struct AttachObject {
var url: String
var name: String
var type: String

var image: UIImage? {
guard let fileType = name.split(separator: ".").last else { return nil }
return Desk360.Config.Images.image(withName: String(fileType))
}
}

extension AttachObject: Codable {
Expand Down
22 changes: 13 additions & 9 deletions Sources/Scenes/Conversation/ConversationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ final class ConversationViewController: UIViewController, Layouting, UITableView
}
let cell = tableView.dequeueReusableCell(ReceiverMessageTableViewCell.self)
cell.clearCell()
cell.delegate = self
cell.configure(for: request.messages[indexPath.row], indexPath, attachment, hasAttach: hasAttach)
return cell
}
Expand All @@ -169,7 +170,7 @@ extension ConversationViewController: InputViewDelegate {
func inputView(_ view: InputView, didTapSendButton button: UIButton, withText text: String) {
chatInputView.setLoading(true)
isAddedMessage = true
addMessage(text, to: request)
addMessage(text.condenseNewlines.condenseWhitespacs, to: request)
}

func inputView(_ view: InputView, didTapAttachButton button: UIButton) {
Expand Down Expand Up @@ -325,6 +326,7 @@ extension ConversationViewController: InputViewDelegate {
func manageAttachView() {
guard files.count <= 5 else { return }
chatInputView.attachmentView.append(attachementsData: files)
chatInputView.setSendButton()
}
}

Expand Down Expand Up @@ -738,6 +740,16 @@ extension ConversationViewController: KeyboardObserving {

}


extension ConversationViewController: ReceiverMessageTableViewCellDelegate {

func didTapPdfFile(_ file: AttachObject) {
if #available(iOS 11.0, *) {
navigationController?.pushViewController(PDFPreviewViewController(file: file), animated: true)
}
}
}

struct FileData: Equatable {
var name: String
var data: Data
Expand Down Expand Up @@ -870,11 +882,3 @@ extension String {
return label.frame.size
}
}

extension UIScrollView {
func scrollToBottom(animated: Bool) {
if self.contentSize.height < self.bounds.size.height { return }
let bottomOffset = CGPoint(x: 0, y: self.contentSize.height - self.bounds.size.height)
self.setContentOffset(bottomOffset, animated: animated)
}
}
54 changes: 54 additions & 0 deletions Sources/Scenes/Conversation/FileView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// FileView.swift
// Desk360
//
// Created by Ali Ammar Hilal on 8.11.2021.
//

import UIKit

/// A UIView based calss to render different files representations on the secren.
final class FileView: UIView {

/// The file icon.
lazy var icon: UIImageView = {
let view = UIImageView()
view.pinSize(.init(width: 38, height: 36))
return view
}()

/// The file name.
lazy var fileName: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 14)
label.textColor = Colors.ticketDetailChatReceiverTextColor
return label
}()

/// The file object of type `AttachObject` to be rendered.
var file: AttachObject? {
didSet {
guard let file = file else { return }
fileName.text = file.name
icon.image = file.image?.withRenderingMode(.alwaysOriginal)
}
}

/// A call back closure to be triggered when atappping on the file name or icon.
var onFileSelected: ((AttachObject) -> Void)?

override func layoutSubviews() {
super.layoutSubviews()
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapFile)))
let stack: UIView = .hStack(alignment: .center, distribution: .fill, spacing: 8, [icon, fileName])
addSubview(stack)
stack.pinToSuperviewEdges(padding: .init(top: 10, left: 0, bottom: 10, right: 12))
}

@objc private func didTapFile() {
guard let file = file else {
return
}
onFileSelected?(file)
}
}
Loading

0 comments on commit 3228522

Please sign in to comment.