mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-30 13:19:44 +02:00
feat(profile): add local profiles with backup and restore
Move Mornye Settings to the Home avatar and keep search above the profile card. Center the metadata artwork and actions, and make artist names clickable in the Material player.
This commit is contained in:
1 parent
5b519070a3
commit
d8d46108bc
19 files changed
+1003
-80
No files matched your search
@@ -10,6 +10,7 @@ import 'package:spotiflac_android/providers/download_queue_provider.dart';
|
||||
import 'package:spotiflac_android/providers/extension_provider.dart';
|
||||
import 'package:spotiflac_android/providers/library_collections_provider.dart';
|
||||
import 'package:spotiflac_android/providers/settings_provider.dart';
|
||||
import 'package:spotiflac_android/providers/user_profile_provider.dart';
|
||||
import 'package:spotiflac_android/services/backup_service.dart';
|
||||
import 'package:spotiflac_android/services/history_database.dart';
|
||||
import 'package:spotiflac_android/utils/logger.dart';
|
||||
@@ -65,6 +66,9 @@ class _BackupRestorePageState extends ConsumerState<BackupRestorePage> {
|
||||
|
||||
final file = await BackupService.writeBackupArchive(
|
||||
settings: settings,
|
||||
profile: _includeSettings
|
||||
? await ref.read(userProfileProvider.future)
|
||||
: null,
|
||||
includeHistory: _includeHistory,
|
||||
loadHistoryPage: (limit, offset) =>
|
||||
HistoryDatabase.instance.getAll(limit: limit, offset: offset),
|
||||
@@ -125,6 +129,11 @@ class _BackupRestorePageState extends ConsumerState<BackupRestorePage> {
|
||||
|
||||
setState(() => _isImporting = true);
|
||||
try {
|
||||
if (bundle.profile != null) {
|
||||
await ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.restoreFromBackup(bundle.profile!);
|
||||
}
|
||||
if (bundle.hasSettings) {
|
||||
await ref
|
||||
.read(settingsProvider.notifier)
|
||||
@@ -201,6 +210,11 @@ class _BackupRestorePageState extends ConsumerState<BackupRestorePage> {
|
||||
icon: Icons.settings_outlined,
|
||||
label: l10n.backupContentsSettings,
|
||||
),
|
||||
if (bundle.profile != null)
|
||||
_ContentRow(
|
||||
icon: Icons.person_outline,
|
||||
label: l10n.profileTitle,
|
||||
),
|
||||
if (bundle.hasHistory)
|
||||
_ContentRow(
|
||||
icon: Icons.history,
|
||||
@@ -281,6 +295,7 @@ class _BackupRestorePageState extends ConsumerState<BackupRestorePage> {
|
||||
SettingsSwitchItem(
|
||||
icon: Icons.settings_outlined,
|
||||
title: l10n.backupContentsSettings,
|
||||
subtitle: l10n.backupIncludesProfile,
|
||||
value: _includeSettings,
|
||||
onChanged: _isBusy
|
||||
? null
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_picker/file_picker.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/user_profile_provider.dart';
|
||||
import 'package:spotiflac_android/services/user_profile_store.dart';
|
||||
import 'package:spotiflac_android/utils/adaptive_layout.dart';
|
||||
import 'package:spotiflac_android/widgets/app_action_button.dart';
|
||||
import 'package:spotiflac_android/widgets/app_sliver_header.dart';
|
||||
import 'package:spotiflac_android/widgets/profile_avatar.dart';
|
||||
import 'package:spotiflac_android/widgets/settings_group.dart';
|
||||
|
||||
class ProfileSettingsPage extends ConsumerStatefulWidget {
|
||||
const ProfileSettingsPage({super.key, required this.profile});
|
||||
|
||||
final UserProfile profile;
|
||||
|
||||
@override
|
||||
ConsumerState<ProfileSettingsPage> createState() =>
|
||||
_ProfileSettingsPageState();
|
||||
}
|
||||
|
||||
class _ProfileSettingsPageState extends ConsumerState<ProfileSettingsPage> {
|
||||
late final _name = TextEditingController(text: widget.profile.name);
|
||||
Uint8List? _photo;
|
||||
bool _removePhoto = false;
|
||||
bool _busy = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_name.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _pickPhoto() async {
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
final picked = await FilePicker.pickFile(
|
||||
type: FileType.image,
|
||||
darwinOptions: const DarwinOptions(
|
||||
assetRepresentationMode: DarwinAssetRepresentationMode.compatible,
|
||||
),
|
||||
);
|
||||
if (picked == null) return;
|
||||
if ((await picked.length() ?? 0) > 20 * 1024 * 1024) {
|
||||
throw const FormatException('Photo too large');
|
||||
}
|
||||
final bytes = await picked.readAsBytes();
|
||||
final photo = await prepareProfilePhoto(bytes);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_photo = photo;
|
||||
_removePhoto = false;
|
||||
});
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.profilePhotoError)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
await ref
|
||||
.read(userProfileProvider.notifier)
|
||||
.save(name: _name.text, photo: _photo, removePhoto: _removePhoto);
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.profileSaveError)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final inset = wideListInset(context);
|
||||
final hasPhoto =
|
||||
_photo != null || (!_removePhoto && widget.profile.photoPath != null);
|
||||
return PopScope(
|
||||
canPop: !_busy,
|
||||
child: Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
AppSliverHeader.page(title: context.l10n.profileTitle),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.fromLTRB(24 + inset, 16, 24 + inset, 32),
|
||||
sliver: SliverToBoxAdapter(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Center(
|
||||
child: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _name,
|
||||
builder: (context, value, _) => ProfileAvatar(
|
||||
name: value.text,
|
||||
photo: _photo,
|
||||
photoPath: _removePhoto
|
||||
? null
|
||||
: widget.profile.photoPath,
|
||||
size: 128,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: AppActionButton(
|
||||
onPressed: _busy ? null : _pickPhoto,
|
||||
icon: const Icon(Icons.photo_library_outlined),
|
||||
label: Text(context.l10n.profileChangePhoto),
|
||||
outlined: true,
|
||||
tonal: true,
|
||||
),
|
||||
),
|
||||
if (hasPhoto)
|
||||
Center(
|
||||
child: TextButton(
|
||||
onPressed: _busy
|
||||
? null
|
||||
: () => setState(() {
|
||||
_photo = null;
|
||||
_removePhoto = true;
|
||||
}),
|
||||
child: Text(context.l10n.profileRemovePhoto),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
SettingsGroup(
|
||||
margin: EdgeInsets.zero,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: TextField(
|
||||
controller: _name,
|
||||
enabled: !_busy,
|
||||
maxLength: 50,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _busy ? null : _save(),
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.profileName,
|
||||
hintText: context.l10n.profileNameHint,
|
||||
border: InputBorder.none,
|
||||
counterText: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
AppActionButton(
|
||||
onPressed: _busy ? null : _save,
|
||||
icon: _busy
|
||||
? const SizedBox.square(
|
||||
dimension: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.check),
|
||||
label: Text(context.l10n.dialogSave),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: SizedBox(height: MediaQuery.paddingOf(context).bottom),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:spotiflac_android/constants/app_info.dart';
|
||||
import 'package:spotiflac_android/l10n/l10n.dart';
|
||||
import 'package:spotiflac_android/providers/user_profile_provider.dart';
|
||||
import 'package:spotiflac_android/screens/settings/profile_settings_page.dart';
|
||||
import 'package:spotiflac_android/screens/settings/about_page.dart';
|
||||
import 'package:spotiflac_android/screens/settings/app_settings_page.dart';
|
||||
import 'package:spotiflac_android/screens/settings/appearance_settings_page.dart';
|
||||
@@ -24,6 +26,7 @@ import 'package:spotiflac_android/widgets/animation_utils.dart';
|
||||
import 'package:spotiflac_android/widgets/app_search_field.dart';
|
||||
import 'package:spotiflac_android/widgets/app_sliver_header.dart';
|
||||
import 'package:spotiflac_android/widgets/settings_group.dart';
|
||||
import 'package:spotiflac_android/widgets/profile_avatar.dart';
|
||||
|
||||
/// One entry on the Settings tab.
|
||||
class _Destination {
|
||||
@@ -66,7 +69,9 @@ class _Group {
|
||||
}
|
||||
|
||||
class SettingsTab extends ConsumerStatefulWidget {
|
||||
const SettingsTab({super.key});
|
||||
const SettingsTab({super.key, this.asPage = false});
|
||||
|
||||
final bool asPage;
|
||||
|
||||
@override
|
||||
ConsumerState<SettingsTab> createState() => _SettingsTabState();
|
||||
@@ -389,7 +394,10 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
|
||||
return MornyeSettingsTheme(
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
AppSliverHeader.tabRoot(title: context.l10n.settingsTitle),
|
||||
if (widget.asPage)
|
||||
AppSliverHeader.page(title: context.l10n.settingsTitle)
|
||||
else
|
||||
AppSliverHeader.tabRoot(title: context.l10n.settingsTitle),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
@@ -408,6 +416,45 @@ class _SettingsTabState extends ConsumerState<SettingsTab> {
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final profile = ref.watch(userProfileProvider).value;
|
||||
return SettingsGroup(
|
||||
margin: margin,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 16,
|
||||
),
|
||||
leading: ProfileAvatar(
|
||||
name: profile?.name ?? '',
|
||||
photoPath: profile?.photoPath,
|
||||
size: 64,
|
||||
),
|
||||
title: Text(
|
||||
profile?.name.isNotEmpty == true
|
||||
? profile!.name
|
||||
: context.l10n.profileSetUp,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
subtitle: Text(context.l10n.profileEdit),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: profile == null
|
||||
? null
|
||||
: () => _navigateTo(
|
||||
context,
|
||||
ProfileSettingsPage(profile: profile),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
...body,
|
||||
const NavBarSliverSpacer(),
|
||||
const SliverFillRemaining(hasScrollBody: false, child: SizedBox()),
|
||||
|
||||
Reference in new issue
Block a user