Created new picker for setting link's device limit
This commit is contained in:
parent
2eba2a9954
commit
9bdeffae3e
3 changed files with 155 additions and 1 deletions
|
@ -55,3 +55,5 @@ const int intMaxValue = 9223372036854775807;
|
|||
const double restrictedMaxWidth = 430;
|
||||
|
||||
const double mobileSmallThreshold = 336;
|
||||
|
||||
const deviceLimits = [50, 25, 10, 5, 2, 1];
|
||||
|
|
|
@ -16,9 +16,11 @@ import 'package:photos/ui/components/captioned_text_widget.dart';
|
|||
import 'package:photos/ui/components/divider_widget.dart';
|
||||
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
|
||||
import 'package:photos/ui/components/menu_section_description_widget.dart';
|
||||
import 'package:photos/ui/viewer/actions/picker_widget.dart';
|
||||
import 'package:photos/utils/crypto_util.dart';
|
||||
import 'package:photos/utils/date_time_util.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
import 'package:photos/utils/navigation_util.dart';
|
||||
import 'package:photos/utils/toast_util.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
|
@ -138,7 +140,8 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
|
|||
alignCaptionedTextToLeft: true,
|
||||
isBottomBorderRadiusRemoved: true,
|
||||
onTap: () async {
|
||||
await _showDeviceLimitPicker();
|
||||
// await _showDeviceLimitPicker();
|
||||
routeToPage(context, PickerWidget(widget.collection!));
|
||||
},
|
||||
surfaceExecutionStates: false,
|
||||
),
|
||||
|
|
149
lib/ui/viewer/actions/picker_widget.dart
Normal file
149
lib/ui/viewer/actions/picker_widget.dart
Normal file
|
@ -0,0 +1,149 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/captioned_text_widget.dart';
|
||||
import 'package:photos/ui/components/divider_widget.dart';
|
||||
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
|
||||
import 'package:photos/ui/components/title_bar_title_widget.dart';
|
||||
import 'package:photos/ui/components/title_bar_widget.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
import 'package:photos/utils/separators_util.dart';
|
||||
|
||||
class PickerWidget extends StatelessWidget {
|
||||
final Collection collection;
|
||||
const PickerWidget(this.collection, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
const TitleBarWidget(
|
||||
flexibleSpaceTitle: TitleBarTitleWidget(
|
||||
title: "Device Limit",
|
||||
),
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 20,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
child: ItemsWidget(collection),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ItemsWidget extends StatefulWidget {
|
||||
final Collection collection;
|
||||
const ItemsWidget(this.collection, {super.key});
|
||||
|
||||
@override
|
||||
State<ItemsWidget> createState() => _ItemsWidgetState();
|
||||
}
|
||||
|
||||
class _ItemsWidgetState extends State<ItemsWidget> {
|
||||
late int currentDeviceLimit;
|
||||
List<Widget> items = [];
|
||||
bool isCustomLimit = false;
|
||||
@override
|
||||
void initState() {
|
||||
currentDeviceLimit = widget.collection.publicURLs!.first!.deviceLimit;
|
||||
if (!deviceLimits.contains(currentDeviceLimit)) {
|
||||
isCustomLimit = true;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
items.clear();
|
||||
if (isCustomLimit) {
|
||||
items.add(
|
||||
MenuItemWidget(
|
||||
key: ValueKey(currentDeviceLimit),
|
||||
menuItemColor: getEnteColorScheme(context).fillFaint,
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: "$currentDeviceLimit",
|
||||
),
|
||||
trailingIcon: Icons.check,
|
||||
alignCaptionedTextToLeft: true,
|
||||
isTopBorderRadiusRemoved: true,
|
||||
isBottomBorderRadiusRemoved: true,
|
||||
),
|
||||
);
|
||||
isCustomLimit = false;
|
||||
}
|
||||
// else {
|
||||
// items.clear();
|
||||
// }
|
||||
for (int deviceLimit in deviceLimits) {
|
||||
items.add(
|
||||
MenuItemWidget(
|
||||
key: ValueKey(deviceLimit),
|
||||
menuItemColor: getEnteColorScheme(context).fillFaint,
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: "$deviceLimit",
|
||||
),
|
||||
trailingIcon: currentDeviceLimit == deviceLimit ? Icons.check : null,
|
||||
alignCaptionedTextToLeft: true,
|
||||
isTopBorderRadiusRemoved: true,
|
||||
isBottomBorderRadiusRemoved: true,
|
||||
showOnlyLoadingState: true,
|
||||
onTap: () async {
|
||||
await _updateUrlSettings(context, {
|
||||
'deviceLimit': deviceLimit,
|
||||
}).then(
|
||||
(value) => setState(() {
|
||||
currentDeviceLimit = deviceLimit;
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
items = addSeparators(
|
||||
items,
|
||||
DividerWidget(
|
||||
dividerType: DividerType.menuNoIcon,
|
||||
bgColor: getEnteColorScheme(context).fillFaint,
|
||||
),
|
||||
);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: items,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _updateUrlSettings(
|
||||
BuildContext context,
|
||||
Map<String, dynamic> prop,
|
||||
) async {
|
||||
try {
|
||||
await CollectionsService.instance.updateShareUrl(widget.collection, prop);
|
||||
} catch (e) {
|
||||
showGenericErrorDialog(context: context);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue