Commit 971be4de authored by 林生雨's avatar 林生雨

commit :

parent 877d09a4
...@@ -5,7 +5,17 @@ ...@@ -5,7 +5,17 @@
<option name="TOOL_WINDOW_CONFIGURED_FILTER" value="Show only selected application" /> <option name="TOOL_WINDOW_CONFIGURED_FILTER" value="Show only selected application" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="5be6bbb5-7d6e-4540-a24f-d2b3bf78b3ba" name="Default Changelist" comment="" /> <list default="true" id="5be6bbb5-7d6e-4540-a24f-d2b3bf78b3ba" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/lib/AlbumModel/page/album/AlbumModel.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/lib/AlbumModel/page/album/AlbumModel.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/lib/AlbumModel/page/album/AlbumPage.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/lib/AlbumModel/page/album/AlbumPage.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/ios/Classes/GengmeiFlutterPlugin.m" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/ios/Classes/GengmeiFlutterPlugin.m" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/ScanImagePlugn.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/ScanImagePlugn.dart" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" /> <ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" /> <ignored path="$PROJECT_DIR$/.idea/" />
<ignored path="$PROJECT_DIR$/.pub/" /> <ignored path="$PROJECT_DIR$/.pub/" />
...@@ -27,8 +37,8 @@ ...@@ -27,8 +37,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="336"> <state relative-caret-position="141">
<caret line="68" selection-start-line="68" selection-end-line="68" /> <caret line="233" column="20" selection-start-line="233" selection-start-column="20" selection-end-line="233" selection-end-column="20" />
<folding> <folding>
<element signature="e#46#66#0" expanded="true" /> <element signature="e#46#66#0" expanded="true" />
</folding> </folding>
...@@ -39,8 +49,8 @@ ...@@ -39,8 +49,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119"> <state relative-caret-position="-1229">
<caret line="206" column="106" selection-start-line="206" selection-start-column="106" selection-end-line="206" selection-end-column="106" /> <caret line="221" column="20" selection-start-line="221" selection-start-column="20" selection-end-line="221" selection-end-column="20" />
<folding> <folding>
<element signature="e#45#62#0" expanded="true" /> <element signature="e#45#62#0" expanded="true" />
</folding> </folding>
...@@ -48,11 +58,11 @@ ...@@ -48,11 +58,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/ScanImagePlugn.dart"> <entry file="file://$PROJECT_DIR$/lib/ScanImagePlugn.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76"> <state relative-caret-position="289">
<caret line="27" column="19" selection-start-line="27" selection-start-column="16" selection-end-line="27" selection-end-column="19" /> <caret line="38" column="64" selection-start-line="38" selection-start-column="60" selection-end-line="38" selection-end-column="64" />
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -69,7 +79,7 @@ ...@@ -69,7 +79,7 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="207"> <state relative-caret-position="207">
...@@ -102,8 +112,8 @@ ...@@ -102,8 +112,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m"> <entry file="file://$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="8514"> <state relative-caret-position="9768">
<caret line="387" column="22" selection-start-line="387" selection-start-column="12" selection-end-line="387" selection-end-column="22" /> <caret line="457" column="22" selection-start-line="457" selection-start-column="22" selection-end-line="457" selection-end-column="22" />
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -145,6 +155,9 @@ ...@@ -145,6 +155,9 @@
<find>phoneImages</find> <find>phoneImages</find>
<find>_eventSink</find> <find>_eventSink</find>
<find>isAdd</find> <find>isAdd</find>
<find>onE</find>
<find>realPath</find>
<find>DATTTTTT</find>
</findStrings> </findStrings>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
...@@ -168,19 +181,19 @@ ...@@ -168,19 +181,19 @@
<option value="$PROJECT_DIR$/android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/luban/Engine.kt" /> <option value="$PROJECT_DIR$/android/src/main/java/com/example/gengmei_flutter_plugin/ImagePlugin/repository/luban/Engine.kt" />
<option value="$PROJECT_DIR$/lib/SharedPlugin.dart" /> <option value="$PROJECT_DIR$/lib/SharedPlugin.dart" />
<option value="$PROJECT_DIR$/example/lib/main.dart" /> <option value="$PROJECT_DIR$/example/lib/main.dart" />
<option value="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart" />
<option value="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart" />
<option value="$PROJECT_DIR$/lib/ScanImagePlugn.dart" />
<option value="$PROJECT_DIR$/lib/gengmei_flutter_plugin.dart" /> <option value="$PROJECT_DIR$/lib/gengmei_flutter_plugin.dart" />
<option value="$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart" /> <option value="$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart" />
<option value="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart" />
<option value="$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart" />
<option value="$PROJECT_DIR$/lib/ScanImagePlugn.dart" />
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds">
<option name="x" value="673" /> <option name="x" value="618" />
<option name="y" value="-861" /> <option name="y" value="-877" />
<option name="width" value="1440" /> <option name="width" value="1440" />
<option name="height" value="811" /> <option name="height" value="812" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView"> <component name="ProjectView">
...@@ -295,9 +308,10 @@ ...@@ -295,9 +308,10 @@
<servers /> <servers />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="673" y="-861" width="1440" height="811" extended-state="0" /> <frame x="618" y="-877" width="1440" height="812" extended-state="0" />
<editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.1509299" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.19742489" />
<window_info id="Captures" order="1" side_tool="true" /> <window_info id="Captures" order="1" side_tool="true" />
<window_info id="Structure" order="2" side_tool="true" /> <window_info id="Structure" order="2" side_tool="true" />
<window_info id="Image Layers" order="3" /> <window_info id="Image Layers" order="3" />
...@@ -307,12 +321,12 @@ ...@@ -307,12 +321,12 @@
<window_info id="Capture Tool" order="7" /> <window_info id="Capture Tool" order="7" />
<window_info id="Favorites" order="8" side_tool="true" /> <window_info id="Favorites" order="8" side_tool="true" />
<window_info anchor="bottom" id="Dart Analysis" order="0" weight="0.32963988" /> <window_info anchor="bottom" id="Dart Analysis" order="0" weight="0.32963988" />
<window_info anchor="bottom" id="Run" order="1" weight="0.46175244" /> <window_info anchor="bottom" id="Run" order="1" visible="true" weight="0.375" />
<window_info anchor="bottom" id="TODO" order="2" /> <window_info anchor="bottom" id="TODO" order="2" />
<window_info anchor="bottom" id="Android Profiler" order="3" show_stripe_button="false" /> <window_info anchor="bottom" id="Android Profiler" order="3" show_stripe_button="false" />
<window_info anchor="bottom" id="Logcat" order="4" weight="0.5479833" /> <window_info anchor="bottom" id="Logcat" order="4" weight="0.5479833" />
<window_info anchor="bottom" id="Debug" order="5" /> <window_info anchor="bottom" id="Debug" order="5" />
<window_info active="true" anchor="bottom" id="Terminal" order="6" visible="true" weight="0.36717662" /> <window_info anchor="bottom" id="Terminal" order="6" weight="0.36666667" />
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
<window_info anchor="bottom" id="Flutter Performance" order="8" side_tool="true" /> <window_info anchor="bottom" id="Flutter Performance" order="8" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="9" /> <window_info anchor="bottom" id="Version Control" order="9" />
...@@ -327,6 +341,17 @@ ...@@ -327,6 +341,17 @@
<window_info anchor="right" id="Preview" order="7" /> <window_info anchor="right" id="Preview" order="7" />
</layout> </layout>
</component> </component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="Dart">
<url>file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart</url>
<line>74</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/test/gengmei_flutter_plugin_test.dart" /> <entry file="file://$PROJECT_DIR$/test/gengmei_flutter_plugin_test.dart" />
<entry file="file://$USER_HOME$/Downloads/flutter/packages/flutter/lib/src/services/message_codecs.dart"> <entry file="file://$USER_HOME$/Downloads/flutter/packages/flutter/lib/src/services/message_codecs.dart">
...@@ -534,8 +559,8 @@ ...@@ -534,8 +559,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m"> <entry file="file://$PROJECT_DIR$/ios/Classes/GengmeiFlutterPlugin.m">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="8514"> <state relative-caret-position="9768">
<caret line="387" column="22" selection-start-line="387" selection-start-column="12" selection-end-line="387" selection-end-column="22" /> <caret line="457" column="22" selection-start-line="457" selection-start-column="22" selection-end-line="457" selection-end-column="22" />
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -545,50 +570,50 @@ ...@@ -545,50 +570,50 @@
<entry file="file://$PROJECT_DIR$/ios/Classes/Image/ResultManager.m"> <entry file="file://$PROJECT_DIR$/ios/Classes/Image/ResultManager.m">
<provider selected="true" editor-type-id="text-editor" /> <provider selected="true" editor-type-id="text-editor" />
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="336"> <state relative-caret-position="207">
<caret line="68" selection-start-line="68" selection-end-line="68" /> <caret line="40" column="23" selection-start-line="40" selection-start-column="23" selection-end-line="40" selection-end-column="23" />
<folding> <folding>
<element signature="e#46#66#0" expanded="true" /> <element signature="e#46#106#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart"> <entry file="file://$PROJECT_DIR$/lib/gengmei_flutter_plugin.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119"> <state relative-caret-position="176">
<caret line="206" column="106" selection-start-line="206" selection-start-column="106" selection-end-line="206" selection-end-column="106" /> <caret line="21" column="19" selection-start-line="21" selection-start-column="19" selection-end-line="21" selection-end-column="19" />
<folding> <folding>
<element signature="e#45#62#0" expanded="true" /> <element signature="e#0#20#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/ScanImagePlugn.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumPage.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76"> <state relative-caret-position="-1229">
<caret line="27" column="19" selection-start-line="27" selection-start-column="16" selection-end-line="27" selection-end-column="19" /> <caret line="221" column="20" selection-start-line="221" selection-start-column="20" selection-end-line="221" selection-end-column="20" />
<folding>
<element signature="e#45#62#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/gengmei_flutter_plugin.dart"> <entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/page/album/AlbumModel.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="176"> <state relative-caret-position="141">
<caret line="21" column="19" selection-start-line="21" selection-start-column="19" selection-end-line="21" selection-end-column="19" /> <caret line="233" column="20" selection-start-line="233" selection-start-column="20" selection-end-line="233" selection-end-column="20" />
<folding> <folding>
<element signature="e#0#20#0" expanded="true" /> <element signature="e#46#66#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/lib/AlbumModel/repository/AlbumRepository.dart"> <entry file="file://$PROJECT_DIR$/lib/ScanImagePlugn.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="207"> <state relative-caret-position="289">
<caret line="40" column="23" selection-start-line="40" selection-start-column="23" selection-end-line="40" selection-end-column="23" /> <caret line="38" column="64" selection-start-line="38" selection-start-column="60" selection-end-line="38" selection-end-column="64" />
<folding>
<element signature="e#46#106#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
......
...@@ -56,19 +56,52 @@ class AlbumModel { ...@@ -56,19 +56,52 @@ class AlbumModel {
void _onEvent(Object event) { void _onEvent(Object event) {
var map = (event as Map); var map = (event as Map);
// var list = map[_nowDirName]; if (_mainValue == null || _mainValue.length == 0) {
_mainValue.forEach((k, itemList) { _mainValue = map;
var key = map[k]; } else {
if (key != null) { _mainValue.forEach((k, itemList) {
for (int i = 0; i < itemList.length; i++) { var key = map[k];
if (key[i] == null) { if (key != null) {
continue; for (int i = 0; i < itemList.length; i++) {
if (key[i] == null) {
continue;
}
itemList[i].path = key[i]["path"];
itemList[i].realPath = key[i]["realPath"];
} }
itemList[i].path = key[i]["path"];
itemList[i].realPath = key[i]["realPath"];
} }
} });
}); }
// var map = Map<String, List<dynamic>>.from(event);
//
// var newMap = Map<String, List<ScanImageItem>>();
// map.forEach((k, v) {
// var key = newMap["k"];
// if(key==null){
// newMap["k"]=new List<ScanImageItem>();
// }
// v.forEach((value){
// ScanImageItem item=new ScanImageItem();
// item.path=value["path"];
// item.isVideo=value["isVideo"]=="T"?true:false;
// item.during = value["during"] ?? "0";
// newMap["k"].add(item);
// });
// });
// _mainValue=newMap;
// var list = map[_nowDirName];
// _mainValue.forEach((k, itemList) {
// var key = map[k];
// if (key != null) {
// for (int i = 0; i < itemList.length; i++) {
// if (key[i] == null) {
// continue;
// }
// itemList[i].path = key[i]["path"];
// itemList[i].realPath = key[i]["realPath"];
// }
// }
// });
// var recordList=_mainValue[_nowDirName]; // var recordList=_mainValue[_nowDirName];
// List<ScanImageItem> tempList = new List(); // List<ScanImageItem> tempList = new List();
// if (list != null && !list.isEmpty) { // if (list != null && !list.isEmpty) {
...@@ -195,11 +228,38 @@ class AlbumModel { ...@@ -195,11 +228,38 @@ class AlbumModel {
return; return;
} }
AlbumRepository.getInstance().nativeCamera().listen((data) { AlbumRepository.getInstance().nativeCamera().listen((data) {
print("DATTTTTT ${data}"); if (data == null) {
if (data == null || data.isEmpty || data == "") {
// Toast.show(context, "没有拍摄照片"); // Toast.show(context, "没有拍摄照片");
} else { } else {
Navigator.pop(context, data); print(data);
ScanImageItem item = new ScanImageItem();
item.realPath = data["realPath"]==null?null:data["realPath"] as String;
item.path = data["path"] as String;
item.isVideo = false;
String foldName = data["folderName"] as String;
var list = _mainValue[foldName];
if (list == null) {
_mainValue[foldName] = new List();
_mainValue[foldName].add(item);
} else {
list.insert(0, item);
}
_mainValue[MainDir].insert(0, item);
_selectList.add(item.realPath);
bool haveIt = false;
_dirList.forEach((it) {
if (it.dirName == foldName) {
haveIt = true;
it.picCount++;
}
});
if (!haveIt) {
_dirList.add(new DirBean(foldName, 1, File(item.path)));
}
dirLive.notifyView(_dirList);
albumLive.notifyView(_mainValue[_nowDirName]);
// selectSizeLive.notifyView(_selectList.length + _selectVideoList.length);
// Navigator.pop(context, data);
// _selectList.add(data); // _selectList.add(data);
//TODO //TODO
} }
......
...@@ -32,7 +32,6 @@ class AlbumState extends State<AlbumPage> { ...@@ -32,7 +32,6 @@ class AlbumState extends State<AlbumPage> {
_model.initScanImages(context); _model.initScanImages(context);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -177,8 +176,9 @@ class AlbumState extends State<AlbumPage> { ...@@ -177,8 +176,9 @@ class AlbumState extends State<AlbumPage> {
} }
int newIndex = index - 2; int newIndex = index - 2;
if (imgList.data[newIndex] == null || if (imgList.data[newIndex] == null ||
imgList.data[newIndex].path == null|| imgList.data[newIndex].path == null
imgList.data[newIndex].realPath == null) { // || imgList.data[newIndex].realPath == null
) {
return Container(); return Container();
} }
return GestureDetector( return GestureDetector(
...@@ -204,13 +204,25 @@ class AlbumState extends State<AlbumPage> { ...@@ -204,13 +204,25 @@ class AlbumState extends State<AlbumPage> {
color: Colors.grey, color: Colors.grey,
size: 25, size: 25,
), ),
imgList.data[newIndex].isVideo?Icon(Icons.cancel,color: Colors.yellow,):Container(), imgList.data[newIndex].isVideo
? Icon(
Icons.cancel,
color: Colors.yellow,
)
: Container(),
_model.isFullSelect() && !_model.isSelect(newIndex) _model.isFullSelect() && !_model.isSelect(newIndex)
? Container( ? Container(
width: double.maxFinite, width: double.maxFinite,
height: double.maxFinite, height: double.maxFinite,
color: Colors.white60, color: Colors.white60,
) )
: Container(),
imgList.data[newIndex].isVideo&&imgList.data[newIndex].during != null
? Text(
imgList.data[newIndex].during,
style:
TextStyle(fontSize: 20, color: Colors.green),
)
: Container() : Container()
], ],
), ),
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
@property(atomic)Boolean execdTask; @property(atomic)Boolean execdTask;
@property(atomic)Boolean copyScareImgOk; @property(atomic)Boolean copyScareImgOk;
@property(atomic)Boolean finishScanImg; @property(atomic)Boolean finishScanImg;
@property(atomic,strong)NSMutableDictionary<NSString*,PHAsset *>*scanMap;
@property(atomic,strong)NSMutableDictionary<NSString*,NSString *>*takePhotoMap;
@end @end
@implementation GengmeiFlutterPlugin @implementation GengmeiFlutterPlugin
...@@ -28,9 +30,10 @@ UIViewController * viewController; ...@@ -28,9 +30,10 @@ UIViewController * viewController;
dispatch_queue_t queue; dispatch_queue_t queue;
NSObject<FlutterPluginRegistrar>* resign; NSObject<FlutterPluginRegistrar>* resign;
FlutterEventSink _eventSink; FlutterEventSink _eventSink;
NSString *cacheDirectory;
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar { + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
GengmeiFlutterPlugin* instance = [[GengmeiFlutterPlugin alloc] init]; GengmeiFlutterPlugin* instance = [[GengmeiFlutterPlugin alloc] init];
// resign=registrar; // resign=registrar;
FlutterMethodChannel* channel = [FlutterMethodChannel FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"gengmei_flutter_plugin" methodChannelWithName:@"gengmei_flutter_plugin"
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
...@@ -43,6 +46,12 @@ FlutterEventSink _eventSink; ...@@ -43,6 +46,12 @@ FlutterEventSink _eventSink;
eventChannelWithName:@"gengmei_flutter_plugin_event" eventChannelWithName:@"gengmei_flutter_plugin_event"
binaryMessenger:[registrar messenger]]; binaryMessenger:[registrar messenger]];
[chargingChannel setStreamHandler:instance]; [chargingChannel setStreamHandler:instance];
NSString *cacheDirectory1 = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];
cacheDirectory = [NSString stringWithFormat:@"%@/GM", cacheDirectory1];
if (![[NSFileManager defaultManager] fileExistsAtPath:cacheDirectory]) {
[[NSFileManager defaultManager] createDirectoryAtPath:cacheDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
} }
...@@ -85,12 +94,16 @@ FlutterEventSink _eventSink; ...@@ -85,12 +94,16 @@ FlutterEventSink _eventSink;
}else if(authStatus == AVAuthorizationStatusNotDetermined){ }else if(authStatus == AVAuthorizationStatusNotDetermined){
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){ if(granted){
[self nativeCamera]; dispatch_async(dispatch_get_main_queue(), ^{
[self nativeCamera];
});
} }
}]; }];
}else { }else {
NSLog(@"相机可用"); NSLog(@"相机可用");
[self nativeCamera]; dispatch_async(dispatch_get_main_queue(), ^{
[self nativeCamera];
});
} }
}else if([@"quit_page" isEqualToString:call.method]){ }else if([@"quit_page" isEqualToString:call.method]){
self.quitPage=true; self.quitPage=true;
...@@ -208,8 +221,50 @@ FlutterEventSink _eventSink; ...@@ -208,8 +221,50 @@ FlutterEventSink _eventSink;
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:temp] :@YES]; [[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:temp] :@YES];
}); });
}); });
} }else if([@"IOS_IMAGE_BY_PATH" isEqualToString:call.method]){
else{ NSString *path=call.arguments[@"path"];
long resultTemp=self.resultKey;
if(path!=nil){
dispatch_async(queue, ^{
if([[self.scanMap allKeys] containsObject:path]){
NSString *tempPath = NSTemporaryDirectory();
NSString* tempTake= [tempPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image_picker_%@", [[NSProcessInfo processInfo] globallyUniqueString]]];
PHAsset * assets=self.scanMap[path];
int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight];
float tempScareSize=1;
float limit=1560.0;
float max=MAX(picWidth, picHeight);
if(max>limit){
tempScareSize=limit/max;
}
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
imageRequestOption.synchronous =YES;
imageRequestOption.networkAccessAllowed = YES;
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable res, NSDictionary * _Nullable info) {
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(res, 0.8) ;
[data writeToFile:tempTake atomically:YES];
data=nil;
res=nil;
}
dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :tempTake];
});
}];
}else if ([[self.takePhotoMap allKeys] containsObject:path]){
dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :self.takePhotoMap[path]];
});
}else{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :nil];
}
});
}else{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :nil];
}
}else{
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
} }
} }
...@@ -238,78 +293,124 @@ FlutterEventSink _eventSink; ...@@ -238,78 +293,124 @@ FlutterEventSink _eventSink;
[viewController presentViewController:self.imagePicker animated:YES completion:nil]; [viewController presentViewController:self.imagePicker animated:YES completion:nil];
} }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; NSString *message = @"";
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; if (!error) {
NSData *data; dispatch_async(queue, ^{
NSString *tempPath = NSTemporaryDirectory();
data= UIImagePNGRepresentation(image); NSString* tempTake= [tempPath stringByAppendingPathComponent:[NSString stringWithFormat:@"image_picker_%@", [[NSProcessInfo processInfo] globallyUniqueString]]];
// if (UIImagePNGRepresentation(image) == nil){ NSData *takeData= UIImageJPEGRepresentation(image,0.8);
// data = UIImageJPEGRepresentation(image, 1); [takeData writeToFile:tempTake atomically:YES];
// } else { CGFloat fixelW = CGImageGetWidth(image.CGImage);
// data = UIImagePNGRepresentation(image); CGFloat fixelH = CGImageGetHeight(image.CGImage);
// } CGFloat max=MAX(fixelW, fixelH);
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString]; float scare=1.0;
NSString *tmpFile = [NSString stringWithFormat:@"image_picker_%@", guid]; if(max>320.0){
NSString* tmpPath= [cacheDirectory stringByAppendingPathComponent:tmpFile]; scare=320.0/max;
if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:data attributes:nil]) { }
dispatch_async(dispatch_get_main_queue(), ^{ CGSize newSize=CGSizeMake(fixelW*scare,fixelH*scare);
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :tmpPath]; UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data= UIImageJPEGRepresentation(newImage,0.8);
NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString];
NSString *tmpFile = [NSString stringWithFormat:@"image_picker_%@", guid];
NSString* tmpPath= [cacheDirectory stringByAppendingPathComponent:tmpFile];
[data writeToFile:tmpPath atomically:YES];
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableDictionary * dict=[[NSMutableDictionary alloc] init];
[dict setObject:tmpPath forKey:@"path"];
[dict setObject:@"GengmeiAlbum" forKey:@"folderName"];
[self.takePhotoMap setObject:tempTake forKey:tmpPath];
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :dict];
});
}); });
} else { }else
{
NSLog(@"TACK PIC ERROR");
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :@""]; [[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :nil];
}); });
} }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
[picker dismissViewControllerAnimated:YES completion:nil]; [picker dismissViewControllerAnimated:YES completion:nil];
/* 此处参数 info 是一个字典,下面是字典中的键值 (从相机获取的图片和相册获取的图片时,两者的info值不尽相同)
* UIImagePickerControllerMediaType; // 媒体类型
* UIImagePickerControllerOriginalImage; // 原始图片
* UIImagePickerControllerEditedImage; // 裁剪后图片
* UIImagePickerControllerCropRect; // 图片裁剪区域(CGRect)
* UIImagePickerControllerMediaURL; // 媒体的URL
* UIImagePickerControllerReferenceURL // 原件的URL
* UIImagePickerControllerMediaMetadata // 当数据来源是相机时,此值才有效
*/
// 从info中将图片取出,并加载到imageView当中
// UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// self.imageView.image = image;
// // 创建保存图像时需要传入的选择器对象(回调方法格式固定)
// SEL selectorToCall = @selector(image:didFinishSavingWithError:contextInfo:);
// // 将图像保存到相册(第三个参数需要传入上面格式的选择器对象)
// UIImageWriteToSavedPhotosAlbum(image, self, selectorToCall, NULL);
} }
// 取消选取调用的方法 // 取消选取调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[viewController dismissViewControllerAnimated:YES completion:nil]; [viewController dismissViewControllerAnimated:YES completion:nil];
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :@""]; [[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:self.nativeCameraKey] :nil];
} }
bool isRunning=false;
-(void)scanPhone:(long)resultId{ -(void)scanPhone:(long)resultId{
self.quitPage=false; self.quitPage=false;
if (self.finishScanImg) { if (self.finishScanImg) {
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultId] :self.finalMap]; [[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultId] :self.finalMap];
return; return;
} }
// if(isRunning){
// isRunning=true;
// return;
// }
if (self.finalMap==nil) { if (self.finalMap==nil) {
self.finalMap=[NSMutableDictionary dictionary]; self.finalMap=[NSMutableDictionary dictionary];
} }
if(self.scanMap==nil){
self.scanMap=[NSMutableDictionary dictionary];
}
if(self.takePhotoMap==nil){
self.takePhotoMap=[NSMutableDictionary dictionary];
}
[self.finalMap removeAllObjects];
[self.scanMap removeAllObjects];
[self.takePhotoMap removeAllObjects];
self.nowSize=0; self.nowSize=0;
self.needSize=0; self.needSize=0;
[self.finalMap removeAllObjects];
[assetCollectionList removeAllObjects]; [assetCollectionList removeAllObjects];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ dispatch_async(queue, ^{
[self scanPhoneImage]; [self scanPhoneImage];
[self copyImg:resultId]; [self copyImg:resultId];
}); });
} }
- (void)getThumbnailImages
{
// 获得所有的自定义相簿
PHFetchResult<PHAssetCollection *> *assetCollections = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
// 遍历所有的自定义相簿
for (PHAssetCollection *assetCollection in assetCollections) {
[self enumerateAssetsInAssetCollection:assetCollection original:NO];
}
// 获得相机胶卷
PHAssetCollection *cameraRoll = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:nil].lastObject;
[self enumerateAssetsInAssetCollection:cameraRoll original:NO];
}
- (void)enumerateAssetsInAssetCollection:(PHAssetCollection *)assetCollection original:(BOOL)original
{
NSLog(@"相簿名:%@", assetCollection.localizedTitle);
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
// 同步获得图片, 只会返回1张图片
options.synchronous = YES;
// 获得某个相簿中的所有PHAsset对象
PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsInAssetCollection:assetCollection options:nil];
for (PHAsset *asset in assets) {
// 是否要原图
CGSize size = original ? CGSizeMake(asset.pixelWidth, asset.pixelHeight) : CGSizeZero;
// 从asset中获得图片
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
NSLog(@"%@", result);
}];
}
}
-(void)scanPhoneImage{ -(void)scanPhoneImage{
PHFetchResult<PHAssetCollection *> *favoritesCollection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumFavorites options:NO]; PHFetchResult<PHAssetCollection *> *favoritesCollection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeSmartAlbumFavorites options:NO];
// 获得相机胶卷 // 获得相机胶卷
...@@ -351,37 +452,6 @@ bool isRunning=false; ...@@ -351,37 +452,6 @@ bool isRunning=false;
} }
} }
-(void)resultImgs:(long)resultId{
if(self.quitPage){
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultId] :self.finalMap];
// if(self.execdTask){
// return ;
// }
// self.execdTask=true;
// [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:@selector(thread:) toTarget:self withObject:@"baby"];
// [NSThread detachNewThreadSelector: toTarget:<#(nonnull id)#> withObject:<#(nullable id)#>:^{
// NSLog(@"block run...");
//
// }];
// [self performSelectorInBackground:@selector(run) withObject:nil];
// dispatch_queue_t queue1 = dispatch_queue_create("com.onealon.gcdTest1", DISPATCH_QUEUE_CONCURRENT);
// dispatch_sync(queue1, ^{
//
// });
});
}
- (void)thread:(id)parameter{
     [self execRealImg];
}
-(void)upImgs{ -(void)upImgs{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if(_eventSink!=nil&&!self.quitPage){ if(_eventSink!=nil&&!self.quitPage){
...@@ -391,7 +461,20 @@ bool isRunning=false; ...@@ -391,7 +461,20 @@ bool isRunning=false;
} }
-(void) copyImg:(long)resultId{ -(void) copyImg:(long)resultId{
NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; self.copySize=0;
self.nowSize=0;
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
imageRequestOption.synchronous =NO;
imageRequestOption.networkAccessAllowed = YES;
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
//PHImageRequestOptionsDeliveryModeHighQualityFormat。//PHImageRequestOptionsDeliveryModeFastFormat
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;//PHImageManagerMaximumSize
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.networkAccessAllowed = true;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
for (int j=0; j<assetCollectionList.count; j++) { for (int j=0; j<assetCollectionList.count; j++) {
AlbumItem * item=assetCollectionList[j]; AlbumItem * item=assetCollectionList[j];
...@@ -409,69 +492,82 @@ bool isRunning=false; ...@@ -409,69 +492,82 @@ bool isRunning=false;
imgName=[NSString stringWithFormat:@"IMG_%@",timeSp]; imgName=[NSString stringWithFormat:@"IMG_%@",timeSp];
} }
__block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName]; __block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName];
if ([fileManager fileExistsAtPath:tmpPath]==YES){ if(assets.mediaType==PHAssetMediaTypeVideo){
self.nowSize++; if ([fileManager fileExistsAtPath:tmpPath]==YES){
NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary]; [[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
[queryItemDict setObject:tmpPath forKey:@"path"]; AVURLAsset *urlAsset = (AVURLAsset *)asset;
if(assets.mediaType==PHAssetMediaTypeVideo){ self.nowSize++;
[queryItemDict setObject:@"T" forKey:@"isVideo"]; NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
}else{ [queryItemDict setObject:[self getVideoDuring:urlAsset.duration] forKey:@"during"];
[queryItemDict setObject:@"F" forKey:@"isVideo"]; [queryItemDict setObject:tmpPath forKey:@"path"];
} [queryItemDict setObject:@"T" forKey:@"isVideo"];
NSMutableArray * arr=self.finalMap[docName]; [self.scanMap setObject:assets forKey:tmpPath];
if (arr==nil) { NSMutableArray * arr=self.finalMap[docName];
self.finalMap[docName]=[NSMutableArray array]; if (arr==nil) {
[self.finalMap[docName] addObject:queryItemDict]; self.finalMap[docName]=[NSMutableArray array];
}else{ [self.finalMap[docName] addObject:queryItemDict];
[self.finalMap[docName] addObject:queryItemDict]; }else{
} [self.finalMap[docName] addObject:queryItemDict];
[self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict]; }
NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize); [self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict];
if (self.nowSize==self.needSize) { NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize);
[self resultImgs:resultId]; if (self.nowSize==self.needSize) {
} [self resultImgs:resultId];
}else{ }
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init]; }];
imageRequestOption.synchronous =YES;
int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight];
float tempScareSize=1;
if(picWidth>picHeight){
if (picWidth>320.0) {
tempScareSize=320.0/picWidth;
}
}else{ }else{
if (picHeight>320.0) { int picWidth=[assets pixelWidth];
tempScareSize=320.0/picHeight; int picHeight=[assets pixelHeight];
float tempScareSize=1;
if(picWidth>picHeight){
if (picWidth>320.0) {
tempScareSize=320.0/picWidth;
}
}else{
if (picHeight>320.0) {
tempScareSize=320.0/picHeight;
}
} }
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 0.8) ;
[data writeToFile:tmpPath atomically:YES];
data=nil;
result=nil;
}
[[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
AVURLAsset *urlAsset = (AVURLAsset *)asset;
self.nowSize++;
NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
[queryItemDict setObject:[self getVideoDuring:urlAsset.duration] forKey:@"during"];
[queryItemDict setObject:tmpPath forKey:@"path"];
[queryItemDict setObject:@"T" forKey:@"isVideo"];
[self.scanMap setObject:assets forKey:tmpPath];
NSMutableArray * arr=self.finalMap[docName];
if (arr==nil) {
self.finalMap[docName]=[NSMutableArray array];
[self.finalMap[docName] addObject:queryItemDict];
}else{
[self.finalMap[docName] addObject:queryItemDict];
}
[self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict];
NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize);
if (self.nowSize==self.needSize) {
[self resultImgs:resultId];
}
}];
}];
} }
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize); }else{
imageRequestOption.networkAccessAllowed = YES; if ([fileManager fileExistsAtPath:tmpPath]==YES){
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat; NSLog(@"EXISTTTTTTT");
//PHImageRequestOptionsDeliveryModeHighQualityFormat。//PHImageRequestOptionsDeliveryModeFastFormat self.nowSize++;
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
//PHImageManagerMaximumSize
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 0.7) ;
[data writeToFile:tmpPath atomically:YES];
data=nil;
result=nil;
}
// [UIImageJPEGRepresentation(result,1) writeToFile:tmpPath atomically:YES];
// [UIImageJPEGRepresentation([self image:result byScalingToSize:temp],0.8) writeToFile:realPath atomically:YES ];
NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary]; NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
[queryItemDict setObject:tmpPath forKey:@"path"]; [queryItemDict setObject:tmpPath forKey:@"path"];
[queryItemDict setObject:imgName forKey:@"name"]; [queryItemDict setObject:@"F" forKey:@"isVideo"];
if(assets.mediaType==PHAssetMediaTypeVideo){ [self.scanMap setObject:assets forKey:tmpPath];
[queryItemDict setObject:@"T" forKey:@"isVideo"];
}else{
[queryItemDict setObject:@"F" forKey:@"isVideo"];
}
NSMutableArray * arr=self.finalMap[docName]; NSMutableArray * arr=self.finalMap[docName];
self.nowSize++;
if (arr==nil) { if (arr==nil) {
self.finalMap[docName]=[NSMutableArray array]; self.finalMap[docName]=[NSMutableArray array];
[self.finalMap[docName] addObject:queryItemDict]; [self.finalMap[docName] addObject:queryItemDict];
...@@ -480,25 +576,86 @@ bool isRunning=false; ...@@ -480,25 +576,86 @@ bool isRunning=false;
} }
[self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict]; [self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict];
NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize); NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize);
result=nil;
if (self.nowSize==self.needSize) { if (self.nowSize==self.needSize) {
[self resultImgs:resultId]; [self resultImgs:resultId];
} }
}]; }else{
int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight];
float tempScareSize=1;
if(picWidth>picHeight){
if (picWidth>320.0) {
tempScareSize=320.0/picWidth;
}
}else{
if (picHeight>320.0) {
tempScareSize=320.0/picHeight;
}
}
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
self.nowSize++;
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 0.8) ;
[data writeToFile:tmpPath atomically:YES];
data=nil;
result=nil;
}
NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
[queryItemDict setObject:tmpPath forKey:@"path"];
[queryItemDict setObject:@"F" forKey:@"isVideo"];
[self.scanMap setObject:assets forKey:tmpPath];
NSMutableArray * arr=self.finalMap[docName];
self.copySize++;
if (arr==nil) {
self.finalMap[docName]=[NSMutableArray array];
[self.finalMap[docName] addObject:queryItemDict];
}else{
[self.finalMap[docName] addObject:queryItemDict];
}
[self.finalMap[@"IsGengmeiAlbumAllImages"] addObject:queryItemDict];
NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize);
if (self.nowSize==self.needSize) {
[self resultImgs:resultId];
}
// if(self.needSize>80&&self.copySize==80){
// [self resultImgs:resultId];
// }else if(self.needSize<=80&&self.nowSize==self.needSize){
// [self resultImgs:resultId];
// }else if(self.needSize>80&&self.nowSize==self.needSize){
// [self upImgs];
// }else if(self.needSize>80&&self.copySize>80&&self.copySize%200==0){
// [self upImgs];
// }
}];
}
} }
} }
} }
} }
-(void)execRealImg{ -(NSString*) getVideoDuring:(CMTime)duration{
NSUInteger videoDurationSeconds = CMTimeGetSeconds(duration);
NSUInteger dMinutes = floor(videoDurationSeconds % 3600 / 60);
NSUInteger dSeconds = floor(videoDurationSeconds % 3600 % 60);
if(dMinutes>99){
dMinutes=99;
}
NSString *videoDurationText = [NSString stringWithFormat:@"%02i:%02i", dMinutes, dSeconds];
NSLog(@"ISVIDEO DURING %@",videoDurationText);
return videoDurationText;
}
-(void)execRealImg:(long)resultId{
dispatch_queue_t queue = dispatch_queue_create("execRealImg", DISPATCH_QUEUE_CONCURRENT);
self.nowSize=0; self.nowSize=0;
self.copySize=0; self.copySize=0;
NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
for (int j=0; j<assetCollectionList.count; j++) { for (int j=0; j<assetCollectionList.count; j++) {
AlbumItem * item=assetCollectionList[j]; AlbumItem * item=assetCollectionList[j];
PHFetchResult<PHAsset *> * assetResult =[item assets]; PHFetchResult<PHAsset *> * assetResult =[item assets];
NSLog(@"09090909090 %d %d",[assetResult count],self.needSize);
for (int i=0; i<[assetResult count]; i++) { for (int i=0; i<[assetResult count]; i++) {
if(self.quitPage){ if(self.quitPage){
return; return;
...@@ -514,92 +671,126 @@ bool isRunning=false; ...@@ -514,92 +671,126 @@ bool isRunning=false;
imgRealName=[NSString stringWithFormat:@"REAL_PATH_IMG_%@",timeSp]; imgRealName=[NSString stringWithFormat:@"REAL_PATH_IMG_%@",timeSp];
} }
__block NSString *realPath=[cacheDirectory stringByAppendingPathComponent:imgRealName]; __block NSString *realPath=[cacheDirectory stringByAppendingPathComponent:imgRealName];
NSLog(@"REALLL %@",realPath);
__block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName]; __block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName];
if ([fileManager fileExistsAtPath:realPath]==YES){ if ([fileManager fileExistsAtPath:realPath]==YES){
self.nowSize++; self.nowSize++;
if(assets.mediaType==PHAssetMediaTypeVideo){
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.networkAccessAllowed = true;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
[[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
}];
}else{
}
NSLog(@"!!!REAL IS EXIE!! %@",realPath); NSLog(@"!!!REAL IS EXIE!! %@",realPath);
NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName]; [self searchPath:realPath :tmpPath :docName];
for (int x=0; x<[array count]; x++) {
NSMutableDictionary<NSString*,NSObject*>* map=[array objectAtIndex:x];
NSString* index=[map objectForKey:@"path"];
if ([index isEqualToString:tmpPath]) {
[map setObject:realPath forKey:@"realPath"];
break;
}
}
NSLog(@"SIZEEE %d %d ",self.nowSize,self.needSize); NSLog(@"SIZEEE %d %d ",self.nowSize,self.needSize);
if (self.nowSize==self.needSize) { if (self.nowSize==self.needSize) {
[self upImgs]; // [self upImgs];
[self reslutImg:resultId];
self.finishScanImg=true; self.finishScanImg=true;
// self.execdTask=true;
} }
}else{ }else{
NSLog(@"file NOT EXIT !! %@",realPath); NSLog(@"file NOT EXIT !! %@",realPath);
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init]; dispatch_async(queue, ^{
imageRequestOption.synchronous =YES; if(assets.mediaType==PHAssetMediaTypeVideo){
int picWidth=[assets pixelWidth]; PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
int picHeight=[assets pixelHeight]; options.version = PHImageRequestOptionsVersionCurrent;
float tempScareSize=1; options.networkAccessAllowed = true;
float limit=1560.0; options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
if(picWidth>picHeight){ [[PHImageManager defaultManager]requestAVAssetForVideo:assets options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
if (picWidth>limit) { self.nowSize++;
tempScareSize=limit/picWidth; AVURLAsset *urlAsset = (AVURLAsset *)asset;
} NSString* videoUrl=[NSString stringWithFormat:@"%@",urlAsset.URL];
}else{ [self searchPath:videoUrl :tmpPath :docName];
if (picHeight>limit) { if (self.nowSize==self.needSize) {
tempScareSize=limit/picHeight; [self upImgs];
} // [self reslutImg:resultId];
} self.finishScanImg=true;
NSLog(@"SCARE SZIE %d %d %f %f %f",picWidth,picHeight,tempScareSize,picWidth*tempScareSize,picHeight*tempScareSize);
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize); }
imageRequestOption.networkAccessAllowed = YES; }];
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat; }else{
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat; PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast; imageRequestOption.synchronous =NO;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted; int picWidth=[assets pixelWidth];
[[PHImageManager defaultManager] requestImageDataForAsset:assets options:imageRequestOption resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { int picHeight=[assets pixelHeight];
// UIImage *image = [UIImage imageWithData:imageData]; float tempScareSize=1;
[imageData writeToFile:realPath atomically:YES]; float limit=1560.0;
//获取照片 image if(picWidth>picHeight){
self.nowSize++; if (picWidth>limit) {
self.copySize++; tempScareSize=limit/picWidth;
NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName]; }
for (int x=0; x<[array count]; x++) { }else{
NSMutableDictionary<NSString*,NSObject*>* map=[array objectAtIndex:x]; if (picHeight>limit) {
NSString* index=[map objectForKey:@"path"]; tempScareSize=limit/picHeight;
if ([index isEqualToString:tmpPath]) { }
[map setObject:realPath forKey:@"realPath"];
break;
} }
NSLog(@"SCARE SZIE %d %d %f %f %f",picWidth,picHeight,tempScareSize,picWidth*tempScareSize,picHeight*tempScareSize);
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
imageRequestOption.networkAccessAllowed = YES;
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
[[PHImageManager defaultManager] requestImageDataForAsset:assets options:imageRequestOption resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
self.nowSize++;
self.copySize++;
NSString* finalRealPath;
if([info objectForKey:@"PHImageFileURLKey"]){
NSURL * path=[info objectForKey:@"PHImageFileURLKey"];
NSLog(@"PATHHHH %@",path);
finalRealPath=[NSString stringWithFormat:@"%@",path];
}else{
NSLog(@"NOT HAVE IT!!! %@",realPath);
[imageData writeToFile:realPath atomically:YES];
finalRealPath=realPath;
}
[self searchPath:finalRealPath :tmpPath :docName];
NSLog(@"SIZEEE %d %d %d",self.nowSize,self.needSize,self.copySize);
if (self.nowSize==self.needSize) {
[self upImgs];
// [self reslutImg:resultId];
self.finishScanImg=true;
}
// else if(self.copySize%100==0||self.copySize==50){
// [self upImgs];
// }
}];
} }
NSLog(@"SIZEEE %d %d %d",self.nowSize,self.needSize,self.copySize); });
// result=nil;
if (self.nowSize==self.needSize) {
[self upImgs];
self.finishScanImg=true;
self.execdTask=true;
}else if(self.copySize%20==0||self.copySize==10){
[self upImgs];
}
}];
} }
} }
} }
} }
-(void)resultImgs:(long)resultId{
dispatch_async(dispatch_get_main_queue(), ^{
if(!self.quitPage){
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultId] :self.finalMap];
// dispatch_async(queue, ^{
// [self execRealImg:resultId];
// });
}
});
}
-(void)reslutImg:(long)resultId{
dispatch_async(dispatch_get_main_queue(), ^{
if(!self.quitPage){
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultId] :self.finalMap];
}
});
}
-(void)searchPath:(NSString*)finalRealPath :(NSString*)tmpPath :(NSString*)docName{
NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName];
for (int x=0; x<[array count]; x++) {
NSMutableDictionary<NSString*,NSObject*>* map=[array objectAtIndex:x];
NSString* index=[map objectForKey:@"path"];
if ([index isEqualToString:tmpPath]) {
[map setObject:finalRealPath forKey:@"realPath"];
break;
}
}
}
-(void)writeImage:(UIImage *)image dest:(NSString*)path{ -(void)writeImage:(UIImage *)image dest:(NSString*)path{
@autoreleasepool { @autoreleasepool {
CFURLRef url=(__bridge CFURLRef)[NSURL fileURLWithPath:path]; CFURLRef url=(__bridge CFURLRef)[NSURL fileURLWithPath:path];
......
...@@ -34,6 +34,11 @@ class ScanImagePlugn { ...@@ -34,6 +34,11 @@ class ScanImagePlugn {
static Future<bool> quitPage(MethodChannel channel) async { static Future<bool> quitPage(MethodChannel channel) async {
return await channel.invokeMethod("quit_page"); return await channel.invokeMethod("quit_page");
} }
static Future<String> ios_album_path(
MethodChannel channel, String path) async {
return await channel.invokeMethod("IOS_IMAGE_BY_PATH", {"path", path});
}
} }
class ScanImageItem { class ScanImageItem {
......
...@@ -23,6 +23,10 @@ class GengmeiFlutterPlugin { ...@@ -23,6 +23,10 @@ class GengmeiFlutterPlugin {
return await ScanImagePlugn.nativeCamera(_channel, authority); return await ScanImagePlugn.nativeCamera(_channel, authority);
} }
static Future<String> ios_album_path(String path) async {
return await ScanImagePlugn.ios_album_path(_channel, path);
}
static Future<bool> quitPage() async { static Future<bool> quitPage() async {
return await ScanImagePlugn.quitPage(_channel); return await ScanImagePlugn.quitPage(_channel);
} }
......
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