diff --git a/front_end/lib/pages/calendar_inbox_page.dart b/front_end/lib/pages/calendar_inbox_page.dart index 0a3d341..342b407 100644 --- a/front_end/lib/pages/calendar_inbox_page.dart +++ b/front_end/lib/pages/calendar_inbox_page.dart @@ -33,7 +33,8 @@ class CalendarInboxPage extends StatelessWidget { final items = inbox.items; if (items.isEmpty) { return const Center( - child: Text('インボックスは空です', style: TextStyle(color: Colors.black54)), + child: + Text('インボックスは空です', style: TextStyle(color: Colors.black54)), ); } return ListView.separated( @@ -43,9 +44,13 @@ class CalendarInboxPage extends StatelessWidget { final item = items[index]; final p = item.proposal; return ListTile( - title: Text(p.summary, style: const TextStyle(color: Colors.black87)), + title: Text(p.summary, + style: const TextStyle(color: Colors.black87)), subtitle: Text( - _formatDateTime(p) + (p.location != null && p.location!.isNotEmpty ? ' @ ${p.location}' : ''), + _formatDateTime(p) + + (p.location != null && p.location!.isNotEmpty + ? ' @ ${p.location}' + : ''), style: const TextStyle(color: Colors.black54), ), trailing: Row( @@ -63,10 +68,14 @@ class CalendarInboxPage extends StatelessWidget { uiService: null, onConfirm: (updated) { // 設定のみ保存して閉じる - context.read().updateProposal(item.id, updated); + context + .read() + .updateProposal(item.id, updated); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('設定を保存しました: ${updated.summary}')), + SnackBar( + content: Text( + '設定を保存しました: ${updated.summary}')), ); } }, @@ -83,9 +92,12 @@ class CalendarInboxPage extends StatelessWidget { await svc.createEventFromProposal(p); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('カレンダーに追加しました: ${p.summary}')), + SnackBar( + content: Text('カレンダーに追加しました: ${p.summary}')), ); - context.read().removeById(item.id); + context + .read() + .removeById(item.id); } } catch (e) { if (context.mounted) { @@ -99,7 +111,9 @@ class CalendarInboxPage extends StatelessWidget { ), TextButton( onPressed: () { - context.read().removeById(item.id); + context + .read() + .removeById(item.id); ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('削除しました: ${p.summary}')), ); diff --git a/front_end/lib/services/voiceRecognitionService.dart b/front_end/lib/services/voiceRecognitionService.dart index 2dd6ca4..993883d 100644 --- a/front_end/lib/services/voiceRecognitionService.dart +++ b/front_end/lib/services/voiceRecognitionService.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:flutter_speech_to_text/services/googleCalendarService.dart'; import 'package:http/http.dart' as http; import '../providers/textsDataProvider.dart'; import '../providers/recognitionProvider.dart'; @@ -64,9 +62,6 @@ class VoiceRecognitionService { String _currentPhrasePrefix = ""; int maxWords = 100; - // 呼び出し済みのsummarizedTextsを追跡するセット - Set calledeventTime = {}; - // フレーズ変更時の更新処理 void updatePhraseIfNeeded(String newRecognizedText, String selectedClass, TextsDataProvider textsDataProvider) { @@ -179,9 +174,6 @@ class VoiceRecognitionService { print('キーワード "$keyword" を保存しました: $snippet'); - // 日時パターン検出とカレンダー登録 - await _processCalendarRegistration(snippet, keywordData.detectionTime); - // 保存が完了したらマップから削除 _pendingKeywordData.remove(uniqueKey); } catch (e) { @@ -191,88 +183,6 @@ class VoiceRecognitionService { } } - // カレンダー登録処理 - Future _processCalendarRegistration( - String snippet, DateTime detectionTime) async { - final now = detectionTime; - DateTime? eventDt; - - // 1. 相対日+時刻:「今日」「明日」「明後日」 - final rel = - RegExp(r'(今日|明日|明後日)(?:\s*(\d{1,2}:\d{2}))?').firstMatch(snippet); - if (rel != null) { - int days = rel.group(1) == '明日' - ? 1 - : rel.group(1) == '明後日' - ? 2 - : 0; - final base = now.add(Duration(days: days)); - if (rel.group(2) != null) { - final p = rel.group(2)!.split(':'); - eventDt = DateTime( - base.year, base.month, base.day, int.parse(p[0]), int.parse(p[1])); - } else { - eventDt = DateTime(base.year, base.month, base.day, 9, 0); - } - } - // 2. 「YYYY/MM/DD [HH:mm]」 - else { - final ymd = - RegExp(r'(\d{4})[/-](\d{1,2})[/-](\d{1,2})(?:\s*(\d{1,2}:\d{2}))?') - .firstMatch(snippet); - if (ymd != null) { - final y = int.parse(ymd.group(1)!), - m = int.parse(ymd.group(2)!), - d = int.parse(ymd.group(3)!); - if (ymd.group(4) != null) { - final p = ymd.group(4)!.split(':'); - eventDt = DateTime(y, m, d, int.parse(p[0]), int.parse(p[1])); - } else { - eventDt = DateTime(y, m, d, 9, 0); - } - } - // 3. 「M月D日 [HH:mm]」 - else { - final md = RegExp(r'(\d{1,2})月(\d{1,2})日(?:\s*(\d{1,2}:\d{2}))?') - .firstMatch(snippet); - if (md != null) { - final m = int.parse(md.group(1)!), d = int.parse(md.group(2)!); - if (md.group(3) != null) { - final p = md.group(3)!.split(':'); - eventDt = - DateTime(now.year, m, d, int.parse(p[0]), int.parse(p[1])); - } else { - eventDt = DateTime(now.year, m, d, 9, 0); - } - } - // 4. 時刻のみ「HH:mm」 - else { - final t = RegExp(r'(\d{1,2}:\d{2})').firstMatch(snippet); - if (t != null) { - final p = t.group(1)!.split(':'); - eventDt = DateTime( - now.year, now.month, now.day, int.parse(p[0]), int.parse(p[1])); - } - } - } - } - - if (eventDt != null && FirebaseAuth.instance.currentUser != null) { - try { - final service = GoogleCalendarService(); - await service.createEvent( - eventTime: eventDt, - summary: snippet, - duration: Duration(hours: 1), - timeZone: 'Asia/Tokyo', - ); - print('Googleカレンダーにイベントを追加しました'); - } catch (e) { - print('カレンダー登録エラー: $e'); - } - } - } - // キーワード検出処理 bool checkForKeyword(String text, KeywordProvider keywordProvider) { List keywords = keywordProvider.keywords; diff --git a/front_end/lib/widgets/editable_calendar_event_sheet.dart b/front_end/lib/widgets/editable_calendar_event_sheet.dart index c457658..7307daf 100644 --- a/front_end/lib/widgets/editable_calendar_event_sheet.dart +++ b/front_end/lib/widgets/editable_calendar_event_sheet.dart @@ -104,6 +104,7 @@ class _EditableCalendarEventSheetState if (pickedDate != null) { setState(() { if (isStart) { + final prevEnd = _endDateTime; _startDateTime = DateTime( pickedDate.year, pickedDate.month, @@ -111,6 +112,19 @@ class _EditableCalendarEventSheetState _startDateTime.hour, _startDateTime.minute, ); + // 終了日付が開始とずれていた場合は同日にそろえる(時間は保持) + if (prevEnd != null && + (prevEnd.year != _startDateTime.year || + prevEnd.month != _startDateTime.month || + prevEnd.day != _startDateTime.day)) { + _endDateTime = DateTime( + _startDateTime.year, + _startDateTime.month, + _startDateTime.day, + prevEnd.hour, + prevEnd.minute, + ); + } // 開始日が終了日より後になった場合、終了日を調整 if (_endDateTime != null && _startDateTime.isAfter(_endDateTime!)) { _endDateTime = _startDateTime.add(Duration(hours: 1));