Skip to content

Commit

Permalink
refactor dialog
Browse files Browse the repository at this point in the history
- made fully generic now
  • Loading branch information
Chaphasilor committed Nov 28, 2023
1 parent e8cfc97 commit b9bc901
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
21 changes: 15 additions & 6 deletions lib/components/AlbumScreen/download_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../../models/jellyfin_models.dart';
import '../../models/finamp_models.dart';
import '../error_snackbar.dart';
import 'download_dialog.dart';
import 'downloaded_album_delete_dialog.dart';
import '../confirmation_prompt_dialog.dart';

class DownloadButton extends StatefulWidget {
const DownloadButton({
Expand Down Expand Up @@ -65,12 +65,21 @@ class _DownloadButtonState extends State<DownloadButton> {
if (isDownloaded) {
showDialog(
context: context,
builder: (context) => DownloadedAlbumDeleteDialog(
builder: (context) => ConfirmationPromptDialog(
onConfirmed: () {
_downloadsHelper.deleteDownloads(
jellyfinItemIds: widget.items.map((e) => e.id).toList(),
deletedFor: widget.parent.id
).onError((error, stackTrace) => errorSnackbar(error, context));
Navigator.of(context).pop();
_downloadsHelper
.deleteDownloads(
jellyfinItemIds:
widget.items.map((e) => e.id).toList(),
deletedFor: widget.parent.id)
.then((value) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Downloads deleted.")));
}).onError((error, stackTrace) {
errorSnackbar(error, context);
});
},
onAborted: () {},
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';

import '../../models/jellyfin_models.dart';
import '../../services/downloads_helper.dart';
import '../error_snackbar.dart';
import '../models/jellyfin_models.dart';
import '../services/downloads_helper.dart';
import 'error_snackbar.dart';

class DownloadedAlbumDeleteDialog extends AlertDialog {
const DownloadedAlbumDeleteDialog({
class ConfirmationPromptDialog extends AlertDialog {
const ConfirmationPromptDialog({
Key? key,
required this.onConfirmed,
required this.onAborted,
Expand All @@ -15,13 +15,6 @@ class DownloadedAlbumDeleteDialog extends AlertDialog {
final void Function()? onConfirmed;
final void Function()? onAborted;

// used to make sure isDownloaded in DownloadButton is checked after downloads
// actually get deleted
void exitDialog(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Downloads deleted.")));
Navigator.of(context).pop();
}

@override
Widget build(BuildContext context) {
Expand All @@ -38,7 +31,6 @@ class DownloadedAlbumDeleteDialog extends AlertDialog {
TextButton(
child: const Text("DELETE"),
onPressed: () {
exitDialog(context);
onConfirmed?.call();
},
),
Expand Down

0 comments on commit b9bc901

Please sign in to comment.