Commit c26a67b1 authored by yqz's avatar yqz

隐私空间 流程

显示图片和视频
parent a7116f46
//
// PMShowImgCell.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import UIKit
let PMShowImgCellID = "PMShowImgCell"
class PMShowImgCell: UICollectionViewCell {
var icon:UIImage = UIImage() {
didSet {
iconView.image = icon
var size = icon.size
if size.height < size.width {
let width = self.width
size = CGSize(width: width, height: size.height * (width/size.width) )
}else{
let width = self.width
let height = size.height * (width/size.width)
if height > self.height {
size = CGSize(width: width * (self.height/height), height: height )
}else {
size = CGSize(width: width, height: height )
}
}
iconView.snp.remakeConstraints { make in
make.centerX.centerY.equalToSuperview()
make.size.equalTo(size)
}
}
}
private lazy var iconView: UIImageView = {
let info = UIImageView()
info.contentMode = .scaleToFill
contentView.addSubview(info)
info.clipsToBounds = true
return info
}()
override init(frame: CGRect) {
super.init(frame: frame)
setup()
clipsToBounds = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() -> Void {
iconView.snp.makeConstraints { make in
make.left.right.bottom.top.equalToSuperview()
}
}
}
//
// PMShowItemCell.swift
// PhoneManager
//
// Created by edy on 2025/4/10.
//
import UIKit
let PMShowItemCellID = "PMShowItemCell"
class PMShowItemCell: UICollectionViewCell {
var isCurrent:Bool = false {
didSet {
if isCurrent {
layer.borderColor = UIColor.colorWithHex(hexStr: "#0082FF").cgColor
layer.borderWidth = 4
}else{
layer.borderColor = UIColor.clear.cgColor
layer.borderWidth = 0
}
}
}
var icon:UIImage? {
didSet {
iconV.image = icon
}
}
private lazy var iconV: UIImageView = {
let ic = UIImageView()
ic.contentMode = .scaleAspectFill
contentView.addSubview(ic)
return ic
}()
override init(frame: CGRect) {
super.init(frame: frame)
clipsToBounds = true
self.layer.cornerRadius = 12
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() -> Void {
iconV.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
}
}
//
// PMShowVideoCell.swift
// PhoneManager
//
// Created by edy on 2025/4/9.
//
import UIKit
let PMShowVideoCellID = "PMShowVideoCell"
class PMShowVideoCell: UICollectionViewCell {
var playURL:String = ""
func reload() -> Void {
let url:URL = "SecretIm".document().appendingPathComponent(playURL)
player.playVideo(from: url)
player.pause()
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() -> Void {
player.snp.makeConstraints { make in
make.left.top.bottom.right.equalToSuperview()
}
}
var zPlayer : SecretVideoPlayer {
get {
return player
}
}
private lazy var player: SecretVideoPlayer = {
let p = SecretVideoPlayer()
p.layer.cornerRadius = 8
p.clipsToBounds = true
contentView.addSubview(p)
return p
}()
}
//
// SecretShowImgVideoController.swift
// PhoneManager
//
// Created by edy on 2025/4/3.
//
import UIKit
class PMShowImgVideoController: BaseViewController {
enum ShowState {
case secret
}
var state:ShowState = .secret
var imageVideoPath:[String] = []
var currentIdx = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.MaxCollection.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(20)
make.top.top.equalTo(titleView.snp.bottom).offset(20)
make.bottom.equalToSuperview().inset(100)
}
self.bottItems.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(MaxCollection.snp.bottom)
make.bottom.equalToSuperview()
}
self.view.layoutIfNeeded()
self.MaxCollection.scrollToItem(at: IndexPath(row: currentIdx, section: 0), at: .centeredHorizontally, animated: false)
}
private lazy var MaxCollection: UICollectionView = {
let flowlayout = UICollectionViewFlowLayout()
flowlayout.sectionInset = UIEdgeInsets()
flowlayout.minimumInteritemSpacing = 0
flowlayout.minimumLineSpacing = 0
flowlayout.scrollDirection = .horizontal
let col = UICollectionView(frame: CGRect(), collectionViewLayout: flowlayout)
col.delegate = self;
col.dataSource = self;
col.showsHorizontalScrollIndicator = false
col.isPagingEnabled = true
col.register(PMShowImgCell.self, forCellWithReuseIdentifier: PMShowImgCellID)
col.register(PMShowVideoCell.self, forCellWithReuseIdentifier: PMShowVideoCellID)
view.addSubview(col)
return col
}()
private lazy var bottItems: UICollectionView = {
let flowlayout = UICollectionViewFlowLayout()
flowlayout.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
flowlayout.minimumInteritemSpacing = 0
flowlayout.minimumLineSpacing = 10
flowlayout.scrollDirection = .horizontal
let col = UICollectionView(frame: CGRect(), collectionViewLayout: flowlayout)
col.delegate = self;
col.dataSource = self;
col.register(PMShowItemCell.self, forCellWithReuseIdentifier: PMShowItemCellID)
col.showsHorizontalScrollIndicator = false
col.isPagingEnabled = true
view.addSubview(col)
return col
}()
}
extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let collectView = scrollView as? UICollectionView else { return }
if collectView == MaxCollection {
let offsetx = MaxCollection.contentOffset.x
let width = collectView.width
let current:Int = Int(offsetx / width)
currentIdx = current
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
Print("1")
guard let collectView = scrollView as? UICollectionView else { return }
if collectView == MaxCollection {
bottItems.reloadData()
}
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
Print("2")
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == bottItems {
if currentIdx != indexPath.row {
currentIdx = indexPath.row
MaxCollection.scrollToItem(at: indexPath, at: .left, animated: false)
collectionView.reloadData()
}
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageVideoPath.count
}
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if state == .secret && collectionView == MaxCollection{
let showName = imageVideoPath[indexPath.row]
if !showName.hasSuffix(".png") {
guard let zCell:PMShowVideoCell = cell as? PMShowVideoCell else { return }
zCell.zPlayer.pause()
}
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if state == .secret {
let showName = imageVideoPath[indexPath.row]
if collectionView == MaxCollection {
if showName.hasSuffix(".png") {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowImgCellID, for: indexPath) as! PMShowImgCell
showName.loadPhotoOrVideo { durs, icon in
cell.icon = icon
}
return cell
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell
cell.playURL = showName
cell.reload()
return cell
}
}else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell
showName.loadPhotoOrVideo { duration, icon in
DispatchQueue.main.async {
cell.icon = icon
}
}
cell.isCurrent = (self.currentIdx == indexPath.row)
return cell
}
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "", for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if collectionView == MaxCollection {
return collectionView.size
}
return CGSize(width: 68, height: 68)
}
}
......@@ -10,19 +10,19 @@ import UIKit
class SecretSetViewController: BaseViewController, UITextFieldDelegate {
enum SecretType {
case create
case verify
case create // 新建
case verify // 验证
case del // 删除
}
var Callback:((_ suc:Bool)->Void)?
var secretType:SecretType = .create {
didSet{
if secretType == .create {
setTitle.text = "Create New PlN"
setTitle.text = "Create New PIN"
}else{
setTitle.text = "Please Enter PlN"
setTitle.text = "Please Enter PIN"
}
}
}
......@@ -35,22 +35,65 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
setUI()
ps.becomeFirstResponder()
collect.register(SecretSetPsCell.self, forCellWithReuseIdentifier: SecretSetPsCellID)
self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
}
override func close(animation: Bool = true) {
if secretType == .verify {
self.navigationController?.popToRootViewController(animated: true)
return
}
if Callback != nil {
Callback!(false)
}
super.close(animation: animation)
}
private var createViesget = ""
private var Secret = "" {
didSet {
collect.reloadData()
if Secret.count == 4 {
if secretType == .verify {
if secretType == .verify || secretType == .del{
let Ps:String = UserDefaults.standard.object(forKey: SecretViewController.psKey) as? String ?? ""
if Ps != Secret {
alert("Pin Verification Failed")
Secret = ""
self.ps.text = ""
descpLabel.text = "The entered PIN code is incorrect, please re-enter"
return
}else{
if secretType == .del {
UserDefaults.standard.set("", forKey: SecretViewController.psKey)
}
}
}else{
UserDefaults.standard.set(Secret, forKey: SecretViewController.psKey)
if createViesget.count > 2 {
if createViesget != Secret {
descpLabel.text = "The PIN entered twice is different, please re-enter"
Secret = ""
self.ps.text = ""
}else{
UserDefaults.standard.set(Secret, forKey: SecretViewController.psKey)
let alert = UIAlertController(title: nil, message: "Your space is locked", preferredStyle: .alert)
self.present(alert, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
alert.dismiss(animated: true) {
guard self.Callback != nil else {
return
}
self.Callback!(true)
self.navigationController?.popViewController(animated: true)
}
}
}
}else{
createViesget = Secret
Secret = ""
self.ps.text = ""
setTitle.text = "Confirm PIN code"
}
return
}
guard Callback != nil else {
return
......@@ -65,6 +108,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
view.addSubview(setInfo)
view.addSubview(setTitle)
view.addSubview(collect)
view.addSubview(descpLabel)
setInfo.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(titleView.snp.bottom).offset(62)
......@@ -73,6 +117,10 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
make.centerX.equalToSuperview()
make.top.equalTo(setInfo.snp.bottom).offset(16)
}
descpLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(setTitle.snp.bottom).offset(5)
}
collect.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.width.equalTo(20*4.0 + 3 * 20.0 )
......@@ -106,12 +154,21 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
private lazy var setTitle: UILabel = {
let st = UILabel()
st.text = "Create New PlN"
st.text = "Create New PIN"
st.font = UIFont.boldSystemFont(ofSize: 20)
st.textColor = .black
st.textAlignment = .center
return st
}()
private lazy var descpLabel: UILabel = {
let st = UILabel()
st.text = ""
st.font = UIFont.systemFont(ofSize: 14)
st.textColor = .red
st.textAlignment = .center
return st
}()
}
......@@ -138,7 +195,7 @@ extension SecretSetViewController:UICollectionViewDelegate,UICollectionViewDataS
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var st:NSString = textField.text as? NSString ?? ""
st = st.replacingCharacters(in: range, with: string) as NSString
if st.length > 4 {
if st.length >= 4 {
Secret = st.substring(to: 4)
textField.text = ""
return false
......
//
// SecretShowImgVideoController.swift
// PhoneManager
//
// Created by edy on 2025/4/3.
//
import UIKit
class SecretShowImgVideoController: BaseViewController {
var imageVideoPath:String = ""
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
showPlay()
}
private func setUI( _ icon:UIImage) -> Void {
showImage.snp.remakeConstraints { make in
make.left.right.equalToSuperview().inset(24)
make.top.equalTo(self.titleView.snp.bottom).offset(20)
make.height.equalTo(self.showImage.snp.width).multipliedBy(icon.size.height/icon.size.width)
}
}
private func showPlay() -> Void {
if imageVideoPath.hasSuffix(".png") {
self.showImage.isHidden = false
imageVideoPath.loadPhotoOrVideo({[weak self] dur, icon in
self?.showImage.image = icon
self?.setUI(icon)
})
}else{
player.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(20)
make.top.equalTo(self.titleView.snp.bottom).offset(20)
make.bottom.equalToSuperview().offset(-40)
}
player.isHidden = false
let url = "SecretIm".document().appendingPathComponent(imageVideoPath)
player.playVideo(from: url)
}
}
private lazy var showImage: UIImageView = {
let img = UIImageView()
img.contentMode = .scaleAspectFill
img.isHidden = true
view.addSubview(img)
return img
}()
private lazy var player: SecretVideoPlayer = {
let p = SecretVideoPlayer()
view.addSubview(p)
p.layer.cornerRadius = 8
p.clipsToBounds = true
p.isHidden = true
return p
}()
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
player.pause()
}
}
......@@ -13,31 +13,27 @@ class SecretViewController: BaseViewController {
static let psKey:String = "SecretKey"
var pass:String {
private var pass:String {
get {
return UserDefaults.standard.object(forKey: SecretViewController.psKey) as? String ?? ""
}
}
private var selectArray = NSMutableSet() {
didSet{
secretCollect.reloadData()
bottomm.state = selectArray.count > 0 ? .del : .add
/** 首次显示 */
private var isShow:Bool {
get {
guard let show = UserDefaults.standard.object(forKey: "SecretFirstShow") else {
UserDefaults.standard.set("1", forKey: "SecretFirstShow")
return false
}
return true
}
}
var isVerify:Bool = false {
didSet {
if isVerify {
NotDataView.isHidden = dataSource.count > 0
secretCollect.isHidden = !(dataSource.count > 0)
seletedAllBtn.isHidden = secretCollect.isHidden
}else{
NotDataView.isHidden = false
secretCollect.isHidden = true
seletedAllBtn.isHidden = true
}
private var selectArray = NSMutableSet() {
didSet{
secretCollect.reloadData()
bottomm.state = selectArray.count > 0 ? .del : .add
}
}
......@@ -45,6 +41,9 @@ class SecretViewController: BaseViewController {
var dataSource:[String] = [] {
didSet {
NotDataView.isHidden = dataSource.count > 0
secretCollect.isHidden = !(dataSource.count > 0)
seletedAllBtn.isHidden = secretCollect.isHidden
secretCollect.reloadData()
}
}
......@@ -53,11 +52,18 @@ class SecretViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
isVerify = false
_ = Resource.isDirect()
if pass.count == 4 {
titleView.isHidden = false
setUI()
if isShow {
if pass.count > 2 {
let set = SecretSetViewController()
set.secretType = .verify
set.Callback = {[weak self] su in
self?.ShowUI()
}
self.navigationController?.pushViewController(set, animated: true)
}else{
self.ShowUI()
}
}else{
let alert = SecretAlert()
titleView.isHidden = true
......@@ -65,18 +71,24 @@ class SecretViewController: BaseViewController {
alert.dismiss(animated: true)
if idx == 1 {
let set = SecretSetViewController()
set.Callback = { suc in
self?.isVerify = suc
set.secretType = .create
set.Callback = { su in
self?.ShowUI()
}
self?.navigationController?.pushViewController(set, animated: true)
}else{
self?.ShowUI()
}
self?.setUI()
self?.titleView.isHidden = false
}
alert.show()
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
secretLock.isSelected = !(pass.count > 1)
}
@discardableResult
private func loadData() -> [String] {
let file:[String] = "SecretIm".contentOfDir()
......@@ -107,39 +119,24 @@ class SecretViewController: BaseViewController {
}
Print("删除成功")
dataSource = loadData()
bottomm.state = .add
}
@objc private func lockTouch(_ sender:UIButton) -> Void {
if pass.count < 4 {
let alert = SecretAlert()
titleView.isHidden = true
alert.callback = { [weak self] idx in
alert.dismiss(animated: true)
if idx == 1 {
let set = SecretSetViewController()
set.Callback = { suc in
self?.isVerify = suc
sender.isSelected = suc
}
self?.navigationController?.pushViewController(set, animated: true)
}
self?.setUI()
self?.titleView.isHidden = false
if pass.count > 2 {
let set = SecretSetViewController()
set.secretType = .del
set.Callback = { bt in
}
alert.show()
self.navigationController?.pushViewController(set, animated: true)
}else{
if isVerify == false {
let set = SecretSetViewController()
set.secretType = .verify
set.Callback = {[weak self] suc in
self?.isVerify = suc
sender.isSelected = suc
}
self.navigationController?.pushViewController(set, animated: true)
return
let set = SecretSetViewController()
set.secretType = .create
set.Callback = { cr in
}
sender.isSelected = !sender.isSelected
isVerify = sender.isSelected;
self.navigationController?.pushViewController(set, animated: true)
}
}
......@@ -244,9 +241,7 @@ class SecretViewController: BaseViewController {
}()
private lazy var seletedAllBtn:UIButton = {
let btn:UIButton = UIButton(frame: CGRect(x: 0, y: 0, width: 115, height: 32))
btn.addTarget(self, action: #selector(seletedAllBtnClick), for: .touchUpInside)
btn.backgroundColor = UIColor.colorWithHex(hexStr: "#F2F6FC")
btn.setImage(UIImage.init(named: "ic_check_similar"), for: .normal)
......@@ -275,7 +270,7 @@ class SecretViewController: BaseViewController {
extension SecretViewController : UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (dataSource.count > 0 && isVerify) ? dataSource.count : 0;
return dataSource.count;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
......@@ -291,8 +286,9 @@ extension SecretViewController : UICollectionViewDelegate,UICollectionViewDataSo
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let play = SecretShowImgVideoController()
play.imageVideoPath = dataSource[indexPath.row]
let play = PMShowImgVideoController()
play.currentIdx = indexPath.row
play.imageVideoPath = dataSource
self.navigationController?.pushViewController(play, animated: true)
}
......@@ -318,10 +314,15 @@ extension SecretViewController : UICollectionViewDelegate,UICollectionViewDataSo
}
}
}
}
extension SecretViewController : UIImagePickerControllerDelegate , UINavigationControllerDelegate{
extension SecretViewController : UIImagePickerControllerDelegate , UINavigationControllerDelegate {
private func ShowUI() -> Void {
self.setUI()
self.titleView.isHidden = false
dataSource = self.loadData()
}
private func selectImgVideo(_ row:Int) -> Void {
let set:NSMutableSet = NSMutableSet(set: selectArray)
......@@ -378,8 +379,6 @@ extension SecretViewController : UIImagePickerControllerDelegate , UINavigationC
let name = String(format: "%ld.mp4", Date().timeIntervalSince1970)
SaveSecret(name, d)
}
let isv = isVerify
isVerify = isv
loadData()
}
}
......
......@@ -108,7 +108,7 @@ extension String {
pv(-1,UIImage.Clear())
return
}
icon.compressImage(0.3) { image in
icon.resizeAndCompressImage().compressImage(0.3) { image in
SecretImageCache.share.saveImageCache(self, image)
pv(-1,image)
}
......@@ -121,7 +121,7 @@ extension String {
do {
let cgImage = try imageGenerator.copyCGImage(at: CMTime(value: 0, timescale: 1), actualTime: nil)
let icon = UIImage(cgImage: cgImage);
icon.compressImage(0.3) { image in
icon.resizeAndCompressImage(0.3).compressImage(0.3) { image in
SecretImageCache.share.saveImageCache(self, image,CMTimeGetSeconds(duration))
pv(CMTimeGetSeconds(duration) ,image)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment