feat(mobile): add three-day and custom activity periods (#9964)

## Summary

Add a **3 days** preset and a **Custom…** option to the mobile Active
filter. Custom opens a wheel for 1–365 days, using UIKit on iOS.
Confirming returns to Display Options with the selected duration.
Canceling restores the previous duration. Both paths preserve the other
pending choices until Apply.

## Testing

- Exercised the picker on an iPhone Air and Pixel 10.
- Extended the section options test to cover the preset, canceling a
custom period, confirming 11 days, applying it, and reopening the saved
setting.
- Ran Flutter analysis, formatting, and the mobile test suite.

## Related issue

No duplicate found.

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
This commit is contained in:
klopez4212
2026-11-30 08:25:20 +00:00
committed by GitHub
parent 832ff39a3c
commit e9fdd1aef5
7 changed files with 284 additions and 30 deletions

View File

@@ -22,6 +22,7 @@
DAAD00000000000000000001 /* QuickSend.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAAD00000000000000000002 /* QuickSend.swift */; };
C0AF00000000000000000001 /* NativeConfirmationDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AF00000000000000000002 /* NativeConfirmationDialog.swift */; };
C0AF00000000000000000021 /* NativePresenceMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AF00000000000000000022 /* NativePresenceMenu.swift */; };
A4DC00000000000000000021 /* ActiveDaysWheel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4DC00000000000000000022 /* ActiveDaysWheel.swift */; };
C0AF00000000000000000011 /* NativeAddMembersSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AF00000000000000000012 /* NativeAddMembersSheet.swift */; };
D0AF00000000000000000011 /* NativeChannelActionsSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF00000000000000000012 /* NativeChannelActionsSheet.swift */; };
C0AF00000000000000000071 /* NativeCreateChannelSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0AF00000000000000000072 /* NativeCreateChannelSheet.swift */; };
@@ -133,6 +134,7 @@
DAAB00000000000000000002 /* NativeTabler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeTabler.swift; sourceTree = "<group>"; };
C0AF00000000000000000002 /* NativeConfirmationDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeConfirmationDialog.swift; sourceTree = "<group>"; };
C0AF00000000000000000022 /* NativePresenceMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePresenceMenu.swift; sourceTree = "<group>"; };
A4DC00000000000000000022 /* ActiveDaysWheel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveDaysWheel.swift; sourceTree = "<group>"; };
C0AF00000000000000000012 /* NativeAddMembersSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAddMembersSheet.swift; sourceTree = "<group>"; };
D0AF00000000000000000012 /* NativeChannelActionsSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeChannelActionsSheet.swift; sourceTree = "<group>"; };
C0AF00000000000000000072 /* NativeCreateChannelSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeCreateChannelSheet.swift; sourceTree = "<group>"; };
@@ -367,6 +369,7 @@
4A71C0182F40C00100A17E01 /* HuddleAudioEngine.swift */,
C0AF00000000000000000002 /* NativeConfirmationDialog.swift */,
C0AF00000000000000000022 /* NativePresenceMenu.swift */,
A4DC00000000000000000022 /* ActiveDaysWheel.swift */,
C0AF00000000000000000012 /* NativeAddMembersSheet.swift */,
D0AF00000000000000000012 /* NativeChannelActionsSheet.swift */,
C0AF00000000000000000072 /* NativeCreateChannelSheet.swift */,
@@ -775,6 +778,7 @@
4A71C0172F40C00100A17E01 /* HuddleAudioEngine.swift in Sources */,
C0AF00000000000000000001 /* NativeConfirmationDialog.swift in Sources */,
C0AF00000000000000000021 /* NativePresenceMenu.swift in Sources */,
A4DC00000000000000000021 /* ActiveDaysWheel.swift in Sources */,
C0AF00000000000000000011 /* NativeAddMembersSheet.swift in Sources */,
D0AF00000000000000000011 /* NativeChannelActionsSheet.swift in Sources */,
C0AF00000000000000000071 /* NativeCreateChannelSheet.swift in Sources */,

View File

