Add swingmusic-mobile submodule to replace Android app

- Updated .gitmodules to include mobile app submodule
- Added swingmusic_mobile directory with Flutter app
- Mobile app will now be built in unified release workflow
This commit is contained in:
Tomas Dvorak
2026-03-18 19:29:44 +01:00
parent 109384c7a1
commit 9f1623bb34
160 changed files with 18433 additions and 0 deletions
@@ -0,0 +1,845 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../shared/providers/auth_provider.dart';
import '../../shared/providers/enhanced_library_provider.dart';
import '../../core/constants/app_spacing.dart';
class EnhancedSettingsScreen extends StatefulWidget {
const EnhancedSettingsScreen({super.key});
@override
State<EnhancedSettingsScreen> createState() => _EnhancedSettingsScreenState();
}
class _EnhancedSettingsScreenState extends State<EnhancedSettingsScreen> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.surface,
elevation: 0,
title: Text(
'Settings',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w600,
),
),
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
Icons.arrow_back,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
body: SingleChildScrollView(
padding: AppSpacing.paddingLG,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Connection Settings
_buildSection(
context,
'Connection',
Icons.cloud,
[
_buildServerUrlTile(context),
_buildAuthStatusTile(context),
_buildConnectionTestTile(context),
],
),
const SizedBox(height: 24),
// Audio Settings
_buildSection(
context,
'Audio',
Icons.music_note,
[
_buildAudioQualityTile(context),
_buildCrossfadeTile(context),
_buildGaplessTile(context),
_buildVolumeTile(context),
],
),
const SizedBox(height: 24),
// Download Settings
_buildSection(
context,
'Downloads',
Icons.download,
[
_buildDownloadQualityTile(context),
_buildDownloadLocationTile(context),
_buildWifiOnlyTile(context),
_buildMaxDownloadSizeTile(context),
],
),
const SizedBox(height: 24),
// Theme Settings
_buildSection(
context,
'Appearance',
Icons.palette,
[
_buildThemeTile(context),
_buildAccentColorTile(context),
],
),
const SizedBox(height: 24),
// Cache Settings
_buildSection(
context,
'Storage',
Icons.storage,
[
_buildCacheSizeTile(context),
_buildClearCacheTile(context),
],
),
const SizedBox(height: 24),
// About
_buildSection(
context,
'About',
Icons.info,
[
_buildVersionTile(context),
_buildBuildNumberTile(context),
_buildDeveloperTile(context),
],
),
],
),
),
);
}
Widget _buildSection(
BuildContext context,
String title,
IconData icon,
List<Widget> children,
) {
return Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Icon(
icon,
color: Theme.of(context).colorScheme.primary,
size: 20,
),
const SizedBox(width: 12),
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
),
...children,
],
),
);
}
Widget _buildServerUrlTile(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, authProvider, child) {
return ListTile(
leading: Icon(
Icons.link,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Server URL',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
authProvider.baseUrl ?? 'Not set',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _showServerUrlDialog(context, authProvider),
icon: Icon(
Icons.edit,
color: Theme.of(context).colorScheme.primary,
),
),
);
},
);
}
Widget _buildAuthStatusTile(BuildContext context) {
return Consumer<AuthProvider>(
builder: (context, authProvider, child) {
return ListTile(
leading: Icon(
authProvider.isLoggedIn ? Icons.check_circle : Icons.error,
color: authProvider.isLoggedIn
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.error,
),
title: Text(
'Authentication Status',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
authProvider.isLoggedIn ? 'Connected' : 'Not connected',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: authProvider.isLoggedIn
? Theme.of(context).colorScheme.onSurface.withOpacity(0.7)
: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: authProvider.isLoggedIn
? IconButton(
onPressed: () => _showLogoutDialog(context, authProvider),
icon: Icon(
Icons.logout,
color: Theme.of(context).colorScheme.error,
),
)
: null,
);
},
);
}
Widget _buildConnectionTestTile(BuildContext context) {
return ListTile(
leading: Icon(
Icons.wifi,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Test Connection',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Check server connectivity',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _testConnection(context),
icon: Icon(
Icons.play_arrow,
color: Theme.of(context).colorScheme.primary,
),
),
);
}
Widget _buildAudioQualityTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.high_quality,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Audio Quality',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Higher quality uses more storage',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['audioQuality'] ?? '320kbps',
items: const ['128kbps', '320kbps', '512kbps', 'flac'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'audioQuality': value,
}),
),
);
},
);
}
Widget _buildCrossfadeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.blur_on,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Crossfade',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Smooth transitions between tracks',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['crossfade'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'crossfade': value,
}),
),
);
},
);
}
Widget _buildGaplessTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.skip_next,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Gapless Playback',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Remove silence between tracks',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['gapless'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'gapless': value,
}),
),
);
},
);
}
Widget _buildVolumeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.volume_up,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Default Volume',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Set default volume level',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<double>(
value: (libraryProvider.userPreferences['defaultVolume'] ?? 1.0).toDouble(),
items: [0.25, 0.5, 0.75, 1.0],
onChanged: (value) => libraryProvider.updateUserPreferences({
'defaultVolume': value,
}),
),
);
},
);
}
Widget _buildDownloadQualityTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.download,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Download Quality',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Choose audio quality for downloads',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['downloadQuality'] ?? '320kbps',
items: const ['128kbps', '320kbps', '512kbps', 'flac'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'downloadQuality': value,
}),
),
);
},
);
}
Widget _buildDownloadLocationTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.folder,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Download Location',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Where to save downloaded files',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['downloadLocation'] ?? 'Music',
items: const ['Music', 'Downloads', 'Custom'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'downloadLocation': value,
}),
),
);
},
);
}
Widget _buildWifiOnlyTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.wifi,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Wi-Fi Only',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Download only when connected to Wi-Fi',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: Switch(
value: libraryProvider.userPreferences['wifiOnly'] ?? false,
onChanged: (value) => libraryProvider.updateUserPreferences({
'wifiOnly': value,
}),
),
);
},
);
}
Widget _buildMaxDownloadSizeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.sd_storage,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Max Download Size',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Maximum size for automatic downloads',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['maxDownloadSize'] ?? '100MB',
items: const ['50MB', '100MB', '500MB', '1GB'],
onChanged: (value) => libraryProvider.updateUserPreferences({
'maxDownloadSize': value,
}),
),
);
},
);
}
Widget _buildThemeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.palette,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Theme',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Choose app appearance',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<ThemeMode>(
value: _getThemeMode(libraryProvider.userPreferences['theme']),
items: const [
DropdownMenuItem(value: ThemeMode.system, child: Text('System')),
DropdownMenuItem(value: ThemeMode.light, child: Text('Light')),
DropdownMenuItem(value: ThemeMode.dark, child: Text('Dark')),
],
onChanged: (ThemeMode? value) => libraryProvider.updateUserPreferences({
'theme': value?.name,
}),
),
);
},
);
}
Widget _buildAccentColorTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.color_lens,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Accent Color',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Customize accent colors',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['accentColor'] ?? 'Blue',
items: const [
DropdownMenuItem(value: 'Blue', child: Text('Blue')),
DropdownMenuItem(value: 'Green', child: Text('Green')),
DropdownMenuItem(value: 'Purple', child: Text('Purple')),
DropdownMenuItem(value: 'Orange', child: Text('Orange')),
DropdownMenuItem(value: 'Red', child: Text('Red')),
],
onChanged: (String? value) => libraryProvider.updateUserPreferences({
'accentColor': value,
}),
),
);
},
);
}
Widget _buildCacheSizeTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.cached,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Cache Size',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Maximum cache size',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: DropdownButton<String>(
value: libraryProvider.userPreferences['cacheSize'] ?? '500MB',
items: const ['100MB', '500MB', '1GB', '2GB', '5GB'],
onChanged: (String? value) => libraryProvider.updateUserPreferences({
'cacheSize': value,
}),
),
);
},
);
}
Widget _buildClearCacheTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.clear_all,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Clear Cache',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'Free up storage space',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
trailing: IconButton(
onPressed: () => _showClearCacheDialog(context),
icon: Icon(
Icons.delete_sweep,
color: Theme.of(context).colorScheme.error,
),
),
);
},
);
}
Widget _buildVersionTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.info,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Version',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
libraryProvider.statistics['version'] ?? 'Unknown',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
);
},
);
}
Widget _buildBuildNumberTile(BuildContext context) {
return Consumer<EnhancedLibraryProvider>(
builder: (context, libraryProvider, child) {
return ListTile(
leading: Icon(
Icons.build,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Build Number',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
libraryProvider.statistics['buildNumber'] ?? 'Unknown',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
);
},
);
}
Widget _buildDeveloperTile(BuildContext context) {
return ListTile(
leading: Icon(
Icons.code,
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
'Developer',
style: Theme.of(context).textTheme.bodyLarge,
),
subtitle: Text(
'View developer options',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
trailing: IconButton(
onPressed: () => _showDeveloperOptions(context),
icon: Icon(
Icons.more_horiz,
color: Theme.of(context).colorScheme.primary,
),
),
);
}
ThemeMode _getThemeMode(String? themeString) {
switch (themeString) {
case 'system':
return ThemeMode.system;
case 'light':
return ThemeMode.light;
case 'dark':
return ThemeMode.dark;
default:
return ThemeMode.system;
}
}
void _showServerUrlDialog(BuildContext context, AuthProvider authProvider) {
final controller = TextEditingController(text: authProvider.baseUrl ?? '');
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Server URL'),
content: TextField(
controller: controller,
decoration: InputDecoration(
labelText: 'Server URL',
hintText: 'https://your-server.com',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
authProvider.updateBaseUrl(controller.text.trim());
Navigator.of(context).pop();
},
child: Text('Save'),
),
],
),
);
}
void _showLogoutDialog(BuildContext context, AuthProvider authProvider) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Logout'),
content: Text('Are you sure you want to logout?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
authProvider.logout();
Navigator.of(context).pop();
},
child: Text('Logout'),
),
],
),
);
}
void _testConnection(BuildContext context) {
// TODO: Implement connection test
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Connection test not implemented yet')),
);
}
void _showClearCacheDialog(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Clear Cache'),
content: Text('Are you sure you want to clear all cached data?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cache cleared successfully')),
);
},
child: Text('Clear'),
),
],
),
);
}
void _showDeveloperOptions(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Developer Options'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListTile(
title: Text('Debug Mode'),
trailing: Switch(
value: false,
onChanged: (value) {
// TODO: Implement debug mode
},
),
),
ListTile(
title: Text('Enable Logging'),
trailing: Switch(
value: false,
onChanged: (value) {
// TODO: Implement logging
},
),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Close'),
),
],
),
);
}
}
@@ -0,0 +1,518 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/constants/app_constants.dart';
class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key});
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
bool _isLoading = false;
// Connection settings
String _serverUrl = '';
String _username = '';
bool _isConnected = false;
// Audio settings
double _volume = 1.0;
double _audioQuality = 1.0; // 0.5 = Low, 1.0 = High
bool _gaplessPlayback = false;
bool _crossfade = true;
double _crossfadeDuration = 5.0;
// Theme settings
ThemeMode _themeMode = ThemeMode.system;
// Download settings
String _downloadQuality = 'high'; // 'low', 'medium', 'high'
bool _wifiOnlyDownloads = true;
int _maxDownloadSize = 1000; // MB
// Cache settings
int _cacheSize = 500; // MB
bool _clearCacheOnStart = false;
// Analytics settings
bool _enableAnalytics = true;
bool _shareListeningData = false;
@override
void initState() {
super.initState();
_loadSettings();
}
Future<void> _loadSettings() async {
setState(() {
_isLoading = true;
});
final prefs = await SharedPreferences.getInstance();
setState(() {
_serverUrl = prefs.getString('server_url') ?? AppConstants.defaultApiUrl;
_username = prefs.getString('username') ?? '';
_isConnected = prefs.getBool('is_connected') ?? false;
_volume = prefs.getDouble('volume') ?? 1.0;
_audioQuality = prefs.getDouble('audio_quality') ?? 1.0;
_gaplessPlayback = prefs.getBool('gapless_playback') ?? false;
_crossfade = prefs.getBool('crossfade') ?? true;
_crossfadeDuration = prefs.getDouble('crossfade_duration') ?? 5.0;
final themeIndex = prefs.getInt('theme_mode') ?? 2;
_themeMode = ThemeMode.values[themeIndex];
_downloadQuality = prefs.getString('download_quality') ?? 'high';
_wifiOnlyDownloads = prefs.getBool('wifi_only_downloads') ?? true;
_maxDownloadSize = prefs.getInt('max_download_size') ?? 1000;
_cacheSize = prefs.getInt('cache_size') ?? 500;
_clearCacheOnStart = prefs.getBool('clear_cache_on_start') ?? false;
_enableAnalytics = prefs.getBool('enable_analytics') ?? true;
_shareListeningData = prefs.getBool('share_listening_data') ?? false;
_isLoading = false;
});
}
Future<void> _saveSettings() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('server_url', _serverUrl);
await prefs.setString('username', _username);
await prefs.setBool('is_connected', _isConnected);
await prefs.setDouble('volume', _volume);
await prefs.setDouble('audio_quality', _audioQuality);
await prefs.setBool('gapless_playback', _gaplessPlayback);
await prefs.setBool('crossfade', _crossfade);
await prefs.setDouble('crossfade_duration', _crossfadeDuration);
await prefs.setInt('theme_mode', _themeMode.index);
await prefs.setString('download_quality', _downloadQuality);
await prefs.setBool('wifi_only_downloads', _wifiOnlyDownloads);
await prefs.setInt('max_download_size', _maxDownloadSize);
await prefs.setInt('cache_size', _cacheSize);
await prefs.setBool('clear_cache_on_start', _clearCacheOnStart);
await prefs.setBool('enable_analytics', _enableAnalytics);
await prefs.setBool('share_listening_data', _shareListeningData);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Settings'),
elevation: 0,
backgroundColor: Theme.of(context).colorScheme.surface,
actions: [
TextButton(
onPressed: _saveSettings,
child: const Text('Save'),
),
],
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16.0),
children: [
// Connection Section
_buildSectionHeader('Connection'),
_buildServerUrlField(),
_buildUsernameField(),
_buildConnectionStatus(),
const SizedBox(height: 24),
// Audio Section
_buildSectionHeader('Audio'),
_buildVolumeSlider(),
_buildAudioQualityDropdown(),
_buildGaplessPlaybackSwitch(),
_buildCrossfadeSwitch(),
_buildCrossfadeDurationSlider(),
const SizedBox(height: 24),
// Theme Section
_buildSectionHeader('Appearance'),
_buildThemeSelector(),
const SizedBox(height: 24),
// Download Section
_buildSectionHeader('Downloads'),
_buildDownloadQualityDropdown(),
_buildWifiOnlySwitch(),
_buildMaxDownloadSizeField(),
const SizedBox(height: 24),
// Cache Section
_buildSectionHeader('Storage'),
_buildCacheSizeField(),
_buildClearCacheSwitch(),
_buildClearCacheButton(),
const SizedBox(height: 24),
// Analytics Section
_buildSectionHeader('Analytics'),
_buildAnalyticsSwitch(),
_buildShareDataSwitch(),
const SizedBox(height: 24),
// About Section
_buildSectionHeader('About'),
_buildAppInfo(),
_buildVersionInfo(),
],
),
);
}
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
title,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
);
}
Widget _buildServerUrlField() {
return TextField(
controller: TextEditingController(text: _serverUrl),
decoration: const InputDecoration(
labelText: 'Server URL',
hintText: 'http://192.168.1.100:1970',
border: OutlineInputBorder(),
),
onChanged: (value) {
_serverUrl = value;
},
);
}
Widget _buildUsernameField() {
return TextField(
controller: TextEditingController(text: _username),
decoration: const InputDecoration(
labelText: 'Username',
border: OutlineInputBorder(),
),
onChanged: (value) {
_username = value;
},
);
}
Widget _buildConnectionStatus() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: _isConnected ? Colors.green : Colors.red,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(
_isConnected ? Icons.check_circle : Icons.error,
color: Colors.white,
),
const SizedBox(width: 8),
Text(
_isConnected ? 'Connected' : 'Disconnected',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
],
),
);
}
Widget _buildVolumeSlider() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Volume: ${(_volume * 100).round()}%'),
Slider(
value: _volume,
min: 0.0,
max: 1.0,
divisions: 20,
onChanged: (value) {
setState(() {
_volume = value;
});
},
),
],
);
}
Widget _buildAudioQualityDropdown() {
return DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: 'Audio Quality',
border: OutlineInputBorder(),
),
items: ['Low', 'Medium', 'High'].map((quality) {
return DropdownMenuItem(
value: quality,
child: Text(quality),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_audioQuality = value == 'Low' ? 0.5 : value == 'High' ? 1.0 : 0.75;
});
}
},
);
}
Widget _buildGaplessPlaybackSwitch() {
return SwitchListTile(
title: const Text('Gapless Playback'),
subtitle: const Text('Remove gaps between tracks'),
value: _gaplessPlayback,
onChanged: (value) {
setState(() {
_gaplessPlayback = value;
});
},
);
}
Widget _buildCrossfadeSwitch() {
return SwitchListTile(
title: const Text('Crossfade'),
subtitle: const Text('Smooth transition between tracks'),
value: _crossfade,
onChanged: (value) {
setState(() {
_crossfade = value;
});
},
);
}
Widget _buildCrossfadeDurationSlider() {
if (!_crossfade) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Crossfade Duration: ${_crossfadeDuration.round()}s'),
Slider(
value: _crossfadeDuration,
min: 1.0,
max: 10.0,
divisions: 18,
onChanged: (value) {
setState(() {
_crossfadeDuration = value;
});
},
),
],
);
}
Widget _buildThemeSelector() {
return Column(
children: [
RadioListTile<ThemeMode>(
title: const Text('Light'),
value: ThemeMode.light,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
RadioListTile<ThemeMode>(
title: const Text('Dark'),
value: ThemeMode.dark,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
RadioListTile<ThemeMode>(
title: const Text('System'),
value: ThemeMode.system,
groupValue: _themeMode,
onChanged: (ThemeMode? value) {
if (value != null) {
setState(() {
_themeMode = value;
});
}
},
),
],
);
}
Widget _buildDownloadQualityDropdown() {
return DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: 'Download Quality',
border: OutlineInputBorder(),
),
items: ['Low', 'Medium', 'High'].map((quality) {
return DropdownMenuItem(
value: quality,
child: Text(quality),
);
}).toList(),
onChanged: (value) {
if (value != null) {
setState(() {
_downloadQuality = value;
});
}
},
);
}
Widget _buildWifiOnlySwitch() {
return SwitchListTile(
title: const Text('Wi-Fi Only Downloads'),
subtitle: const Text('Only download when connected to Wi-Fi'),
value: _wifiOnlyDownloads,
onChanged: (value) {
setState(() {
_wifiOnlyDownloads = value;
});
},
);
}
Widget _buildMaxDownloadSizeField() {
return TextField(
controller: TextEditingController(text: _maxDownloadSize.toString()),
decoration: const InputDecoration(
labelText: 'Max Download Size (MB)',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
onChanged: (value) {
_maxDownloadSize = int.tryParse(value) ?? _maxDownloadSize;
},
);
}
Widget _buildCacheSizeField() {
return TextField(
controller: TextEditingController(text: _cacheSize.toString()),
decoration: const InputDecoration(
labelText: 'Cache Size (MB)',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
onChanged: (value) {
_cacheSize = int.tryParse(value) ?? _cacheSize;
},
);
}
Widget _buildClearCacheSwitch() {
return SwitchListTile(
title: const Text('Clear Cache on Start'),
subtitle: const Text('Clear cache when app starts'),
value: _clearCacheOnStart,
onChanged: (value) {
setState(() {
_clearCacheOnStart = value;
});
},
);
}
Widget _buildClearCacheButton() {
return ElevatedButton.icon(
onPressed: () async {
// Clear cache logic
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Cache cleared')),
);
},
icon: const Icon(Icons.delete_outline),
label: const Text('Clear Cache'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
);
}
Widget _buildAnalyticsSwitch() {
return SwitchListTile(
title: const Text('Enable Analytics'),
subtitle: const Text('Track listening statistics'),
value: _enableAnalytics,
onChanged: (value) {
setState(() {
_enableAnalytics = value;
});
},
);
}
Widget _buildShareDataSwitch() {
return SwitchListTile(
title: const Text('Share Listening Data'),
subtitle: const Text('Share anonymous listening data for improvements'),
value: _shareListeningData,
onChanged: (value) {
setState(() {
_shareListeningData = value;
});
},
);
}
Widget _buildAppInfo() {
return ListTile(
leading: const Icon(Icons.info_outline),
title: const Text('About SwingMusic'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
showAboutDialog(
context: context,
applicationName: 'SwingMusic',
applicationVersion: '1.0.0',
applicationIcon: const Icon(Icons.music_note),
children: [
const Text('A modern music player for SwingMusic server'),
const Text('Built with Flutter'),
],
);
},
);
}
Widget _buildVersionInfo() {
return ListTile(
leading: const Icon(Icons.code),
title: const Text('Version'),
subtitle: const Text('1.0.0 (Flutter)'),
trailing: const Icon(Icons.arrow_forward_ios),
onTap: () {
// Show changelog
},
);
}
}