diff --git a/app/lib/backend/preferences.dart b/app/lib/backend/preferences.dart index 9fa60301b..420c1704d 100644 --- a/app/lib/backend/preferences.dart +++ b/app/lib/backend/preferences.dart @@ -424,4 +424,12 @@ class SharedPreferencesUtil { Future clear() async { return await _preferences?.clear() ?? false; } + + Future saveSpeakerName(int speakerId, String name) async { + return await saveString('speaker_name_$speakerId', name); + } + + String? getSpeakerName(int speakerId) { + return getString('speaker_name_$speakerId'); + } } diff --git a/app/lib/pages/memory_detail/memory_detail_provider.dart b/app/lib/pages/memory_detail/memory_detail_provider.dart index b03c1d39e..db0219a50 100644 --- a/app/lib/pages/memory_detail/memory_detail_provider.dart +++ b/app/lib/pages/memory_detail/memory_detail_provider.dart @@ -258,4 +258,32 @@ class MemoryDetailProvider extends ChangeNotifier with MessageNotifierMixin { assignMemoryTranscriptSegment(memoryId, segmentIdx); notifyListeners(); } + + Future updateSpeakerName(int speakerId, String newName, bool updateAll) async { + toggleEditSegmentLoading(true); + + try { + if (updateAll) { + // Update all segments with matching speakerId + for (var segment in memory.transcriptSegments) { + if (segment.speakerId == speakerId) { + segment.speaker = 'SPEAKER_${speakerId.toString().padLeft(2, '0')}'; + // Store the display name mapping in SharedPreferences + await SharedPreferencesUtil().saveSpeakerName(speakerId, newName); + } + } + } else { + // Update single segment + memory.transcriptSegments[selectedSegmentIndex].speaker = + 'SPEAKER_${speakerId.toString().padLeft(2, '0')}'; + await SharedPreferencesUtil().saveSpeakerName(speakerId, newName); + } + + notifyListeners(); + } catch (e) { + showError('Failed to update speaker name'); + } finally { + toggleEditSegmentLoading(false); + } + } } diff --git a/app/lib/pages/memory_detail/page.dart b/app/lib/pages/memory_detail/page.dart index 1f57b1a9a..aaaf52bac 100644 --- a/app/lib/pages/memory_detail/page.dart +++ b/app/lib/pages/memory_detail/page.dart @@ -466,6 +466,25 @@ class EditSegmentWidget extends StatelessWidget { // ) // : const SizedBox(), const SizedBox(height: 12), + ListTile( + title: Text('Edit Speaker ${provider.memory.transcriptSegments[segmentIdx].speakerId} Name'), + trailing: const Icon(Icons.edit), + onTap: () { + showDialog( + context: context, + builder: (context) => EditSpeakerNameDialog( + speakerId: provider.memory.transcriptSegments[segmentIdx].speakerId, + onUpdate: (name, updateAll) { + provider.updateSpeakerName( + provider.memory.transcriptSegments[segmentIdx].speakerId, + name, + updateAll, + ); + }, + ), + ); + }, + ), CheckboxListTile( title: const Text('Yours'), value: provider.memory.transcriptSegments[segmentIdx].isUser, diff --git a/app/lib/widgets/transcript.dart b/app/lib/widgets/transcript.dart index 352408b96..cc50104b8 100644 --- a/app/lib/widgets/transcript.dart +++ b/app/lib/widgets/transcript.dart @@ -82,7 +82,7 @@ class _TranscriptWidgetState extends State { : 'You' : data.personId != null ? person?.name ?? 'Deleted Person' - : 'Speaker ${data.speakerId}', + : SharedPreferencesUtil().getSpeakerName(data.speakerId) ?? 'Speaker ${data.speakerId}', style: const TextStyle( // person != null ? speakerColors[person.colorIdx!] : color: Colors.white,