@@ -0,0 +1,47 @@
import Flutter
import UIKit
final class ActiveDaysWheelFactory: NSObject, FlutterPlatformViewFactory {
private let messenger: FlutterBinaryMessenger
init(messenger: FlutterBinaryMessenger) {
self.messenger = messenger
}
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
FlutterStandardMessageCodec.sharedInstance()
}
func create(withFrame frame: CGRect, viewIdentifier id: Int64, arguments args: Any?) -> FlutterPlatformView {
ActiveDaysWheel(frame: frame, id: id, messenger: messenger, options: args as? [String: Any] ?? [:])
}
}
private final class ActiveDaysWheel: NSObject, FlutterPlatformView, UIPickerViewDataSource, UIPickerViewDelegate {
private let picker: UIPickerView
private let channel: FlutterMethodChannel
private let maximum: Int
init(frame: CGRect, id: Int64, messenger: FlutterBinaryMessenger, options: [String: Any]) {
picker = UIPickerView(frame: frame)
maximum = max(1, options["maximum"] as? Int ?? 365)
channel = FlutterMethodChannel(name: "buzz/active_days_wheel/\(id)", binaryMessenger: messenger)
super.init()
picker.dataSource = self
picker.delegate = self
picker.overrideUserInterfaceStyle = options["dark"] as? Bool == true ? .dark : .light
picker.selectRow(min(maximum, max(1, options["initial"] as? Int ?? 1)) - 1, inComponent: 0, animated: false)
channel.setMethodCallHandler { [weak self] call, result in
guard call.method == "selection" else { result(FlutterMethodNotImplemented); return }
result(self.map { $0.picker.selectedRow(inComponent: 0) + 1 })
}
}
deinit { channel.setMethodCallHandler(nil) }
func view() -> UIView { picker }
func numberOfComponents(in pickerView: UIPickerView) -> Int { 1 }
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { maximum }
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
row == 0 ? "1 day" : "\(row + 1) days"
}
}

View File

@@ -82,6 +82,9 @@ import os.log
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
engineBridge.pluginRegistry.registrar(forPlugin: "BuzzToastLayer")?.register(
ToastLayerFactory(), withId: "buzz/toast_layer")
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "ActiveDaysWheel") {
registrar.register(ActiveDaysWheelFactory(messenger: registrar.messenger()), withId: "buzz/active_days_wheel")
}
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "BuzzIosMediaCarousel") {
registrar.register(IosMediaCarouselFactory(messenger: registrar.messenger()), withId: "buzz/ios_media_carousel")
}

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:math';
const maxActiveWindowDays = 365;
const defaultActiveWindowSeconds = 30 * 86400;
const sectionCounts = [5, 10, 15, 20, 0]; // Zero means all matching chats.
@@ -10,7 +11,7 @@ enum ChannelFilterMode { all, unreads, active }
bool validActiveWindow(Object? value) =>
value is int &&
value >= 86400 &&
value <= 365 * 86400 &&
value <= maxActiveWindowDays * 86400 &&
value % 86400 == 0;
/// Retains the entire encrypted record. Metadata is authoritative, including

View File

