forked from jmshrv/finamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of queue history and restore page.
- Loading branch information
1 parent
e913e6e
commit bd88212
Showing
8 changed files
with
228 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
import '../models/finamp_models.dart'; | ||
import '../services/queue_service.dart'; | ||
import 'error_snackbar.dart'; | ||
|
||
class QueueRestoreTile extends StatelessWidget { | ||
const QueueRestoreTile({Key? key, required this.info}) : super(key: key); | ||
|
||
final FinampStorableQueueInfo info; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final _queuesBox = Hive.box<FinampStorableQueueInfo>("Queues"); | ||
final _queueService = GetIt.instance<QueueService>(); | ||
int itemCount = info.queue.length + info.nextUp.length + ((info.currentTrack == null)?0:1); | ||
|
||
return ListTile( | ||
// TODO attempt to load current track album cover here | ||
title: Text('Queue contaning $itemCount songs.'), | ||
subtitle: Text('Created '+DateTime.fromMillisecondsSinceEpoch(info.creation).toString()),// TODO format date better? | ||
trailing: IconButton( | ||
icon: const Icon(Icons.delete),//TODO change to button with word restore or better icon | ||
onPressed: () async { | ||
var latest = _queuesBox.get("latest"); | ||
if ( latest != null ){ | ||
await _queuesBox.put(latest.creation.toString(), latest); | ||
} | ||
await _queueService.loadSavedQueue(info).catchError((x) => errorSnackbar(x,context)); | ||
// TODO add some sort of loading spinner on click | ||
Navigator.of(context).pop(); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
import '../components/queue_restore_tile.dart'; | ||
import '../models/finamp_models.dart'; | ||
|
||
class QueueRestoreScreen extends StatelessWidget { | ||
const QueueRestoreScreen({Key? key}) : super(key: key); | ||
|
||
static const routeName = "/queues"; | ||
|
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final _queuesBox = Hive.box<FinampStorableQueueInfo>("Queues"); | ||
var queueMap = _queuesBox.toMap(); | ||
queueMap.remove("latest"); | ||
var queueList = queueMap.values.toList(); | ||
queueList.sort((x,y)=>x.creation-y.creation); | ||
|
||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(AppLocalizations.of(context)!.queuesScreen), | ||
), | ||
body: Scrollbar( | ||
child: ListView.builder( | ||
itemCount: queueList.length, | ||
reverse: true, | ||
itemBuilder: (context, index) { | ||
return QueueRestoreTile( | ||
info: queueList.reversed.elementAt(index)); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.