Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
riverscuomo committed Aug 6, 2024
1 parent adcb745 commit 10cfe1c
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 93 deletions.
26 changes: 15 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/widgets.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:spotkin_flutter/app_core.dart';

Expand Down Expand Up @@ -99,24 +100,27 @@ final spotifyThemeData = ThemeData(
textTheme: ButtonTextTheme.primary,
// padding: const EdgeInsets.all(16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
borderRadius: BorderRadius.circular(20),
),
),
expansionTileTheme: ExpansionTileThemeData(
backgroundColor: spotifyWidgetColor,
collapsedBackgroundColor: spotifyWidgetColor,
textColor: Colors.white,
collapsedTextColor: Colors.white,
iconColor: Colors.white,
collapsedIconColor: Colors.white,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(4),
// // side: BorderSide(color: Colors.white24),
// ),
collapsedShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
// textColor: Colors.white,
// collapsedTextColor: Colors.white,
// iconColor: Colors.white,
// collapsedIconColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
// side: BorderSide(color: Colors.white24),
),
),
textTheme: TextTheme(
titleLarge:
const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
titleLarge: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 28),
bodyMedium: const TextStyle(color: Colors.white70),
// titleMedium: TextStyle(color: Colors.white54),
labelMedium: TextStyle(color: Colors.grey[400]),
Expand Down
129 changes: 59 additions & 70 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class _HomeScreenState extends State<HomeScreen> {
return Scaffold(
appBar: AppBar(
title: const Text('Spotkin'),
titleTextStyle: Theme.of(context).textTheme.titleLarge,
automaticallyImplyLeading: false,
actions: [
IconButton(
Expand All @@ -195,89 +196,77 @@ class _HomeScreenState extends State<HomeScreen> {
children: [
Column(
children: [
Material(
elevation: 1,
borderRadius: BorderRadius.circular(12.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: ExpansionTile(
key: _expansionTileKey,
title: Column(children: [
PlaylistImageIcon(
playlist: targetPlaylist,
size: 160,
),
const SizedBox(height: 16),
Column(
ExpansionTile(
key: _expansionTileKey,
title: Column(children: [
PlaylistImageIcon(
playlist: targetPlaylist,
size: 160,
),
const SizedBox(height: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
PlaylistTitle(context, targetPlaylist,
style: Theme.of(context)
.textTheme
.titleLarge),
const SizedBox(height: 5),
Row(
children: [
PlaylistTitle(context, targetPlaylist,
playlistSubtitle(targetPlaylist, context),
const SizedBox(width: 10),
if (jobResults.isNotEmpty)
Text(
jobResults[0]['result'],
style: Theme.of(context)
.textTheme
.titleLarge),
const SizedBox(height: 5),
Row(
children: [
playlistSubtitle(
targetPlaylist, context),
const SizedBox(width: 10),
if (jobResults.isNotEmpty)
Text(
jobResults[0]['result'],
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
fontStyle:
FontStyle.italic),
),
const SizedBox(width: 10),
if (jobResults.isNotEmpty)
Icon(
size: 14,
jobResults[0]['status'] ==
'Success'
? Icons.check_circle
: Icons.error,
color: jobResults[0]['status'] ==
'Success'
? Colors.green
: Colors.red,
),
],
),
.labelMedium!
.copyWith(
fontStyle: FontStyle.italic),
),
const SizedBox(width: 10),
if (jobResults.isNotEmpty)
Icon(
size: 14,
jobResults[0]['status'] == 'Success'
? Icons.check_circle
: Icons.error,
color: jobResults[0]['status'] ==
'Success'
? Colors.green
: Colors.red,
),
],
),
SpotifyButton(
isProcessing: isProcessing,
processJobs: _processJobs),
],
)
),
SpotifyButton(
isProcessing: isProcessing,
processJobs: _processJobs),
],
)
]),
// leading: ,
// subtitle: ,
initiallyExpanded: _isExpanded,
onExpansionChanged: (expanded) {
setState(() {
_isExpanded = expanded;
});
},
children: [
buildTargetPlaylistSelectionOptions(),
],
),
),
)
]),
// leading: ,
// subtitle: ,
initiallyExpanded: _isExpanded,
onExpansionChanged: (expanded) {
setState(() {
_isExpanded = expanded;
});
},
children: [
buildTargetPlaylistSelectionOptions(),
],
),
SizedBox(height: widgetPadding),
...jobs.asMap().entries.map((entry) {
Expand Down
75 changes: 75 additions & 0 deletions lib/screens/job_management_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:spotkin_flutter/app_core.dart';
import 'package:spotkin_flutter/services/backup_service.dart';

class JobManagementScreen extends StatefulWidget {
const JobManagementScreen({super.key});

@override
_JobManagementScreenState createState() => _JobManagementScreenState();
}

class _JobManagementScreenState extends State<JobManagementScreen> {
final StorageService _storageService = StorageService();
late BackupService _backupService;
List<Job> _jobs = [];

@override
void initState() {
super.initState();
_backupService = BackupService(_storageService);
_loadJobs();
}

void _loadJobs() {
setState(() {
_jobs = _storageService.getJobs();
});
}

void _createBackup() {
_backupService.createBackup();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Backup file created. Check your downloads.')),
);
}

Future<void> _importBackup() async {
await _backupService.importBackup();
_loadJobs(); // Reload jobs after import
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Backup imported and jobs updated.')),
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Job Management')),
body: Column(
children: [
ElevatedButton(
onPressed: _createBackup,
child: const Text('Create Backup File'),
),
ElevatedButton(
onPressed: _importBackup,
child: const Text('Import Backup File'),
),
Expanded(
child: ListView.builder(
itemCount: _jobs.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_jobs[index].targetPlaylist.name ?? 'Untitled'),
subtitle: Text('Recipe count: ${_jobs[index].recipe.length}'),
);
},
),
),
],
),
);
}
}
64 changes: 52 additions & 12 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,69 @@ import 'package:spotkin_flutter/app_core.dart';
class SettingsScreen extends StatelessWidget {
final List<Job> jobs;
final Function(int, Job) updateJob;
final StorageService storageService = StorageService();
late final BackupService backupService;

const SettingsScreen({
SettingsScreen({
Key? key,
required this.jobs,
required this.updateJob,
}) : super(key: key);
}) : super(key: key) {
backupService = BackupService(storageService);
}

void _createBackup(BuildContext context) {
backupService.createBackup();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Backup file created. Check your downloads.')),
);
}

Future<void> _importBackup(BuildContext context) async {
await backupService.importBackup();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Backup imported and jobs updated.')),
);
// You might want to refresh the jobs list here or in the parent widget
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Settings'),
actions: [InfoButton()],
actions: const [InfoButton()],
),
body: ListView.builder(
itemCount: jobs.length,
itemBuilder: (context, index) {
return SettingsCard(
index: index,
job: jobs[index],
updateJob: updateJob,
);
},
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: jobs.length,
itemBuilder: (context, index) {
return SettingsCard(
index: index,
job: jobs[index],
updateJob: updateJob,
);
},
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: () => _createBackup(context),
child: const Text('Create Backup'),
),
ElevatedButton(
onPressed: () => _importBackup(context),
child: const Text('Import Backup'),
),
],
),
const SizedBox(height: 16),
],
),
);
}
Expand Down
Loading

0 comments on commit 10cfe1c

Please sign in to comment.