Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions front_end/lib/pages/calendar_inbox_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -63,10 +68,14 @@ class CalendarInboxPage extends StatelessWidget {
uiService: null,
onConfirm: (updated) {
// 設定のみ保存して閉じる
context.read<CalendarInboxProvider>().updateProposal(item.id, updated);
context
.read<CalendarInboxProvider>()
.updateProposal(item.id, updated);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('設定を保存しました: ${updated.summary}')),
SnackBar(
content: Text(
'設定を保存しました: ${updated.summary}')),
);
}
},
Expand All @@ -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<CalendarInboxProvider>().removeById(item.id);
context
.read<CalendarInboxProvider>()
.removeById(item.id);
}
} catch (e) {
if (context.mounted) {
Expand All @@ -99,7 +111,9 @@ class CalendarInboxPage extends StatelessWidget {
),
TextButton(
onPressed: () {
context.read<CalendarInboxProvider>().removeById(item.id);
context
.read<CalendarInboxProvider>()
.removeById(item.id);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('削除しました: ${p.summary}')),
);
Expand Down
90 changes: 0 additions & 90 deletions front_end/lib/services/voiceRecognitionService.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,9 +62,6 @@ class VoiceRecognitionService {
String _currentPhrasePrefix = "";
int maxWords = 100;

// 呼び出し済みのsummarizedTextsを追跡するセット
Set<String> calledeventTime = {};

// フレーズ変更時の更新処理
void updatePhraseIfNeeded(String newRecognizedText, String selectedClass,
TextsDataProvider textsDataProvider) {
Expand Down Expand Up @@ -179,9 +174,6 @@ class VoiceRecognitionService {

print('キーワード "$keyword" を保存しました: $snippet');

// 日時パターン検出とカレンダー登録
await _processCalendarRegistration(snippet, keywordData.detectionTime);

// 保存が完了したらマップから削除
_pendingKeywordData.remove(uniqueKey);
} catch (e) {
Expand All @@ -191,88 +183,6 @@ class VoiceRecognitionService {
}
}

// カレンダー登録処理
Future<void> _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<String> keywords = keywordProvider.keywords;
Expand Down
14 changes: 14 additions & 0 deletions front_end/lib/widgets/editable_calendar_event_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,27 @@ class _EditableCalendarEventSheetState
if (pickedDate != null) {
setState(() {
if (isStart) {
final prevEnd = _endDateTime;
_startDateTime = DateTime(
pickedDate.year,
pickedDate.month,
pickedDate.day,
_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));
Expand Down