diff --git a/lib/intent/deep_link/utils.dart b/lib/intent/deep_link/utils.dart index 8bd09c039..77cac4f39 100644 --- a/lib/intent/deep_link/utils.dart +++ b/lib/intent/deep_link/utils.dart @@ -23,8 +23,12 @@ String encodeBytesForUrl(Uint8List original, {bool compress = true}) { if (kDebugMode) { if (compress) { debugPrint("${original.length} => ${bytes.length}"); - assert(bytes.length <= original.length, "compressed is ${bytes.length} > original is ${original.length}"); - assert(compressedStr.length <= base64Encode(original).length); + if(kDebugMode && !(bytes.length <= original.length)){ + print("compressed is ${bytes.length} > original is ${original.length}"); + } + if(kDebugMode && !(compressedStr.length <= base64Encode(original).length)){ + print("compressed string is ${compressedStr.length} > original string is ${base64Encode(original).length}"); + } } else { debugPrint("${original.length}"); } diff --git a/lib/timetable/patch/page/patch.dart b/lib/timetable/patch/page/patch.dart index 8e4118cbf..b786de1b4 100644 --- a/lib/timetable/patch/page/patch.dart +++ b/lib/timetable/patch/page/patch.dart @@ -219,76 +219,75 @@ class _TimetablePatchEditorPageState extends State { } Widget buildPatchEntry(TimetablePatchEntry entry, int index, SitTimetable timetable) { - return switch (entry) { - TimetablePatchSet() => TimetablePatchEntryDroppable( - patch: entry, - onMerged: (other) { - removePatch(patches.indexOf(other)); - patches[index] = entry.copyWith(patches: List.of(entry.patches)..add(other)); - markChanged(); - }, - builder: (dropping) => TimetablePatchSetCard( - key: widget.initialEditing == entry ? initialEditingKey : null, - selected: dropping, - patchSet: entry, - timetable: timetable, - optimizedForTouch: true, - onDeleted: () { - removePatch(index); - }, - onUnpacked: () { - removePatch(index); - patches.insertAll(index, entry.patches); - markChanged(); - }, - onEdit: () async { - await editPatchSet(index, entry); - }, - ).padSymmetric(v: 4), - ), - TimetablePatch() => WithSwipeAction( - key: widget.initialEditing == entry ? initialEditingKey : null, - childKey: ValueKey(entry), - right: SwipeAction.delete( - icon: context.icons.delete, - action: () { - removePatch(index); - }, - ), - child: TimetablePatchEntryDroppable( + return WithSwipeAction( + key: widget.initialEditing == entry ? initialEditingKey : null, + childKey: ValueKey(entry), + right: SwipeAction.delete( + icon: context.icons.delete, + action: () { + removePatch(index); + }, + ), + child: switch (entry) { + TimetablePatchSet() => TimetablePatchEntryDroppable( patch: entry, onMerged: (other) { - final patchSet = TimetablePatchSet( - name: allocValidFileName( - i18n.patch.defaultName, - all: patches.whereType().map((set) => set.name).toList(), - ), - patches: [entry, other], - ); - patches.insert(index, patchSet); - removePatch(patches.indexOf(entry)); removePatch(patches.indexOf(other)); + patches[index] = entry.copyWith(patches: List.of(entry.patches)..add(other)); markChanged(); }, - builder: (dropping) => TimetablePatchWidget( - selected: dropping || widget.initialEditing == entry, - optimizedForTouch: true, - leading: (ctx, child) => TimetablePatchDraggable( - patch: entry, - child: child, - ), - patch: entry, + builder: (dropping) => TimetablePatchSetWidget( + selected: dropping, + patchSet: entry, timetable: timetable, + optimizedForTouch: true, onDeleted: () { removePatch(index); }, + onUnpacked: () { + removePatch(index); + patches.insertAll(index, entry.patches); + markChanged(); + }, onEdit: () async { - await editPatch(index, entry); + await editPatchSet(index, entry); }, + ).padSymmetric(v: 4), + ), + TimetablePatch() => TimetablePatchEntryDroppable( + patch: entry, + onMerged: (other) { + final patchSet = TimetablePatchSet( + name: allocValidFileName( + i18n.patch.defaultName, + all: patches.whereType().map((set) => set.name).toList(), + ), + patches: [entry, other], + ); + patches.insert(index, patchSet); + removePatch(patches.indexOf(entry)); + removePatch(patches.indexOf(other)); + markChanged(); + }, + builder: (dropping) => TimetablePatchWidget( + selected: dropping || widget.initialEditing == entry, + optimizedForTouch: true, + leading: (ctx, child) => TimetablePatchDraggable( + patch: entry, + child: child, ), + patch: entry, + timetable: timetable, + onDeleted: () { + removePatch(index); + }, + onEdit: () async { + await editPatch(index, entry); + }, ), ), - }; + }, + ); } Future editPatchSet(int index, TimetablePatchSet patchSet) async { @@ -508,7 +507,7 @@ class ReadonlyTimetablePatchEntryWidget extends StatelessWidget { Widget build(BuildContext context) { final entry = this.entry; return switch (entry) { - TimetablePatchSet() => TimetablePatchSetCard( + TimetablePatchSet() => TimetablePatchSetWidget( patchSet: entry, enableQrCode: enableQrCode, ), diff --git a/lib/timetable/patch/page/patch_set.dart b/lib/timetable/patch/page/patch_set.dart index 6987a9ebf..cefed84be 100644 --- a/lib/timetable/patch/page/patch_set.dart +++ b/lib/timetable/patch/page/patch_set.dart @@ -138,18 +138,6 @@ class _TimetablePatchSetEditorPageState extends State Icon(patch.type.icon)).toList().wrap(spacing: 4); + return patchSet.patches.map((patch) => Icon(patch.type.icon)).toList().wrap(spacing: 4); } } diff --git a/lib/timetable/patch/widget/patch_set.dart b/lib/timetable/patch/widget/patch_set.dart index e0578d7f7..72413dc88 100644 --- a/lib/timetable/patch/widget/patch_set.dart +++ b/lib/timetable/patch/widget/patch_set.dart @@ -1,17 +1,16 @@ -import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:mimir/timetable/patch/page/patch_set.dart'; import 'package:rettulf/rettulf.dart'; import 'package:mimir/design/adaptive/menu.dart'; import 'package:mimir/design/adaptive/multiplatform.dart'; -import 'package:mimir/design/widgets/expansion_tile.dart'; import '../../entity/timetable.dart'; import '../../i18n.dart'; import '../../page/preview.dart'; import '../entity/patch.dart'; import 'shared.dart'; -class TimetablePatchSetCard extends StatelessWidget { +class TimetablePatchSetWidget extends StatelessWidget { final TimetablePatchSet patchSet; final bool selected; final SitTimetable? timetable; @@ -21,7 +20,7 @@ class TimetablePatchSetCard extends StatelessWidget { final bool enableQrCode; final bool optimizedForTouch; - const TimetablePatchSetCard({ + const TimetablePatchSetWidget({ super.key, required this.patchSet, this.timetable, @@ -35,43 +34,17 @@ class TimetablePatchSetCard extends StatelessWidget { @override Widget build(BuildContext context) { - final detailsColor = selected ? context.colorScheme.primary : context.colorScheme.onSurfaceVariant; - final detailsStyle = context.textTheme.bodyMedium?.copyWith( - color: detailsColor, - ); - return Card.outlined( - clipBehavior: Clip.hardEdge, - margin: EdgeInsets.zero, - child: AnimatedExpansionTile( - selected: selected, - leading: PatchIcon( - icon: Icons.dashboard_customize, - optimizedForTouch: optimizedForTouch, - inCard: false, - ), - title: patchSet.name.text(), - trailing: buildMoreActions(), - rotateTrailing: false, - children: patchSet.patches - .mapIndexed( - (i, p) => RichText( - text: TextSpan( - style: detailsStyle, - children: [ - WidgetSpan( - child: Icon( - p.type.icon, - color: detailsColor, - size: 16, - ), - ), - TextSpan(text: p.l10n()), - ], - ), - ).padSymmetric(h: 16), - ) - .toList(), + return ListTile( + selected: selected, + isThreeLine: true, + leading: PatchIcon( + icon: Icons.dashboard_customize, + optimizedForTouch: optimizedForTouch, ), + title: patchSet.name.text(), + subtitle: TimetablePatchSetPatchesPreview(patchSet), + trailing: buildMoreActions(), + onTap: onEdit, ); } @@ -80,12 +53,6 @@ class TimetablePatchSetCard extends StatelessWidget { return PullDownMenuButton( itemBuilder: (context) { return [ - if (timetable != null) - PullDownItem( - icon: context.icons.edit, - title: i18n.edit, - onTap: onEdit, - ), PullDownItem( icon: context.icons.preview, title: i18n.preview, @@ -107,12 +74,6 @@ class TimetablePatchSetCard extends StatelessWidget { title: i18n.patch.unpack, onTap: onUnpacked, ), - if (onDeleted != null) - PullDownItem.delete( - icon: context.icons.delete, - title: i18n.delete, - onTap: onDeleted, - ), ]; }, );