From a7e1dbc85f770534c5a7e7f8d34351e0ea753551 Mon Sep 17 00:00:00 2001 From: WilsonLe Date: Thu, 27 Jun 2024 12:57:39 -0400 Subject: [PATCH] remove mysterious auto generated files --- .../widgets/start_igc_button 2.dart | 168 ------------------ .../controllers/span_data_controller 2.dart | 89 ---------- .../room_capacity_button 2.dart | 157 ---------------- lib/utils/voip/video_renderer 2.dart | 86 --------- 4 files changed, 500 deletions(-) delete mode 100644 lib/pangea/choreographer/widgets/start_igc_button 2.dart delete mode 100644 lib/pangea/controllers/span_data_controller 2.dart delete mode 100644 lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button 2.dart delete mode 100644 lib/utils/voip/video_renderer 2.dart diff --git a/lib/pangea/choreographer/widgets/start_igc_button 2.dart b/lib/pangea/choreographer/widgets/start_igc_button 2.dart deleted file mode 100644 index ceb5af193..000000000 --- a/lib/pangea/choreographer/widgets/start_igc_button 2.dart +++ /dev/null @@ -1,168 +0,0 @@ -import 'dart:async'; -import 'dart:math' as math; - -import 'package:fluffychat/config/app_config.dart'; -import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; -import 'package:fluffychat/pangea/constants/colors.dart'; -import 'package:fluffychat/pangea/controllers/subscription_controller.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; - -import '../../../pages/chat/chat.dart'; - -class StartIGCButton extends StatefulWidget { - const StartIGCButton({ - super.key, - required this.controller, - }); - - final ChatController controller; - - @override - State createState() => StartIGCButtonState(); -} - -class StartIGCButtonState extends State - with SingleTickerProviderStateMixin { - AssistanceState get assistanceState => - widget.controller.choreographer.assistanceState; - AnimationController? _controller; - StreamSubscription? choreoListener; - AssistanceState? prevState; - - @override - void initState() { - _controller = AnimationController( - vsync: this, - duration: const Duration(seconds: 2), - ); - choreoListener = widget.controller.choreographer.stateListener.stream - .listen(updateSpinnerState); - super.initState(); - } - - void updateSpinnerState(_) { - if (prevState != AssistanceState.fetching && - assistanceState == AssistanceState.fetching) { - _controller?.repeat(); - } else if (prevState == AssistanceState.fetching && - assistanceState != AssistanceState.fetching) { - _controller?.stop(); - _controller?.reverse(); - } - setState(() => prevState = assistanceState); - } - - @override - Widget build(BuildContext context) { - final bool itEnabled = widget.controller.choreographer.itEnabled; - final bool igcEnabled = widget.controller.choreographer.igcEnabled; - final CanSendStatus canSendStatus = - widget.controller.pangeaController.subscriptionController.canSendStatus; - final bool grammarCorrectionEnabled = - (itEnabled || igcEnabled) && canSendStatus == CanSendStatus.subscribed; - - if (!grammarCorrectionEnabled || - widget.controller.choreographer.isAutoIGCEnabled || - widget.controller.choreographer.choreoMode == ChoreoMode.it) { - return const SizedBox.shrink(); - } - - final Widget icon = Icon( - Icons.autorenew_rounded, - size: 46, - color: assistanceState.stateColor(context), - ); - - return SizedBox( - height: 50, - width: 50, - child: FloatingActionButton( - tooltip: assistanceState.tooltip( - L10n.of(context)!, - ), - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - disabledElevation: 0, - shape: const CircleBorder(), - onPressed: () { - if (assistanceState != AssistanceState.complete) { - widget.controller.choreographer - .getLanguageHelp( - false, - true, - ) - .then((_) { - if (widget.controller.choreographer.igc.igcTextData != null && - widget.controller.choreographer.igc.igcTextData!.matches - .isNotEmpty) { - widget.controller.choreographer.igc.showFirstMatch(context); - } - }); - } - }, - child: Stack( - alignment: Alignment.center, - children: [ - _controller != null - ? RotationTransition( - turns: Tween(begin: 0.0, end: math.pi * 2) - .animate(_controller!), - child: icon, - ) - : icon, - Container( - width: 26, - height: 26, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Theme.of(context).scaffoldBackgroundColor, - ), - ), - Container( - width: 20, - height: 20, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: assistanceState.stateColor(context), - ), - ), - Icon( - size: 16, - Icons.check, - color: Theme.of(context).scaffoldBackgroundColor, - ), - ], - ), - ), - ); - } -} - -extension AssistanceStateExtension on AssistanceState { - Color stateColor(context) { - switch (this) { - case AssistanceState.noMessage: - case AssistanceState.notFetched: - case AssistanceState.fetching: - return Theme.of(context).colorScheme.primary; - case AssistanceState.fetched: - return PangeaColors.igcError; - case AssistanceState.complete: - return AppConfig.success; - } - } - - String tooltip(L10n l10n) { - switch (this) { - case AssistanceState.noMessage: - case AssistanceState.notFetched: - return l10n.runGrammarCorrection; - case AssistanceState.fetching: - return ""; - case AssistanceState.fetched: - return l10n.grammarCorrectionFailed; - case AssistanceState.complete: - return l10n.grammarCorrectionComplete; - } - } -} diff --git a/lib/pangea/controllers/span_data_controller 2.dart b/lib/pangea/controllers/span_data_controller 2.dart deleted file mode 100644 index 5f83f1a53..000000000 --- a/lib/pangea/controllers/span_data_controller 2.dart +++ /dev/null @@ -1,89 +0,0 @@ -import 'dart:async'; -import 'dart:developer'; - -import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; -import 'package:fluffychat/pangea/models/span_data.dart'; -import 'package:fluffychat/pangea/repo/span_data_repo.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; -import 'package:flutter/foundation.dart'; - -class _SpanDetailsCacheItem { - Future data; - - _SpanDetailsCacheItem({required this.data}); -} - -class SpanDataController { - late Choreographer choreographer; - final Map _cache = {}; - Timer? _cacheClearTimer; - - SpanDataController(this.choreographer) { - _initializeCacheClearing(); - } - - void _initializeCacheClearing() { - const duration = Duration(minutes: 2); - _cacheClearTimer = Timer.periodic(duration, (Timer t) => clearCache()); - } - - void clearCache() { - _cache.clear(); - } - - void dispose() { - _cacheClearTimer?.cancel(); - } - - Future getSpanDetails(int matchIndex) async { - if (choreographer.igc.igcTextData == null || - choreographer.igc.igcTextData!.matches.isEmpty || - matchIndex < 0 || - matchIndex >= choreographer.igc.igcTextData!.matches.length) { - debugger(when: kDebugMode); - return; - } - - /// Retrieves the span data from the `igcTextData` matches at the specified `matchIndex`. - /// Creates a `SpanDetailsRepoReqAndRes` object with the retrieved span data and other parameters. - /// Generates a cache key based on the created `SpanDetailsRepoReqAndRes` object. - final SpanData span = - choreographer.igc.igcTextData!.matches[matchIndex].match; - final req = SpanDetailsRepoReqAndRes( - userL1: choreographer.l1LangCode!, - userL2: choreographer.l2LangCode!, - enableIGC: choreographer.igcEnabled, - enableIT: choreographer.itEnabled, - span: span, - ); - final int cacheKey = req.hashCode; - - /// Retrieves the [SpanDetailsRepoReqAndRes] response from the cache if it exists, - /// otherwise makes an API call to get the response and stores it in the cache. - Future response; - if (_cache.containsKey(cacheKey)) { - response = _cache[cacheKey]!.data; - } else { - response = SpanDataRepo.getSpanDetails( - await choreographer.accessToken, - request: SpanDetailsRepoReqAndRes( - userL1: choreographer.l1LangCode!, - userL2: choreographer.l2LangCode!, - enableIGC: choreographer.igcEnabled, - enableIT: choreographer.itEnabled, - span: span, - ), - ); - _cache[cacheKey] = _SpanDetailsCacheItem(data: response); - } - - try { - choreographer.igc.igcTextData!.matches[matchIndex].match = - (await response).span; - } catch (err, s) { - ErrorHandler.logError(e: err, s: s); - } - - choreographer.setState(); - } -} diff --git a/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button 2.dart b/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button 2.dart deleted file mode 100644 index 7be6e8ec3..000000000 --- a/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button 2.dart +++ /dev/null @@ -1,157 +0,0 @@ -import 'package:adaptive_dialog/adaptive_dialog.dart'; -import 'package:fluffychat/pages/chat_details/chat_details.dart'; -import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; -import 'package:future_loading_dialog/future_loading_dialog.dart'; -import 'package:matrix/matrix.dart'; - -class RoomCapacityButton extends StatefulWidget { - final Room? room; - final ChatDetailsController? controller; - const RoomCapacityButton({ - super.key, - this.room, - this.controller, - }); - - @override - RoomCapacityButtonState createState() => RoomCapacityButtonState(); -} - -class RoomCapacityButtonState extends State { - int? capacity; - String? nonAdmins; - - RoomCapacityButtonState({Key? key}); - - @override - void initState() { - super.initState(); - capacity = widget.room?.capacity; - widget.room?.numNonAdmins.then( - (value) => setState(() { - nonAdmins = value.toString(); - overCapacity(); - }), - ); - } - - @override - void didUpdateWidget(RoomCapacityButton oldWidget) { - super.didUpdateWidget(oldWidget); - if (oldWidget.room != widget.room) { - capacity = widget.room?.capacity; - widget.room?.numNonAdmins.then( - (value) => setState(() { - nonAdmins = value.toString(); - overCapacity(); - }), - ); - } - } - - Future overCapacity() async { - if ((widget.room?.isRoomAdmin ?? false) && - capacity != null && - nonAdmins != null && - int.parse(nonAdmins!) > capacity!) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - L10n.of(context)!.roomExceedsCapacity, - ), - ), - ); - } - } - - @override - Widget build(BuildContext context) { - final iconColor = Theme.of(context).textTheme.bodyLarge!.color; - return Column( - children: [ - ListTile( - onTap: (widget.room?.isRoomAdmin ?? true) ? setRoomCapacity : null, - leading: CircleAvatar( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - foregroundColor: iconColor, - child: const Icon(Icons.reduce_capacity), - ), - subtitle: Text( - (capacity == null) - ? L10n.of(context)!.capacityNotSet - : (nonAdmins != null) - ? '$nonAdmins/$capacity' - : '$capacity', - ), - title: Text( - L10n.of(context)!.roomCapacity, - style: TextStyle( - color: Theme.of(context).colorScheme.secondary, - fontWeight: FontWeight.bold, - ), - ), - ), - ], - ); - } - - Future setCapacity(int newCapacity) async { - capacity = newCapacity; - } - - Future setRoomCapacity() async { - final input = await showTextInputDialog( - context: context, - title: L10n.of(context)!.roomCapacity, - message: L10n.of(context)!.roomCapacityExplanation, - okLabel: L10n.of(context)!.ok, - cancelLabel: L10n.of(context)!.cancel, - textFields: [ - DialogTextField( - initialText: ((capacity != null) ? '$capacity' : ''), - keyboardType: TextInputType.number, - maxLength: 3, - validator: (value) { - if (value == null || - value.isEmpty || - int.tryParse(value) == null || - int.parse(value) < 0) { - return L10n.of(context)!.enterNumber; - } - if (nonAdmins != null && int.parse(value) < int.parse(nonAdmins!)) { - return L10n.of(context)!.capacitySetTooLow; - } - return null; - }, - ), - ], - ); - if (input == null || - input.first == "" || - int.tryParse(input.first) == null) { - return; - } - - final newCapacity = int.parse(input.first); - final success = await showFutureLoadingDialog( - context: context, - future: () => ((widget.room != null) - ? (widget.room!.updateRoomCapacity( - capacity = newCapacity, - )) - : setCapacity(newCapacity)), - ); - if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - L10n.of(context)!.roomCapacityHasBeenChanged, - ), - ), - ); - setState(() {}); - } - } -} diff --git a/lib/utils/voip/video_renderer 2.dart b/lib/utils/voip/video_renderer 2.dart deleted file mode 100644 index 46171fdb5..000000000 --- a/lib/utils/voip/video_renderer 2.dart +++ /dev/null @@ -1,86 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/material.dart'; - -import 'package:flutter_webrtc/flutter_webrtc.dart'; -import 'package:matrix/matrix.dart'; - -class VideoRenderer extends StatefulWidget { - final WrappedMediaStream? stream; - final bool mirror; - final RTCVideoViewObjectFit fit; - - const VideoRenderer( - this.stream, { - this.mirror = false, - this.fit = RTCVideoViewObjectFit.RTCVideoViewObjectFitContain, - super.key, - }); - - @override - State createState() => _VideoRendererState(); -} - -class _VideoRendererState extends State { - RTCVideoRenderer? _renderer; - bool _rendererReady = false; - MediaStream? get mediaStream => widget.stream?.stream; - StreamSubscription? _streamChangeSubscription; - - Future _initializeRenderer() async { - _renderer ??= RTCVideoRenderer(); - await _renderer!.initialize(); - _renderer!.srcObject = mediaStream; - return _renderer!; - } - - void disposeRenderer() { - try { - _renderer?.srcObject = null; - _renderer?.dispose(); - _renderer = null; - // ignore: empty_catches - } catch (e) {} - } - - @override - void initState() { - _streamChangeSubscription = - widget.stream?.onStreamChanged.stream.listen((stream) { - setState(() { - _renderer?.srcObject = stream; - }); - }); - setupRenderer(); - super.initState(); - } - - Future setupRenderer() async { - await _initializeRenderer(); - setState(() => _rendererReady = true); - } - - @override - void dispose() { - _streamChangeSubscription?.cancel(); - disposeRenderer(); - super.dispose(); - } - - @override - Widget build(BuildContext context) => !_rendererReady - ? Container() - : Builder( - key: widget.key, - builder: (ctx) { - return RTCVideoView( - _renderer!, - mirror: widget.mirror, - filterQuality: FilterQuality.medium, - objectFit: widget.fit, - placeholderBuilder: (_) => - Container(color: Colors.white.withOpacity(0.18)), - ); - }, - ); -}