Skip to content

Commit

Permalink
feat: add language dropdown in speech modal
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Nov 17, 2024
1 parent 0369383 commit 138a651
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
7 changes: 7 additions & 0 deletions lib/features/journal/state/entry_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ class EntryController extends _$EntryController {
return _persistenceLogic.addTagDefinition(tag);
}

Future<void> setLanguage(String language) async {
return _persistenceLogic.updateLanguage(
journalEntityId: entryId,
language: language,
);
}

Future<void> addTagIds(List<String> addedTagIds) async {
await _persistenceLogic.addTagsWithLinked(
journalEntityId: entryId,
Expand Down
58 changes: 58 additions & 0 deletions lib/features/speech/ui/widgets/speech_modal/language_dropdown.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/features/journal/state/entry_controller.dart';
import 'package:lotti/l10n/app_localizations_context.dart';
import 'package:lotti/themes/theme.dart';

class LanguageDropdown extends ConsumerWidget {
const LanguageDropdown({
required this.entryId,
super.key,
});

final String entryId;

@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = entryControllerProvider(id: entryId);
final notifier = ref.read(provider.notifier);
final entryState = ref.watch(provider).value;
final item = entryState?.entry;

if (item == null || item is! JournalAudio) {
return const SizedBox.shrink();
}

return Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(context.messages.speechModalSelectLanguage),
const SizedBox(width: 10),
DropdownButton(
value: item.data.language,
iconEnabledColor: context.colorScheme.outline,
items: const [
DropdownMenuItem(
value: '',
child: Text('auto'),
),
DropdownMenuItem(
value: 'en',
child: Text('English'),
),
DropdownMenuItem(
value: 'de',
child: Text('Deutsch'),
),
],
onChanged: (String? value) {
if (value != null) {
notifier.setLanguage(value);
}
},
),
],
);
}
}
2 changes: 2 additions & 0 deletions lib/features/speech/ui/widgets/speech_modal/speech_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/features/journal/state/entry_controller.dart';
import 'package:lotti/features/speech/ui/widgets/speech_modal/language_dropdown.dart';
import 'package:lotti/features/speech/ui/widgets/speech_modal/transcribe_button.dart';
import 'package:lotti/features/speech/ui/widgets/speech_modal/transcripts_list.dart';
import 'package:lotti/l10n/app_localizations_context.dart';
Expand Down Expand Up @@ -35,6 +36,7 @@ class SpeechModal {
children: [
const SizedBox(height: 20),
TranscribeButton(entryId: entryId),
LanguageDropdown(entryId: entryId),
TranscriptsList(entryId: entryId),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class TranscribeButton extends ConsumerWidget {
}

final provider = entryControllerProvider(id: entryId);

final notifier = ref.read(provider.notifier);

final entryState = ref.watch(provider).value;

final item = entryState?.entry;
Expand Down
5 changes: 3 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aiAssistantTitle": "AI Assistant",
"entryActions": "Entry Actions",
"entryActions": "Actions",
"aiAssistantCreateChecklist": "Create checklist items",
"aiAssistantRunPrompt": "Ask Llama3",
"addActionAddAudioRecording": "Start Audio Recording",
Expand Down Expand Up @@ -299,8 +299,9 @@
"settingsThemingTitle": "Theming",
"settingThemingDark": "Dark Theme",
"settingThemingLight": "Light Theme",
"speechModalTitle": "Manage Speech Recognition",
"speechModalTitle": "Speech Recognition",
"speechModalAddTranscription": "Add Transcription",
"speechModalSelectLanguage": "Select Language",
"syncAssistantHeadline": "Sync Assistant",
"syncAssistantPage1": "Let's get the synchronization between Lotti on Desktop and Lotti on your mobile device set up, shall we? You need to start on the desktop side.",
"syncAssistantPage2": "The communication between happens without you having to give your data away to cloud-based services. Instead, you provide your own email account and each device in the communication stores encrypted messages for your other devices in an IMAP folder. Please provide your server settings on the next page.",
Expand Down
42 changes: 41 additions & 1 deletion lib/logic/persistence_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,53 @@ class PersistenceLogic {
_loggingDb.captureException(
exception,
domain: 'persistence_logic',
subDomain: 'updateTask',
subDomain: 'updateEvent',
stackTrace: stackTrace,
);
}
return true;
}

Future<void> updateLanguage({
required String journalEntityId,
required String language,
}) async {
try {
final now = DateTime.now();
final journalEntity = await _journalDb.journalEntityById(journalEntityId);

await journalEntity?.maybeMap(
journalAudio: (JournalAudio item) async {
final vc = await _vectorClockService.getNextVectorClock(
previous: journalEntity.meta.vectorClock,
);

final newEvent = item.copyWith(
meta: item.meta.copyWith(
updatedAt: now,
vectorClock: vc,
),
data: item.data.copyWith(language: language),
);

await updateDbEntity(newEvent, enqueueSync: true);
},
orElse: () async => _loggingDb.captureException(
'not an audio entry',
domain: 'persistence_logic',
subDomain: 'updateLanguage',
),
);
} catch (exception, stackTrace) {
_loggingDb.captureException(
exception,
domain: 'persistence_logic',
subDomain: 'updateLanguage',
stackTrace: stackTrace,
);
}
}

Future<bool> addAudioTranscript({
required String journalEntityId,
required AudioTranscript transcript,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.531+2730
version: 0.9.531+2731

msix_config:
display_name: LottiApp
Expand Down

0 comments on commit 138a651

Please sign in to comment.