mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
fix(ios): scan app documents without the Files folder picker
This commit is contained in:
1 parent
c263feb722
commit
f953c46f81
3 files changed
+204
-13
No files matched your search
@@ -17,6 +17,7 @@ import 'package:spotiflac_android/widgets/duplicate_review_sheet.dart';
|
||||
import 'package:spotiflac_android/widgets/app_bottom_sheet.dart';
|
||||
import 'package:spotiflac_android/widgets/settings_group.dart';
|
||||
import 'package:spotiflac_android/widgets/app_sliver_header.dart';
|
||||
import 'package:spotiflac_android/widgets/ios_library_folder_sheet.dart';
|
||||
|
||||
class LibrarySettingsPage extends ConsumerStatefulWidget {
|
||||
const LibrarySettingsPage({super.key});
|
||||
@@ -137,15 +138,16 @@ class _LibrarySettingsPageState extends ConsumerState<LibrarySettingsPage> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Legacy: request permission and use file picker for older Android / iOS
|
||||
// Older Android needs storage permission; iOS chooses internal or Files.
|
||||
if (!_hasStoragePermission) {
|
||||
final granted = await _requestStoragePermission();
|
||||
if (!granted) return;
|
||||
}
|
||||
if (Platform.isIOS) {
|
||||
if (!mounted) return;
|
||||
IosPickedDirectory? picked;
|
||||
try {
|
||||
picked = await PlatformBridge.pickIosDirectory();
|
||||
picked = await showIosLibraryFolderSheet(context);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -160,17 +162,16 @@ class _LibrarySettingsPageState extends ConsumerState<LibrarySettingsPage> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (picked != null) {
|
||||
final source = await ref
|
||||
.read(localLibraryProvider.notifier)
|
||||
.addSource(
|
||||
path: picked.path,
|
||||
displayName: picked.path,
|
||||
bookmark: picked.bookmark,
|
||||
);
|
||||
await ref
|
||||
.read(localLibraryProvider.notifier)
|
||||
.startSourceScan(source.id);
|
||||
if (picked != null && mounted) {
|
||||
final library = ref.read(localLibraryProvider.notifier);
|
||||
final source = await library.addSource(
|
||||
path: picked.path,
|
||||
displayName: picked.bookmark.isEmpty
|
||||
? context.l10n.setupAppDocumentsFolder
|
||||
: picked.path,
|
||||
bookmark: picked.bookmark,
|
||||
);
|
||||
await library.startSourceScan(source.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:spotiflac_android/l10n/l10n.dart';
|
||||
import 'package:spotiflac_android/services/platform_bridge.dart';
|
||||
import 'package:spotiflac_android/widgets/app_bottom_sheet.dart';
|
||||
|
||||
enum _LibraryFolderLocation { documents, files }
|
||||
|
||||
/// App-owned music does not need a grant from the system Files picker.
|
||||
Future<IosPickedDirectory?> showIosLibraryFolderSheet(
|
||||
BuildContext context,
|
||||
) async {
|
||||
final location = await showAppModalBottomSheet<_LibraryFolderLocation>(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
builder: (context) => AppBottomSheet(
|
||||
title: context.l10n.libraryAddFolder,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AppSheetOption(
|
||||
leading: const Icon(Icons.folder_special_outlined),
|
||||
title: Text(context.l10n.setupAppDocumentsFolder),
|
||||
subtitle: Text(context.l10n.setupAppDocumentsFolderSubtitle),
|
||||
onTap: () =>
|
||||
Navigator.pop(context, _LibraryFolderLocation.documents),
|
||||
),
|
||||
AppSheetOption(
|
||||
leading: const Icon(Icons.folder_open_outlined),
|
||||
title: Text(context.l10n.setupChooseFromFiles),
|
||||
subtitle: Text(context.l10n.setupChooseFromFilesSubtitle),
|
||||
onTap: () => Navigator.pop(context, _LibraryFolderLocation.files),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (location == null || !context.mounted) return null;
|
||||
if (location == _LibraryFolderLocation.files) {
|
||||
// Keep the native picker and its bookmark for folders outside our sandbox.
|
||||
return PlatformBridge.pickIosDirectory();
|
||||
}
|
||||
|
||||
// Scan Documents recursively, including the SpotiFLAC subfolder created by
|
||||
// setup and music the user copied into the app through Files. No bookmark is
|
||||
// needed: app-owned paths can be rebased when iOS relocates the container.
|
||||
final documents = await getApplicationDocumentsDirectory();
|
||||
return IosPickedDirectory(path: documents.path, bookmark: '');
|
||||
}
|
||||
Reference in new issue
Block a user