@@ -0,0 +1,122 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../../../shared/theme/buzz_icons.dart';
import '../../../shared/widgets/buzz_sheet_header.dart';
import '../../../shared/widgets/ios_glass_navigation_button.dart';
import '../../../shared/widgets/modal_presentation.dart';
import '../channel_filter/channel_filter_store.dart';
Future<int?> showActiveDaysPicker(BuildContext context, int initial) async {
ModalRoute<dynamic>? route;
final days = await showBuzzModalBottomSheet<int>(
context: context,
nativeIosBarrier: defaultTargetPlatform == TargetPlatform.iOS,
showCloseButton: false,
showDragHandle: false,
enableDrag: false,
isScrollControlled: true,
builder: (context) {
route = ModalRoute.of(context);
return _ActiveDaysPicker(initial: initial);
},
);
await route?.completed;
return days;
}
class _ActiveDaysPicker extends HookWidget {
const _ActiveDaysPicker({required this.initial});
final int initial;
@override
Widget build(BuildContext context) {
final ios = defaultTargetPlatform == TargetPlatform.iOS;
final native = useState<MethodChannel?>(null);
final selected = useRef(initial);
final controller = useFixedExtentScrollController(initialItem: initial - 1);
Future<void> confirm() async {
final route = ModalRoute.of(context);
final days = ios
? await native.value?.invokeMethod<int>('selection')
: selected.value;
if (days != null && context.mounted && route?.isCurrent == true) {
Navigator.pop(context, days);
}
}
void cancel() => Navigator.pop(context);
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
BuzzSheetHeader(
title: 'Custom period',
leading: ios
? IosGlassNavigationButton(
icon: IosGlassNavigationIcon.close,
semanticLabel: 'Cancel',
onPressed: cancel,
)
: IconButton(
tooltip: 'Cancel',
icon: const Icon(BuzzIcons.x),
onPressed: cancel,
),
trailing: ios
? IosGlassNavigationButton(
icon: IosGlassNavigationIcon.check,
semanticLabel: 'Use period',
onPressed: native.value == null ? null : confirm,
)
: IconButton(
tooltip: 'Use period',
icon: const Icon(BuzzIcons.check),
onPressed: confirm,
),
),
Flexible(
child: SizedBox(
height: 216,
child: ios
? UiKitView(
viewType: 'buzz/active_days_wheel',
creationParamsCodec: const StandardMessageCodec(),
creationParams: {
'initial': initial,
'maximum': maxActiveWindowDays,
'dark': Theme.of(context).brightness == Brightness.dark,
},
gestureRecognizers: {
Factory<EagerGestureRecognizer>(
EagerGestureRecognizer.new,
),
},
onPlatformViewCreated: (id) {
if (context.mounted) {
native.value = MethodChannel(
'buzz/active_days_wheel/$id',
);
}
},
)
: CupertinoPicker.builder(
scrollController: controller,
itemExtent: 44,
childCount: maxActiveWindowDays,
onSelectedItemChanged: (row) => selected.value = row + 1,
itemBuilder: (context, row) => Center(
child: Text(row == 0 ? '1 day' : '${row + 1} days'),
),
),
),
),
],
),
);
}
}

View File

