Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
60958b75
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
12 个月 前同步成功
通知
166
Star
19623
Fork
3062
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DoraemonKit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
60958b75
编写于
5月 24, 2019
作者:
Y
yixiangboy
提交者:
GitHub
5月 24, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #203 from HuginChen/master
沙盒浏览,修改成 QLPreviewController 打开
上级
40e0b34f
f7299e57
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
97 deletion
+12
-97
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
...ore/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
+12
-97
未找到文件。
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
浏览文件 @
60958b75
...
...
@@ -30,109 +30,24 @@
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self
.
title
=
DoraemonLocalizedString
(
@"文件预览"
);
if
(
self
.
filePath
.
length
>
0
)
{
if
(
self
.
filePath
.
length
>
0
)
{
NSString
*
path
=
self
.
filePath
;
if
([
path
hasSuffix
:
@".png"
]
||
[
path
hasSuffix
:
@".PNG"
]
||
[
path
hasSuffix
:
@".jpg"
]
||
[
path
hasSuffix
:
@".JPG"
]
||
[
path
hasSuffix
:
@".jpeg"
]
||
[
path
hasSuffix
:
@".JPEG"
]
||
[
path
hasSuffix
:
@".gif"
]
||
[
path
hasSuffix
:
@".GIF"
])
{
// 图片文件
UIImage
*
img
=
[[
UIImage
alloc
]
initWithContentsOfFile
:
self
.
filePath
];
[
self
setOriginalImage
:
img
];
}
else
if
([
path
hasSuffix
:
@".strings"
]
||
[
path
hasSuffix
:
@".plist"
]
||
[
path
hasSuffix
:
@".txt"
]
||
[
path
hasSuffix
:
@".log"
]
||
[
path
hasSuffix
:
@".csv"
])
{
// 文本文件
if
(
[
path
hasSuffix
:
@".plist"
]
||
[
path
hasSuffix
:
@".strings"
]
){
[
self
setContent
:[[
NSDictionary
dictionaryWithContentsOfFile
:
path
]
description
]];
}
else
{
NSData
*
data
=
[
NSData
dataWithContentsOfFile
:
path
];
[
self
setContent
:[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
]];
}
}
else
if
([
path
hasSuffix
:
@".mp4"
]
||
[
path
hasSuffix
:
@".MP4"
]
||
[
path
hasSuffix
:
@".mov"
]
||
[
path
hasSuffix
:
@".MOV"
]
||
[
path
hasSuffix
:
@".mp3"
]
||
[
path
hasSuffix
:
@".MP3"
])
{
// 音视频文件
[
self
setMediaFile
:
self
.
filePath
];
}
else
if
([
path
hasSuffix
:
@".DB"
]
||
[
path
hasSuffix
:
@".db"
]
||
[
path
hasSuffix
:
@".sqlite"
]
||
[
path
hasSuffix
:
@".SQLITE"
]){
if
([
path
hasSuffix
:
@".DB"
]
||
[
path
hasSuffix
:
@".db"
]
||
[
path
hasSuffix
:
@".sqlite"
]
||
[
path
hasSuffix
:
@".SQLITE"
]){
//数据库文件
self
.
title
=
DoraemonLocalizedString
(
@"数据库预览"
);
[
self
browseDBTable
];
}
else
{
}
else
{
// 其他文件 尝试使用 QLPreviewController进行打开
QLPreviewController
*
myQlPreViewController
=
[[
QLPreviewController
alloc
]
init
];
myQlPreViewController
.
delegate
=
self
;
myQlPreViewController
.
dataSource
=
self
;
[
myQlPreViewController
setCurrentPreviewItemIndex
:
0
];
[
self
presentViewController
:
myQlPreViewController
animated
:
YES
completion
:
nil
];
QLPreviewController
*
previewController
=
[[
QLPreviewController
alloc
]
init
];
previewController
.
delegate
=
self
;
previewController
.
dataSource
=
self
;
[
self
presentViewController
:
previewController
animated
:
YES
completion
:
nil
];
}
}
else
{
[
DoraemonToastUtil
showToast
:
DoraemonLocalizedString
(
@"文件不存在"
)
inView
:
self
.
view
];
}
}
-
(
void
)
setContent
:(
NSString
*
)
text
{
_textView
=
[[
UITextView
alloc
]
initWithFrame
:
self
.
view
.
bounds
];
_textView
.
font
=
[
UIFont
systemFontOfSize
:
12
.
0
f
];
_textView
.
textColor
=
[
UIColor
blackColor
];
_textView
.
textAlignment
=
NSTextAlignmentLeft
;
_textView
.
editable
=
NO
;
_textView
.
dataDetectorTypes
=
UIDataDetectorTypeLink
;
_textView
.
scrollEnabled
=
YES
;
_textView
.
backgroundColor
=
[
UIColor
whiteColor
];
_textView
.
layer
.
borderColor
=
[
UIColor
grayColor
].
CGColor
;
_textView
.
layer
.
borderWidth
=
2
.
0
f
;
_textView
.
text
=
text
;
[
self
.
view
addSubview
:
_textView
];
}
-
(
void
)
setOriginalImage
:(
UIImage
*
)
originalImage
{
CGFloat
viewWidth
=
self
.
view
.
doraemon_width
;
CGFloat
viewHeight
=
self
.
view
.
doraemon_height
;
CGFloat
imageWidth
=
originalImage
.
size
.
width
;
CGFloat
imageHeight
=
originalImage
.
size
.
height
;
BOOL
isPortrait
=
imageHeight
/
viewHeight
>
imageWidth
/
viewWidth
;
CGFloat
scaledImageWidth
,
scaledImageHeight
;
CGFloat
x
,
y
;
CGFloat
imageScale
;
if
(
isPortrait
)
{
//图片竖屏分量比较大
imageScale
=
imageHeight
/
viewHeight
;
scaledImageHeight
=
viewHeight
;
scaledImageWidth
=
imageWidth
/
imageScale
;
x
=
(
viewWidth
-
scaledImageWidth
)
/
2
;
y
=
0
;
}
else
{
//图片横屏分量比较大
imageScale
=
imageWidth
/
viewWidth
;
scaledImageWidth
=
viewWidth
;
scaledImageHeight
=
imageHeight
/
imageScale
;
x
=
0
;
y
=
(
viewHeight
-
scaledImageHeight
)
/
2
;
}
_imageView
=
[[
UIImageView
alloc
]
initWithFrame
:
CGRectMake
(
x
,
y
,
scaledImageWidth
,
scaledImageHeight
)];
_imageView
.
image
=
originalImage
;
_imageView
.
userInteractionEnabled
=
YES
;
[
self
.
view
addSubview
:
_imageView
];
}
-
(
void
)
setMediaFile
:(
NSString
*
)
mediaFile
{
_playerView
=
[[
AVPlayerViewController
alloc
]
init
];
NSURL
*
sourceMediaURL
=
[
NSURL
fileURLWithPath
:
mediaFile
];
AVAsset
*
mediaAsset
=
[
AVURLAsset
URLAssetWithURL
:
sourceMediaURL
options
:
nil
];
AVPlayerItem
*
playerItem
=
[
AVPlayerItem
playerItemWithAsset
:
mediaAsset
];
AVPlayer
*
player
=
[
AVPlayer
playerWithPlayerItem
:
playerItem
];
self
.
playerView
.
player
=
player
;
self
.
playerView
.
showsPlaybackControls
=
YES
;
[
self
.
playerView
.
player
play
];
[
self
addChildViewController
:
self
.
playerView
];
[
self
.
view
addSubview
:
self
.
playerView
.
view
];
self
.
playerView
.
view
.
frame
=
self
.
view
.
bounds
;
}
//浏览数据库中所有数据表
-
(
void
)
browseDBTable
{
[
DoraemonDBManager
shareManager
].
dbPath
=
self
.
filePath
;
...
...
@@ -161,7 +76,7 @@
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
[
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
YES
];
NSString
*
tableName
=
[
self
.
tableNameArray
objectAtIndex
:
indexPath
.
row
];
NSString
*
tableName
=
[
self
.
tableNameArray
objectAtIndex
:
indexPath
.
row
];
[
DoraemonDBManager
shareManager
].
tableName
=
tableName
;
DoraemonDBTableViewController
*
vc
=
[[
DoraemonDBTableViewController
alloc
]
init
];
...
...
@@ -169,15 +84,15 @@
}
#pragma mark - QLPreviewControllerDataSource
#pragma mark - QLPreviewControllerDataSource
, QLPreviewControllerDelegate
-
(
NSInteger
)
numberOfPreviewItemsInPreviewController
:(
QLPreviewController
*
)
controller
{
return
1
;
}
-
(
id
)
previewController
:(
QLPreviewController
*
)
controller
previewItemAtIndex
:(
NSInteger
)
index
{
return
[
NSURL
fileURLWithPath
:
self
.
filePath
];
}
-
(
void
)
previewControllerDidDismiss
:(
QLPreviewController
*
)
controller
{
[
self
leftNavBackClick
:
nil
];
}
@end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录