mirror of
https://github.com/spotiflacapp/SpotiFLAC-Mobile.git
synced 2026-05-31 19:05:05 +07:00
All search, metadata, and download providers are now exclusively supplied by extensions. The built-in provider registry that previously exposed Deezer/Tidal/Qobuz as hardcoded providers is fully removed. Removed across Go, Dart, Kotlin, and Swift: - BuiltInProviderSpec class, registry, and all accessor helpers - SearchProviderAllJSON, GetBuiltInProvidersJSON, ParseProviderURLJSON, ParseDeezerURLExport Go exports and their platform channel bindings - Built-in provider items in search dropdown, service picker, and provider priority UI lists - provider_ui_utils.dart helper file Deezer metadata enrichment (ISRC lookup, extended metadata, cover upgrade) remains fully functional through direct DeezerClient calls in the download pipeline — these are not part of the provider registry and are unaffected. Mark deezer as a retired built-in metadata provider so stale user priority lists are cleaned up on next launch.
247 lines
7.4 KiB
Dart
247 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:spotiflac_android/l10n/l10n.dart';
|
|
import 'package:spotiflac_android/providers/extension_provider.dart';
|
|
import 'package:spotiflac_android/widgets/priority_settings_scaffold.dart';
|
|
|
|
class MetadataProviderPriorityPage extends ConsumerStatefulWidget {
|
|
const MetadataProviderPriorityPage({super.key});
|
|
|
|
@override
|
|
ConsumerState<MetadataProviderPriorityPage> createState() =>
|
|
_MetadataProviderPriorityPageState();
|
|
}
|
|
|
|
class _MetadataProviderPriorityPageState
|
|
extends ConsumerState<MetadataProviderPriorityPage> {
|
|
late List<String> _providers;
|
|
bool _hasChanges = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadProviders();
|
|
}
|
|
|
|
void _loadProviders() {
|
|
final extState = ref.read(extensionProvider);
|
|
final allProviders = ref
|
|
.read(extensionProvider.notifier)
|
|
.getAllMetadataProviders();
|
|
|
|
if (extState.metadataProviderPriority.isNotEmpty) {
|
|
_providers = List.from(extState.metadataProviderPriority);
|
|
for (final provider in allProviders) {
|
|
if (!_providers.contains(provider)) {
|
|
_providers.add(provider);
|
|
}
|
|
}
|
|
_providers.removeWhere((p) => !allProviders.contains(p));
|
|
} else {
|
|
_providers = allProviders;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PrioritySettingsScaffold(
|
|
hasChanges: _hasChanges,
|
|
title: context.l10n.metadataProviderPriorityTitle,
|
|
description: context.l10n.metadataProviderPriorityDescription,
|
|
descriptionPadding: const EdgeInsets.all(16),
|
|
infoText: context.l10n.metadataProviderPriorityInfo,
|
|
saveLabel: context.l10n.dialogSave,
|
|
onSave: _saveChanges,
|
|
onConfirmDiscard: _confirmDiscard,
|
|
slivers: [
|
|
SliverPadding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
sliver: SliverReorderableList(
|
|
itemCount: _providers.length,
|
|
itemBuilder: (context, index) {
|
|
final provider = _providers[index];
|
|
return _MetadataProviderItem(
|
|
key: ValueKey(provider),
|
|
provider: provider,
|
|
index: index,
|
|
isFirst: index == 0,
|
|
isLast: index == _providers.length - 1,
|
|
extension: ref
|
|
.read(extensionProvider)
|
|
.extensions
|
|
.where((ext) => ext.id == provider)
|
|
.firstOrNull,
|
|
);
|
|
},
|
|
onReorder: (oldIndex, newIndex) {
|
|
setState(() {
|
|
if (newIndex > oldIndex) {
|
|
newIndex -= 1;
|
|
}
|
|
final item = _providers.removeAt(oldIndex);
|
|
_providers.insert(newIndex, item);
|
|
_hasChanges = true;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<bool> _confirmDiscard(BuildContext context) async {
|
|
final result = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: Text(context.l10n.dialogDiscardChanges),
|
|
content: Text(context.l10n.dialogUnsavedChanges),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: Text(context.l10n.dialogCancel),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: Text(context.l10n.dialogDiscard),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return result ?? false;
|
|
}
|
|
|
|
Future<void> _saveChanges() async {
|
|
await ref
|
|
.read(extensionProvider.notifier)
|
|
.setMetadataProviderPriority(_providers);
|
|
setState(() {
|
|
_hasChanges = false;
|
|
});
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(context.l10n.snackbarMetadataProviderSaved)),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
class _MetadataProviderItem extends StatelessWidget {
|
|
final String provider;
|
|
final int index;
|
|
final bool isFirst;
|
|
final bool isLast;
|
|
final Extension? extension;
|
|
|
|
const _MetadataProviderItem({
|
|
super.key,
|
|
required this.provider,
|
|
required this.index,
|
|
required this.isFirst,
|
|
required this.isLast,
|
|
this.extension,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
final backgroundColor = isDark
|
|
? Color.alphaBlend(
|
|
Colors.white.withValues(alpha: 0.05),
|
|
colorScheme.surface,
|
|
)
|
|
: colorScheme.surfaceContainerHigh;
|
|
|
|
final info = _getProviderInfo(context, provider, extension);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 8),
|
|
child: Material(
|
|
color: backgroundColor,
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: ReorderableDragStartListener(
|
|
index: index,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 28,
|
|
height: 28,
|
|
decoration: BoxDecoration(
|
|
color: isFirst
|
|
? colorScheme.primaryContainer
|
|
: colorScheme.surfaceContainerHighest,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'${index + 1}',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: isFirst
|
|
? colorScheme.onPrimaryContainer
|
|
: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Icon(
|
|
info.icon,
|
|
color: colorScheme.secondary,
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
info.name,
|
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
Text(
|
|
info.description,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Icon(Icons.drag_handle, color: colorScheme.onSurfaceVariant),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_MetadataProviderInfo _getProviderInfo(
|
|
BuildContext context,
|
|
String provider,
|
|
Extension? extension,
|
|
) {
|
|
return _MetadataProviderInfo(
|
|
name: extension?.displayName ?? provider,
|
|
icon: Icons.extension,
|
|
description: context.l10n.providerExtension,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _MetadataProviderInfo {
|
|
final String name;
|
|
final IconData icon;
|
|
final String description;
|
|
|
|
_MetadataProviderInfo({
|
|
required this.name,
|
|
required this.icon,
|
|
required this.description,
|
|
});
|
|
}
|