@@ -1,5 +1,6 @@
export 'messages_display.dart';
import 'messages_display.dart';
import 'active_days_picker.dart';
import '../channel_sort/channel_sort_provider.dart';
import '../channel_sections/section_reorder_sheet.dart';
import '../../../shared/widgets/app_list.dart';
@@ -85,29 +86,60 @@ Future<String?> showSectionViewSheet(
: BottomUpPageRoute.retainControlsForSheet(presentingRoute);
ModalRoute<dynamic>? sheetRoute;
String? action;
MessagesDisplay? draft;
final container = ProviderScope.containerOf(context, listen: false);
final scope = container.read(mobileSectionOrderKeyProvider);
final hostRoute = ModalRoute.of(context);
bool canReopen() =>
context.mounted &&
hostRoute?.isCurrent != false &&
scope == container.read(mobileSectionOrderKeyProvider);
try {
action = await showBuzzModalBottomSheet<String>(
context: context,
nativeIosBarrier: presentingRoute != null,
showCloseButton: false,
showDragHandle: false,
isScrollControlled: true,
isDismissible: true,
enableDrag: false,
builder: (sheetContext) {
sheetRoute = ModalRoute.of(sheetContext);
return _SectionViewSheet(
centralized:
group == null || context.widget is MessagesSectionOptions,
canReorder: orderScope != null,
title: title,
group: group,
initialSort: sortMode,
onSort: onSort,
custom: custom,
do {
action = await showBuzzModalBottomSheet<String>(
context: context,
nativeIosBarrier: presentingRoute != null,
showCloseButton: false,
showDragHandle: false,
isScrollControlled: true,
isDismissible: true,
enableDrag: false,
builder: (sheetContext) {
sheetRoute = ModalRoute.of(sheetContext);
return _SectionViewSheet(
centralized:
group == null || context.widget is MessagesSectionOptions,
canReorder: orderScope != null,
title: title,
group: group,
initialSort: sortMode,
onSort: onSort,
custom: custom,
draft: draft,
onCustom: (value) {
draft = value;
Navigator.pop(sheetContext, 'customDays');
},
);
},
);
if (action == 'customDays') {
await sheetRoute?.completed;
if (!canReopen() || !context.mounted) return null;
final previous = draft!;
final picked = await showActiveDaysPicker(
context,
previous.days ?? defaultActiveWindowSeconds ~/ 86400,
);
},
);
if (!canReopen() || !context.mounted) return null;
draft = MessagesDisplay(
sort: previous.sort,
mode: previous.mode,
count: previous.count,
days: picked ?? previous.days,
);
}
} while (action == 'customDays');
// Keep the same Home header mounted through both reverse transitions.
final opensEditor = action == 'reorder' || action == 'editSections';
if (release != null || opensEditor) await sheetRoute?.completed;
@@ -134,6 +166,8 @@ class _SectionViewSheet extends HookConsumerWidget {
final ChannelSortMode? initialSort;
final ValueChanged<ChannelSortMode>? onSort;
final bool custom;
final MessagesDisplay? draft;
final ValueChanged<MessagesDisplay> onCustom;
const _SectionViewSheet({
required this.centralized,
@@ -143,6 +177,8 @@ class _SectionViewSheet extends HookConsumerWidget {
required this.initialSort,
required this.onSort,
required this.custom,
required this.draft,
required this.onCustom,
});
@override
@@ -171,24 +207,36 @@ class _SectionViewSheet extends HookConsumerWidget {
channelSectionsProvider.select((state) => state.editable),
);
final originalManager = useRef(manager);
final sort = useState(global ? display.sort : initialSort);
final sort = useState(
draft != null
? draft!.sort
: global
? display.sort
: initialSort,
);
final mode = useState(
global
draft != null
? draft!.mode
: global
? display.mode
: manager?.store.modeFor(group) ?? ChannelFilterMode.all,
);
final count = useState(
global
draft != null
? draft!.count
: global
? display.count
: manager?.store.countFor(group) ?? sectionCounts.first,
);
final days = useState(
global
draft != null
? draft!.days
: global
? display.days
: (manager?.store.windowFor(group) ?? defaultActiveWindowSeconds) ~/
86400,
);
final filterDirty = useState(false);
final filterDirty = useState(draft != null);
final saving = useState(false);
final failed = useState(false);
// A confirmed initial load may arrive while the sheet is open. Preserve edits.
@@ -413,16 +461,29 @@ class _SectionViewSheet extends HookConsumerWidget {
{
for (final day in {
1,
3,
7,
30,
90,
if (days.value != null) days.value!,
})
day: '$day ${day == 1 ? 'day' : 'days'}',
0: 'Custom…',
},
days.value,
writable
? (value) {
if (value == 0) {
onCustom(
MessagesDisplay(
sort: sort.value,
mode: mode.value,
count: count.value,
days: days.value,
),
);
return;
}
filterDirty.value = true;
days.value = value;
}

View File

@@ -618,17 +618,33 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('Active in the past'), findsNothing);
await _chooseSectionOption(tester, 'View', 'Active');
await _chooseSectionOption(tester, 'Active in the past', '7 days');
await _chooseSectionOption(tester, 'Active in the past', '3 days');
await _chooseSectionOption(tester, 'Active in the past', 'Custom…');
expect(find.text('Active in the past'), findsNothing);
await tester.drag(find.byType(ListWheelScrollView), const Offset(0, -44));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Cancel'));
await tester.pumpAndSettle();
expect(find.text('3 days'), findsOneWidget);
await _chooseSectionOption(tester, 'Active in the past', 'Custom…');
final wheel = tester.widget<ListWheelScrollView>(
find.byType(ListWheelScrollView),
);
(wheel.controller! as FixedExtentScrollController).jumpToItem(10);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Use period'));
await tester.pumpAndSettle();
expect(find.text('11 days'), findsOneWidget);
expect(manager.store.modeFor('channels'), ChannelFilterMode.unreads);
await tester.tap(find.byTooltip('Apply changes'));
await tester.pumpAndSettle();
expect(manager.store.modeFor('channels'), ChannelFilterMode.active);
expect(manager.store.windowFor('channels'), 7 * 86400);
expect(manager.store.windowFor('channels'), 11 * 86400);
await tester.tap(find.byTooltip('Team options'));
await tester.pumpAndSettle();
final days = tester.widget<AppListRow>(
find.ancestor(
of: find.text('7 days'),
of: find.text('11 days'),
matching: find.byType(AppListRow),
),
);