import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../app/router.dart'; import '../../app/theme.dart'; import '../../data/user_library.dart'; import '../../offline/download_store.dart'; import '../player/sound_sheet.dart'; const supportEmail = 'support@nkbmusic.com'; Future contactSupport({String subject = 'Nanga Kathai'}) => launchUrl(Uri(scheme: 'mailto', path: supportEmail, query: 'subject=${Uri.encodeComponent(subject)}')); /// Download only on Wi-Fi (on by default, so nobody burns their mobile data by surprise). class WifiOnlyDownloads extends Notifier { static const _key = 'downloads_wifi_only'; @override bool build() => ref.read(sharedPrefsProvider).getBool(_key) ?? true; void set(bool value) { state = value; ref.read(sharedPrefsProvider).setBool(_key, value); } } final wifiOnlyDownloadsProvider = NotifierProvider(WifiOnlyDownloads.new); class SettingsScreen extends ConsumerWidget { const SettingsScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final wifiOnly = ref.watch(wifiOnlyDownloadsProvider); final downloads = ref.watch(downloadsProvider); final mb = (downloads.totalBytes / (1 << 20)).round(); Widget section(String title) => Padding( padding: const EdgeInsets.fromLTRB(16, 20, 16, 4), child: Text(title.toUpperCase(), style: const TextStyle(color: NkColors.sun, fontSize: 12, fontWeight: FontWeight.w700, letterSpacing: 1.2)), ); Widget tile(IconData icon, String title, {String? subtitle, VoidCallback? onTap}) => ListTile( leading: Icon(icon), title: Text(title), subtitle: subtitle == null ? null : Text(subtitle, style: const TextStyle(color: NkColors.muted)), trailing: onTap == null ? null : const Icon(Icons.chevron_right, color: NkColors.muted), onTap: onTap, ); return Scaffold( appBar: AppBar(title: const Text('Settings & help')), body: ListView( padding: const EdgeInsets.only(bottom: 32), children: [ section('Account'), if (isSignedIn) tile(Icons.person_outline, 'Your profile', onTap: () => context.push('/profile')) else tile(Icons.login, 'Sign in or create an account', subtitle: 'Listen to full songs and download them', onTap: () => context.push('/login?mode=signup')), section('Playback'), tile(Icons.equalizer_rounded, 'Sound and equalizer', onTap: () => showSoundSettings(context)), section('Downloads'), SwitchListTile( secondary: const Icon(Icons.wifi), title: const Text('Download on Wi-Fi only'), subtitle: const Text('Saves your mobile data', style: TextStyle(color: NkColors.muted)), value: wifiOnly, onChanged: ref.read(wifiOnlyDownloadsProvider.notifier).set, ), tile(Icons.sd_storage_outlined, 'Storage used', subtitle: '${downloads.entries.length} songs · $mb MB', onTap: downloads.entries.isEmpty ? null : () => _removeAll(context, ref)), // The support tips aren't set up on the App Store yet, so iOS doesn't offer them. if (defaultTargetPlatform != TargetPlatform.iOS) ...[ section('Support us'), tile(Icons.favorite_outline, 'Support Nanga Kathai', subtitle: 'Help keep Badaga music free', onTap: () => context.push('/support')), ], section('Help'), tile(Icons.help_outline, 'Help & FAQ', onTap: () => context.push('/help')), tile(Icons.flag_outlined, 'Is this your song? Report a song', onTap: () => context.push('/report')), tile(Icons.mail_outline, 'Contact us', subtitle: supportEmail, onTap: () => contactSupport()), section('About'), tile(Icons.info_outline, 'About Nanga Kathai', onTap: () => context.push('/about')), tile(Icons.privacy_tip_outlined, 'Privacy Policy', onTap: () => context.push('/privacy')), tile(Icons.description_outlined, 'Terms of Use', onTap: () => context.push('/terms')), tile(Icons.code, 'Open-source licences', onTap: () => showLicensePage(context: context, applicationName: 'Nanga Kathai', applicationVersion: '1.0.0')), const Padding( padding: EdgeInsets.fromLTRB(16, 16, 16, 0), child: Text('Nanga Kathai 1.0.0 · Metatroncube Software Solutions', style: TextStyle(color: NkColors.muted, fontSize: 12)), ), ], ), ); } void _removeAll(BuildContext context, WidgetRef ref) { showDialog( context: context, builder: (dialog) => AlertDialog( title: const Text('Remove all downloads?'), content: const Text('This frees up space. You can download the songs again any time.'), actions: [ TextButton(onPressed: () => Navigator.pop(dialog), child: const Text('Cancel')), FilledButton( onPressed: () { ref.read(downloadStoreProvider).removeAll(); Navigator.pop(dialog); }, child: const Text('Remove'), ), ], ), ); } }