forked from mirrors/linphone-iphone
Change Progress bar to CircularProgressBar (Like Android) in Download Bubble Chat Message
This commit is contained in:
parent
fc4d7659bb
commit
e4eff6aba9
5 changed files with 82 additions and 7 deletions
54
Classes/Swift/Chat/Views/CircularProgressBarView.swift
Normal file
54
Classes/Swift/Chat/Views/CircularProgressBarView.swift
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// CircularProgressBarView.swift
|
||||
// linphone
|
||||
//
|
||||
// Created by Benoît Martins on 21/03/2023.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class CircularProgressBarView: UIView {
|
||||
|
||||
private var circleLayer = CAShapeLayer()
|
||||
private var progressLayer = CAShapeLayer()
|
||||
|
||||
private var startPoint = CGFloat(-Double.pi / 2)
|
||||
private var endPoint = CGFloat(3 * Double.pi / 2)
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
createCircularPath()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
func createCircularPath() {
|
||||
let circularPath = UIBezierPath(arcCenter: CGPoint(x: 69, y: 69), radius: 20, startAngle: startPoint, endAngle: endPoint, clockwise: true)
|
||||
circleLayer.path = circularPath.cgPath
|
||||
circleLayer.fillColor = UIColor.clear.cgColor
|
||||
circleLayer.lineCap = .round
|
||||
circleLayer.lineWidth = 10.0
|
||||
circleLayer.strokeEnd = 1.0
|
||||
circleLayer.strokeColor = VoipTheme.backgroundWhiteBlack.get().cgColor
|
||||
layer.addSublayer(circleLayer)
|
||||
progressLayer.path = circularPath.cgPath
|
||||
progressLayer.fillColor = VoipTheme.backgroundWhiteBlack.get().cgColor
|
||||
progressLayer.lineCap = .round
|
||||
progressLayer.lineWidth = 5.0
|
||||
progressLayer.strokeEnd = 0
|
||||
progressLayer.strokeColor = VoipTheme.primary_color.cgColor
|
||||
layer.addSublayer(progressLayer)
|
||||
}
|
||||
|
||||
func progressAnimation(fromValue: Float, toValue: Float) {
|
||||
let circularProgressAnimation = CABasicAnimation(keyPath: "strokeEnd")
|
||||
circularProgressAnimation.duration = 0
|
||||
circularProgressAnimation.fromValue = fromValue
|
||||
circularProgressAnimation.toValue = toValue
|
||||
circularProgressAnimation.fillMode = .forwards
|
||||
circularProgressAnimation.isRemovedOnCompletion = false
|
||||
progressLayer.add(circularProgressAnimation, forKey: "progressAnim")
|
||||
}
|
||||
}
|
||||
|
|
@ -14,10 +14,12 @@ class DownloadMessageCell: UIView {
|
|||
let downloadImageView = UIImageView(image: UIImage(named: "file_picture_default"))
|
||||
let downloadNameLabel = StyledLabel(VoipTheme.chat_conversation_download_button)
|
||||
let downloadButtonLabel = StyledLabel(VoipTheme.chat_conversation_download_button)
|
||||
let downloadProgressBar = UIProgressView()
|
||||
var circularProgressBarView = CircularProgressBarView()
|
||||
let circularProgressBarLabel = StyledLabel(VoipTheme.chat_conversation_download_progress_text)
|
||||
let downloadSpacing = UIView()
|
||||
|
||||
var content: Content? = nil
|
||||
var fromValue : Float = 0.0
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
|
@ -30,10 +32,8 @@ class DownloadMessageCell: UIView {
|
|||
downloadView.addSubview(downloadImageView)
|
||||
downloadStackView.addArrangedSubview(downloadNameLabel)
|
||||
downloadStackView.addArrangedSubview(downloadButtonLabel)
|
||||
downloadStackView.addArrangedSubview(downloadProgressBar)
|
||||
downloadStackView.addArrangedSubview(downloadSpacing)
|
||||
|
||||
|
||||
downloadStackView.backgroundColor = VoipTheme.backgroundWhiteBlack.get()
|
||||
|
||||
downloadStackView.size(w: 138, h: 138).done()
|
||||
|
|
@ -42,11 +42,25 @@ class DownloadMessageCell: UIView {
|
|||
downloadButtonLabel.size(w: 130, h: 22).done()
|
||||
downloadSpacing.size(w: 138, h: 14).done()
|
||||
downloadImageView.center = CGPoint(x: 69, y: 40)
|
||||
downloadProgressBar.size(w: 120, h: 22).done()
|
||||
downloadProgressBar.isHidden = true
|
||||
|
||||
addSubview(circularProgressBarView)
|
||||
circularProgressBarView.isHidden = true
|
||||
circularProgressBarLabel.text = "0%"
|
||||
circularProgressBarLabel.size(w: 30, h: 30).done()
|
||||
circularProgressBarView.addSubview(circularProgressBarLabel)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func setUpCircularProgressBarView(toValue: Float) {
|
||||
|
||||
circularProgressBarLabel.text = "\(Int(toValue*100))%"
|
||||
circularProgressBarLabel.center = CGPoint(x: 69, y: 69)
|
||||
|
||||
|
||||
circularProgressBarView.progressAnimation(fromValue: fromValue, toValue: toValue)
|
||||
fromValue = toValue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1174,7 +1174,8 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
}
|
||||
|
||||
downloadContentCollection[indexTransferProgress]!.downloadButtonLabel.isHidden = true
|
||||
downloadContentCollection[indexTransferProgress]!.downloadProgressBar.isHidden = false
|
||||
downloadContentCollection[indexTransferProgress]!.circularProgressBarView.isHidden = false
|
||||
//downloadContentCollection[indexTransferProgress]!.downloadProgressBar.isHidden = false
|
||||
}
|
||||
|
||||
DispatchQueue.main.async(execute: { [self] in
|
||||
|
|
@ -1187,7 +1188,8 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI
|
|||
collectionViewImagesGrid.reloadItems(at: [IndexPath(row: indexTransferProgress, section: 0)])
|
||||
indexTransferProgress = -1
|
||||
} else {
|
||||
downloadContentCollection[indexTransferProgress]!.downloadProgressBar.setProgress(p, animated: true)
|
||||
downloadContentCollection[indexTransferProgress]!.setUpCircularProgressBarView(toValue: p)
|
||||
//downloadContentCollection[indexTransferProgress]!.downloadProgressBar.setProgress(p, animated: true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ import UIKit
|
|||
static let chat_conversation_forward_label = TextStyle(fgColor: LightDarkColor(voip_dark_gray,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .left, font: fontName+"-Regular", size: 12.0)
|
||||
|
||||
static let chat_conversation_download_button = TextStyle(fgColor: LightDarkColor(voip_dark_gray,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .center, font: fontName+"-Regular", size: 14.0)
|
||||
static let chat_conversation_download_progress_text = TextStyle(fgColor: LightDarkColor(voip_dark_gray,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .center, font: fontName+"-Regular", size: 12.0)
|
||||
|
||||
// Buttons Background (State colors)
|
||||
|
||||
|
|
|
|||
|
|
@ -947,6 +947,7 @@
|
|||
D7013DB82940AA12004EEAAE /* MessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7013DB72940AA12004EEAAE /* MessageView.swift */; };
|
||||
D7097B35296D684900AEF6C5 /* FileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7097B34296D684900AEF6C5 /* FileType.swift */; };
|
||||
D71418E329C9B4E0002EEF75 /* DownloadMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71418E229C9B4E0002EEF75 /* DownloadMessageCell.swift */; };
|
||||
D71418E529C9E2CD002EEF75 /* CircularProgressBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71418E429C9E2CD002EEF75 /* CircularProgressBarView.swift */; };
|
||||
D7421D9E29228A5200290CAB /* ChatConversationViewSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7421D9D29228A5200290CAB /* ChatConversationViewSwift.swift */; };
|
||||
D74A44912923BAF90017D063 /* BackActionsNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74A44902923BAF90017D063 /* BackActionsNavigationView.swift */; };
|
||||
D77057F1292E4A340031A970 /* ChatConversationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77057F0292E4A340031A970 /* ChatConversationViewModel.swift */; };
|
||||
|
|
@ -2209,6 +2210,7 @@
|
|||
D7013DB72940AA12004EEAAE /* MessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageView.swift; sourceTree = "<group>"; };
|
||||
D7097B34296D684900AEF6C5 /* FileType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileType.swift; sourceTree = "<group>"; };
|
||||
D71418E229C9B4E0002EEF75 /* DownloadMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadMessageCell.swift; sourceTree = "<group>"; };
|
||||
D71418E429C9E2CD002EEF75 /* CircularProgressBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularProgressBarView.swift; sourceTree = "<group>"; };
|
||||
D7421D9D29228A5200290CAB /* ChatConversationViewSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatConversationViewSwift.swift; sourceTree = "<group>"; };
|
||||
D74A44902923BAF90017D063 /* BackActionsNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackActionsNavigationView.swift; sourceTree = "<group>"; };
|
||||
D77057F0292E4A340031A970 /* ChatConversationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatConversationViewModel.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -3892,6 +3894,7 @@
|
|||
D7C6DE812948CF3100756E03 /* DropDownCell.swift */,
|
||||
D7C6DE822948CF3100756E03 /* DropDownCell.xib */,
|
||||
D71418E229C9B4E0002EEF75 /* DownloadMessageCell.swift */,
|
||||
D71418E429C9E2CD002EEF75 /* CircularProgressBarView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -5311,6 +5314,7 @@
|
|||
C63F7250285A24B10066163B /* CallStatsView.swift in Sources */,
|
||||
6306440E1BECB08500134C72 /* FirstLoginView.m in Sources */,
|
||||
C63F721F285A24B10066163B /* BackNextNavigationView.swift in Sources */,
|
||||
D71418E529C9E2CD002EEF75 /* CircularProgressBarView.swift in Sources */,
|
||||
D3807FC315C28940005BE9BC /* DCRoundSwitchOutlineLayer.m in Sources */,
|
||||
C63F723D285A24B10066163B /* TextStyle.swift in Sources */,
|
||||
C6548823292D369500BF646B /* AbstractCallView.swift in Sources */,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue