mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-08 23:18:16 -07:00
feature: Re-implemented syncing
This commit is contained in:
parent
c5c7f71b84
commit
86ff355e21
51 changed files with 3067 additions and 1147 deletions
139
lib/screens/syncing/widgets/sync_options_button.dart
Normal file
139
lib/screens/syncing/widgets/sync_options_button.dart
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:iconsax_plus/iconsax_plus.dart';
|
||||
|
||||
import 'package:fladder/models/syncing/sync_item.dart';
|
||||
import 'package:fladder/providers/sync/sync_provider_helpers.dart';
|
||||
import 'package:fladder/providers/sync_provider.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:fladder/util/refresh_state.dart';
|
||||
import 'package:fladder/widgets/shared/filled_button_await.dart';
|
||||
|
||||
class SyncOptionsButton extends ConsumerWidget {
|
||||
final SyncedItem syncedItem;
|
||||
final List<SyncedItem> children;
|
||||
const SyncOptionsButton({
|
||||
required this.syncedItem,
|
||||
required this.children,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
final unSyncedChildren = children.where((element) {
|
||||
final hasDownload = ref.read(syncDownloadStatusProvider(element, []));
|
||||
return element.hasVideoFile && !element.videoFile.existsSync() && hasDownload?.status == TaskStatus.notFound;
|
||||
}).toList();
|
||||
|
||||
final syncedChildren =
|
||||
children.where((element) => element.hasVideoFile && element.videoFile.existsSync()).toList();
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
const Icon(IconsaxPlusLinear.refresh_2),
|
||||
Text(context.localized.refreshMetadata),
|
||||
],
|
||||
),
|
||||
onTap: () => context.refreshData(),
|
||||
),
|
||||
if (children.isNotEmpty) ...[
|
||||
PopupMenuItem(
|
||||
enabled: unSyncedChildren.isNotEmpty,
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
const Icon(IconsaxPlusLinear.cloud_add),
|
||||
Text(context.localized.sync),
|
||||
],
|
||||
),
|
||||
onTap: () async => _syncRemainingItems(context, syncedItem, unSyncedChildren, ref),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: syncedChildren.isNotEmpty,
|
||||
child: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
const Icon(IconsaxPlusLinear.trash),
|
||||
Text(context.localized.delete),
|
||||
],
|
||||
),
|
||||
onTap: () async => _deleteSyncedItems(context, syncedItem, syncedChildren, ref),
|
||||
)
|
||||
]
|
||||
];
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> _deleteSyncedItems(
|
||||
BuildContext context, SyncedItem syncedItem, List<SyncedItem> syncedChildren, WidgetRef ref) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(context.localized.syncDeleteAllItemsTitle(syncedItem.itemModel?.name ?? "")),
|
||||
content: Text(
|
||||
context.localized.syncDeleteAllItemsDesc(syncedItem.itemModel?.name ?? "", syncedChildren.length),
|
||||
),
|
||||
scrollable: true,
|
||||
actions: [
|
||||
ElevatedButton(onPressed: () => Navigator.of(context).pop(), child: Text(context.localized.cancel)),
|
||||
FilledButtonAwait(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.errorContainer,
|
||||
foregroundColor: Theme.of(context).colorScheme.onErrorContainer,
|
||||
iconColor: Theme.of(context).colorScheme.onErrorContainer,
|
||||
),
|
||||
onPressed: () async {
|
||||
final deleteList = syncedChildren.map((e) => ref.read(syncProvider.notifier).deleteFullSyncFiles(e, null));
|
||||
await Future.wait(deleteList);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
context.localized.delete,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<dynamic> _syncRemainingItems(
|
||||
BuildContext context, SyncedItem syncedItem, List<SyncedItem> unSyncedChildren, WidgetRef ref) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(context.localized.syncAllItemsTitle(syncedItem.itemModel?.name ?? "")),
|
||||
content: Text(
|
||||
context.localized.syncAllItemsDesc(
|
||||
syncedItem.itemModel?.name ?? "",
|
||||
unSyncedChildren.length,
|
||||
),
|
||||
),
|
||||
scrollable: true,
|
||||
actions: [
|
||||
ElevatedButton(onPressed: () => Navigator.of(context).pop(), child: Text(context.localized.cancel)),
|
||||
FilledButtonAwait(
|
||||
onPressed: () async {
|
||||
final syncList = unSyncedChildren.map((e) => ref.read(syncProvider.notifier).syncFile(e, false));
|
||||
await Future.wait(syncList);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
context.localized.sync,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:iconsax_plus/iconsax_plus.dart';
|
||||
|
||||
|
|
@ -22,12 +23,10 @@ class SyncedEpisodeItem extends ConsumerStatefulWidget {
|
|||
super.key,
|
||||
required this.episode,
|
||||
required this.syncedItem,
|
||||
required this.hasFile,
|
||||
});
|
||||
|
||||
final EpisodeModel episode;
|
||||
final SyncedItem syncedItem;
|
||||
final bool hasFile;
|
||||
|
||||
@override
|
||||
ConsumerState<SyncedEpisodeItem> createState() => _SyncedEpisodeItemState();
|
||||
|
|
@ -40,91 +39,94 @@ class _SyncedEpisodeItemState extends ConsumerState<SyncedEpisodeItem> {
|
|||
final downloadTask = ref.watch(downloadTasksProvider(syncedItem.id));
|
||||
final hasFile = widget.syncedItem.videoFile.existsSync();
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * 0.3),
|
||||
child: FlatButton(
|
||||
onTap: () {
|
||||
widget.episode.navigateTo(context);
|
||||
return context.maybePop();
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 175,
|
||||
child: EpisodePoster(
|
||||
episode: widget.episode,
|
||||
syncedItem: syncedItem,
|
||||
actions: [],
|
||||
showLabel: false,
|
||||
isCurrentEpisode: false,
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * 0.3),
|
||||
child: FlatButton(
|
||||
onTap: () {
|
||||
widget.episode.navigateTo(context);
|
||||
return context.maybePop();
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 175,
|
||||
child: EpisodePoster(
|
||||
episode: widget.episode,
|
||||
actions: [],
|
||||
showLabel: false,
|
||||
isCurrentEpisode: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.episode.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Opacity(
|
||||
opacity: 0.75,
|
||||
child: Text(
|
||||
widget.episode.seasonEpisodeLabel(context),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.episode.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!widget.hasFile && downloadTask.hasDownload)
|
||||
Flexible(
|
||||
child: SyncProgressBar(item: syncedItem, task: downloadTask),
|
||||
)
|
||||
else
|
||||
Flexible(
|
||||
child: SyncLabel(
|
||||
label: context.localized.totalSize(ref.watch(syncSizeProvider(syncedItem, [])).byteFormat ?? '--'),
|
||||
status: ref.watch(syncStatusesProvider(syncedItem, [])).value ?? SyncStatus.partially,
|
||||
Opacity(
|
||||
opacity: 0.75,
|
||||
child: Text(
|
||||
widget.episode.seasonEpisodeLabel(context),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
if (!hasFile && downloadTask.hasDownload)
|
||||
Flexible(
|
||||
child: SyncProgressBar(item: syncedItem, task: downloadTask),
|
||||
)
|
||||
else
|
||||
Flexible(
|
||||
child: SyncLabel(
|
||||
label:
|
||||
context.localized.totalSize(ref.watch(syncSizeProvider(syncedItem, [])).byteFormat ?? '--'),
|
||||
status: ref.watch(syncDownloadStatusProvider(syncedItem, [])
|
||||
.select((value) => value?.status ?? TaskStatus.notFound)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!hasFile && !downloadTask.hasDownload)
|
||||
IconButtonAwait(
|
||||
onPressed: () async => await ref.read(syncProvider.notifier).syncFile(syncedItem, false),
|
||||
icon: const Icon(IconsaxPlusLinear.cloud_change),
|
||||
)
|
||||
else if (hasFile)
|
||||
IconButtonAwait(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
onPressed: () async {
|
||||
await showDefaultAlertDialog(
|
||||
context,
|
||||
context.localized.syncRemoveDataTitle,
|
||||
context.localized.syncRemoveDataDesc,
|
||||
(context) async {
|
||||
await ref.read(syncProvider.notifier).deleteFullSyncFiles(syncedItem, downloadTask.task);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
context.localized.delete,
|
||||
(context) => Navigator.pop(context),
|
||||
context.localized.cancel,
|
||||
);
|
||||
},
|
||||
icon: const Icon(IconsaxPlusLinear.trash),
|
||||
)
|
||||
].addInBetween(const SizedBox(width: 16)),
|
||||
if (!hasFile && !downloadTask.hasDownload)
|
||||
IconButtonAwait(
|
||||
onPressed: () async => await ref.read(syncProvider.notifier).syncFile(syncedItem, false),
|
||||
icon: const Icon(IconsaxPlusLinear.cloud_change),
|
||||
)
|
||||
else if (hasFile)
|
||||
IconButtonAwait(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
onPressed: () async {
|
||||
await showDefaultAlertDialog(
|
||||
context,
|
||||
context.localized.syncRemoveDataTitle,
|
||||
context.localized.syncRemoveDataDesc,
|
||||
(context) async {
|
||||
await ref.read(syncProvider.notifier).deleteFullSyncFiles(syncedItem, downloadTask.task);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
context.localized.delete,
|
||||
(context) => Navigator.pop(context),
|
||||
context.localized.cancel,
|
||||
);
|
||||
},
|
||||
icon: const Icon(IconsaxPlusLinear.trash),
|
||||
)
|
||||
].addInBetween(const SizedBox(width: 16)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:iconsax_plus/iconsax_plus.dart';
|
||||
|
||||
import 'package:fladder/models/items/episode_model.dart';
|
||||
import 'package:fladder/models/items/season_model.dart';
|
||||
import 'package:fladder/models/syncing/sync_item.dart';
|
||||
import 'package:fladder/providers/sync_provider.dart';
|
||||
import 'package:fladder/providers/sync/sync_provider_helpers.dart';
|
||||
import 'package:fladder/screens/shared/flat_button.dart';
|
||||
import 'package:fladder/screens/syncing/sync_widgets.dart';
|
||||
import 'package:fladder/screens/syncing/widgets/sync_options_button.dart';
|
||||
import 'package:fladder/screens/syncing/widgets/sync_progress_builder.dart';
|
||||
import 'package:fladder/screens/syncing/widgets/synced_episode_item.dart';
|
||||
import 'package:fladder/util/fladder_image.dart';
|
||||
import 'package:fladder/widgets/shared/icon_button_await.dart';
|
||||
import 'package:fladder/util/localization_helper.dart';
|
||||
import 'package:fladder/util/size_formatting.dart';
|
||||
|
||||
class SyncedSeasonPoster extends ConsumerStatefulWidget {
|
||||
const SyncedSeasonPoster({
|
||||
|
|
@ -32,72 +36,96 @@ class _SyncedSeasonPosterState extends ConsumerState<SyncedSeasonPoster> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final season = widget.season;
|
||||
final children = ref.read(syncProvider.notifier).getChildren(widget.syncedItem);
|
||||
final unSyncedChildren = children.where((child) => child.status == SyncStatus.partially).toList();
|
||||
return ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
title: Row(
|
||||
spacing: 6,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 75,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 0.65,
|
||||
child: FlatButton(
|
||||
onTap: () {
|
||||
season.navigateTo(context);
|
||||
return context.maybePop();
|
||||
},
|
||||
child: Card(
|
||||
child: FladderImage(
|
||||
image: season.getPosters?.primary ??
|
||||
season.parentImages?.backDrop?.firstOrNull ??
|
||||
season.parentImages?.primary,
|
||||
final nestedChildren = ref.watch(syncedNestedChildrenProvider(widget.syncedItem));
|
||||
return nestedChildren.when(
|
||||
data: (children) => Builder(
|
||||
builder: (context) {
|
||||
final syncedItem = widget.syncedItem;
|
||||
return ExpansionTile(
|
||||
tilePadding: EdgeInsets.zero,
|
||||
shape: const Border(),
|
||||
title: Row(
|
||||
spacing: 12,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 75,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 0.65,
|
||||
child: FlatButton(
|
||||
onTap: () {
|
||||
season.navigateTo(context);
|
||||
return context.maybePop();
|
||||
},
|
||||
child: Card(
|
||||
child: FladderImage(
|
||||
image: season.getPosters?.primary ??
|
||||
season.parentImages?.backDrop?.firstOrNull ??
|
||||
season.parentImages?.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: SyncProgressBuilder(
|
||||
item: syncedItem,
|
||||
children: children,
|
||||
builder: (context, combinedStream) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 4,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
season.name,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: SyncSubtitle(
|
||||
syncItem: syncedItem,
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Consumer(
|
||||
builder: (context, ref, child) => SyncLabel(
|
||||
label: context.localized
|
||||
.totalSize(ref.watch(syncSizeProvider(syncedItem, children))?.byteFormat ?? '--'),
|
||||
status: combinedStream?.status ?? TaskStatus.notFound,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (combinedStream != null && combinedStream.hasDownload == true)
|
||||
SyncProgressBar(item: syncedItem, task: combinedStream)
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
season.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (unSyncedChildren.isNotEmpty)
|
||||
IconButtonAwait(
|
||||
onPressed: () async {
|
||||
for (var i = 0; i < unSyncedChildren.length; i++) {
|
||||
final childSyncedItem = unSyncedChildren[i];
|
||||
await ref.read(syncProvider.notifier).syncFile(childSyncedItem, false);
|
||||
}
|
||||
trailing: SyncOptionsButton(syncedItem: syncedItem, children: children),
|
||||
children: children.map(
|
||||
(item) {
|
||||
final baseItem = item.itemModel;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: SyncedEpisodeItem(
|
||||
episode: baseItem as EpisodeModel,
|
||||
syncedItem: item,
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(IconsaxPlusLinear.cloud_change),
|
||||
),
|
||||
],
|
||||
),
|
||||
children: children.map(
|
||||
(item) {
|
||||
final baseItem = ref.read(syncProvider.notifier).getItem(item);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: IntrinsicHeight(
|
||||
child: SyncedEpisodeItem(
|
||||
episode: baseItem as EpisodeModel,
|
||||
syncedItem: item,
|
||||
hasFile: item.videoFile.existsSync(),
|
||||
),
|
||||
),
|
||||
).toList(),
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
error: (error, stackTrace) => const SizedBox.shrink(),
|
||||
loading: () => const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue