Skip to content

Commit

Permalink
[timetable] [patch] unified swipe to delete action on both patch and …
Browse files Browse the repository at this point in the history
…patch set
  • Loading branch information
liplum committed Sep 1, 2024
1 parent 8a860da commit 922cccf
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 126 deletions.
8 changes: 6 additions & 2 deletions lib/intent/deep_link/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
113 changes: 56 additions & 57 deletions lib/timetable/patch/page/patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,76 +219,75 @@ class _TimetablePatchEditorPageState extends State<TimetablePatchEditorPage> {
}

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<TimetablePatchSet>().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<TimetablePatch>(
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<TimetablePatchSet>().map((set) => set.name).toList(),
),
patches: [entry, other],
);
patches.insert(index, patchSet);
removePatch(patches.indexOf(entry));
removePatch(patches.indexOf(other));
markChanged();
},
builder: (dropping) => TimetablePatchWidget<TimetablePatch>(
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<void> editPatchSet(int index, TimetablePatchSet patchSet) async {
Expand Down Expand Up @@ -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,
),
Expand Down
18 changes: 3 additions & 15 deletions lib/timetable/patch/page/patch_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,6 @@ class _TimetablePatchSetEditorPageState extends State<TimetablePatchSetEditorPag
}
},
),
PullDownItem.delete(
icon: context.icons.clear,
title: i18n.clear,
onTap: patches.isNotEmpty
? () {
setState(() {
patches.clear();
});
markChanged();
}
: null,
),
];
},
);
Expand Down Expand Up @@ -203,15 +191,15 @@ class _TimetablePatchSetEditorPageState extends State<TimetablePatchSetEditorPag
}

class TimetablePatchSetPatchesPreview extends StatelessWidget {
final TimetablePatchSet set;
final TimetablePatchSet patchSet;

const TimetablePatchSetPatchesPreview(
this.set, {
this.patchSet, {
super.key,
});

@override
Widget build(BuildContext context) {
return set.patches.map((patch) => Icon(patch.type.icon)).toList().wrap(spacing: 4);
return patchSet.patches.map((patch) => Icon(patch.type.icon)).toList().wrap(spacing: 4);
}
}
65 changes: 13 additions & 52 deletions lib/timetable/patch/widget/patch_set.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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,
);
}

Expand All @@ -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,
Expand All @@ -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,
),
];
},
);
Expand Down

0 comments on commit 922cccf

Please sign in to comment.