Skip to content

Commit

Permalink
Support pki
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Jul 1, 2022
1 parent a246a3d commit 03f41ba
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 80 deletions.
20 changes: 20 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:mimeType="*/*"
android:pathPattern=".*\\.pkz"
Expand All @@ -60,6 +61,25 @@
android:mimeType="*/*"
android:pathPattern=".*\\.pkz"
android:scheme="file" />

<data
android:mimeType="*/*"
android:pathPattern=".*\\.pki"
android:scheme="content" />
<data
android:mimeType="*/*"
android:pathPattern=".*\\.pki"
android:scheme="file" />

<data
android:mimeType="*/*"
android:pathPattern=".*\\.zip"
android:scheme="content" />
<data
android:mimeType="*/*"
android:pathPattern=".*\\.zip"
android:scheme="file" />

</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
4 changes: 4 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
<key>public.filename-extension</key>
<array>
<string>pkz</string>
<string>pki</string>
<string>zip</string>
</array>
<key>public.mime-type</key>
<array>
<string>text/vnd.niuhuan.pkz</string>
<string>text/vnd.niuhuan.pki</string>
<string>text/vnd.niuhuan.zip</string>
</array>
</dict>
</dict>
Expand Down
35 changes: 33 additions & 2 deletions lib/basic/Common.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
import 'package:uni_links/uni_links.dart';
import 'package:uri_to_file/uri_to_file.dart';

import '../screens/DownloadOnlyImportScreen.dart';
import '../screens/PkzArchiveScreen.dart';
import 'config/TimeOffsetHour.dart';

/// 默认的图片尺寸
Expand Down Expand Up @@ -145,7 +152,8 @@ Future<T?> chooseMapDialog<T>(

/// 输入对话框1
var _controller = TextEditingController.fromValue(const TextEditingValue(text: ''));
var _controller =
TextEditingController.fromValue(const TextEditingValue(text: ''));

Future<String?> displayTextInputDialog(BuildContext context,
{String? title,
Expand Down Expand Up @@ -259,7 +267,7 @@ Future<String?> inputString(BuildContext context, String title,
Text(title),
TextField(
controller: _textEditController,
decoration: InputDecoration(
decoration: InputDecoration(
labelText: hint,
),
),
Expand All @@ -285,3 +293,26 @@ Future<String?> inputString(BuildContext context, String title,
},
);
}

StreamSubscription<String?> linkSubscript(BuildContext context) {
return linkStream.listen((uri) async {
if (uri == null) return;
if (RegExp(r"^.*\.pkz$").allMatches(uri).isNotEmpty) {
File file = await toFile(uri);
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) =>
PkzArchiveScreen(pkzPath: file.path),
),
);
} else if (RegExp(r"^.*\.((pki)|(zip))$").allMatches(uri).isNotEmpty) {
File file = await toFile(uri);
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) =>
DownloadOnlyImportScreen(path: file.path),
),
);
}
});
}
14 changes: 14 additions & 0 deletions lib/basic/Method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ class Method {
});
}

/// 导出下载的漫画到pki
Future<dynamic> exportComicDownloadToPki(String comicId, String dir, String name) {
return _flatInvoke("exportComicDownloadToPki", {
"comicId": comicId,
"dir": dir,
"name": name,
});
}

