Skip to content

Commit

Permalink
feat(mobile): long-press delete button to permanently delete asset (#…
Browse files Browse the repository at this point in the history
…6240)

* feat(mobile): delete assets from device only

* mobile: add backed up only toggle for delete device only

* remove toggle inside alert and show different content

* mobile: change content color for local only

* mobile: delete local only button to dialog

* style: display bottom action in two lines

* feat: separate delete buttons

* fix: incorrect error message for ownedRemoteSelection

* feat(mobile): long-press delete to permanently delete asset

* chore: add todo to handle long press to delete in gallery_viewer

* chore: rebase on deletion branch

* feat(mobile): long-press delete to permanently delete asset

* fix(mobile): update minChildSize of control bottom app bar

---------

Co-authored-by: shalong-tanwen <[email protected]>
Co-authored-by: Alex Tran <[email protected]>
  • Loading branch information
3 people authored Jan 18, 2024
1 parent 04c783f commit f62678f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions mobile/lib/modules/asset_viewer/views/gallery_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ class GalleryViewerPage extends HookConsumerWidget {
);
}

// TODO: Migrate to a custom bottom bar and handle long press to delete
Widget buildBottomBar() {
// !!!! itemsList and actionlist should always be in sync
final itemsList = [
Expand Down
36 changes: 26 additions & 10 deletions mobile/lib/modules/home/ui/control_bottom_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,35 @@ class ControlBottomAppBar extends ConsumerWidget {
ref.watch(serverInfoProvider.select((v) => v.serverFeatures.trash));
final albums = ref.watch(albumProvider).where((a) => a.isRemote).toList();
final sharedAlbums = ref.watch(sharedAlbumProvider);
const bottomPadding = 0.20;

void handleRemoteDelete(
bool force,
void showForceDeleteDialog(
Function(bool) deleteCb, {
String? alertMsg,
}) {
if (!force) {
deleteCb(force);
return;
}
showDialog(
context: context,
builder: (BuildContext context) {
return DeleteDialog(
alert: alertMsg,
onDelete: () => deleteCb(force),
onDelete: () => deleteCb(true),
);
},
);
}

void handleRemoteDelete(
bool force,
Function(bool) deleteCb, {
String? alertMsg,
}) {
if (!force) {
deleteCb(force);
return;
}
return showForceDeleteDialog(deleteCb, alertMsg: alertMsg);
}

List<Widget> renderActionButtons() {
return [
if (hasRemote)
Expand Down Expand Up @@ -132,6 +140,12 @@ class ControlBottomAppBar extends ConsumerWidget {
alertMsg: "delete_dialog_alert_remote",
)
: null,
onLongPressed: enabled
? () => showForceDeleteDialog(
onDeleteServer!,
alertMsg: "delete_dialog_alert_remote",
)
: null,
),
),
if (hasLocal && onDeleteLocal != null)
Expand Down Expand Up @@ -167,6 +181,8 @@ class ControlBottomAppBar extends ConsumerWidget {
onPressed: enabled
? () => handleRemoteDelete(!trashEnabled, onDelete!)
: null,
onLongPressed:
enabled ? () => showForceDeleteDialog(onDelete!) : null,
),
),
if (hasRemote && onEditTime != null)
Expand Down Expand Up @@ -214,9 +230,9 @@ class ControlBottomAppBar extends ConsumerWidget {
}

return DraggableScrollableSheet(
initialChildSize: hasRemote ? 0.30 : 0.18,
minChildSize: 0.18,
maxChildSize: hasRemote ? 0.60 : 0.18,
initialChildSize: hasRemote ? 0.30 : bottomPadding,
minChildSize: bottomPadding,
maxChildSize: hasRemote ? 0.60 : bottomPadding,
snap: true,
builder: (
BuildContext context,
Expand Down
4 changes: 2 additions & 2 deletions mobile/lib/shared/ui/asset_grid/multiselect_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ class MultiselectGrid extends HookConsumerWidget {
msg: '${selection.value.length} $assetOrAssets $trashOrRemoved',
gravity: ToastGravity.BOTTOM,
);
selectionEnabledHook.value = false;
}
} finally {
selectionEnabledHook.value = false;
processing.value = false;
}
}
Expand All @@ -224,9 +224,9 @@ class MultiselectGrid extends HookConsumerWidget {
'${localIds.length} $assetOrAssets removed permanently from your device',
gravity: ToastGravity.BOTTOM,
);
selectionEnabledHook.value = false;
}
} finally {
selectionEnabledHook.value = false;
processing.value = false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions mobile/lib/shared/ui/drag_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ class ControlBoxButton extends StatelessWidget {
required this.label,
required this.iconData,
this.onPressed,
this.onLongPressed,
}) : super(key: key);

final String label;
final IconData iconData;
final void Function()? onPressed;
final void Function()? onLongPressed;

@override
Widget build(BuildContext context) {
return MaterialButton(
padding: const EdgeInsets.all(10),
shape: const CircleBorder(),
onPressed: onPressed,
onLongPress: onLongPressed,
minWidth: 75.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down

0 comments on commit f62678f

Please sign in to comment.