Skip to content

Commit

Permalink
fix android download with saf
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Nov 26, 2022
1 parent cd68ff5 commit f3ba1b2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/v1.3.2+492.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Fix
- 修复前两个版本修改下载导致的一些下载异常问题 (下载后不能正常阅读),异常下载任务请删掉重新下载

# Feature
- 样式设置中,为网格和瀑布流模式添加自定义子项宽度的设置
33 changes: 32 additions & 1 deletion lib/common/controller/download_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ class DownloadController extends GetxController {
Future<void> allowMediaScan(bool allow) async {
final downloadPath = await _getGalleryDownloadPath();

if (Platform.isAndroid) {
final uriList = await ss.persistedUriPermissions();
logger.d('uriList:$uriList');
if (uriList == null || uriList.isEmpty) {
logger.e('allowMediaScan uriList is null');
}
}

final pathList = <String>[];

logger.v('allowMediaScan $pathList');
Expand Down Expand Up @@ -869,6 +877,27 @@ class DownloadController extends GetxController {
return _fileNameWithoutExtension;
}

Future<void> checkSafPath(
{String? uri, bool saveDownloadPath = false}) async {
if (Platform.isAndroid) {
final String checkUri = uri ?? ehConfigService.downloadLocatino;
final uriList = await ss.persistedUriPermissions();
if (uriList == null || uriList.isEmpty) {
logger.e('persisted uriList is null');
} else {
if (!uriList.any((element) => element.uri.toString() == checkUri)) {
logger.e('uriList not contains $checkUri');
final uri =
await ss.openDocumentTree(initialUri: Uri.tryParse(checkUri));
logger.d('uri $uri');
if (uri != null && saveDownloadPath) {
ehConfigService.downloadLocatino = uri.toString();
}
}
}
}
}

/// 获取下载路径
Future<String> _getGalleryDownloadPath({String dirName = ''}) async {
late final String saveDirPath;
Expand All @@ -895,6 +924,8 @@ class DownloadController extends GetxController {
}

if (saveDirPath.isContentUri) {
await checkSafPath(saveDownloadPath: true);

final galleryDirUrl = '${ehConfigService.downloadLocatino}%2F$dirName';
final uri = Uri.parse(galleryDirUrl);
final exists = await ss.exists(uri) ?? false;
Expand Down Expand Up @@ -1080,7 +1111,7 @@ class DownloadController extends GetxController {
.putGalleryTask(galleryTask.copyWith(completCount: completeCount));

if (completeCount == galleryTask.fileCount) {
logger.d('complete ${galleryTask.gid} ${galleryTask.title}');
logger.v('complete ${galleryTask.gid} ${galleryTask.title}');
await galleryTaskComplete(galleryTask.gid);
_updateDownloadView(['DownloadGalleryItem_${galleryTask.gid}']);
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/network/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Future<GalleryList?> getGallery({
_params.addAll(_searchController.favSearchMap);
}

logger.d('url:$_url $_params');
logger.v('url:$_url $_params');

DioHttpResponse httpResponse = await dioHttpClient.get(
_url,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/tab/controller/tabview_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ abstract class TabViewController extends GetxController {

setResultPage(result);

logger.d('reloadData next $next, prev $prev');
logger.v('reloadData next $next, prev $prev');

change(resultList, status: RxStatus.success());
afterJump = false;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: fehviewer
description: An unofficial e-hentai app

publish_to: 'none'
version: 1.3.1+491
version: 1.3.2+492

environment:
sdk: '>=2.17.0 <3.0.0'
Expand Down

0 comments on commit f3ba1b2

Please sign in to comment.