/// 导出下载的图片到HTML+JPG
Future<dynamic> exportComicDownloadToJPG(
String comicId,
Expand Down Expand Up @@ -588,6 +597,11 @@ class Method {
return _flatInvoke("importComicDownload", zipPath);
}

/// 从pki导入漫画
Future<dynamic> importComicDownloadPki(String zipPath) {
return _flatInvoke("importComicDownloadPki", zipPath);
}

/// 从网络接收漫画
Future<dynamic> importComicDownloadUsingSocket(String addr) {
return _flatInvoke("importComicDownloadUsingSocket", addr);
Expand Down
14 changes: 1 addition & 13 deletions lib/screens/AccountScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ class _AccountScreenState extends State<AccountScreen> {

@override
void initState() {
// todo 不必要cancel 随机监听就好了, APP关闭时销毁, 考虑移动到APP里
_linkSubscription = linkStream.listen((uri) async {
if (uri == null) return;
RegExp regExp = RegExp(r"^.*\.pkz$");
final matches = regExp.allMatches(uri.toString());
if (matches.isNotEmpty) {
File file = await toFile(uri.toString());
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
PkzArchiveScreen(pkzPath: file.path),
));
}
});
_linkSubscription = linkSubscript(context);

_loadProperties();
super.initState();
Expand Down
16 changes: 2 additions & 14 deletions lib/screens/AppScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:pikapika/screens/components/Badge.dart';
import 'package:uni_links/uni_links.dart';
import 'package:uri_to_file/uri_to_file.dart';

import '../basic/Common.dart';
import 'CategoriesScreen.dart';
import 'PkzArchiveScreen.dart';
import 'SpaceScreen.dart';
Expand All @@ -25,20 +26,7 @@ class _AppScreenState extends State<AppScreen> {
@override
void initState() {
versionEvent.subscribe(_onVersion);
// todo 不必要cancel 随机监听就好了, APP关闭时销毁, 考虑移动到APP里
_linkSubscription = linkStream.listen((uri) async {
if (uri == null) return;
RegExp regExp = RegExp(r"^.*\.pkz$");
final matches = regExp.allMatches(uri);
if (matches.isNotEmpty) {
File file = await toFile(uri);
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
PkzArchiveScreen(pkzPath: file.path),
));
}
});

_linkSubscription = linkSubscript(context);
super.initState();
}

Expand Down
56 changes: 55 additions & 1 deletion lib/screens/DownloadExportToFileScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class _DownloadExportToFileScreenState
},
child: _buildButtonInner('传输到其他设备'),
),
Container(height: 10),
],
);
},
Expand Down Expand Up @@ -234,7 +235,60 @@ class _DownloadExportToFileScreenState
}
},
child:
_buildButtonInner('导出到xxx.pkz\n(可直接打开观看的格式,不支持导入)\n(可以躲避网盘或者聊天软件的扫描)'),
_buildButtonInner('导出到xxx.pkz\n(可直接打开观看的格式,不支持导入)\n(可以躲避网盘或者聊天软件的扫描)'),
));
widgets.add(Container(height: 10));
/////////////////////
/////////////////////
widgets.add(MaterialButton(
onPressed: () async {
late String? path;
try {
path = await chooseFolder(context);
} catch (e) {
defaultToast(context, "$e");
return;
}
var name = "";
if (currentExportRename()) {
var rename = await inputString(
context,
"请输入保存后的名称",
defaultValue: _task.title,
);
if (rename != null && rename.isNotEmpty) {
name = rename;
} else {
return;
}
}
print("path $path");
if (path != null) {
try {
setState(() {
exporting = true;
});
await method.exportComicDownloadToPki(
widget.comicId,
path,
name,
);
setState(() {
exportResult = "导出成功";
});
} catch (e) {
setState(() {
exportResult = "导出失败 $e";
});
} finally {
setState(() {
exporting = false;
});
}
}
},
child:
_buildButtonInner('导出到xxx.pki\n(只支持导入, 不支持直接阅读)\n(可以躲避网盘或者聊天软件的扫描)\n(后期版本可能支持直接阅读)'),
));
widgets.add(Container(height: 10));
/////////////////////
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/DownloadExportingGroupScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _DownloadExportingGroupScreenState
var rename = await inputString(
context,
"请输入保存后的名称",
defaultValue: "${DateTime.now().millisecondsSinceEpoch}.pkz",
defaultValue: "${DateTime.now().millisecondsSinceEpoch}",
);
if (rename != null && rename.isNotEmpty) {
name = rename;
Expand Down
44 changes: 31 additions & 13 deletions lib/screens/DownloadImportScreen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:flutter/material.dart';
import 'package:pikapika/basic/Channels.dart';
import 'package:pikapika/basic/Common.dart';
Expand Down Expand Up @@ -91,29 +92,46 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
defaultToast(context, "$e");
return;
}
var ls = await FilePicker.platform.pickFiles(
dialogTitle: '选择要导入的文件',
allowMultiple: false,
initialDirectory: chooseRoot,
type: FileType.custom,
allowedExtensions: ['pkz', 'zip'],
allowCompression: false,
);
String? path = ls != null && ls.count > 0 ? ls.paths[0] : null;
String? path;
if (Platform.isAndroid) {
path = await FilesystemPicker.open(
title: 'Open file',
context: context,
rootDirectory: Directory(chooseRoot),
fsType: FilesystemType.file,
folderIconColor: Colors.teal,
allowedExtensions: ['.pkz', '.zip', '.pki'],
fileTileSelectMode: FileTileSelectMode.wholeTile,
);
}else{
var ls = await FilePicker.platform.pickFiles(
dialogTitle: '选择要导入的文件',
allowMultiple: false,
initialDirectory: chooseRoot,
type: FileType.custom,
allowedExtensions: ['pkz', 'zip', 'pki'],
allowCompression: false,
);
path = ls != null && ls.count > 0 ? ls.paths[0] : null;
}
if (path != null) {
if (path.endsWith(".pkz")) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) =>
PkzArchiveScreen(pkzPath: path),
PkzArchiveScreen(pkzPath: path!),
),
);
} else if (path.endsWith(".zip")) {
} else if (path.endsWith(".zip") || path.endsWith(".pki")) {
try {
setState(() {
_importing = true;
});
await method.importComicDownload(path);
if(path.endsWith(".zip")){
await method.importComicDownload(path);
} else if(path.endsWith(".pki")){
await method.importComicDownloadPki(path);
}
setState(() {
_importMessage = "导入成功";
});
Expand All @@ -130,7 +148,7 @@ class _DownloadImportScreenState extends State<DownloadImportScreen> {
}
},
child: const Text(
'选择zip文件进行导入\n选择pkz文件进行阅读',
'选择zip文件进行导入\n选择pki文件进行导入\n选择pkz文件进行阅读',
style: TextStyle(),
textAlign: TextAlign.center,
),
Expand Down
Loading

0 comments on commit 03f41ba

Please sign in to comment.