Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PhoneManager
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yang
PhoneManager
Commits
56ec55dd
Commit
56ec55dd
authored
Apr 10, 2025
by
yqz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop_0409' into Fe
* develop_0409: 修改bug,详情页调试
parents
207fe7b1
4608b52c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
200 additions
and
3 deletions
+200
-3
HomeViewController.swift
...er/Class/Session/Home/Controller/HomeViewController.swift
+47
-0
HomeInfoView.swift
PhoneManager/Class/Session/Home/View/HomeInfoView.swift
+20
-0
HomeInfoTableViewCell.swift
.../Class/Session/Home/View/cell/HomeInfoTableViewCell.swift
+12
-0
PMShowVideoCell.swift
PhoneManager/Class/Session/Secret/Cell/PMShowVideoCell.swift
+10
-1
PMShowImgVideoController.swift
...nager/Class/Session/Secret/PMShowImgVideoController.swift
+107
-2
Info.plist
PhoneManager/Info.plist
+4
-0
No files found.
PhoneManager/Class/Session/Home/Controller/HomeViewController.swift
View file @
56ec55dd
...
...
@@ -18,6 +18,9 @@ class HomeViewController:BaseViewController {
super
.
viewDidLoad
()
let
dataUpdated
=
Notification
.
Name
(
"DataUpdatedNotification"
)
NotificationCenter
.
default
.
addObserver
(
self
,
selector
:
#selector(
handleDataUpdated(_:)
)
,
name
:
dataUpdated
,
object
:
nil
)
view
.
backgroundColor
=
.
green
homeView
=
HomeView
(
frame
:
view
.
bounds
)
...
...
@@ -175,4 +178,48 @@ class HomeViewController:BaseViewController {
}
}
@objc
func
handleDataUpdated
(
_
notification
:
Notification
)
{
if
let
userInfo
=
notification
.
userInfo
{
let
type
:
PhotsFileType
=
userInfo
[
"type"
]
as!
PhotsFileType
let
deleteIndex
:
[
Int
]
=
(
userInfo
[
"deleteIndex"
]
as?
[
Int
])
!
for
item
in
deleteIndex
{
switch
type
{
case
.
duplicates
:
self
.
homeView
?
.
model
?
.
titleModelArray
.
first
?
.
assets
.
remove
(
at
:
item
)
break
case
.
similar
:
self
.
homeView
?
.
model
?
.
titleModelArray
[
1
]
.
assets
.
remove
(
at
:
item
)
break
case
.
similarScreenshots
:
self
.
homeView
?
.
model
?
.
otherModelArray
[
1
]
.
assets
.
remove
(
at
:
item
)
break
case
.
SimilarVideos
:
self
.
homeView
?
.
model
?
.
titleModelArray
[
3
]
.
assets
.
remove
(
at
:
item
)
break
case
.
videos
:
break
case
.
screenshots
:
break
case
.
Other
:
break
}
}
// 更新缓存数据
if
self
.
homeView
?
.
model
!=
nil
{
PhotoDataManager
.
manager
.
saveToFileSystem
(
model
:
(
self
.
homeView
?
.
model
)
!
)
}
DispatchQueue
.
main
.
async
{
self
.
homeView
?
.
collectionView
.
reloadData
()
}
}
else
{
print
(
"接收到数据更新通知,但没有携带额外信息"
)
}
}
}
PhoneManager/Class/Session/Home/View/HomeInfoView.swift
View file @
56ec55dd
...
...
@@ -184,11 +184,31 @@ class HomeInfoView :UIView{
func
deleteModel
()
{
var
modelRecord
:
[
Int
]
=
[]
for
i
in
0
..<
models
.
count
{
// 过滤掉 isSelected 为 true 的 smodel2
let
array
:
[
ImageSeletedCollectionItem
]
=
models
[
i
]
.
smodels
!
for
item
in
array
{
if
item
.
isSeleted
==
true
{
modelRecord
.
append
(
i
)
break
}
}
models
[
i
]
.
smodels
=
models
[
i
]
.
smodels
?
.
filter
{
!
(
$0
.
isSeleted
??
false
)
}
}
var
modelRecordDelete
:
[
Int
]
=
[]
for
index
in
modelRecord
{
if
models
[
index
]
.
smodels
!.
count
<
2
{
models
.
remove
(
at
:
index
)
modelRecordDelete
.
append
(
index
)
}
}
// 更新下首页数据以及缓存数据
let
dataUpdated
=
Notification
.
Name
(
"DataUpdatedNotification"
)
let
userInfo
=
[
"type"
:
self
.
type
as
Any
,
"deleteIndex"
:
modelRecordDelete
]
as
[
String
:
Any
]
NotificationCenter
.
default
.
post
(
name
:
dataUpdated
,
object
:
nil
,
userInfo
:
userInfo
)
DispatchQueue
.
main
.
async
{[
weak
self
]
in
guard
let
self
else
{
return
}
...
...
PhoneManager/Class/Session/Home/View/cell/HomeInfoTableViewCell.swift
View file @
56ec55dd
...
...
@@ -217,6 +217,18 @@ extension HomeInfoTableViewCell:UICollectionViewDelegate,UICollectionViewDataSou
return
10
// 设置列间距
}
func
collectionView
(
_
collectionView
:
UICollectionView
,
didSelectItemAt
indexPath
:
IndexPath
)
{
// 点击之后跳转详情页面
let
vc
=
PMShowImgVideoController
()
if
model
?
.
type
==
.
SimilarVideos
||
model
?
.
type
==
.
videos
{
vc
.
state
=
.
similarVideos
}
else
{
vc
.
state
=
.
similarPhotos
}
vc
.
currentIdx
=
indexPath
.
row
vc
.
homeDataSource
=
self
.
model
?
.
smodels
self
.
responderViewController
()?
.
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
}
...
...
PhoneManager/Class/Session/Secret/Cell/PMShowVideoCell.swift
View file @
56ec55dd
...
...
@@ -13,8 +13,17 @@ class PMShowVideoCell: UICollectionViewCell {
var
playURL
:
String
=
""
var
homeResouceUrl
:
URL
?
var
type
:
Int
=
0
func
reload
()
->
Void
{
let
url
:
URL
=
"SecretIm"
.
document
()
.
appendingPathComponent
(
playURL
)
var
url
:
URL
if
type
==
0
{
url
=
"SecretIm"
.
document
()
.
appendingPathComponent
(
playURL
)
}
else
{
url
=
homeResouceUrl
!
}
player
.
playVideo
(
from
:
url
)
player
.
pause
()
}
...
...
PhoneManager/Class/Session/Secret/PMShowImgVideoController.swift
View file @
56ec55dd
...
...
@@ -6,15 +6,28 @@
//
import
UIKit
import
Photos
class
PMShowImgVideoController
:
BaseViewController
{
enum
ShowState
{
case
secret
case
secret
// 相似图片
case
similarPhotos
// 相似视频
case
similarVideos
}
// 资源类型 0-图片 1-视频
var
homeMediaType
:
Int
=
0
var
state
:
ShowState
=
.
secret
var
imageVideoPath
:[
String
]
=
[]
// 首页过来的数据
var
homeDataSource
:
[
ImageSeletedCollectionItem
]?
var
currentIdx
=
0
override
func
viewDidLoad
()
{
...
...
@@ -106,7 +119,12 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
}
func
collectionView
(
_
collectionView
:
UICollectionView
,
numberOfItemsInSection
section
:
Int
)
->
Int
{
return
imageVideoPath
.
count
if
self
.
state
==
.
secret
{
return
imageVideoPath
.
count
}
else
{
return
self
.
homeDataSource
?
.
count
??
0
}
}
func
collectionView
(
_
collectionView
:
UICollectionView
,
didEndDisplaying
cell
:
UICollectionViewCell
,
forItemAt
indexPath
:
IndexPath
)
{
...
...
@@ -146,6 +164,47 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
return
cell
}
}
if
state
==
.
similarPhotos
{
if
collectionView
==
MaxCollection
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
PMShowImgCellID
,
for
:
indexPath
)
as!
PMShowImgCell
cell
.
icon
=
self
.
homeDataSource
!
[
indexPath
.
row
]
.
image
!
return
cell
}
else
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
PMShowItemCellID
,
for
:
indexPath
)
as!
PMShowItemCell
cell
.
icon
=
self
.
homeDataSource
!
[
indexPath
.
row
]
.
image
!
cell
.
isCurrent
=
(
self
.
currentIdx
==
indexPath
.
row
)
return
cell
}
}
if
state
==
.
similarVideos
{
// 相似视频
if
collectionView
==
MaxCollection
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
PMShowVideoCellID
,
for
:
indexPath
)
as!
PMShowVideoCell
// 获取相似视频的URL
DispatchQueue
.
global
()
.
async
{
self
.
getVideoURLFromLocalIdentifier
(
localIdentifier
:
self
.
homeDataSource
!
[
indexPath
.
row
]
.
id
)
{[
weak
self
]
url
,
error
in
guard
self
!=
nil
else
{
return
}
if
let
error
=
error
{
print
(
"获取视频 URL 时出错:
\(
error
.
localizedDescription
)
"
)
}
else
if
let
url
=
url
{
DispatchQueue
.
main
.
async
{
cell
.
homeResouceUrl
=
url
cell
.
reload
()
}
}
}
}
return
cell
}
else
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
PMShowItemCellID
,
for
:
indexPath
)
as!
PMShowItemCell
cell
.
icon
=
self
.
homeDataSource
!
[
indexPath
.
row
]
.
image
!
cell
.
isCurrent
=
(
self
.
currentIdx
==
indexPath
.
row
)
return
cell
}
}
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
""
,
for
:
indexPath
)
return
cell
}
...
...
@@ -157,4 +216,50 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
return
CGSize
(
width
:
68
,
height
:
68
)
}
/// 根据LocalIdentifier获取视频的URL
/// - Parameters:
/// - localIdentifier: 资源标识
/// - completion: 回调
func
getVideoURLFromLocalIdentifier
(
localIdentifier
:
String
,
completion
:
@escaping
(
URL
?,
Error
?)
->
Void
)
{
// 通过 localIdentifier 获取 PHAsset
let
fetchOptions
=
PHFetchOptions
()
let
assets
=
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
[
localIdentifier
],
options
:
fetchOptions
)
guard
let
asset
=
assets
.
firstObject
,
asset
.
mediaType
==
.
video
else
{
completion
(
nil
,
NSError
(
domain
:
"com.example.error"
,
code
:
1
,
userInfo
:
[
NSLocalizedDescriptionKey
:
"未找到对应视频资源"
]))
return
}
PHPhotoLibrary
.
requestAuthorization
{
status
in
switch
status
{
case
.
authorized
:
print
(
"Access granted"
)
case
.
denied
,
.
restricted
:
print
(
"Access denied"
)
case
.
notDetermined
:
print
(
"Access not determined"
)
@unknown
default
:
print
(
"Unhandled authorization status"
)
}
}
let
options
=
PHVideoRequestOptions
()
options
.
isNetworkAccessAllowed
=
true
// 允许从网络下载
options
.
deliveryMode
=
.
automatic
// 要求高质量格式
PHImageManager
.
default
()
.
requestAVAsset
(
forVideo
:
asset
,
options
:
options
)
{
(
avAsset
,
audioMix
,
info
)
in
if
let
error
=
info
?[
PHImageErrorKey
]
as?
Error
{
completion
(
nil
,
error
)
return
}
if
let
urlAsset
=
avAsset
as?
AVURLAsset
{
completion
(
urlAsset
.
url
,
nil
)
}
else
{
completion
(
nil
,
NSError
(
domain
:
"CustomErrorDomain"
,
code
:
-
1
,
userInfo
:
[
NSLocalizedDescriptionKey
:
"Failed to get video URL"
]))
}
}
}
}
PhoneManager/Info.plist
View file @
56ec55dd
...
...
@@ -2,6 +2,10 @@
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e
//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
k
e
y
>
NSPhotoLibraryUsageDescription
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
NSPhotoLibraryAddUsageDescription
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
NSAppTransportSecurity
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
NSAllowsArbitraryLoads
<
/k
e
y
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment